public bool RemoveActor(uint uid) { ActorBehaviour actor = null; if (!_actorsDic.TryGetValue(uid, out actor)) { return(false); } if (actor != null) { _actorsDic.Remove(uid); actor.RemoveSelf(); GameObject.Destroy(actor.gameObject); } return(true); }
/// <summary> /// 创建ActorBehaviour /// </summary> /// <param name="actorID">角色ID,读表用,不唯一</param> /// <param name="actorType"></param> /// <param name="prefab_path"> 测试用,正式用actorID创建</param> /// <returns></returns> ActorBehaviour CreateActorGameObject(uint actorID, ActorType actorType, ActorGroup actorGroup, string prefab_path = "", Property property = new Property()) { GameObject model = null; switch (actorType) { case ActorType.NONE: break; case ActorType.HERO: model = CreateHeroGameObject(actorID); break; case ActorType.MONSTER: model = CreateMonsterGameObject(actorID); break; case ActorType.SCENE_OBJ: break; case ActorType.TEST_OBJ: model = CreateGameObjectByPrefabPath(prefab_path, FileNameType.RESOURCE_NAME); break; case ActorType.SCENE_SKILLDESTROY_OBJ: break; case ActorType.VIRSUAL_OBJ: break; case ActorType.NONATTACK_OBJ: break; case ActorType.COUNT: break; default: break; } if (model == null && actorType != ActorType.VIRSUAL_OBJ) { Debug.Log(string.Format("create actor Error , actorID :{0} , ActorType :{1}", actorID, actorType)); return(null); } string modelName = model == null ? "VIRSUAL" : model.name; string fileName = string.Format("[{0}].{1}.{2}", actorType, actorID, modelName); ActorBehaviour refActor = ActorBehaviour.CreateActorBehaviour(fileName, model, actorType, actorGroup, actorID); if (refActor != null) { if (!_actorsDic.ContainsKey(refActor.UID)) { _actorsDic.Add(refActor.UID, refActor); } else { Debug.LogError("contain object"); refActor.RemoveSelf(); GameObject.Destroy(refActor.gameObject); } } return(refActor); }