下周学习 2021/5/5
下周学习 2021/5/5
1:mvc
m:model
v : view
c:controller
增加可以重用性
2:创建好文件 脚本
3:
1:mvc
m:model
v : view
c:controller
增加可以重用性
2:创建好文件 脚本
mvc
1、分层处理。
2、
总是要去找Ctrl 何不做一个单例类呢
public abstract class InstanceMonoBehavior<T> : MonoBehaviour
{
private static T _instance;
public static T GetInstance()
{
return _instance;
}
protected virtual void Awake()
{
_instance = ReturnInstance();
}
protected abstract T ReturnInstance();
}
接下来将Ctrl 继承他
public class Ctrl : InstanceMonoBehavior<Ctrl>{
protected override Ctrl ReturnInstance()
{
return this;
}
}
在任何地方都可以使用Ctrl.GetInstance() 获得单例对象
1.GameManager//核心逻辑属于控制层
Bool IsPause 游戏是否暂停
public Shape[] shapes;
给图形添加脚本Shape
public Clolor[] colors;
void SpawnShape(){
int index=Random.range(0,shape.lenth);
int indexColor=random.range(0,color.lenth);
Shape shape=Gameobject.Instantiate(shapes[index]);
shape.init(colors[indexClolor]);
}