using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
namespace Snxxz.UI
|
{
|
public class RealmAnimationBehaviour : MonoBehaviour
|
{
|
[SerializeField] float m_Radius = 100f;
|
[SerializeField] float m_Duration = 1f;
|
[SerializeField] TweenCurve m_TweenCurve;
|
[SerializeField] Transform m_ContainerLine;
|
[SerializeField] RealmStageBehaviour[] m_RealmStages;
|
|
Coroutine m_RotateCoroutine = null;
|
|
float m_DeltaAngle { get { return 360f / 8; } }
|
|
public event Action onRotateComplete;
|
|
public void SetDefault()
|
{
|
m_ContainerLine.gameObject.SetActive(false);
|
for (int i = 0; i < m_RealmStages.Length; i++)
|
{
|
m_RealmStages[i].transform.localPosition = GetPointPosition(i);
|
m_RealmStages[i].animIndex = i;
|
}
|
}
|
|
Vector3 GetPointPosition(int _index)
|
{
|
return GetPointPosition(GetPointAngle(_index));
|
}
|
|
float GetPointAngle(int _index)
|
{
|
return _index * m_DeltaAngle - 90;
|
}
|
|
Vector3 GetPointPosition(float angle)
|
{
|
var _x = transform.position.x + m_Radius * Mathf.Sin(Mathf.Deg2Rad * angle);
|
var _y = transform.position.y + m_Radius * Mathf.Cos(Mathf.Deg2Rad * angle);
|
var _z = transform.position.z;
|
return new Vector3(_x, _y, _z);
|
}
|
|
public void StartRotate()
|
{
|
if (m_RotateCoroutine != null)
|
{
|
StopCoroutine(m_RotateCoroutine);
|
}
|
m_RotateCoroutine = StartCoroutine(Co_Rotate());
|
}
|
|
public void StopRotate()
|
{
|
if (m_RotateCoroutine != null)
|
{
|
StopCoroutine(m_RotateCoroutine);
|
}
|
}
|
|
IEnumerator Co_Rotate()
|
{
|
var timer = 0f;
|
m_ContainerLine.gameObject.SetActive(true);
|
|
bool rotate30 = 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 >= 30 && !rotate30)
|
{
|
foreach (var realmStage in m_RealmStages)
|
{
|
if (realmStage.animIndex == 0)
|
{
|
realmStage.gameObject.SetActive(false);
|
}
|
else
|
{
|
realmStage.gameObject.SetActive(true);
|
}
|
}
|
rotate30 = 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_ContainerLine.gameObject.SetActive(false);
|
foreach (var realmStage in m_RealmStages)
|
{
|
realmStage.animIndex = (realmStage.animIndex + 5) % 9;
|
}
|
|
if (onRotateComplete != null)
|
{
|
onRotateComplete();
|
}
|
}
|
|
[ContextMenu("Reset")]
|
void TestReset()
|
{
|
SetDefault();
|
}
|
|
[ContextMenu("Rotate")]
|
void TestRotate()
|
{
|
StartRotate();
|
}
|
}
|
}
|