using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace Snxxz.UI { public class UI3DHeroSkillShow : MonoBehaviour { static UI3DHeroSkillShow m_Instance = null; public static UI3DHeroSkillShow Instance { get { if (m_Instance == null) { var gameObject = Instantiate(UILoader.LoadTreasure("Misc", "UI3DHeroSkillShow")); m_Instance = gameObject.GetComponent(); Instance.transform.position = new Vector3(0, 4000, 5000); m_Instance.name = "UI3DHeroSkillShow"; m_Instance.gameObject.SetActive(true); DontDestroyOnLoad(gameObject); } return m_Instance; } } [SerializeField] Transform m_Stage; [SerializeField] Camera m_ShowCamera; [SerializeField] Animator m_CameraAnimator; [SerializeField] List m_HeroShowControllers; [SerializeField] List m_TreasureSkills; UI3DShowHero m_HeroShow = new UI3DShowHero(); PackModel playerPack { get { return ModelCenter.Instance.GetModel(); } } Transform m_HeroPoint; public Transform hero { get { return m_HeroPoint; } } Animator m_HeroAnimator; Action m_HeroSkillCompletet; SFXController m_SkillExtraSfx; public int cacheSkillId { get; private set; } public Camera showCamera { get { return m_ShowCamera; } } public Transform MP_Name1 { get { var mp_name = hero.GetChildTransformDeeply("A_Name2"); if (!mp_name) { return hero; } return mp_name; } } public Transform MP_Weapon { get { var mp_weapon = hero.GetChildTransformDeeply(WEAPON_NODE); if (mp_weapon != null) { if (mp_weapon.childCount > 0) { return mp_weapon.GetChild(0); } return mp_weapon; } return hero; } } const string WEAPON_NODE = "Bip001 Prop1"; private void ShowHeroSkill(int _skillId, string _clip) { UI3DTreasureSelectStage.Instance.showCamera.enabled = false; cacheSkillId = _skillId; var _job = PlayerDatas.Instance.baseData.Job; #region 装备 var clothes = playerPack.GetItemByIndex(PackType.Equip, (int)RoleEquipType.Clothes); var _clothesId = clothes == null ? 0 : (int)clothes.itemId; var weapon = playerPack.GetItemByIndex(PackType.Equip, (int)RoleEquipType.Weapon); var _weaponId = weapon == null ? 0 : (int)weapon.itemId; var wings = playerPack.GetItemByIndex(PackType.Equip, (int)RoleEquipType.Wing); var _wingsId = wings == null ? 0 : (int)wings.itemId; var secondary = playerPack.GetItemByIndex(PackType.Equip, (int)RoleEquipType.Weapon2); var _secondaryId = secondary == null ? 0 : (int)secondary.itemId; var fashionClothes = playerPack.GetItemByIndex(PackType.Equip, (int)RoleEquipType.FashionClothes); var fashionClothesId = fashionClothes == null ? 0 : (int)fashionClothes.itemId; var fashionWeapon = playerPack.GetItemByIndex(PackType.Equip, (int)RoleEquipType.FashionWeapon); var fashionWeaponId = fashionWeapon == null ? 0 : (int)fashionWeapon.itemId; var fashionSecondary = playerPack.GetItemByIndex(PackType.Equip, (int)RoleEquipType.FashionWeapon2); var fashionSecondaryId = fashionSecondary == null ? 0 : (int)fashionSecondary.itemId; int _suitLevel = 0; if (clothes != null) { if (clothes.isSuite == 1) { if (clothes.GetUseDataModel(30) != null && clothes.GetUseDataModel(30)[0] != 0) { _suitLevel = clothes.GetUseDataModel(30)[0]; } } } #endregion UI3DPlayerExhibitionData data = new UI3DPlayerExhibitionData() { job = _job, fashionClothesId = fashionClothesId, clothesId = _clothesId, suitLevel = _suitLevel, fashionWeaponId = fashionWeaponId, weaponId = _weaponId, wingsId = _wingsId, fashionSecondaryId = fashionSecondaryId, secondaryId = _secondaryId, isDialogue = false, }; var _hero = m_HeroShow.Show(data, m_Stage); if (_hero != null) { m_HeroPoint = _hero.transform; m_HeroAnimator = _hero.GetComponent(); if (m_HeroAnimator != null) { m_HeroAnimator.runtimeAnimatorController = m_HeroShowControllers[_job - 1]; StartCoroutine(Co_PlaySkill()); } } m_Stage.localEulerAngles = Vector3.zero; m_ShowCamera.gameObject.SetActive(true); m_CameraAnimator.Play(_clip, 0, 0); m_CameraAnimator.speed = 0; } public void ShowTreasureSkill(int _treasureId, Action callback) { StopShow(); Treasure _treasure; ModelCenter.Instance.GetModel().TryGetTreasure(_treasureId, out _treasure); if (_treasure != null) { m_HeroSkillCompletet = callback; var _skillId = _treasure.skillId; var _index = m_TreasureSkills.FindIndex((x) => { return x.treasureId == _treasureId; }); var _treasureSkill = _index != -1 ? m_TreasureSkills[_index] : m_TreasureSkills[0]; _index = _treasureSkill.clip.FindIndex((x) => { return (int)x.job == PlayerDatas.Instance.baseData.Job; }); var _clip = _index != -1 ? _treasureSkill.clip[_index] : _treasureSkill.clip[0]; ShowHeroSkill(_skillId, _clip.clip); if (_treasureSkill.effects != null && _treasureSkill.effects.Count > 0) { _index = _treasureSkill.effects.FindIndex((x) => { return (int)x.job == PlayerDatas.Instance.baseData.Job; }); var _effect = _index != -1 ? _treasureSkill.effects[_index] : _treasureSkill.effects[0]; StartCoroutine(Co_PlayExtraEffect(_effect)); } } } private void StartPlaySkill(int _skillId) { var _cfg = SkillConfig.Get(_skillId); if (_cfg == null) { return; } if (_cfg.Skillactmark > 0 && _cfg.Skillactmark < 20) { switch (_cfg.Skillactmark) { case 10: m_HeroAnimator.Play(GAStaticDefine.State_Attack1Hash, 0); break; case 11: m_HeroAnimator.Play(GAStaticDefine.State_Attack2Hash, 0); break; case 12: m_HeroAnimator.Play(GAStaticDefine.State_Attack3Hash, 0); break; case 13: m_HeroAnimator.Play(GAStaticDefine.State_Attack4Hash, 0); break; } } else { switch (_cfg.Skillactmark) { case 21: m_HeroAnimator.Play(GAStaticDefine.State_Skill21, 0); break; case 22: m_HeroAnimator.Play(GAStaticDefine.State_Skill22, 0); break; case 23: m_HeroAnimator.Play(GAStaticDefine.State_Skill23, 0); break; case 24: m_HeroAnimator.Play(GAStaticDefine.State_Skill24, 0); break; case 25: m_HeroAnimator.Play(GAStaticDefine.State_Skill25, 0); break; case 26: m_HeroAnimator.Play(GAStaticDefine.State_Skill26, 0); break; case 27: m_HeroAnimator.Play(GAStaticDefine.State_Skill27, 0); break; case 28: m_HeroAnimator.Play(GAStaticDefine.State_Skill28, 0); break; case 29: m_HeroAnimator.Play(GAStaticDefine.State_Skill29, 0); break; case 99: m_HeroAnimator.Play(GAStaticDefine.State_RollHash, 0); break; } } } IEnumerator Co_PlaySkill() { yield return WaitingForSecondConst.WaitMS1000; if (m_HeroAnimator != null) { StartPlaySkill(cacheSkillId); } m_CameraAnimator.speed = 1; yield return null; var _showTime = m_CameraAnimator.GetCurrentAnimatorStateInfo(0).length; yield return new WaitForSeconds(_showTime); if (m_HeroSkillCompletet != null) { m_HeroSkillCompletet(); } StopShow(); } IEnumerator Co_PlayExtraEffect(Effect effect) { yield return new WaitForSeconds(effect.startTime); if (m_SkillExtraSfx != null) { SFXPlayUtility.Instance.Release(m_SkillExtraSfx); m_SkillExtraSfx = null; } var parent = hero; if (!string.IsNullOrEmpty(effect.parentName) && hero != null) { parent = hero.GetChildTransformDeeply(effect.parentName, true); } m_SkillExtraSfx = SFXPlayUtility.Instance.Play(effect.id, parent); if (m_SkillExtraSfx != null) { m_SkillExtraSfx.duration = effect.duration; m_SkillExtraSfx.transform.localPosition = effect.position; } } public void StopShow() { UI3DTreasureSelectStage.Instance.showCamera.enabled = true; m_ShowCamera.gameObject.SetActive(false); m_HeroSkillCompletet = null; m_HeroShow.Dispose(); if (m_SkillExtraSfx != null) { SFXPlayUtility.Instance.Release(m_SkillExtraSfx); m_SkillExtraSfx = null; } } [Serializable] public struct CameraClip { public PlayerJob job; public string clip; } [Serializable] public struct Effect { public PlayerJob job; public int id; public float startTime; public float duration; public string parentName; public Vector3 position; } [Serializable] public struct TreasureSkill { public int treasureId; public List clip; public List effects; } public enum PlayerJob { Qiang = 1, Fashi, } } }