From 30b2a647b3a3d1d5b71d14e0cc821a02b8366f70 Mon Sep 17 00:00:00 2001 From: chenxin <chenxin6991@163.com> Date: Tue, 08 Dec 2020 14:20:05 +0800 Subject: [PATCH] 不到二级宝石时间不用计算最小等级 --- Assets/Scripts/TowerDefense/UI/EndlessBossCtrl.cs | 88 +++++++++++++++++++++++++++++++++---------- 1 files changed, 67 insertions(+), 21 deletions(-) diff --git a/Assets/Scripts/TowerDefense/UI/EndlessBossCtrl.cs b/Assets/Scripts/TowerDefense/UI/EndlessBossCtrl.cs index 14bc0f4..e6237b2 100644 --- a/Assets/Scripts/TowerDefense/UI/EndlessBossCtrl.cs +++ b/Assets/Scripts/TowerDefense/UI/EndlessBossCtrl.cs @@ -1,9 +1,8 @@ using DG.Tweening; -using System.Collections; -using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using Core.Utilities; +using TowerDefense.Level; /** * 无尽模式boss控制器 @@ -17,7 +16,7 @@ /// <summary> /// boss动作 /// </summary> - public Animator BossAnimator; + private Animator BossAnimator; /// <summary> /// 动作状态 @@ -26,21 +25,56 @@ public Image Title; + private string titlePath = "UI/Endless/SkillTitle/"; + + private ParticleSystem deadPS, deadMoney; + + private string prefabPath = "Prefabs/Boss/Boss_"; + + private GameObject Body; + // Start is called before the first frame update private void Start() { ColorVal = 0; - EventCenter.Ins.Add((int)KTGMGemClient.EventType.EndlessBossSkillGlintTitle, Glint); + EventCenter.Ins.Add<int>((int)KTGMGemClient.EventType.EndlessBossSkillGlintTitle, Glint); } - // Update is called once per frame - private void Update() + private void LateUpdate() { + if (BossAnimator == null) return; + AnimatorStateInfo stateInfo = BossAnimator.GetCurrentAnimatorStateInfo(0); + + if (stateInfo.IsName("Boss_Summon") && stateInfo.normalizedTime >= 1f) + { + EventCenter.Ins.BroadCast((int)EventType.EndlessBossSummonEnd); + // 召唤动作结束后自动切换到站立状态 + ChangeState(EndlessBossActionState.Standing); + } + else if (stateInfo.IsName("Boss_Death") && stateInfo.normalizedTime >= 1f) + { + ClearBoss(); + EndlessLevelManager.instance.WaveManager.HideTunel(); + } } - private void Glint() + public void ClearBoss() { + BossAnimator = null; + deadPS = null; + deadMoney = null; + + if (Body != null) + { + Destroy(Body); + Body = null; + } + } + + private void Glint(int skillType) + { + Title.sprite = Resources.Load<Sprite>($"{titlePath}{skillType}"); //设置一个DOTween队列 Sequence flashSeq = DOTween.Sequence(); Color c = Title.color; @@ -54,6 +88,7 @@ flashSeq.Append(DOTween.To(() => ColorVal, (v) => ColorVal = v, 0, 0.15f)); flashSeq.Append(DOTween.To(() => ColorVal, (v) => ColorVal = v, 1, 0.3f)); flashSeq.Append(DOTween.To(() => ColorVal, (v) => ColorVal = v, 0, 0.15f)); + flashSeq.AppendCallback(() => { EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.EndlessBossSkillGlintTitleCompleted); }); } private float ColorVal @@ -69,27 +104,38 @@ } /// <summary> - /// 帧事件 - /// </summary> - /// <param name="frameName"></param> - public void FireAnimationEvent(string frameName) - { - if (frameName == "summonEnd") - { - EventCenter.Ins.BroadCast((int)EventType.EndlessBossSummonEnd); - } - } - - /// <summary> /// 切换状态 /// </summary> /// <param name="newState"></param> public void ChangeState(EndlessBossActionState newState) { - if (newState == ActionState) return; - ActionState = newState; + + if (newState == EndlessBossActionState.Death) + { + deadPS?.Play(); + deadMoney?.Play(); + } BossAnimator.SetInteger("State", (int)newState); } + + /// <summary> + /// 刷新boss形象 + /// </summary> + /// <param name="resId"></param> + public void RefreshBody(int resId) + { + GameObject prefab = Resources.Load<GameObject>($"{prefabPath}{resId}"); + + if (prefab == null) + { + Debug.LogError($"---- 加载boss资源出错,resId: {resId} ----"); + return; + } + + Body = Instantiate(prefab); + Body.transform.SetParent(transform, false); + BossAnimator = Body.GetComponent<Animator>(); + } } } \ No newline at end of file -- Gitblit v1.9.1