public static void CreateEnemy(string name, string model_name, Vector3 pos, Quaternion qt, System.Action <EnemyController> fn) { CharacterModel modelToSpawn = CharacterCatalog.Instance.GetModel(model_name); if (model_name.Contains("NPC_Template")) { modelToSpawn = CharacterCatalog.Instance.GetModelTemplate(); modelToSpawn.NPC_Template = model_name.Replace("_NPC_Template", ""); } if (modelToSpawn == null) { EB.Debug.LogError("EnemySpawnLogic:: No model in CharacterModel for Name:{0}", model_name); fn(null); return; } EB.Assets.LoadAsync(RES_Enemy, typeof(GameObject), o => { if (!o) { return; } GameObject spawnedEnemy = Replication.Instantiate(o, pos, qt, RES_Enemy) as GameObject; if (spawnedEnemy == null) { EB.Debug.LogError("EnemySpawnLogic::Trying to initialize null spawned enemy"); fn(null); } else { EnemyController enemyController = spawnedEnemy.GetComponent <EnemyController>(); if (enemyController == null) { EB.Debug.LogError("EnemySpawnLogic::Update can't obtain EnemyController component from spawned enemy object"); fn(null); } else { Player.EnemyHotfixController ehc = enemyController.transform.GetMonoILRComponent <Player.EnemyHotfixController>(); ehc.ObjectName = spawnedEnemy.name; spawnedEnemy.name = name; ehc.OnSpawn(modelToSpawn, -1, false, () => fn(enemyController)); //EventManager.instance.Raise(new SpawnEndedEvent(spawnedEnemy)); //fn(enemyController); } } }); }
/// <summary> /// from Class SceneLogic /// </summary> /// <param name="playerSpawnEntry"></param> /// <param name="themeLoadMgr"></param> /// <param name="pos"></param> /// <param name="rot"></param> /// <param name="userid"></param> public static void CreateOtherPlayer(SceneLogic.PlayerEntry playerSpawnEntry, ThemeLoadManager themeLoadMgr, Vector3 pos, Quaternion rot, long userid) { try { if (pos.Equals(Vector3.zero)) //传送都是这个点 都要换算为出生点 { pos = playerSpawnEntry.position; rot = playerSpawnEntry.rotation; } //lzt 需要排查原因为什么会得到空 string modelName = BuddyAttributesManager.GetModelClass(userid.ToString()); float scale_size = 1f; eDartState dartState = eDartState.None; double fDartState; if (!DataLookupsCache.Instance.SearchDataByID <double>(string.Format("mainlands.pl.{0}.state.TOR", userid), out fDartState)) { EB.Debug.LogError("when intact search data dartState state fail"); } dartState = (eDartState)System.Convert.ToInt32(fDartState); if (AllianceEscortUtil.GetIsInTransferDart(dartState)) { string dartName = dartState.ToString(); modelName = AllianceEscortUtil.GetTransportCartModel(AllianceEscortUtil.ToDartStateStr(dartState)); scale_size = (modelName.IndexOf("M1003") >= 0 || modelName.IndexOf("M1004") >= 0) ? 0.6f : 1; } if (string.IsNullOrEmpty(modelName)) { EB.Debug.Log("CreateOtherPlayer ModelClassIsNullOrEmpty for userid={0}", userid); return; } #region Async Load OtherPlayer EB.Assets.LoadAsync(RES_OtherPlayer, typeof(GameObject), o => { if (!o) { return; } SceneRootEntry sceneRoot = themeLoadMgr.GetSceneRoot(); GameObject localObj = Replication.Instantiate(o, pos, rot) as GameObject; Transform PlayerList = sceneRoot.m_SceneRoot.transform.Find("PlayerList"); if (PlayerList == null) { GameObject partner = new GameObject("PlayerList"); partner.transform.SetParent(sceneRoot.m_SceneRoot.transform); PlayerList = partner.transform; } PlayerList.gameObject.CustomSetActive(true); localObj.transform.SetParent(PlayerList); PlayerController player_controller = localObj.GetComponent <PlayerController>(); player_controller.playerUid = userid; Player.PlayerHotfixController hotfix_controller = player_controller.transform.GetMonoILRComponent <Player.PlayerHotfixController>(); hotfix_controller.SetPlayerSpawnLocation(pos); hotfix_controller.CreateOtherPlayer(modelName, userid, scale_size);//创建其他人 hotfix_controller.InitDataLookupSet(); OtherPlayerTidDataLookup OPTD = player_controller.transform.GetDataLookupILRComponent <OtherPlayerTidDataLookup>(false); if (OPTD == null) { OPTD = player_controller.gameObject.AddDataLookupILRComponent <OtherPlayerTidDataLookup>("Hotfix_LT.UI.OtherPlayerTidDataLookup"); string path = string.Format("mainlands.pl.{0}.tid", userid); string torStatePath = string.Format("mainlands.pl.{0}.state.TOR", userid); DataLookupsCache.Instance.SearchDataByID <string>(path, out OPTD.ModelTid); OPTD.DartState = dartState; OPTD.mDL.RegisterDataID(path); OPTD.mDL.RegisterDataID(torStatePath); //OPTD.DefaultDataID= path; } }); #endregion } catch (System.Exception e) { EB.Debug.LogError("Message: {0}, Stack: {1}", e.Message, e.StackTrace); UnityEngine.Debug.LogException(e); } }