public void Destroy() { var helpers = mDMono.GetComponentsInChildren <MoveEditor.FXHelper>(); if (helpers != null && helpers.Length > 0) { for (var i = 0; i < helpers.Length; i++) { helpers[i].StopAll(true); } } PlayerDataLookupSet pdls = mDMono.transform.GetDataLookupILRComponentInChildren <PlayerDataLookupSet>("Hotfix_LT.UI.PlayerDataLookupSet", showErrorTips: false); if (pdls != null) { pdls.Destroy(); } CharacterVariant variant = mDMono.GetComponentInChildren <CharacterVariant>(); if (variant != null) { variant.Recycle(); PoolModel.DestroyModel(variant.gameObject); } GameObject.Destroy(mDMono.gameObject); }
public void InitDataLookupSet() { PlayerDataLookupSet pdls = mDMono.transform.GetDataLookupILRComponentInChildren <PlayerDataLookupSet>("Hotfix_LT.UI.PlayerDataLookupSet", true, false); if (pdls != null) { pdls.UserId = playerController.playerUid; } }
public void ChangeModel(string modelName, bool firstCreate, float scale = 1) { if (playerController == null) { EB.Debug.LogWarning("playerController is null"); return; } if (playerController.CharacterModel != null && playerController.CharacterModel.ResourcePrefabNameMain.IndexOf(modelName) >= 0) { EB.Debug.LogWarning("ChangeModel: Aready Exist model={0}", modelName); return; } if (_HeadBar != null) { _HeadBar.ClearBars(); _HeadBar = null; } try { CharacterVariant CV = mDMono.transform.GetComponentInChildren <CharacterVariant>(); MoveEditor.FXHelper FH = mDMono.transform.GetComponentInChildren <MoveEditor.FXHelper>(); if (FH != null) { FH.StopAll(true); } if (CV != null && GameEngine.Instance != null) { SetObjLayer(CV.CharacterInstance, GameEngine.Instance.defaultLayer); CV.Recycle(); PoolModel.DestroyModel(CV.gameObject); } if (playerController.SkinnedRigPrefab != null) { PoolModel.DestroyModel(playerController.SkinnedRigPrefab); } /// playerController.Gender = eGender.Male; playerController.CharacterModel = CharacterCatalog.Instance.GetModel(modelName); string prefabName = playerController.CharacterModel.PrefabNameFromGenderMain(playerController.Gender); PoolModel.GetModelAsync(prefabName, mDMono.transform.position, Quaternion.identity, (o, prm) => { var variantObj = o as GameObject; variantObj.transform.SetParent(mDMono.transform); variantObj.transform.localPosition = Vector3.zero; CharacterVariant variant = variantObj.GetComponent <CharacterVariant>(); variant.SyncLoad = true; IDictionary partions = GetPartitionsData(LoginManager.Instance.LocalUserId.Value); variant.InstantiateCharacter(partions); InitDataLookupSet(); playerController.SkinnedRigPrefab = variant.CharacterInstance; playerController.SkinnedRigPrefab.name = prefabName + "_Character"; playerController.SkinnedRigPrefab.tag = "CharacterMesh"; playerController.SkinnedRigPrefab.transform.SetParent(mDMono.transform); playerController.SkinnedRigPrefab.transform.localRotation = Quaternion.identity; playerController.SkinnedRigPrefab.transform.localScale = new Vector3(scale, scale, scale); _combatController = mDMono.GetComponent <CombatController>(); _combatController.Initialize(playerController.SkinnedRigPrefab.transform, playerController.CharacterModel, 1 << LayerMask.NameToLayer("Enemy")); playerController.CharacterComponent = mDMono.GetComponent <CharacterComponent>(); playerController.CharacterComponent.OnSpawn(playerController.CharacterModel, playerController.SkinnedRigPrefab, -1, false); _HeadBar = playerController.SkinnedRigPrefab.GetMonoILRComponent <HeadBars2D>(false); if (_HeadBar == null) { _HeadBar = playerController.SkinnedRigPrefab.AddMonoILRComponent <HeadBars2D>("Hotfix_LT.UI.HeadBars2D"); } if (mDMono.GetComponent <Collider>() != null && mDMono.GetComponent <Collider>() is BoxCollider) { BoxCollider box = mDMono.GetComponent <Collider>() as BoxCollider; box.size = new Vector3(1.5f, 1.5f, 1.5f) + new Vector3(0, playerController.CharacterModel.heightOffset, 0); box.center = new Vector3(0, box.size.y / 2.0f, 0); } _muzzle = GameUtils.SearchHierarchyForBone(playerController.SkinnedRigPrefab.transform, "muzzle"); if (null == _muzzle) { _muzzle = mDMono.transform; } if (firstCreate) { LevelOwnerComponent.AssignLevelOwner(mDMono.gameObject); // this must be called after PlayerManager.RegisterPlayerController(this); } _avatar = playerController.SkinnedRigPrefab.GetComponent <AvatarComponent>(); _shouldSetHideColor = !PerformanceManager.Instance.CurrentEnvironmentInfo.slowDevice; if (!firstCreate) { PlayerDataLookupSet PDLS = playerController.SkinnedRigPrefab.transform.GetDataLookupILRComponent <PlayerDataLookupSet>(); if (PDLS != null) { PDLS.UserId = playerController.playerUid; } } MoveController mc = playerController.SkinnedRigPrefab.GetComponent <MoveController>(); if (mDMono != null && mDMono.GetComponent <CharacterComponent>().State != eCampaignCharacterState.Idle) { mc.TransitionTo(MoveController.CombatantMoveState.kLocomotion); } }, null); } catch (System.NullReferenceException e) { EB.Debug.LogError(e.ToString()); } }