using Snxxz.UI; using System.Collections; using System.Collections.Generic; using UnityEngine; public class ShowActor { public GameObject m_Model { get; private set; } private int m_NpcId = 0; public int npcId { get { return m_NpcId; } } private int m_Index = 0; private int m_Instance = 0; private NPCConfig m_NpcCfg = null; public ActorShowConfig actorShowModel = null; private Animator m_Animator; private RuntimeAnimatorController m_CacheAnimator; private int m_CacheLayer; private int m_CacheEffectLayer; private Vector3 m_CacheScale; SFXController sfxController; private SFXController shadow; private int m_NextAction; public int nextAction { get { if (m_Animator) { m_NextAction = m_Animator.GetInteger(GAStaticDefine.Param_Action); } return m_NextAction; } set { m_NextAction = value; if (m_Animator) { m_Animator.SetInteger(GAStaticDefine.Param_Action, value); } } } public ShowActor(int npcID, int index, int instanceid, ActorShowConfig _actorShowConfig) { this.m_NpcId = npcID; this.m_Index = index; this.m_Instance = instanceid; if (npcId == 1) { Appear(index, _actorShowConfig); } else { m_NpcCfg = NPCConfig.Get(npcID); Appear(index, _actorShowConfig); } } public void Appear(int index, ActorShowConfig _actorShowConfig) { this.m_Index = index; this.actorShowModel = _actorShowConfig; if (m_Model == null) { if (npcId != 1) { m_Model = GameObjectPoolManager.Instance.RequestNpcGameObject(m_NpcId); m_Animator = m_Model.AddMissingComponent(); m_CacheLayer = m_Model.layer; m_Model.gameObject.SetLayer(LayerUtility.BossShow, true); } else { var hero = PlayerDatas.Instance.hero; m_Model = GameObject.Instantiate(hero.ClothedModel) as GameObject; m_Animator = m_Model.AddMissingComponent(); m_CacheLayer = m_Model.layer; m_Model.gameObject.SetLayer(LayerUtility.BossShow, true); } } m_Model.SetActive(true); m_Model.transform.position = new Vector3((float)actorShowModel.PosX[m_Index] / 200, 0, (float)actorShowModel.PosY[m_Index] / 200); m_CacheScale = m_Model.transform.localScale; m_Model.transform.localScale = Vector3.one * ((float)actorShowModel.scale[m_Index] / 100); RaycastHit _hit; var _heightPos = m_Model.transform.position; if (actorShowModel.Height.Length > 1 && m_Index == 0) { _heightPos.x = (float)actorShowModel.Height[0] / 200; _heightPos.y = 0; _heightPos.z = (float)actorShowModel.Height[1] / 200; } Ray _ray = new Ray(_heightPos + new Vector3(0, 100f, 0), Vector3.down); if (Physics.Raycast(_ray, out _hit, 100f, LayerUtility.WalkbleMask)) { m_Model.transform.position = m_Model.transform.position.SetY(_hit.point.y); } m_Model.transform.rotation = MathUtility.GetClientRotationFromAngle(actorShowModel.NpcFace[m_Index]); RuntimeAnimatorController controller = null; if (npcId == 1) { var job = PlayerDatas.Instance.baseData.Job; var _controllerName = "A_Zs"; if (job == 2) { _controllerName = "A_Fs"; } controller = AnimatorControllerLoader.LoadMobController(AnimatorControllerLoader.controllerShowSuffix, _controllerName); } else { controller = AnimatorControllerLoader.LoadMobController(AnimatorControllerLoader.controllerShowSuffix, actorShowModel.mob[m_Index]); } if (controller != null) { m_CacheAnimator = m_Animator.runtimeAnimatorController; m_Animator.runtimeAnimatorController = controller; m_Animator.SetInteger(GAStaticDefine.Param_ActorInstID, m_Instance); if (m_Animator != null) { m_Animator.enabled = true; if (m_Index < actorShowModel.clipActions.Length) { nextAction = actorShowModel.clipActions[m_Index]; } else { nextAction = GAStaticDefine.Act_Show; } m_Animator.Update(0); } } else { if (m_Animator != null) { m_Animator.enabled = true; nextAction = 0; } } if (actorShowModel.effect != null && m_Index < actorShowModel.effect.Length && actorShowModel.effect[m_Index] != 0) { sfxController = SFXPlayUtility.Instance.Play(actorShowModel.effect[m_Index], m_Model.transform); if (sfxController != null) { m_CacheEffectLayer = sfxController.gameObject.layer; sfxController.duration = 0; var _animNodde = sfxController.GetComponent("Animation"); if (_animNodde) { if (_animNodde.HasState(0, GAStaticDefine.State_IdleHash)) { _animNodde.Play(GAStaticDefine.State_IdleHash); } } LayerUtility.SetLayer(sfxController.gameObject, LayerUtility.BossShow, true); } } RequestCircleShadow(); if (shadow && m_NpcId != 1) { shadow.transform.localScale = m_NpcCfg.IsBoss == 1 ? Vector3.one * 3 : Vector3.one; shadow.gameObject.SetLayer(LayerUtility.BossShow, true); } } public void RequestCircleShadow() { RecyleCircleShadow(); if (shadow == null && actorShowModel.shadow == 1) { shadow = SFXPlayUtility.Instance.PlayBattleEffect(999999, m_Model.transform.position, Vector3.forward); shadow.duration = 0; shadow.transform.eulerAngles = new Vector3(0, 0, 0); } } public void RecyleCircleShadow() { if (shadow) { SFXPlayUtility.Instance.Release(shadow); shadow = null; } } public void Disappear() { if (m_Animator != null) { m_Animator.Play(Animator.StringToHash("Idle"), 0, 0); m_Animator.enabled = false; if (m_CacheAnimator) { m_Animator.runtimeAnimatorController = m_CacheAnimator; m_CacheAnimator = null; } } if (m_Model != null) { m_Model.transform.localScale = m_CacheScale; m_Model.SetLayer(m_CacheLayer, true); GameObject _prefab = InstanceResourcesLoader.LoadNpcPrefab(m_NpcId); GameObjectPoolManager.Instance.ReleaseGameObject(_prefab, m_Model); m_Model = null; } if (sfxController != null) { sfxController.gameObject.SetLayer(m_CacheEffectLayer, true); SFXPlayUtility.Instance.Release(sfxController); sfxController = null; } RecyleCircleShadow(); } public void Destroy() { if (m_Model != null) { GameObject.Destroy(m_Model); m_Model = null; } if (sfxController != null) { SFXPlayUtility.Instance.Release(sfxController); sfxController = null; } RecyleCircleShadow(); } }