少年修仙传客户端代码仓库
client_Wu Xijin
2019-03-14 49287ea39a0ad3dde2b9a957d9f516f4b96d098a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
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();
        }
    }
}