using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
namespace vnxbqy.UI
|
{
|
public class RealmAnimationBehaviour : MonoBehaviour
|
{
|
[SerializeField] float m_Radius = 100f;
|
[SerializeField] float m_Duration = 1f;
|
[SerializeField] TweenCurve m_TweenCurve;
|
[SerializeField] Transform m_RealmStageCenter;
|
[SerializeField] Transform m_ContainerLine;
|
[SerializeField] RealmStageBehaviour[] m_RealmStages;
|
[SerializeField] Transform m_ContainerEffectLine;
|
[SerializeField] UIEffect[] m_EffectLines;
|
[SerializeField] UIEffect m_EffectLevelUp;
|
[SerializeField] UIEffect m_EffectBoss;
|
[SerializeField] UIEffect m_EffectBase;
|
[SerializeField] UIEffect m_EffectCover;
|
[SerializeField] UIEffect m_EffectBossWord;
|
|
[SerializeField, Header("小境界升级特效时长")] float m_NormalLevelUpEffectTime = 1.5f;
|
[SerializeField, Header("大境界升级特效时长")] float m_SpecialLevelUpEffectTime = 4.5f;
|
[SerializeField, Header("罩子消失时机"), Range(0, 2f)] float m_CoverDisappearTime = 1.0f;
|
[SerializeField, Header("罩子切换时机")] float m_CoverChangeTime = 3.0f;
|
|
Coroutine m_RotateCoroutine = null;
|
|
float m_DeltaAngle { get { return 360f / 8; } }
|
|
public bool rotating { get; private set; }
|
public bool isPlayingAnimation { get; private set; }
|
public bool isPlayingBossEffect { get; private set; }
|
|
public event Action onRotateComplete;
|
public event Action onLevelUpComplete;
|
public event Action onBossAppearComplete;
|
public event Action onCoverChange;
|
|
RealmModel model { get { return ModelCenter.Instance.GetModel<RealmModel>(); } }
|
|
public void SetDefault()
|
{
|
rotating = false;
|
isPlayingAnimation = false;
|
isPlayingBossEffect = false;
|
m_ContainerLine.SetActive(false);
|
for (int i = 0; i < m_RealmStages.Length; i++)
|
{
|
m_RealmStages[i].transform.localPosition = GetPointPosition(i);
|
m_RealmStages[i].animIndex = i;
|
}
|
foreach (var effectLine in m_EffectLines)
|
{
|
effectLine.StopImediatly();
|
}
|
m_ContainerEffectLine.localEulerAngles = Vector3.zero;
|
DisplayEffectLines();
|
}
|
|
void DisplayEffectLines()
|
{
|
var realmLevel = PlayerDatas.Instance.baseData.realmLevel;
|
var stage = model.GetRealmStage(realmLevel);
|
List<int> realms = null;
|
if (model.TryGetRealmStages(stage, out realms))
|
{
|
for (int i = 0; i < realms.Count; i++)
|
{
|
var level = realms[i] + 1;
|
if (realmLevel >= level)
|
{
|
m_EffectLines[i].effect = model.GetRealmLineEffect(realms[i]);
|
m_EffectLines[i].Play();
|
if (m_EffectLines[i].target != null)
|
{
|
var animator = m_EffectLines[i].target.GetAnimator();
|
animator.Play("idle", 0, 0);
|
}
|
}
|
}
|
}
|
}
|
|
Vector3 GetPointPosition(int _index)
|
{
|
return GetPointPosition(GetPointAngle(_index));
|
}
|
|
float GetPointAngle(int _index)
|
{
|
return _index * m_DeltaAngle - 90;
|
}
|
|
Vector3 GetPointPosition(float angle)
|
{
|
var _x = m_RealmStageCenter.position.x + m_Radius * Mathf.Sin(Mathf.Deg2Rad * angle);
|
var _y = m_RealmStageCenter.position.y + m_Radius * Mathf.Cos(Mathf.Deg2Rad * angle);
|
var _z = m_RealmStageCenter.position.z;
|
return new Vector3(_x, _y, _z);
|
}
|
|
public void DisplayLevelUp(int index)
|
{
|
StartCoroutine(Co_DisplayLevelUp(index));
|
}
|
|
IEnumerator Co_DisplayLevelUp(int index)
|
{
|
if (index >= m_EffectLines.Length)
|
{
|
yield break;
|
}
|
|
isPlayingAnimation = true;
|
|
if (m_EffectBoss.IsPlaying)
|
{
|
if (m_EffectBase.target != null)
|
{
|
var obj = m_EffectBase.target.transform.Find("GameObject/b/b (3)");
|
if (obj != null)
|
{
|
obj.SetActive(true);
|
}
|
}
|
}
|
m_EffectBoss.StopImediatly();
|
|
StartLine(index);
|
|
|
m_EffectLevelUp.StopImediatly();
|
var config = RealmConfig.Get(model.displayRealmLevel - 1);
|
var levelUpEffectId = config.BossID != 0 ? 7037 : 7038;
|
m_EffectLevelUp.effect = levelUpEffectId;
|
m_EffectLevelUp.Play();
|
var effectTime = config.BossID != 0 ? m_SpecialLevelUpEffectTime : m_NormalLevelUpEffectTime;
|
if (config.BossID != 0)
|
{
|
yield return WaitingForSecondConst.GetWaitForSeconds(m_CoverChangeTime);
|
if (onCoverChange != null)
|
{
|
onCoverChange();
|
}
|
yield return WaitingForSecondConst.GetWaitForSeconds(effectTime - m_CoverChangeTime);
|
}
|
else
|
{
|
yield return WaitingForSecondConst.GetWaitForSeconds(effectTime);
|
}
|
|
yield return WaitingForSecondConst.WaitMS500;
|
|
if (index == 3 && model.displayRealmLevel < model.realmMaxLevel)
|
{
|
StartRotate();
|
}
|
|
if (model.SatisfyChallengeBoss(model.displayRealmLevel))
|
{
|
StartBossEffectShow();
|
model.SetBossEffectShow(model.displayRealmLevel);
|
yield return WaitingForSecondConst.WaitMS3000;
|
}
|
|
isPlayingAnimation = false;
|
|
if (onLevelUpComplete != null)
|
{
|
onLevelUpComplete();
|
}
|
}
|
|
RealmStageBehaviour GetRealmStageBeha(int index)
|
{
|
foreach (var realmStage in m_RealmStages)
|
{
|
if (realmStage.animIndex == index)
|
{
|
return realmStage;
|
}
|
}
|
return null;
|
}
|
|
void StartLine(int index)
|
{
|
if (index != -1)
|
{
|
StartCoroutine(Co_StartLine(index));
|
}
|
else
|
{
|
var realmStage = GetRealmStageBeha(index + 1);
|
if (realmStage != null)
|
{
|
realmStage.DisplayEffect(true);
|
}
|
}
|
}
|
|
IEnumerator Co_StartLine(int index)
|
{
|
m_EffectLines[index].effect = model.GetRealmLineEffect(model.displayRealmLevel - 1);
|
m_EffectLines[index].Play();
|
if (m_EffectLines[index].target != null)
|
{
|
var animator = m_EffectLines[index].target.GetAnimator();
|
animator.Play("open", 0, 0);
|
yield return WaitingForSecondConst.WaitMS500;
|
animator.Play("idle", 0);
|
}
|
|
var realmStage = GetRealmStageBeha(index + 1);
|
if (realmStage != null)
|
{
|
realmStage.DisplayEffect(true);
|
}
|
}
|
|
void StartRotate()
|
{
|
rotating = true;
|
if (m_RotateCoroutine != null)
|
{
|
StopCoroutine(m_RotateCoroutine);
|
}
|
m_RotateCoroutine = StartCoroutine(Co_Rotate());
|
}
|
|
IEnumerator Co_Rotate()
|
{
|
var timer = 0f;
|
m_ContainerLine.SetActive(true);
|
|
bool rotate45 = false;
|
|
while (timer < m_Duration)
|
{
|
timer += Time.deltaTime;
|
yield return null;
|
var t = Mathf.Clamp01(timer / m_Duration);
|
var value = m_TweenCurve.Evaluate(t);
|
var angle = Mathf.LerpUnclamped(0, 180, value);
|
|
if (angle >= 45 && !rotate45)
|
{
|
foreach (var realmStage in m_RealmStages)
|
{
|
if (realmStage.animIndex == 0 || realmStage.animIndex == 1)
|
{
|
realmStage.Dispose();
|
realmStage.SetActive(false);
|
}
|
else
|
{
|
realmStage.SetActive(true);
|
}
|
}
|
m_EffectLines[0].StopImediatly();
|
rotate45 = true;
|
}
|
|
for (int i = 0; i < m_RealmStages.Length; i++)
|
{
|
var cacheAngle = GetPointAngle(m_RealmStages[i].animIndex);
|
var position = GetPointPosition(cacheAngle - angle);
|
m_RealmStages[i].transform.localPosition = position;
|
}
|
|
m_ContainerEffectLine.localEulerAngles = new Vector3(0, 0, angle);
|
}
|
m_ContainerLine.SetActive(false);
|
foreach (var realmStage in m_RealmStages)
|
{
|
if (realmStage.animIndex == 1)
|
{
|
realmStage.SetActive(true);
|
}
|
realmStage.animIndex = (realmStage.animIndex + 5) % 9;
|
}
|
|
foreach (var effectLine in m_EffectLines)
|
{
|
effectLine.StopImediatly();
|
}
|
m_ContainerEffectLine.localEulerAngles = Vector3.zero;
|
|
rotating = false;
|
|
if (onRotateComplete != null)
|
{
|
onRotateComplete();
|
}
|
}
|
|
public void StartBossEffectShow()
|
{
|
StartCoroutine(Co_BossEffectShow());
|
}
|
|
IEnumerator Co_BossEffectShow()
|
{
|
isPlayingBossEffect = true;
|
m_EffectBoss.Play();
|
m_EffectBossWord.Play();
|
Animator animator = null;
|
if (m_EffectBoss.target != null)
|
{
|
animator = m_EffectBoss.target.GetAnimator();
|
animator.Play("Effect_JingJieBJ_02", 0, 0);
|
}
|
|
if (m_EffectBase.target != null)
|
{
|
var obj = m_EffectBase.target.transform.Find("GameObject/b/b (3)");
|
if (obj != null)
|
{
|
obj.SetActive(false);
|
}
|
}
|
yield return WaitingForSecondConst.GetWaitForSeconds(m_CoverDisappearTime);
|
if (m_EffectCover.IsPlaying)
|
{
|
m_EffectCover.StopImediatly();
|
}
|
yield return WaitingForSecondConst.GetWaitForSeconds(2f - m_CoverDisappearTime);
|
|
isPlayingBossEffect = false;
|
|
if (onBossAppearComplete != null)
|
{
|
onBossAppearComplete();
|
}
|
}
|
|
public void Dispose()
|
{
|
rotating = false;
|
isPlayingAnimation = false;
|
isPlayingBossEffect = false;
|
StopAllCoroutines();
|
if (m_RotateCoroutine != null)
|
{
|
StopCoroutine(m_RotateCoroutine);
|
m_RotateCoroutine = null;
|
}
|
}
|
|
[ContextMenu("Reset")]
|
void TestReset()
|
{
|
SetDefault();
|
}
|
}
|
}
|
|