里氏替换原则
实现 开闭原则的方式之一
单一职责
只有一个引起它变化的原因
//创建物体的3种方式
public GameObject prefab;
void Start () {
GameObject go = new GameObject("cube");
GameObject.Instantiate(prefab);
GameObject.CreatePrimitive(PrimitiveType.Capsule);
}
//测试方法的性能用的
public int count = 10000000;
void Start()
{
float time1 = Time.realtimeSinceStartup;
for (int i = 0; i < count; i++)
{
Method1();
}
float time2 = Time.realtimeSinceStartup;
Debug.Log(time2-time1);
float time3 = Time.realtimeSinceStartup;
for (int i = 0; i < count; i++)
{
Method2();
}
float time4 = Time.realtimeSinceStartup;
Debug.Log(time4-time3);
}