| | |
| | | using System.Collections; |
| | | using System.Collections.Generic; |
| | | using DG.Tweening; |
| | | using UnityEngine; |
| | | using UnityEngine.UI; |
| | | using Core.Utilities; |
| | | using TowerDefense.Level; |
| | | |
| | | /** |
| | | * 无尽模式boss控制器 |
| | |
| | | /// <summary> |
| | | /// boss动作 |
| | | /// </summary> |
| | | public Animator BossAnimator; |
| | | private Animator BossAnimator; |
| | | |
| | | /// <summary> |
| | | /// 动作状态 |
| | | /// </summary> |
| | | public EndlessBossActionState ActionState { get; set; } |
| | | |
| | | 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>((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); |
| | | |
| | | /// <summary> |
| | | /// 帧事件 |
| | | /// </summary> |
| | | /// <param name="frameName"></param> |
| | | public void FireAnimationEvent(string frameName) |
| | | { |
| | | if (frameName == "summonEnd") |
| | | 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(); |
| | | } |
| | | } |
| | | |
| | | 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; |
| | | c.a = 0; |
| | | Title.color = c; |
| | | Title.gameObject.SetActive(true); |
| | | |
| | | flashSeq.Append(DOTween.To(() => ColorVal, (v) => ColorVal = v, 1, 0.3f)); |
| | | 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.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 |
| | | { |
| | | get { return Title.color.a; } |
| | | set |
| | | { |
| | | Title.gameObject.SetActive(value != 0); |
| | | Color c = Title.color; |
| | | c.a = value; |
| | | Title.color = c; |
| | | } |
| | | } |
| | | |
| | |
| | | /// <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>(); |
| | | } |
| | | } |
| | | } |