public void DestroyObject(CObject obj) { if (obj == null) { return; } //如果是主目标,取消选择 if (obj == mMainTarget) { mMainTarget = null; } if (obj == mNearestTargetOLD) { mNearestTargetOLD = null; } mObjects.Remove(obj.ID); mServerObjects.Remove(obj.ServerID); //如果被ui关心,发出事件并清除 int id = obj.ID; Dictionary <string, OBJECT_BECARED> .Enumerator enumerator = mapCaredObjects.GetEnumerator(); while (enumerator.MoveNext()) { OBJECT_BECARED careItem = enumerator.Current.Value; if (careItem.id == id) { //产生事件 List <string> vParam = new List <string>(); vParam.Add(id.ToString()); vParam.Add("destroy"); CEventSystem.Instance.PushEvent(GAME_EVENT_ID.GE_OBJECT_CARED_EVENT, vParam); mapCaredObjects.Remove(enumerator.Current.Key); break; } } //删除队列中其他同ID的物体 enumerator = mapCaredObjects.GetEnumerator(); while (enumerator.MoveNext()) { OBJECT_BECARED careItem = enumerator.Current.Value; if (careItem.id == id) { mapCaredObjects.Remove(enumerator.Current.Key); enumerator = mapCaredObjects.GetEnumerator(); } } if (obj.GetParent() != null) { obj.GetParent().EraseChild(obj); } obj.Release(); }