依赖倒转原则
高层模块不依赖底层模块,都依赖于接口
抽象不依赖于细节,细节依赖于抽象
针对接口编程,不针对实现编程
//创建物体的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);
}