超大量的更新 修复很多问题,gameplay特效初步
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using DG.Tweening;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class ui_Panel_Setting : MonoBehaviour
|
||||
{
|
||||
@@ -10,6 +12,19 @@ public class ui_Panel_Setting : MonoBehaviour
|
||||
[SerializeField] Toggle toggle_View;
|
||||
[SerializeField] Toggle toggle_View_Pie;
|
||||
[SerializeField] GameObject view_Content;
|
||||
|
||||
[Header("Enter Animation")]
|
||||
[SerializeField] bool playEnterAnimation = true;
|
||||
[SerializeField] float enterItemDuration = 0.24f;
|
||||
[SerializeField] float enterItemStagger = 0.03f;
|
||||
[SerializeField] float enterOffsetY = 28f;
|
||||
[SerializeField] Ease enterEase = Ease.OutCubic;
|
||||
|
||||
private readonly List<RectTransform> enterItems = new List<RectTransform>();
|
||||
private readonly List<CanvasGroup> enterGroups = new List<CanvasGroup>();
|
||||
private readonly List<Vector2> enterBasePos = new List<Vector2>();
|
||||
private Sequence enterSequence;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
button_Close?.onClick.AddListener(Close);
|
||||
@@ -36,6 +51,20 @@ public class ui_Panel_Setting : MonoBehaviour
|
||||
|
||||
toggle_Game.isOn = true;
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (playEnterAnimation)
|
||||
{
|
||||
PlayEnterAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
KillEnterAnimation();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Escape))
|
||||
@@ -43,8 +72,79 @@ public class ui_Panel_Setting : MonoBehaviour
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
||||
private void PlayEnterAnimation()
|
||||
{
|
||||
KillEnterAnimation();
|
||||
CacheEnterItems();
|
||||
if (enterItems.Count == 0)
|
||||
return;
|
||||
|
||||
enterSequence = DOTween.Sequence().SetUpdate(true);
|
||||
for (int i = 0; i < enterItems.Count; i++)
|
||||
{
|
||||
RectTransform rt = enterItems[i];
|
||||
CanvasGroup cg = enterGroups[i];
|
||||
Vector2 basePos = enterBasePos[i];
|
||||
|
||||
if (rt == null || cg == null)
|
||||
continue;
|
||||
|
||||
rt.DOKill();
|
||||
cg.DOKill();
|
||||
|
||||
rt.anchoredPosition = basePos - new Vector2(0f, Mathf.Abs(enterOffsetY));
|
||||
cg.alpha = 0f;
|
||||
|
||||
float start = i * Mathf.Max(0f, enterItemStagger);
|
||||
enterSequence.Insert(start,
|
||||
rt.DOAnchorPos(basePos, Mathf.Max(0.01f, enterItemDuration))
|
||||
.SetEase(enterEase)
|
||||
.SetUpdate(true));
|
||||
enterSequence.Insert(start,
|
||||
cg.DOFade(1f, Mathf.Max(0.01f, enterItemDuration))
|
||||
.SetEase(Ease.OutCubic)
|
||||
.SetUpdate(true));
|
||||
}
|
||||
}
|
||||
|
||||
private void CacheEnterItems()
|
||||
{
|
||||
enterItems.Clear();
|
||||
enterGroups.Clear();
|
||||
enterBasePos.Clear();
|
||||
|
||||
for (int i = 0; i < transform.childCount; i++)
|
||||
{
|
||||
Transform child = transform.GetChild(i);
|
||||
if (child == null || !child.gameObject.activeInHierarchy)
|
||||
continue;
|
||||
|
||||
RectTransform rt = child as RectTransform;
|
||||
if (rt == null)
|
||||
continue;
|
||||
|
||||
CanvasGroup cg = rt.GetComponent<CanvasGroup>();
|
||||
if (cg == null)
|
||||
cg = rt.gameObject.AddComponent<CanvasGroup>();
|
||||
|
||||
enterItems.Add(rt);
|
||||
enterGroups.Add(cg);
|
||||
enterBasePos.Add(rt.anchoredPosition);
|
||||
}
|
||||
}
|
||||
|
||||
private void KillEnterAnimation()
|
||||
{
|
||||
if (enterSequence != null)
|
||||
{
|
||||
enterSequence.Kill();
|
||||
enterSequence = null;
|
||||
}
|
||||
}
|
||||
|
||||
void Close()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user