理论:原型模式其实是从一个对象再创建另外一个可定制对象,而且不需要知道任何创建的细节
原型类
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public abstract class Prototype
{
private string id;
public Prototype(string id)
{
this.id = id;
}
public string Id
{
get { return id; }
}
public abstract Prototype Clone();
}
具体原型类
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ConcreatePrototype : Prototype
{
public ConcreatePrototype(string id) : base(id)
{
}
public override Prototype Clone()
{
return (Prototype)this.MemberwiseClone();
}
}