//--------------------------------------------------------
|
// [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;
|
}
|
}
|
}
|
|
}
|