using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using TableConfig; namespace Snxxz.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; 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.gameObject.SetActive(true); DontDestroyOnLoad(gameObject); } return m_Instance; } } PlayerPackModel 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.CheckOpen()) { WindowCenter.Instance.Open(true); } realmLv = _realmLv; StartCoroutine(Co_Start()); } IEnumerator Co_Start() { yield return WaitingForSecondConst.WaitMS500; WindowCenter.Instance.CloseImmediately(); StartBossShow(); } void StartBossShow() { if (IsOpen) { return; } try { IsOpen = true; transform.localPosition = Vector3.zero; var config = Config.Instance.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.gameObject.SetActive(false); WindowCenter.Instance.uiRoot.uicamera.enabled = false; StageManager.Instance.onStartStageLoadingEvent -= OnStartStageLoadingEvent; StageManager.Instance.onStartStageLoadingEvent += OnStartStageLoadingEvent; } void LoadHero() { var _job = PlayerDatas.Instance.baseData.Job; #region 装备 var clothes = playerPack.GetItemModelByIndex(PackType.rptEquip, (int)RoleEquipType.retClothes); var _clothesId = clothes == null ? 0 : (int)clothes.itemInfo.ItemID; var weapon = playerPack.GetItemModelByIndex(PackType.rptEquip, (int)RoleEquipType.retWeapon); var _weaponId = weapon == null ? 0 : (int)weapon.itemInfo.ItemID; var wings = playerPack.GetItemModelByIndex(PackType.rptEquip, (int)RoleEquipType.retWing); var _wingsId = wings == null ? 0 : (int)wings.itemInfo.ItemID; var secondary = playerPack.GetItemModelByIndex(PackType.rptEquip, (int)RoleEquipType.retWeapon2); var _secondaryId = secondary == null ? 0 : (int)secondary.itemInfo.ItemID; int _suitLevel = 0; if (clothes != null) { if (clothes.itemInfo.IsSuite == 1) { if (clothes.GetUseDataModel(30) != null && clothes.GetUseDataModel(30)[0] != 0) { _suitLevel = clothes.GetUseDataModel(30)[0]; } } } #endregion showPoint = m_HeroStage; var _hero = ShowHero(_job, _clothesId, _suitLevel, _weaponId, _wingsId, _secondaryId); 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; StageManager.Instance.onStartStageLoadingEvent -= OnStartStageLoadingEvent; CameraController.Instance.CameraObject.gameObject.SetActive(true); WindowCenter.Instance.uiRoot.uicamera.enabled = true; WindowCenter.Instance.CloseImmediately(); 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; } } GameObject ShowHero(int _job, int _clothes, int suitID, int _weaponId, int _wingsId, int _secondaryId) { PutOnClothes(_job, _clothes, suitID); return clothesModel; } public void SitDown() { if (clothesModel != null) { var animator = clothesModel.GetComponent(); animator.Play(GAStaticDefine.State_SitDown); } } public void PutOnClothes(int _job, int itemID, int suitID) { var newClothes = 0; var config = Config.Instance.Get(_job); if (itemID == 0) { newClothes = config.BaseEquip[0]; } else { var item = Config.Instance.Get(itemID); newClothes = item == null ? newClothes = config.BaseEquip[0] : item.ChangeOrd; } var _prefab = InstanceResourcesLoader.LoadModelRes(newClothes); if (!_prefab) { newClothes = config.BaseEquip[0]; } LoadClothes(newClothes); LoadClothesEffect(_job, itemID, suitID); } private void LoadClothes(int resID) { var prefab = InstanceResourcesLoader.LoadModelRes(resID); 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); 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; } } public void LoadClothesEffect(int job,int clothedID, int suitLevel) { var _equipModel = ModelCenter.Instance.GetModel().GetSinglePackModel(PackType.rptEquip); if (_equipModel == null) { if (DTC0309_tagPlayerLoginInfo.equipSuitID > 0) { PutOnEffect(DTC0309_tagPlayerLoginInfo.equipSuitID); } return; } int _suitCount = 0; int _start = (int)RoleEquipType.retHat; int _end = (int)RoleEquipType.retShoes; ItemModel _itemModel = null; _itemModel = _equipModel.GetItemModelByIndex((int)RoleEquipType.retClothes); if (_itemModel == null) { return; } int _rank = _itemModel.chinItemModel.LV; for (int i = _start; i <= _end; ++i) { _itemModel = _equipModel.GetItemModelByIndex(i); if (_itemModel == null) { continue; } if (_itemModel.chinItemModel.SuiteiD <= 0) { continue; } if (i == (int)RoleEquipType.retClothes) { _rank = _itemModel.chinItemModel.LV; } var suitModel = ModelCenter.Instance.GetModel(); if (suitModel.suitModelDict.ContainsKey(i)) { if (suitModel.suitModelDict[i].ContainsKey(1) || suitModel.suitModelDict[i].ContainsKey(2)) { if (_itemModel.chinItemModel.LV >= _rank) { _suitCount += 1; } } } } if (_suitCount == 5) { int _type = 1; int _suitEffectID = _type * 1000 + job * 100 + _rank; PutOnEffect(_suitEffectID); } } public void PutOnEffect(int id) { SuitEffectConfig _suitEffect = Config.Instance.Get(id); // 上特效 if (_suitEffect != null) { Transform _parent = null; SFXController _sfx = null; for (int i = 0; _suitEffect.bindbones != null && i < _suitEffect.bindbones.Length; ++i) { if (string.IsNullOrEmpty(_suitEffect.bindbones[i]) || _suitEffect.effectIds[i] == 0) { continue; } _parent = clothesModel.transform.GetChildTransformDeeply(_suitEffect.bindbones[i]); if (_parent == null) { Debug.LogErrorFormat("套装: {0} 配置的骨骼节点: {1} 不存在", id, _suitEffect.bindbones[i]); continue; } _sfx = SFXPlayUtility.Instance.PlayBattleEffect(_suitEffect.effectIds[i], _parent); closthesSFXList.Add(_sfx); } } } } }