using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.EventSystems;
|
using UnityEngine.UI;
|
|
|
namespace Snxxz.UI
|
{
|
public class SkillTurnplate : SkillButtonInterface
|
{
|
[SerializeField] RectTransform m_SkillContainer;
|
[SerializeField] Image m_SkillGroupSign;
|
[SerializeField] float m_Sensitiveness;
|
[SerializeField] float m_TimeLimit;
|
[SerializeField, Header("是否可拖拽滑动")] bool m_Drag = true;
|
public bool drag {
|
get { return m_Drag; }
|
set { m_Drag = value; }
|
}
|
|
Vector2 startPoint = Vector2.zero;
|
Vector2 endPoint = Vector2.zero;
|
|
float startTime = 0f;
|
float endTime = 0f;
|
|
float m_TargetRotationZ = 0f;
|
float refRotationZ = 0f;
|
|
int groupIndex = 1;
|
public int GroupIndex { get { return groupIndex; } }
|
bool turnplating = false;
|
|
TreasureModel treasureModel { get { return ModelCenter.Instance.GetModel<TreasureModel>(); } }
|
|
private void Awake()
|
{
|
DTC0102_tagCDBPlayer.switchAccountEvent += OnSwitchAccount;
|
}
|
|
private void OnDestroy()
|
{
|
DTC0102_tagCDBPlayer.switchAccountEvent -= OnSwitchAccount;
|
}
|
|
public void Init()
|
{
|
if (m_SkillGroupSign != null)
|
{
|
m_SkillGroupSign.gameObject.SetActive(IsSecondPanelAllow());
|
}
|
SwitchGroup(groupIndex);
|
}
|
|
public override void OnPointerDown(PointerEventData eventData)
|
{
|
base.OnPointerDown(eventData);
|
|
startTime = Time.time;
|
startPoint = eventData.position;
|
}
|
|
public override void OnPointerUp(PointerEventData eventData)
|
{
|
base.OnPointerUp(eventData);
|
|
endTime = Time.time;
|
endPoint = eventData.position;
|
|
if (IsValidGesture() && !turnplating && m_Drag)
|
{
|
if (IsSecondPanelAllow())
|
{
|
var gesture = MathUtility.GetGestureDirection(startPoint, endPoint);
|
Turn(gesture);
|
}
|
else
|
{
|
var config = TreasureConfig.Get(GeneralDefine.skillPanelUnLock);
|
SysNotifyMgr.Instance.ShowTip("SkillPanel_Unlock", config.Name);
|
}
|
}
|
}
|
|
public void SwitchGroup(int _groupIndex)
|
{
|
if (_groupIndex != 1 && _groupIndex != 2)
|
{
|
return;
|
}
|
|
StopAllCoroutines();
|
groupIndex = _groupIndex;
|
m_SkillContainer.transform.localEulerAngles = groupIndex == 1 ? Vector3.zero : new Vector3(0, 0, 180);
|
if (m_SkillGroupSign != null)
|
{
|
m_SkillGroupSign.SetSprite(groupIndex == 1 ? "Skill_Page_1" : "Skill_Page_2");
|
}
|
}
|
|
public bool Turn(GestureType _type = GestureType.Down)
|
{
|
if (turnplating)
|
{
|
return false;
|
}
|
|
if (groupIndex == 1)
|
{
|
groupIndex = 2;
|
}
|
else
|
{
|
groupIndex = 1;
|
}
|
|
if (m_SkillGroupSign != null)
|
{
|
m_SkillGroupSign.SetSprite(groupIndex == 1 ? "Skill_Page_1" : "Skill_Page_2");
|
}
|
|
switch (_type)
|
{
|
case GestureType.Down:
|
case GestureType.Left:
|
m_TargetRotationZ = m_SkillContainer.localEulerAngles.z + 180f;
|
StartCoroutine(Co_Turnplate(m_SkillContainer.localEulerAngles.z, m_TargetRotationZ));
|
break;
|
case GestureType.Up:
|
case GestureType.Right:
|
m_TargetRotationZ = m_SkillContainer.localEulerAngles.z - 180f;
|
StartCoroutine(Co_Turnplate(m_SkillContainer.localEulerAngles.z, m_TargetRotationZ));
|
break;
|
}
|
return true;
|
}
|
|
bool IsSecondPanelAllow()
|
{
|
Treasure treasure;
|
return treasureModel.TryGetTreasure(GeneralDefine.skillPanelUnLock, out treasure) && treasure.state == TreasureState.Collected;
|
}
|
|
bool IsValidGesture()
|
{
|
if ((endTime - startTime) < m_TimeLimit && Vector2.Distance(startPoint, endPoint) > m_Sensitiveness)
|
{
|
return true;
|
}
|
|
return false;
|
}
|
|
IEnumerator Co_Turnplate(float _startZ, float _endZ)
|
{
|
turnplating = true;
|
|
float timer = 0f;
|
float duration = 0.5f;
|
while (timer < duration)
|
{
|
timer += Time.deltaTime;
|
m_SkillContainer.localEulerAngles = new Vector3(0, 0, Mathf.Lerp(_startZ, _endZ, Mathf.Clamp01(timer / duration)));
|
yield return null;
|
}
|
|
m_SkillContainer.localEulerAngles = new Vector3(0, 0, _endZ);
|
|
turnplating = false;
|
}
|
|
private void OnSwitchAccount()
|
{
|
groupIndex = 1;
|
}
|
|
}
|
}
|