192 lines
5.7 KiB
C#
192 lines
5.7 KiB
C#
|
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using GCGame.Table;
|
|||
|
using Games.LogicObj;
|
|||
|
using Games.Mission;
|
|||
|
using Games.GlobeDefine;
|
|||
|
using Module.Log;
|
|||
|
using Games.Item;
|
|||
|
using System;
|
|||
|
using UnityEngine.Events;
|
|||
|
|
|||
|
public class CircleAnim : MonoBehaviour
|
|||
|
{
|
|||
|
public RectTransform _RotCircle;
|
|||
|
public float _RotTime;
|
|||
|
public float _RotSpeed;
|
|||
|
public float _AccelateSpeed1;
|
|||
|
public float _FinalSpeed;
|
|||
|
public float _FinalSpeed2;
|
|||
|
public bool _IsTargetAngle;
|
|||
|
public float _TargetAngle;
|
|||
|
public float _AccelateTime = 0.5f;
|
|||
|
|
|||
|
[Serializable]
|
|||
|
public class AnimStop : UnityEvent
|
|||
|
{
|
|||
|
public AnimStop() { }
|
|||
|
}
|
|||
|
|
|||
|
[SerializeField]
|
|||
|
public AnimStop _AnimStopCallBack;
|
|||
|
|
|||
|
void Update()
|
|||
|
{
|
|||
|
RotUpdate();
|
|||
|
}
|
|||
|
|
|||
|
#region Rot
|
|||
|
|
|||
|
public void ResetAll()
|
|||
|
{
|
|||
|
ResetRot();
|
|||
|
_RotCircle.localRotation = Quaternion.Euler(Vector3.zero);
|
|||
|
}
|
|||
|
|
|||
|
public void ResetRot()
|
|||
|
{
|
|||
|
_RotSpeedInner = 0;
|
|||
|
_StartRot = false;
|
|||
|
_LastCircleAccelate = 0;
|
|||
|
_RotTimeInner = _RotTime;
|
|||
|
}
|
|||
|
|
|||
|
private float _RotSpeedInner;
|
|||
|
private float _RotTimeInner;
|
|||
|
private bool _StartRot;
|
|||
|
|
|||
|
float moveDis = 0;
|
|||
|
private void RotUpdate()
|
|||
|
{
|
|||
|
if (!_StartRot)
|
|||
|
return;
|
|||
|
|
|||
|
_RotTimeInner -= Time.deltaTime;
|
|||
|
|
|||
|
if (_RotTimeInner < _AccelateTime)
|
|||
|
{
|
|||
|
if (!_IsTargetAngle)
|
|||
|
{
|
|||
|
_RotSpeedInner -= _AccelateSpeed1 * Time.deltaTime;
|
|||
|
if (_RotSpeedInner < 0)
|
|||
|
{
|
|||
|
_RotSpeedInner = 0f;
|
|||
|
}
|
|||
|
_RotCircle.localRotation = Quaternion.Euler(_RotCircle.localRotation.eulerAngles + new Vector3(0, 0, _RotSpeedInner * Time.deltaTime));
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
if (_RotSpeedInner == _FinalSpeed)
|
|||
|
{
|
|||
|
_RotCircle.localRotation = Quaternion.Euler(_RotCircle.localRotation.eulerAngles + new Vector3(0, 0, _RotSpeedInner * Time.deltaTime));
|
|||
|
if (Mathf.Abs(GetAngleDex(_RotCircle.localRotation.eulerAngles.z) - _TargetAngle) < _RotSpeedInner * Time.deltaTime)
|
|||
|
{
|
|||
|
_RotCircle.localRotation = Quaternion.Euler(new Vector3(0, 0, _TargetAngle));
|
|||
|
_RotSpeedInner = 0;
|
|||
|
}
|
|||
|
}
|
|||
|
else if (_RotSpeedInner < _FinalSpeed2)
|
|||
|
{
|
|||
|
_RotSpeedInner -= _FinalSpeed * Time.deltaTime;
|
|||
|
if (_RotSpeedInner < _FinalSpeed)
|
|||
|
{
|
|||
|
_RotSpeedInner = _FinalSpeed;
|
|||
|
}
|
|||
|
_RotCircle.localRotation = Quaternion.Euler(_RotCircle.localRotation.eulerAngles + new Vector3(0, 0, _RotSpeedInner * Time.deltaTime));
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_RotSpeedInner -= _AccelateSpeed1 * Time.deltaTime;
|
|||
|
_RotCircle.localRotation = Quaternion.Euler(_RotCircle.localRotation.eulerAngles + new Vector3(0, 0, _RotSpeedInner * Time.deltaTime));
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
//var lastDis = GetLastCircleDis();
|
|||
|
|
|||
|
//if (_LastCircleAccelate == 0 && lastDis > 0)
|
|||
|
//{
|
|||
|
// SetLastCircleAccelate(lastDis);
|
|||
|
// moveDis = 0;
|
|||
|
//}
|
|||
|
//else
|
|||
|
//{
|
|||
|
// var speedOrg = _RotSpeedInner;
|
|||
|
// _RotSpeedInner += _LastCircleAccelate * Time.deltaTime;
|
|||
|
// if (_RotSpeedInner < 0)
|
|||
|
// {
|
|||
|
// _RotSpeedInner = 0f;
|
|||
|
// }
|
|||
|
// var dis = (speedOrg + _RotSpeedInner) * Time.deltaTime * 0.5f;
|
|||
|
// moveDis += dis;
|
|||
|
// LogModule.DebugLog("moveDis:" + moveDis);
|
|||
|
// _RotCircle.localRotation = Quaternion.Euler(_RotCircle.localRotation.eulerAngles + new Vector3(0, 0, dis));
|
|||
|
//}
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
else if (_RotTimeInner > _RotTime - _AccelateTime)
|
|||
|
{
|
|||
|
_RotSpeedInner += _RotSpeed * Time.deltaTime;
|
|||
|
if (_RotSpeedInner > _RotSpeed)
|
|||
|
{
|
|||
|
_RotSpeedInner = _RotSpeed;
|
|||
|
}
|
|||
|
_RotCircle.localRotation = Quaternion.Euler(_RotCircle.localRotation.eulerAngles + new Vector3(0, 0, _RotSpeedInner * Time.deltaTime));
|
|||
|
}
|
|||
|
|
|||
|
if (_RotSpeedInner == 0)
|
|||
|
{
|
|||
|
LogModule.DebugLog("StopRot");
|
|||
|
StopRot();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private float GetLastCircleDis()
|
|||
|
{
|
|||
|
var circleDis = Mathf.CeilToInt(1) * 360;
|
|||
|
var nowAngle = GetAngleDex(_RotCircle.localRotation.eulerAngles.z);
|
|||
|
return GetAngleDex(_TargetAngle - nowAngle) + circleDis;
|
|||
|
}
|
|||
|
|
|||
|
private float GetAngleDex(float angle)
|
|||
|
{
|
|||
|
if (angle <= 0)
|
|||
|
return 360 + angle;
|
|||
|
|
|||
|
return angle;
|
|||
|
}
|
|||
|
|
|||
|
private float _LastCircleAccelate = 0;
|
|||
|
private void SetLastCircleAccelate(float lastDis)
|
|||
|
{
|
|||
|
//var lastDis = _RotTimeInner * _RotTimeInner * _RotSpeed * 0.5f + _RotSpeedInner * _RotTimeInner + _TargetAngle;
|
|||
|
LogModule.DebugLog("LastDis:" + lastDis);
|
|||
|
_LastCircleAccelate = (2 * lastDis - 2 * _RotSpeedInner * _AccelateTime) / (_AccelateTime * _AccelateTime);
|
|||
|
LogModule.DebugLog("_LastCircleAccelate:" + _LastCircleAccelate + ", speed:" + _RotSpeedInner);
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region interface
|
|||
|
|
|||
|
|
|||
|
public void StartRot()
|
|||
|
{
|
|||
|
_StartRot = true;
|
|||
|
}
|
|||
|
|
|||
|
public void StopRot()
|
|||
|
{
|
|||
|
_StartRot = false;
|
|||
|
if (_AnimStopCallBack != null)
|
|||
|
{
|
|||
|
_AnimStopCallBack.Invoke();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|