private void Start() { //现在game object中只有property和entity GameObject [] objects = GameObject.FindGameObjectsWithTag("Character"); foreach (GameObject obj in objects) { BasicEntity entity = obj.GetComponent <BasicEntity> (); ////能力组件是添加其他所有组件的入口 //AbilityComponent abilityComp = (AbilityComponent)entity.AddComponent (ComponentType.Ability); //abilityComp.Init (ComponentType.Ability, entity); entity.Init(); } //初始化系统组件,把现在的所有实体传入 StateSystem stateSystem = new StateSystem(); stateSystem.M_LinkedType = ComponentType.State; List <BasicEntity> ent = stateSystem.Fliter(ComponentType.Property); //初始化所有需要的组件 if (ent != null) { stateSystem.Init(ent); } //所有系统的初始化函数 foreach (BasicSystem basicSystem in basicSystems) { Debug.Log("init " + basicSystem.M_LinkedType + " System"); List <BasicEntity> entities = basicSystem.Fliter(basicSystem.M_LinkedType); if (entities != null) { Debug.Log("execute system:" + basicSystem.M_LinkedType + "system"); basicSystem.Init(entities); } } //最后才加入系统表,防止二次初始化 basicSystems.Add(stateSystem); }