// Use this for initialization void Start() { if (!GameConfig.IsMultiMode) { // Create Simulator object // GameObject go = new GameObject("Simulator Mgr"); // m_SimulatorMgr = go.gameObject.AddComponent<CSSimulatorMgr>(); // m_SimulatorMgr.transform.parent = transform; // m_SimulatorMgr.Init(ID); // Create colony object if has Dictionary <int, CSDefaultData> objRecords = m_DataInst.GetObjectRecords(); foreach (CSDefaultData defData in objRecords.Values) { CSObjectData objData = defData as CSObjectData; if (objData != null && objData.ID != CSConst.etID_Farm) { if (!objData.m_Alive) { continue; } CSEntityAttr attr = new CSEntityAttr(); attr.m_InstanceId = objData.ID; attr.m_Type = objData.dType; attr.m_Pos = objData.m_Position; attr.m_protoId = objData.ItemID; attr.m_Bound = objData.m_Bounds; CSEntity cse = _createEntity(attr); if (objData.dType == CSConst.dtAssembly) { CSAssembly csa = cse as CSAssembly; csa.ChangeState(); } else { CSCommon csc = cse as CSCommon; if (m_Assembly != null) { m_Assembly.AttachCommonEntity(csc); } } // Create Simulator First // CSSimulator sim = null; // bool isNew = m_SimulatorMgr.CreateSimulator(objData.ID, out sim); // if (isNew) // { // CSSimulatorAttr cssAttr = new CSSimulatorAttr(); // cssAttr.m_Hp = cse.m_Info.m_Durability / 0.6f; // // sim.Init(cssAttr); // } // // sim.Hp = sim.MaxHp * cse.DuraPercent; // sim.Position = cse.Position; // sim.noticeHpChanged = cse.OnLifeChanged; } } //delay load colony npc StartCoroutine(InitColonyNpc()); } else { Debug.Log("<color=red>Creator start! Desc:" + gameObject.name + "</color>"); } }
// // private CSSimulatorMgr m_SimulatorMgr; // public CSSimulatorMgr SimulatorMgr { get { return m_SimulatorMgr;} } // <CETC> Create Managed Entity public override int CreateEntity(CSEntityAttr attr, out CSEntity outEnti) { outEnti = null; if (attr.m_Type == CSConst.etAssembly) { Vector3 travelPos = Vector3.zero; CSBuildingLogic csb = attr.m_LogicObj == null ? null : attr.m_LogicObj.GetComponent <CSBuildingLogic>(); //lz-2017.01.17 基地逻辑预制物体加载成功并且有传送点就用配置的传送点的位置 if (csb != null && csb.travelTrans != null) { travelPos = csb.travelTrans.position; } //lz-2017.01.17 否则就用基地核心向上偏移两米的位置 else { travelPos = m_Assembly.Position + new Vector3(0, 2, 0); } if (m_Assembly == null) { if (GameConfig.IsMultiMode && attr.m_ColonyBase == null) { return(CSConst.rrtUnkown); } outEnti = _createEntity(attr); m_Assembly.ChangeState(); if (CSMain.s_MgCreator == this) { ColonyLabel.Remove(travelPos); new ColonyLabel(travelPos); } } else if (m_Assembly.ID == attr.m_InstanceId) { outEnti = m_Assembly; outEnti.gameLogic = attr.m_LogicObj; outEnti.gameObject = attr.m_Obj; outEnti.Position = attr.m_Pos; outEnti.ItemID = attr.m_protoId; outEnti.Bound = attr.m_Bound; m_Assembly.Data.m_Alive = true; if (CSMain.s_MgCreator == this) { ColonyLabel.Remove(travelPos); new ColonyLabel(travelPos); } } else { if (m_Assembly != null) { return(CSConst.rrtHasAssembly); } } } else { if (m_CommonEntities.ContainsKey(attr.m_InstanceId)) { outEnti = m_CommonEntities[attr.m_InstanceId]; outEnti.gameLogic = attr.m_LogicObj; outEnti.gameObject = attr.m_Obj; outEnti.Position = attr.m_Pos; outEnti.ItemID = attr.m_protoId; outEnti.BaseData.m_Alive = true; outEnti.Bound = attr.m_Bound; } else { if (m_Assembly == null) { return(CSConst.rrtNoAssembly); } if (!m_Assembly.InRange(attr.m_Pos)) { return(CSConst.rrtOutOfRadius); } // Is powerplant ? CSConst.ObjectType obj_type; // if ((attr.m_Type & CSConst.etPowerPlant) != 0) // obj_type = CSConst.ObjectType.PowerPlant; // else obj_type = (CSConst.ObjectType)attr.m_Type; if (!m_Assembly.OutOfCount(obj_type)) { return(CSConst.rrtOutOfRange); } if (GameConfig.IsMultiMode && attr.m_ColonyBase == null) { return(CSConst.rrtUnkown); } outEnti = _createEntity(attr); CSCommon csc = outEnti as CSCommon; m_Assembly.AttachCommonEntity(csc); } } ExecuteEvent(CSConst.cetAddEntity, outEnti); return(CSConst.rrtSucceed); }