using Snxxz.UI; using System.Collections; using System.Collections.Generic; using TableConfig; 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 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; m_NpcCfg = Config.Instance.Get(npcID); Appear(index, _actorShowConfig); } public void Appear(int index, ActorShowConfig _actorShowConfig) { this.m_Index = index; this.actorShowModel = _actorShowConfig; if (m_Model == null) { m_Model = GameObjectPoolManager.Instance.RequestNpcGameObject(m_NpcId); 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) { _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]); var 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; nextAction = GAStaticDefine.Act_Show; } if (actorShowModel.effect != 0) { sfxController = SFXPlayUtility.Instance.Play(actorShowModel.effect, m_Model.transform); if (sfxController != null) { sfxController.duration = 0; } } RequestCircleShadow(); if (shadow) { 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.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) { SFXPlayUtility.Instance.Release(sfxController); sfxController = null; } RecyleCircleShadow(); } }