using System; using System.Collections; using System.Collections.Generic; using UnityEngine; namespace vnxbqy.UI { public class RealmBossShow : MonoBehaviour { [SerializeField, Header("隐藏场景时间")] float m_HideGroundTime = 2.02f; [SerializeField, Header("展示时间")] float m_DisplayTime = 15f; [SerializeField, Header("特效位置")] Vector3 m_EffectPosition = Vector3.zero; GameObject clothesModel; GameObject secondaryModel; GameObject extraSecondaryModel; Animator clothesAnimator; Transform showPoint; List closthesSFXList = new List(); static RealmBossShow m_Instance = null; public static RealmBossShow Instance { get { if (m_Instance == null) { var gameObject = Instantiate(UILoader.LoadPrefab("RealmBossShow")); m_Instance = gameObject.GetComponent(); m_Instance.transform.position = new Vector3(0, 4000, 5000); m_Instance.name = "RealmBossShow"; m_Instance.IsOpen = false; m_Instance.SetActive(true); DontDestroyOnLoad(gameObject); } return m_Instance; } } PackModel playerPack { get { return ModelCenter.Instance.GetModel(); } } DungeonModel dungeonModel { get { return ModelCenter.Instance.GetModel(); } } SFXController m_Effect; Camera showCamera; Transform m_HeroStage; public bool IsOpen { get; private set; } DateTime overdueTime = DateTime.Now; DateTime hideGroundTime = DateTime.Now; DateTime forceCloseTime = DateTime.Now; int realmLv { get; set; } public void Open(int _realmLv) { if (!WindowCenter.Instance.IsOpen()) { WindowCenter.Instance.Open(true); } realmLv = _realmLv; StartCoroutine(Co_Start()); } IEnumerator Co_Start() { yield return WaitingForSecondConst.WaitMS500; WindowCenter.Instance.Close(); StartBossShow(); } void StartBossShow() { if (IsOpen) { return; } try { IsOpen = true; transform.localPosition = Vector3.zero; var config = RealmConfig.Get(realmLv); m_Effect = SFXPlayUtility.Instance.Play(config.effectId, transform); m_Effect.duration = 0; m_Effect.transform.localPosition = Vector3.zero; LayerUtility.SetLayer(m_Effect.gameObject, LayerUtility.BossShow, true); showCamera = m_Effect.transform.GetComponentInChildren(); m_HeroStage = m_Effect.transform.Find("Animation/zhujue/guadian"); overdueTime = DateTime.Now.AddSeconds(m_DisplayTime); hideGroundTime = DateTime.Now.AddSeconds(m_HideGroundTime); forceCloseTime = DateTime.Now.AddSeconds(m_DisplayTime + 10); showCamera.cullingMask = 1 << LayerUtility.GroundLayer; CameraUtility.AddCullingMask(showCamera, LayerUtility.DefaultLayer); CameraUtility.AddCullingMask(showCamera, LayerUtility.BossShow); showCamera.enabled = true; LoadHero(); } catch (Exception e) { IsOpen = false; ExitDungeon(); DebugEx.LogError(e.Message); return; } CameraController.Instance.CameraObject.SetActive(false); WindowCenter.Instance.uiRoot.uicamera.enabled = false; StageLoad.Instance.onStartStageLoadingEvent -= OnStartStageLoadingEvent; StageLoad.Instance.onStartStageLoadingEvent += OnStartStageLoadingEvent; } void LoadHero() { var _job = PlayerDatas.Instance.baseData.Job; #region 装备 var appearance = ModelCenter.Instance.GetModel().GetAppearance(); var _clothesId = appearance.clothes; var _secondaryId = appearance.secondary; var fashionClothesId = appearance.fashionClothes; var fashionSecondaryId = appearance.fashionSecondary; #endregion showPoint = m_HeroStage; var _hero = ShowHero(_job, _clothesId, _secondaryId, fashionClothesId, fashionSecondaryId); if (_hero != null) { SitDown(); LayerUtility.SetLayer(m_HeroStage.gameObject, LayerUtility.BossShow, true); } } private void LateUpdate() { if (IsOpen && DateTime.Now > overdueTime) { ExitDungeon(); } if (IsOpen && DateTime.Now > forceCloseTime) { Stop(); } if (IsOpen && DateTime.Now > hideGroundTime) { HideGound(); } } public void HideGound() { CameraUtility.RemoveCullingMask(showCamera, LayerUtility.GroundLayer); CameraUtility.RemoveCullingMask(showCamera, LayerUtility.DefaultLayer); } void ExitDungeon() { IsOpen = false; dungeonModel.ExitCurrentDungeon(); } private void OnStartStageLoadingEvent(int obj) { Stop(); } public void Stop() { IsOpen = false; StageLoad.Instance.onStartStageLoadingEvent -= OnStartStageLoadingEvent; CameraController.Instance.CameraObject.SetActive(true); WindowCenter.Instance.uiRoot.uicamera.enabled = true; WindowCenter.Instance.Close(); showCamera.enabled = false; m_Effect.gameObject.SetActive(false); transform.localPosition = new Vector3(0, 4000, 5000); if (m_Effect != null) { SFXPlayUtility.Instance.Release(m_Effect); m_Effect = null; } for (int i = closthesSFXList.Count - 1; i >= 0; i--) { if (closthesSFXList[i] != null) { Destroy(closthesSFXList[i].gameObject); } } closthesSFXList.Clear(); if (clothesModel != null) { Destroy(clothesModel); clothesModel = null; clothesAnimator = null; } if (secondaryModel != null) { Destroy(secondaryModel); secondaryModel = null; } } GameObject ShowHero(int job, int clothesId, int secondaryId, int fashionClothesId, int fashionSecondaryId) { clothesId = fashionClothesId > 0 ? fashionClothesId : clothesId; secondaryId = fashionSecondaryId > 0 ? fashionSecondaryId : secondaryId; var jobConfig = JobSetupConfig.Get(job); var clothesResId = 0; if (clothesId == 0) { clothesResId = jobConfig.BaseEquip[0]; } else { var item = ItemConfig.Get(clothesId); clothesResId = item == null ? clothesResId = jobConfig.BaseEquip[0] : item.ChangeOrd; } PutOnClothes(job, clothesResId); var secondaryResId = 0; if (secondaryId == 0) { if (fashionClothesId <= 0) { if (job == 1) { secondaryResId = ModelResConfig.GetHandByClothesID(clothesId); } } } else { var item = ItemConfig.Get(secondaryId); if (item != null) { secondaryResId = item.ChangeOrd; } } if (secondaryResId == 0) { secondaryResId = jobConfig.BaseEquip[2]; } PutOnSecondary(job, secondaryResId); var extraSecondaryId = 0; if (job == 1) { extraSecondaryId = ModelResConfig.GetHandByClothesID(0); if (fashionClothesId > 0) { var _item = ItemConfig.Get(fashionClothesId); if (_item != null) { extraSecondaryId = ModelResConfig.GetHandByClothesID(_item.ChangeOrd); } } else if (clothesId > 0) { var _item = ItemConfig.Get(clothesId); if (_item != null) { extraSecondaryId = ModelResConfig.GetHandByClothesID(_item.ChangeOrd); } } if (secondaryResId == 0 || (fashionClothesId != 0 && fashionSecondaryId > 0) || (fashionClothesId == 0 && fashionSecondaryId > 0)) { PutOnExtraSecondary(job, extraSecondaryId); } } return clothesModel; } public void SitDown() { if (clothesModel != null) { var animator = clothesModel.GetComponent(); animator.SetInteger(GAStaticDefine.Param_Action, GAStaticDefine.Act_Dazuo); } } public void PutOnClothes(int _job, int clothesResId) { var config = JobSetupConfig.Get(_job); var _prefab = InstanceResourcesLoader.LoadModelRes(clothesResId, true); if (!_prefab) { clothesResId = config.BaseEquip[0]; } LoadClothes(clothesResId, _job); } private void PutOnSecondary(int _job, int secondaryResId) { if (_job == 2) { return; } if (secondaryResId != 0) { var prefab = InstanceResourcesLoader.LoadModelRes(secondaryResId); if (!prefab) { var config = JobSetupConfig.Get(_job); secondaryResId = config.BaseEquip[2]; prefab = InstanceResourcesLoader.LoadModelRes(secondaryResId); } if (prefab) { if (secondaryModel == null) { secondaryModel = Instantiate(prefab, Constants.Special_Hide_Position, Quaternion.identity); var parent = clothesModel.transform.GetChildTransformDeeply(GAStaticDefine.SecondaryBindBoneName[_job - 1]); secondaryModel.transform.SetParentEx(parent, Vector3.zero, Quaternion.identity, Vector3.one); } } } } private void PutOnExtraSecondary(int job, int extraSecondaryId) { if (job == 2) { return; } if (extraSecondaryId != 0) { var prefab = InstanceResourcesLoader.LoadModelRes(extraSecondaryId); if (!prefab) { var config = JobSetupConfig.Get(job); extraSecondaryId = config.BaseEquip[2]; prefab = InstanceResourcesLoader.LoadModelRes(extraSecondaryId); } if (prefab) { if (extraSecondaryModel == null) { extraSecondaryModel = Instantiate(prefab, Constants.Special_Hide_Position, Quaternion.identity); var parent = clothesModel.transform.GetChildTransformDeeply(GAStaticDefine.SecondaryBindBoneName[job - 1]); extraSecondaryModel.transform.SetParentEx(parent, Vector3.zero, Quaternion.identity, Vector3.one); } } } } private void LoadClothes(int resID, int job) { var prefab = InstanceResourcesLoader.LoadModelRes(resID, true); if (clothesModel == null) { clothesModel = Instantiate(prefab, Constants.Special_Hide_Position, Quaternion.identity); } clothesModel.transform.SetParent(null); clothesModel.transform.localScale = Vector3.one; LayerUtility.SetLayer(clothesModel, LayerUtility.Player, false); var skinnedMeshRenderer = clothesModel.GetComponentInChildren(true); var mat = MaterialLoader.LoadClothesMaterial(resID, false, false); if (mat) { skinnedMeshRenderer.material = mat; } LayerUtility.SetLayer(skinnedMeshRenderer.gameObject, LayerUtility.Player, false); clothesModel.SetActive(true); clothesModel.transform.SetParentEx(showPoint, Vector3.zero, Quaternion.identity, Vector3.one); clothesAnimator = clothesModel.GetComponent(); if (clothesAnimator == null) { DebugEx.LogErrorFormat("角色资源: {0} 没有动画控制器", resID); } // 动画状态机修改 if (clothesAnimator) { RuntimeAnimatorController _controller = AnimatorControllerLoader.Load(AnimatorControllerLoader.controllerUISuffix, resID); clothesAnimator.runtimeAnimatorController = _controller; clothesAnimator.enabled = true; } } } }