少年修仙传客户端代码仓库
client_Wu Xijin
2019-02-13 c7f64d977c4e2884d5411a5a2d0f37b6afa52963
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Friday, September 21, 2018
//--------------------------------------------------------
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using DG.Tweening;
using System;
 
 
namespace Snxxz.UI
{
    public class RotatePointer : MonoBehaviour
    {
        public bool _isRotate = false;//是否旋转      
        private float Speed = 2000;//旋转速度
        public float Angle = 0; // 这个是设置停止的角度
        private float Acceleration = 0;//加速度
        private float _time;
        private bool IsRotateBool = false;//是否进行旋转
        private int BindJadeWheelNotice = 0;//所需提示的金额
        public static event Action<bool> IsButtonShow;
        [Header("总旋转时间")]
        public float ContinuousTime = 4;//旋转时间
        [Header("加速减速时间")]
        public float SpeedTime = 1;
        [Header("最小速度")]
        public float MinSpeed = 400;
        [Header("最大速度")]
        public float MaxSpeed = 800;
        [Header("最大速度")]
        public float _Speed = 1f;
        WheelOfFortuneModel wheelOfFortuneModel { get { return ModelCenter.Instance.GetModel<WheelOfFortuneModel>(); } }
        [SerializeField] CheckDisplay m_CheckDisplay;
        private int FairyJade = 0;
        public void Init()
        {
            IsRotateBool = false;
            _time = 0;
            Angle = wheelOfFortuneModel.AngleSave;
            transform.localRotation = Quaternion.Euler(0, 0, -Angle);
            Acceleration = (MaxSpeed - MinSpeed) / SpeedTime;
            m_CheckDisplay.CloseAll();
            if (BindJadeWheelNotice <= 0)
            {
                var config = FuncConfigConfig.Get("BindJadeWheelNotice").Numerical1;
                BindJadeWheelNotice = int.Parse(config);
            }
        }
        private void OnEnable()
        {
            FairyJade = (int)UIHelper.GetMoneyCnt(2);
        }
        private void OnDisable()
        {
            sequence.Kill();
        }
        private Sequence sequence;
        void Update()
        {
 
            if (!_isRotate)
            {
                if (Math.Abs((360 - Angle) - transform.eulerAngles.z) > 0.2 && Angle - transform.eulerAngles.z != 0)
                {
                    transform.DOPause();
                    sequence.Kill();
                    transform.localRotation = Quaternion.Euler(0, 0, -Angle);
                    m_CheckDisplay.ShowSelected(wheelOfFortuneModel.Lattice);
                    int money = ((int)UIHelper.GetMoneyCnt(2) - FairyJade);
                    string str=UIHelper.ServerStringTrim(PlayerDatas.Instance.baseData.PlayerName);
                    if (money>=BindJadeWheelNotice)
                    {
                        SysNotifyMgr.Instance.ShowTip("BindJadeNotice", str, money);
                    }
                  
                    FairyJade = (int)UIHelper.GetMoneyCnt(2);
                    if (IsButtonShow != null)
                    {
                        IsButtonShow(true);
                    }
                    _time = 0;
                    IsRotateBool = false;
                    _isRotate = false;
                }
                return; //不旋转结束
            }
            if (IsRotateBool)
            {
                _time += Time.deltaTime;
                if (_time < SpeedTime)//匀加速
                {
                    Speed = MinSpeed + Acceleration * _time;
                    if (Speed >= MaxSpeed)
                    {
                        Speed = MaxSpeed;
                    }
                }
                else if (_time > ContinuousTime - SpeedTime)//匀减速
                {
                    Speed = MaxSpeed - Acceleration * (_time - (ContinuousTime - SpeedTime));
                    if (Speed <= MinSpeed)
                    {
                        Speed = MinSpeed;
                    }
                }
                else//匀速
                {
                    Speed = MaxSpeed;
                }
                if (_time < ContinuousTime) // 没结束
                {
                    transform.Rotate(-Vector3.forward * Speed * Time.deltaTime);
                }
                else
                {
                    //结束,使用DoTween旋转到结束角度,耗时1秒
                    //这里有个360,使用来防止指针回转的,如果不加这个360,你会看到指针倒退
                    sequence = DOTween.Sequence();
                    sequence.SetAutoKill(false);
                    sequence.Append(transform.DORotate(new Vector3(0, 0, -(360 + Angle)), _Speed, RotateMode.FastBeyond360));
                    sequence.AppendCallback(() =>
                    {
                        _isRotate = false; // 设置不旋转
                        if (IsButtonShow != null)
                        {
                            IsButtonShow(true);
                        }
                        m_CheckDisplay.ShowSelected(wheelOfFortuneModel.Lattice);
                        int money = ((int)UIHelper.GetMoneyCnt(2) - FairyJade);
                        string str = UIHelper.ServerStringTrim(PlayerDatas.Instance.baseData.PlayerName);
                        if (money >= BindJadeWheelNotice)
                        {
                            SysNotifyMgr.Instance.ShowTip("BindJadeNotice", str, money);
                        }
                        FairyJade = (int)UIHelper.GetMoneyCnt(2);
                    });
                    IsRotateBool = false;
                }
            }
        }
        //外部调用,初始化时间和打开旋转,设置停止角度
        public void SetTime(bool _bool)
        {
            _time = 0;
            Angle = wheelOfFortuneModel.AngleSave;
            if (_bool)
            {
                IsRotateBool = false;
                _isRotate = false;
            }
            else
            {
                SoundPlayer.Instance.PlayUIAudio(69);
                IsRotateBool = true;
                _isRotate = true;
            }
        }
    }
 
}