public void SetEntity(CSEntity enti) { if (enti == null) { Debug.LogWarning("Reference Entity is null."); return; } if (m_Assembly != null) { m_Assembly.RemoveEventListener(AssemblyEventHandler); } m_Assembly = enti as CSAssembly; m_Assembly.AddEventListener(AssemblyEventHandler); if (m_Assembly == null) { Debug.LogWarning("Reference Entity is not a Assembly Entity."); return; } m_Entity = enti; UpdateUpgradeMat(); UpdateBuildingNum(); m_HideShieldCB.isChecked = !m_Assembly.bShowShield; }
// Dwellings change state call back void OnDwellingsChangeState(int event_type, CSEntity entiy, object arg) { if (event_type == CSConst.eetDwellings_ChangeState) { bool state = (bool)arg; if (state) // Add { CSAssembly assem = Dwellings.Assembly; // if (m_WorkMode == CSConst.pwtPatrol) // { // Dwellings.Assembly.AddSoldier(this); // List<CSCommon> commons = Dwellings.Assembly.GetBelongCommons(); // // foreach (CSCommon common in commons) // common.AddSoldier(this); // } // else if (m_WorkMode == CSConst.pwtGuard) // { // if ( CSUtils.SphereContainsAndIntersectBound(m_GuardTrigger.Pos, m_GuardTrigger.Radius, assem.Bound)) // assem.AddSoldier(this); // // List<CSCommon> commons = assem.GetBelongCommons(); // foreach (CSCommon common in commons) // { // if (CSUtils.SphereContainsAndIntersectBound(m_GuardTrigger.Pos, m_GuardTrigger.Radius, common.Bound)) // common.AddSoldier(this); // } // } assem.AddEventListener(OnAssemblyEventHandler); m_Assembly = assem; } else // Remove { // if (m_WorkMode == CSConst.pwtPatrol || m_WorkMode == CSConst.pwtGuard) // { // CSMgCreator mgCreator = m_Creator as CSMgCreator; // if (mgCreator != null) // { // mgCreator.Assembly.RemoveSoldier(this); // Dictionary<int, CSCommon> commons = mgCreator.GetCommonEntities(); // // foreach (KeyValuePair<int, CSCommon> kvp in commons) // kvp.Value.RemoveSoldier(this); // } // } if (m_Assembly != null) { m_Assembly.RemoveEventListener(OnAssemblyEventHandler); m_Assembly = null; } } m_Running = state; } }