改动与优化

This commit is contained in:
FloatGaming
2026-07-20 22:19:25 +08:00
parent 0a0872c4f4
commit b5d1cdcbc5
83 changed files with 2475 additions and 276 deletions
+15 -3
View File
@@ -59,7 +59,7 @@ class UI_Panel_Character : MonoBehaviour
{
if (Input.GetKeyDown(KeyCode.Escape))
{
gameObject.SetActive(false);
ClosePanel();
}
}
@@ -77,7 +77,7 @@ class UI_Panel_Character : MonoBehaviour
confirm_thisHero.onClick.AddListener(OnConfirmHeroClicked);
if (quitButton != null)
quitButton.onClick.AddListener(() => gameObject.SetActive(false));
quitButton.onClick.AddListener(ClosePanel);
if (Image_Character_Illustration != null)
{
@@ -126,6 +126,7 @@ class UI_Panel_Character : MonoBehaviour
for (int i = 0; i < allyHeroList.Count; i++)
{
var slotObject = Instantiate(button_Character_Slot_Prefab, content_Character_Slot);
UI_OrderedEntryAnimator.PlayFadeOnly(slotObject, i, 0.16f, 0.012f, true);
var displayPrefab = slotObject.GetComponent<uiui_character_displayPrefab>();
var slotButton = displayPrefab != null ? displayPrefab.characterProfileButton : slotObject.GetComponent<Button>();
if (slotButton == null && slotObject.transform.parent != null)
@@ -178,7 +179,7 @@ class UI_Panel_Character : MonoBehaviour
{
if (SaveCurrentCharacter(true))
{
gameObject.SetActive(false);
ClosePanel();
}
}
@@ -315,4 +316,15 @@ class UI_Panel_Character : MonoBehaviour
.SetLink(text_char_name.gameObject);
}
}
private void ClosePanel()
{
UI_PanelExitUtility.PlayExitThen(gameObject, () =>
{
if (gameObject != null)
{
gameObject.SetActive(false);
}
});
}
}
+13 -2
View File
@@ -38,7 +38,7 @@ class UI_Panel_Level : MonoBehaviour
{
if (Input.GetKeyDown(KeyCode.Escape))
{
gameObject.SetActive(false);
ClosePanel();
}
}
void Start()
@@ -60,4 +60,15 @@ class UI_Panel_Level : MonoBehaviour
//obj++;
//Text_Level.text = obj.ToString();
}
}
private void ClosePanel()
{
UI_PanelExitUtility.PlayExitThen(gameObject, () =>
{
if (gameObject != null)
{
gameObject.SetActive(false);
}
});
}
}
+100 -4
View File
@@ -53,6 +53,8 @@ public class UI_Panel_Mail : MonoBehaviour
mailSlotPrefab selectedSlot;
mail_so selectedMailData;
bool _mailServiceSubscribed;
Coroutine noticeSlotsLayoutRefreshRoutine;
Coroutine rewardSlotsLayoutRefreshRoutine;
public bool UsesServerMail => fetchMailsFromServer;
@@ -187,6 +189,7 @@ public class UI_Panel_Mail : MonoBehaviour
ShowMailDetails(null);
ShowMailRewards(null);
RefreshReceiveButton();
RequestNoticeSlotsLayoutRebuild();
return;
}
ApplySavedState(cachedMails);
@@ -209,6 +212,7 @@ public class UI_Panel_Mail : MonoBehaviour
var mail = mails[i];
if (mail == null) continue;
var go = Instantiate(noticeSlotPrefab, content_Notice_Slot);
UI_OrderedEntryAnimator.PlayFadeOnly(go, i, 0.18f, 0.012f, true);
var slot = go.GetComponent<mailSlotPrefab>();
if (selectedSlot == null) selectedSlot = slot;
if (slot != null)
@@ -239,7 +243,7 @@ public class UI_Panel_Mail : MonoBehaviour
}
}
LayoutRebuilder.ForceRebuildLayoutImmediate(content_Notice_Slot as RectTransform);
RequestNoticeSlotsLayoutRebuild();
if (selectedSlot != null && cachedMails != null)
{
for (int i = 0; i < cachedMails.Count; i++)
@@ -411,6 +415,7 @@ public class UI_Panel_Mail : MonoBehaviour
ShowMailRewards(mail);
OnMailRead(slot, mail);
RefreshReceiveButton();
PlayMailDetailsRefresh();
}
async void OnMailReceived(mailSlotPrefab slot, mail_so mail)
@@ -471,20 +476,105 @@ public class UI_Panel_Mail : MonoBehaviour
Destroy(content_Reward_Slot.GetChild(i).gameObject);
}
if (mail == null || mail.rewardList == null || mail.rewardList.Count == 0) return;
if (mail == null || mail.rewardList == null || mail.rewardList.Count == 0)
{
RequestRewardSlotsLayoutRebuild();
return;
}
for (int i = 0; i < mail.rewardList.Count; i++)
{
var reward = mail.rewardList[i];
if (reward == null) continue;
var go = Instantiate(rewardSlotPrefab, content_Reward_Slot);
UI_OrderedEntryAnimator.PlayFadeOnly(go, i, 0.16f, 0.02f, true);
var slot = go.GetComponent<rewardSlotPrefab>();
if (slot == null) continue;
slot.BindReward(reward);
if (slot.detailBtm != null) slot.detailBtm.SetActive(false);
}
LayoutRebuilder.ForceRebuildLayoutImmediate(content_Reward_Slot as RectTransform);
RequestRewardSlotsLayoutRebuild();
}
void RequestNoticeSlotsLayoutRebuild()
{
if (content_Notice_Slot == null)
{
return;
}
if (noticeSlotsLayoutRefreshRoutine != null)
{
StopCoroutine(noticeSlotsLayoutRefreshRoutine);
noticeSlotsLayoutRefreshRoutine = null;
}
if (isActiveAndEnabled)
{
noticeSlotsLayoutRefreshRoutine = StartCoroutine(RebuildNoticeSlotsLayoutNextFrame());
return;
}
RebuildLayoutNow(content_Notice_Slot);
}
void RequestRewardSlotsLayoutRebuild()
{
if (content_Reward_Slot == null)
{
return;
}
if (rewardSlotsLayoutRefreshRoutine != null)
{
StopCoroutine(rewardSlotsLayoutRefreshRoutine);
rewardSlotsLayoutRefreshRoutine = null;
}
if (isActiveAndEnabled)
{
rewardSlotsLayoutRefreshRoutine = StartCoroutine(RebuildRewardSlotsLayoutNextFrame());
return;
}
RebuildLayoutNow(content_Reward_Slot);
}
IEnumerator RebuildNoticeSlotsLayoutNextFrame()
{
yield return null;
RebuildLayoutNow(content_Notice_Slot);
noticeSlotsLayoutRefreshRoutine = null;
}
IEnumerator RebuildRewardSlotsLayoutNextFrame()
{
yield return null;
RebuildLayoutNow(content_Reward_Slot);
rewardSlotsLayoutRefreshRoutine = null;
}
void RebuildLayoutNow(Transform target)
{
RectTransform rect = target as RectTransform;
if (rect == null)
{
return;
}
Canvas.ForceUpdateCanvases();
LayoutRebuilder.ForceRebuildLayoutImmediate(rect);
Canvas.ForceUpdateCanvases();
}
void PlayMailDetailsRefresh()
{
GameObject target = null;
if (thisMail_title != null) target = thisMail_title.gameObject;
if (target == null && thisMail_body != null) target = thisMail_body.gameObject;
if (target == null && content_Reward_Slot != null) target = content_Reward_Slot.gameObject;
UI_OrderedEntryAnimator.PlayRefresh(target, 0.14f, -6f, 0.99f, true);
}
void SetSelectedSlot(mailSlotPrefab slot)
@@ -532,7 +622,13 @@ public class UI_Panel_Mail : MonoBehaviour
void CloseMailPanel()
{
gameObject.SetActive(false);
UI_PanelExitUtility.PlayExitThen(gameObject, () =>
{
if (gameObject != null)
{
gameObject.SetActive(false);
}
});
}
void RefreshReceiveButton()
+106 -30
View File
@@ -362,6 +362,7 @@ public class UI_Panel_Main : Singleton_Mono<UI_Panel_Main>
enterAnim.enabled = true;
}
panel.SetActive(true);
Ensure_Panel_Popup_If_Needed(panel);
RegisterManagedPanel(panel);
return true;
}
@@ -375,7 +376,7 @@ public class UI_Panel_Main : Singleton_Mono<UI_Panel_Main>
if (panel.activeSelf)
{
panel.SetActive(false);
ClosePanelWithExitAnim(panel);
return;
}
@@ -388,8 +389,9 @@ public class UI_Panel_Main : Singleton_Mono<UI_Panel_Main>
}
panel.SetActive(true);
Ensure_Panel_Popup_If_Needed(panel);
RegisterManagedPanel(panel);
}
}
GameObject Try_Open_Prefab(GameObject prefab, ref GameObject instance)
{
@@ -414,6 +416,7 @@ public class UI_Panel_Main : Singleton_Mono<UI_Panel_Main>
}
panel.SetActive(true);
Ensure_Panel_Popup_If_Needed(panel);
RegisterManagedPanel(panel);
}
@@ -431,7 +434,7 @@ public class UI_Panel_Main : Singleton_Mono<UI_Panel_Main>
{
if (panel != null)
{
panel.SetActive(false);
ClosePanelWithExitAnim(panel);
}
return true;
@@ -473,6 +476,40 @@ public class UI_Panel_Main : Singleton_Mono<UI_Panel_Main>
rect.DOScale(Vector3.one, prefab_Enter_Time).SetEase(prefab_Enter_Ease);
cg.DOFade(1f, prefab_Enter_Time).SetEase(prefab_Enter_Ease);
}
void Ensure_Panel_Popup_If_Needed(GameObject panel)
{
if (panel == null || panel == ui_Panel_Setting)
{
return;
}
if (panel.GetComponent<UI_SettingsPanelEnterAnim>() != null)
{
return;
}
UI_PanelPopupTween tween = panel.GetComponent<UI_PanelPopupTween>();
if (tween == null)
{
panel.AddComponent<UI_PanelPopupTween>();
}
}
void ClosePanelWithExitAnim(GameObject panel)
{
if (panel == null)
{
return;
}
UI_PanelExitUtility.PlayExitThen(panel, () =>
{
if (panel != null)
{
panel.SetActive(false);
}
});
}
void Try_Load_Select_Scene()
{
if (selectScene_Loading)
@@ -1499,14 +1536,20 @@ public class UI_Panel_Main : Singleton_Mono<UI_Panel_Main>
{
continue;
}
if (cached_Pos.TryGetValue(rect, out Vector2 pos))
{
rect.anchoredPosition = pos;
}
if (cached_Scale.TryGetValue(rect, out Vector3 scale))
{
rect.localScale = scale;
}
if (cached_Pos.TryGetValue(rect, out Vector2 pos))
{
if (!UI_OrderedEntryAnimator.IsLayoutSensitive(rect))
{
rect.anchoredPosition = pos;
}
}
if (cached_Scale.TryGetValue(rect, out Vector3 scale))
{
if (!UI_OrderedEntryAnimator.IsLayoutSensitive(rect))
{
rect.localScale = scale;
}
}
if (cached_RotationZ.TryGetValue(rect, out float rotZ))
{
Vector3 euler = rect.localEulerAngles;
@@ -1516,19 +1559,23 @@ public class UI_Panel_Main : Singleton_Mono<UI_Panel_Main>
}
if (group_Top != null)
{
group_Top.anchoredPosition = pos_Top + Vector2.up * enter_Offset_Y;
if (!UI_OrderedEntryAnimator.IsLayoutSensitive(group_Top))
group_Top.anchoredPosition = pos_Top + Vector2.up * enter_Offset_Y;
}
if (group_Bottom != null)
{
group_Bottom.anchoredPosition = pos_Bottom - Vector2.up * enter_Offset_Y;
if (!UI_OrderedEntryAnimator.IsLayoutSensitive(group_Bottom))
group_Bottom.anchoredPosition = pos_Bottom - Vector2.up * enter_Offset_Y;
}
if (group_DailyTasks != null)
{
group_DailyTasks.anchoredPosition = pos_Daily + Vector2.left * enter_Offset_X;
if (!UI_OrderedEntryAnimator.IsLayoutSensitive(group_DailyTasks))
group_DailyTasks.anchoredPosition = pos_Daily + Vector2.left * enter_Offset_X;
}
if (group_StartButton != null)
{
group_StartButton.anchoredPosition = pos_Start;
if (!UI_OrderedEntryAnimator.IsLayoutSensitive(group_StartButton))
group_StartButton.anchoredPosition = pos_Start;
}
for (int i = 0; i < top_Items.Count; i++)
@@ -1644,15 +1691,18 @@ public class UI_Panel_Main : Singleton_Mono<UI_Panel_Main>
if (group_Top != null)
{
enter_Sequence.Insert(uiStart, group_Top.DOAnchorPos(pos_Top, enter_Bar_Time_Runtime).SetEase(enter_Move_Ease));
if (!UI_OrderedEntryAnimator.IsLayoutSensitive(group_Top))
enter_Sequence.Insert(uiStart, group_Top.DOAnchorPos(pos_Top, enter_Bar_Time_Runtime).SetEase(enter_Move_Ease));
}
if (group_Bottom != null)
{
enter_Sequence.Insert(uiStart, group_Bottom.DOAnchorPos(pos_Bottom, enter_Bar_Time_Runtime).SetEase(enter_Move_Ease));
if (!UI_OrderedEntryAnimator.IsLayoutSensitive(group_Bottom))
enter_Sequence.Insert(uiStart, group_Bottom.DOAnchorPos(pos_Bottom, enter_Bar_Time_Runtime).SetEase(enter_Move_Ease));
}
if (group_DailyTasks != null)
{
enter_Sequence.Insert(uiStart, group_DailyTasks.DOAnchorPos(pos_Daily, enter_Bar_Time_Runtime).SetEase(enter_Move_Ease));
if (!UI_OrderedEntryAnimator.IsLayoutSensitive(group_DailyTasks))
enter_Sequence.Insert(uiStart, group_DailyTasks.DOAnchorPos(pos_Daily, enter_Bar_Time_Runtime).SetEase(enter_Move_Ease));
}
float topItemsStart = uiStart + enter_Bar_Time_Runtime * 0.6f;
@@ -1837,11 +1887,13 @@ public class UI_Panel_Main : Singleton_Mono<UI_Panel_Main>
if (group_Top != null)
{
group_Top.anchoredPosition = pos_Top + Vector2.up * enter_Offset_Y;
if (!UI_OrderedEntryAnimator.IsLayoutSensitive(group_Top))
group_Top.anchoredPosition = pos_Top + Vector2.up * enter_Offset_Y;
}
if (group_Bottom != null)
{
group_Bottom.anchoredPosition = pos_Bottom - Vector2.up * enter_Offset_Y;
if (!UI_OrderedEntryAnimator.IsLayoutSensitive(group_Bottom))
group_Bottom.anchoredPosition = pos_Bottom - Vector2.up * enter_Offset_Y;
}
for (int i = 0; i < top_Items.Count; i++)
@@ -1865,7 +1917,8 @@ public class UI_Panel_Main : Singleton_Mono<UI_Panel_Main>
bars_Sequence.SetUpdate(true);
bars_Sequence.SetAutoKill(false);
bars_Sequence.OnKill(() => bars_Sequence = null);
bars_Sequence.Append(group_Top.DOAnchorPos(pos_Top, enter_Bar_Time_Runtime).SetEase(enter_Move_Ease));
if (!UI_OrderedEntryAnimator.IsLayoutSensitive(group_Top))
bars_Sequence.Append(group_Top.DOAnchorPos(pos_Top, enter_Bar_Time_Runtime).SetEase(enter_Move_Ease));
float topItemsStart = bars_Sequence.Duration();
for (int i = 0; i < top_Items.Count; i++)
@@ -1886,7 +1939,8 @@ public class UI_Panel_Main : Singleton_Mono<UI_Panel_Main>
}
float bottomStart = topItemsStart + enter_Bar_Time_Runtime * 0.5f;
bars_Sequence.Insert(bottomStart, group_Bottom.DOAnchorPos(pos_Bottom, enter_Bar_Time_Runtime).SetEase(enter_Move_Ease));
if (!UI_OrderedEntryAnimator.IsLayoutSensitive(group_Bottom))
bars_Sequence.Insert(bottomStart, group_Bottom.DOAnchorPos(pos_Bottom, enter_Bar_Time_Runtime).SetEase(enter_Move_Ease));
float bottomItemsStart = bottomStart + enter_Bar_Time_Runtime;
for (int i = 0; i < bottomItems.Count; i++)
@@ -1911,6 +1965,10 @@ public class UI_Panel_Main : Singleton_Mono<UI_Panel_Main>
{
continue;
}
if (UI_OrderedEntryAnimator.IsLayoutSensitive(rect))
{
continue;
}
if (!cached_Pos.TryGetValue(rect, out Vector2 origin))
{
origin = rect.anchoredPosition;
@@ -1946,11 +2004,13 @@ public class UI_Panel_Main : Singleton_Mono<UI_Panel_Main>
}
if (cached_Pos.TryGetValue(rect, out Vector2 pos))
{
rect.anchoredPosition = pos;
if (!UI_OrderedEntryAnimator.IsLayoutSensitive(rect))
rect.anchoredPosition = pos;
}
if (cached_Scale.TryGetValue(rect, out Vector3 scale))
{
rect.localScale = scale;
if (!UI_OrderedEntryAnimator.IsLayoutSensitive(rect))
rect.localScale = scale;
}
if (cached_RotationZ.TryGetValue(rect, out float rotZ))
{
@@ -2053,8 +2113,11 @@ public class UI_Panel_Main : Singleton_Mono<UI_Panel_Main>
float rotate = Mathf.Lerp(-bg_Deco_Rotate, bg_Deco_Rotate, Hash01(seed, 3));
float scaleMul = Mathf.Lerp(bg_Deco_Scale_From, bg_Deco_Scale_From + 0.15f, Hash01(seed, 4));
rect.anchoredPosition = cached_Pos[rect] + new Vector2(offsetX, offsetY);
rect.localScale = cached_Scale[rect] * Mathf.Max(0.01f, scaleMul);
if (!UI_OrderedEntryAnimator.IsLayoutSensitive(rect))
{
rect.anchoredPosition = cached_Pos[rect] + new Vector2(offsetX, offsetY);
rect.localScale = cached_Scale[rect] * Mathf.Max(0.01f, scaleMul);
}
Vector3 euler = rect.localEulerAngles;
euler.z = cached_RotationZ[rect] + rotate;
rect.localEulerAngles = euler;
@@ -2079,11 +2142,13 @@ public class UI_Panel_Main : Singleton_Mono<UI_Panel_Main>
}
if (cached_Pos.TryGetValue(rect, out Vector2 targetPos))
{
sequence.Insert(at, rect.DOAnchorPos(targetPos, bg_Deco_Time_Runtime).SetEase(bg_Deco_Ease));
if (!UI_OrderedEntryAnimator.IsLayoutSensitive(rect))
sequence.Insert(at, rect.DOAnchorPos(targetPos, bg_Deco_Time_Runtime).SetEase(bg_Deco_Ease));
}
if (cached_Scale.TryGetValue(rect, out Vector3 targetScale))
{
sequence.Insert(at, rect.DOScale(targetScale, bg_Deco_Time_Runtime).SetEase(bg_Deco_Ease));
if (!UI_OrderedEntryAnimator.IsLayoutSensitive(rect))
sequence.Insert(at, rect.DOScale(targetScale, bg_Deco_Time_Runtime).SetEase(bg_Deco_Ease));
}
if (cached_RotationZ.TryGetValue(rect, out float targetRotZ))
{
@@ -2101,7 +2166,10 @@ public class UI_Panel_Main : Singleton_Mono<UI_Panel_Main>
return;
}
Cache_Pos(rect);
rect.anchoredPosition = cached_Pos[rect] + offset;
if (!UI_OrderedEntryAnimator.IsLayoutSensitive(rect))
{
rect.anchoredPosition = cached_Pos[rect] + offset;
}
if (fade)
{
CanvasGroup group = Ensure_CanvasGroup(rect.gameObject);
@@ -2127,12 +2195,16 @@ public class UI_Panel_Main : Singleton_Mono<UI_Panel_Main>
{
return;
}
bool layoutSensitive = UI_OrderedEntryAnimator.IsLayoutSensitive(rect);
if (!cached_Pos.TryGetValue(rect, out Vector2 target))
{
target = rect.anchoredPosition;
}
float duration = enter_Item_Time_Runtime > 0f ? enter_Item_Time_Runtime : enter_Item_Time;
sequence.Insert(at, rect.DOAnchorPos(target, duration).SetEase(enter_Move_Ease));
if (!layoutSensitive)
{
sequence.Insert(at, rect.DOAnchorPos(target, duration).SetEase(enter_Move_Ease));
}
if (rect.TryGetComponent(out CanvasGroup group))
{
sequence.Insert(at, group.DOFade(1f, duration).SetEase(enter_Move_Ease));
@@ -2957,6 +3029,10 @@ public class UI_Panel_Main : Singleton_Mono<UI_Panel_Main>
{
continue;
}
if (UI_OrderedEntryAnimator.IsLayoutSensitive(rect))
{
continue;
}
Vector2 pos = rect.anchoredPosition;
pos.y += delta;
rect.anchoredPosition = pos;
+11 -2
View File
@@ -41,7 +41,7 @@ public class UI_Panel_Note : MonoBehaviour
{
if (Input.GetKeyDown(KeyCode.Escape))
{
gameObject.SetActive(false);
Close();
}
}
private void Awake()
@@ -51,7 +51,13 @@ public class UI_Panel_Note : MonoBehaviour
}
void Close()
{
gameObject.SetActive(false);
UI_PanelExitUtility.PlayExitThen(gameObject, () =>
{
if (gameObject != null)
{
gameObject.SetActive(false);
}
});
}
private void Start()
{
@@ -170,6 +176,7 @@ public class UI_Panel_Note : MonoBehaviour
Character_Data_SO item = data_List[i];
UI_Button_Character btn = null;
btn = Add_Select_Button(item, type_Index >= 2);
UI_OrderedEntryAnimator.PlayFadeOnly(btn.gameObject, i, 0.16f, 0.014f, true);
if (i == 0)
{
btn.Init();
@@ -217,6 +224,7 @@ public class UI_Panel_Note : MonoBehaviour
text_Only.gameObject.SetActive(true);
transform_Description_Content.gameObject.SetActive(false);
text_Only.text = item.data.personalityDescription;
UI_OrderedEntryAnimator.PlayRefresh(text_Only.gameObject, 0.14f, -6f, 0.99f, true);
}
public void Set_Character_Description(Character_Data_SO item)
{
@@ -235,5 +243,6 @@ public class UI_Panel_Note : MonoBehaviour
text_Character_Data.text = data.data.registrationDate;
text_Character_Description.text = data.data.personalityDescription;
scrollbar_Character_Description.value = 1;
UI_OrderedEntryAnimator.PlayRefresh(transform_Description_Content.gameObject, 0.14f, -6f, 0.99f, true);
}
}
+13 -2
View File
@@ -23,7 +23,7 @@ class UI_Panel_Notice : MonoBehaviour
{
if (Input.GetKeyDown(KeyCode.Escape))
{
gameObject.SetActive(false);
ClosePanel();
}
}
void Start()
@@ -48,4 +48,15 @@ class UI_Panel_Notice : MonoBehaviour
}
}
}
private void ClosePanel()
{
UI_PanelExitUtility.PlayExitThen(gameObject, () =>
{
if (gameObject != null)
{
gameObject.SetActive(false);
}
});
}
}
+50 -6
View File
@@ -23,6 +23,7 @@ public class ui_Panel_Setting : MonoBehaviour
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 readonly List<bool> enterRestoreTransform = new List<bool>();
private Sequence enterSequence;
private void Awake()
@@ -86,6 +87,7 @@ public class ui_Panel_Setting : MonoBehaviour
RectTransform rt = enterItems[i];
CanvasGroup cg = enterGroups[i];
Vector2 basePos = enterBasePos[i];
bool restoreTransform = i < enterRestoreTransform.Count && enterRestoreTransform[i];
if (rt == null || cg == null)
continue;
@@ -93,19 +95,28 @@ public class ui_Panel_Setting : MonoBehaviour
rt.DOKill();
cg.DOKill();
rt.anchoredPosition = basePos - new Vector2(0f, Mathf.Abs(enterOffsetY));
if (restoreTransform)
{
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));
if (restoreTransform)
{
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));
}
enterSequence.OnKill(RestoreEnterAnimationState);
enterSequence.OnComplete(RestoreEnterAnimationState);
}
private void CacheEnterItems()
@@ -113,6 +124,7 @@ public class ui_Panel_Setting : MonoBehaviour
enterItems.Clear();
enterGroups.Clear();
enterBasePos.Clear();
enterRestoreTransform.Clear();
for (int i = 0; i < transform.childCount; i++)
{
@@ -131,6 +143,7 @@ public class ui_Panel_Setting : MonoBehaviour
enterItems.Add(rt);
enterGroups.Add(cg);
enterBasePos.Add(rt.anchoredPosition);
enterRestoreTransform.Add(!UI_OrderedEntryAnimator.IsLayoutSensitive(rt));
}
}
@@ -143,8 +156,39 @@ public class ui_Panel_Setting : MonoBehaviour
}
}
private void RestoreEnterAnimationState()
{
for (int i = 0; i < enterItems.Count; i++)
{
RectTransform rt = enterItems[i];
CanvasGroup cg = i < enterGroups.Count ? enterGroups[i] : null;
bool restoreTransform = i < enterRestoreTransform.Count && enterRestoreTransform[i];
if (rt != null)
{
rt.DOKill();
if (restoreTransform && i < enterBasePos.Count)
{
rt.anchoredPosition = enterBasePos[i];
}
}
if (cg != null)
{
cg.DOKill();
cg.alpha = 1f;
}
}
}
void Close()
{
gameObject.SetActive(false);
UI_PanelExitUtility.PlayExitThen(gameObject, () =>
{
if (gameObject != null)
{
gameObject.SetActive(false);
}
});
}
}
+8 -2
View File
@@ -17,6 +17,12 @@ public class UI_Panel_Story : MonoBehaviour
}
void Close()
{
gameObject.SetActive(false);
UI_PanelExitUtility.PlayExitThen(gameObject, () =>
{
if (gameObject != null)
{
gameObject.SetActive(false);
}
});
}
}
}
@@ -0,0 +1,125 @@
using System;
using System.Collections.Generic;
using DG.Tweening;
using UnityEngine;
public static class UI_PanelExitUtility
{
private const float FallbackExitDuration = 0.16f;
private const float FallbackExitScale = 0.96f;
private static readonly HashSet<GameObject> ExitingPanels = new HashSet<GameObject>();
public static bool PlayExitThen(GameObject panel, Action onComplete)
{
if (panel == null || !panel.activeInHierarchy)
{
onComplete?.Invoke();
return false;
}
if (ExitingPanels.Contains(panel))
{
return true;
}
ExitingPanels.Add(panel);
bool completed = false;
Action safeComplete = () =>
{
if (completed)
{
return;
}
completed = true;
ExitingPanels.Remove(panel);
onComplete?.Invoke();
};
DOVirtual.DelayedCall(2.5f, () => safeComplete(), true);
UI_SettingsPanelEnterAnim settingsAnim = panel.GetComponent<UI_SettingsPanelEnterAnim>();
if (settingsAnim != null && settingsAnim.enabled)
{
settingsAnim.PlayExitThen(safeComplete);
return true;
}
UI_PanelPopupTween popupTween = panel.GetComponent<UI_PanelPopupTween>();
if (popupTween != null && popupTween.enabled)
{
popupTween.PlayExitThen(safeComplete);
return true;
}
return PlayFallbackExitThen(panel, safeComplete);
}
private static bool PlayFallbackExitThen(GameObject panel, Action onComplete)
{
RectTransform rect = panel != null ? panel.transform as RectTransform : null;
CanvasGroup group = panel != null ? panel.GetComponent<CanvasGroup>() : null;
if (rect == null && group == null)
{
onComplete?.Invoke();
return false;
}
if (group == null)
{
group = panel.AddComponent<CanvasGroup>();
}
Vector3 baseScale = rect != null ? rect.localScale : Vector3.one;
float baseAlpha = group.alpha;
float duration = Mathf.Max(0.01f, FallbackExitDuration);
bool canScale = rect == null || !UI_OrderedEntryAnimator.IsLayoutSensitive(rect);
if (rect != null)
{
rect.DOKill();
}
group.DOKill();
group.interactable = false;
group.blocksRaycasts = false;
Sequence seq = DOTween.Sequence().SetUpdate(true);
if (rect != null && canScale)
{
seq.Join(rect.DOScale(baseScale * FallbackExitScale, duration).SetEase(Ease.InCubic));
}
seq.Join(group.DOFade(0f, duration).SetEase(Ease.InCubic));
bool restored = false;
Action restore = () =>
{
if (restored)
{
return;
}
restored = true;
if (rect != null && canScale)
{
rect.localScale = baseScale;
}
if (group != null)
{
group.alpha = baseAlpha;
group.interactable = true;
group.blocksRaycasts = true;
}
};
seq.OnComplete(() =>
{
restore();
onComplete?.Invoke();
});
seq.OnKill(() => restore());
return true;
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 0f3638fba040b34429d7d54c473508b5
@@ -0,0 +1,199 @@
using DG.Tweening;
using UnityEngine;
[DisallowMultipleComponent]
public class UI_PanelPopupTween : MonoBehaviour
{
[SerializeField] private RectTransform moveTarget;
[SerializeField] private CanvasGroup fadeTarget;
[SerializeField] private bool playOnEnable = true;
[SerializeField] private float enterDuration = 0.2f;
[SerializeField] private float exitDuration = 0.16f;
[SerializeField] private float fromOffsetY = 24f;
[SerializeField] private float scaleFrom = 0.96f;
[SerializeField] private Ease enterEase = Ease.OutCubic;
[SerializeField] private Ease exitEase = Ease.InCubic;
[SerializeField] private bool useUnscaledTime = true;
private Sequence enterSequence;
private bool baseCached;
private Vector2 basePos;
private Vector3 baseScale;
private void Awake()
{
AutoWire();
CacheBaseState();
}
private void OnEnable()
{
if (playOnEnable)
{
Play();
}
}
private void OnDisable()
{
KillTween();
ResetToBase();
}
public void Play()
{
AutoWire();
CacheBaseState();
if (moveTarget == null || fadeTarget == null)
{
return;
}
KillTween();
Vector2 fromPos = basePos + new Vector2(0f, -Mathf.Abs(fromOffsetY));
bool canAnimateTransform = !UI_OrderedEntryAnimator.IsLayoutSensitive(moveTarget);
if (canAnimateTransform)
{
moveTarget.anchoredPosition = fromPos;
moveTarget.localScale = baseScale * Mathf.Max(0.01f, scaleFrom);
}
fadeTarget.alpha = 0f;
fadeTarget.interactable = false;
fadeTarget.blocksRaycasts = false;
float duration = Mathf.Max(0.01f, enterDuration);
enterSequence = DOTween.Sequence().SetUpdate(useUnscaledTime);
if (canAnimateTransform)
{
enterSequence.Join(moveTarget.DOAnchorPos(basePos, duration).SetEase(enterEase));
enterSequence.Join(moveTarget.DOScale(baseScale, duration).SetEase(enterEase));
}
enterSequence.Join(fadeTarget.DOFade(1f, duration).SetEase(Ease.OutCubic));
enterSequence.OnComplete(() =>
{
fadeTarget.interactable = true;
fadeTarget.blocksRaycasts = true;
enterSequence = null;
});
enterSequence.OnKill(() =>
{
ResetToBase();
enterSequence = null;
});
}
public void PlayExitThen(System.Action onComplete)
{
AutoWire();
CacheBaseState();
if (moveTarget == null || fadeTarget == null)
{
onComplete?.Invoke();
return;
}
KillTween();
fadeTarget.interactable = false;
fadeTarget.blocksRaycasts = false;
Vector2 targetPos = basePos + new Vector2(0f, -Mathf.Abs(fromOffsetY));
Vector3 targetScale = baseScale * Mathf.Max(0.01f, scaleFrom);
float duration = Mathf.Max(0.01f, exitDuration);
bool canAnimateTransform = !UI_OrderedEntryAnimator.IsLayoutSensitive(moveTarget);
enterSequence = DOTween.Sequence().SetUpdate(useUnscaledTime);
if (canAnimateTransform)
{
enterSequence.Join(moveTarget.DOAnchorPos(targetPos, duration).SetEase(exitEase));
enterSequence.Join(moveTarget.DOScale(targetScale, duration).SetEase(exitEase));
}
enterSequence.Join(fadeTarget.DOFade(0f, duration).SetEase(Ease.InCubic));
enterSequence.OnComplete(() =>
{
enterSequence = null;
ResetToBase();
onComplete?.Invoke();
});
enterSequence.OnKill(() =>
{
ResetToBase();
enterSequence = null;
});
}
private void AutoWire()
{
if (moveTarget == null)
{
moveTarget = transform as RectTransform;
if (moveTarget == null)
{
moveTarget = GetComponentInChildren<RectTransform>(true);
}
}
if (fadeTarget == null)
{
fadeTarget = GetComponent<CanvasGroup>();
}
if (fadeTarget == null)
{
fadeTarget = gameObject.AddComponent<CanvasGroup>();
}
}
private void CacheBaseState()
{
if (moveTarget == null || baseCached)
{
return;
}
basePos = moveTarget.anchoredPosition;
baseScale = moveTarget.localScale;
baseCached = true;
}
private void ResetToBase()
{
if (moveTarget != null && baseCached)
{
if (!UI_OrderedEntryAnimator.IsLayoutSensitive(moveTarget))
{
moveTarget.anchoredPosition = basePos;
moveTarget.localScale = baseScale;
}
}
if (fadeTarget != null)
{
fadeTarget.alpha = 1f;
fadeTarget.interactable = true;
fadeTarget.blocksRaycasts = true;
}
}
private void KillTween()
{
if (enterSequence != null)
{
enterSequence.Kill();
enterSequence = null;
}
if (moveTarget != null)
{
moveTarget.DOKill();
}
if (fadeTarget != null)
{
fadeTarget.DOKill();
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 684368a613daac84599aaf0ef6b4c77a
@@ -8,8 +8,10 @@ public class UI_SettingsPanelEnterAnim : MonoBehaviour
[SerializeField] private CanvasGroup fadeTarget;
[SerializeField] private bool playOnEnable = true;
[SerializeField] private float enterDuration = 0.3f;
[SerializeField] private float exitDuration = 0.18f;
[SerializeField] private float fromOffsetY = 32f;
[SerializeField] private Ease enterEase = Ease.OutCubic;
[SerializeField] private Ease exitEase = Ease.InCubic;
[SerializeField] private bool useUnscaledTime = true;
private Sequence enterSequence;
@@ -44,13 +46,20 @@ public class UI_SettingsPanelEnterAnim : MonoBehaviour
KillTween();
moveTarget.anchoredPosition = basePos - new Vector2(0f, Mathf.Abs(fromOffsetY));
bool canAnimateTransform = !UI_OrderedEntryAnimator.IsLayoutSensitive(moveTarget);
if (canAnimateTransform)
{
moveTarget.anchoredPosition = basePos - new Vector2(0f, Mathf.Abs(fromOffsetY));
}
fadeTarget.alpha = 0f;
fadeTarget.interactable = false;
fadeTarget.blocksRaycasts = false;
enterSequence = DOTween.Sequence().SetUpdate(useUnscaledTime);
enterSequence.Join(moveTarget.DOAnchorPos(basePos, Mathf.Max(0.01f, enterDuration)).SetEase(enterEase));
if (canAnimateTransform)
{
enterSequence.Join(moveTarget.DOAnchorPos(basePos, Mathf.Max(0.01f, enterDuration)).SetEase(enterEase));
}
enterSequence.Join(fadeTarget.DOFade(1f, Mathf.Max(0.01f, enterDuration)).SetEase(Ease.OutCubic));
enterSequence.OnComplete(() =>
{
@@ -58,6 +67,50 @@ public class UI_SettingsPanelEnterAnim : MonoBehaviour
fadeTarget.blocksRaycasts = true;
enterSequence = null;
});
enterSequence.OnKill(() =>
{
ResetToBase();
enterSequence = null;
});
}
public void PlayExitThen(System.Action onComplete)
{
AutoWire();
CacheBasePos();
if (moveTarget == null || fadeTarget == null)
{
onComplete?.Invoke();
return;
}
KillTween();
fadeTarget.interactable = false;
fadeTarget.blocksRaycasts = false;
Vector2 targetPos = basePos - new Vector2(0f, Mathf.Abs(fromOffsetY));
float duration = Mathf.Max(0.01f, exitDuration);
bool canAnimateTransform = !UI_OrderedEntryAnimator.IsLayoutSensitive(moveTarget);
enterSequence = DOTween.Sequence().SetUpdate(useUnscaledTime);
if (canAnimateTransform)
{
enterSequence.Join(moveTarget.DOAnchorPos(targetPos, duration).SetEase(exitEase));
}
enterSequence.Join(fadeTarget.DOFade(0f, duration).SetEase(Ease.InCubic));
enterSequence.OnComplete(() =>
{
enterSequence = null;
ResetToBase();
onComplete?.Invoke();
});
enterSequence.OnKill(() =>
{
ResetToBase();
enterSequence = null;
});
}
private void AutoWire()
@@ -90,7 +143,10 @@ public class UI_SettingsPanelEnterAnim : MonoBehaviour
private void ResetToBase()
{
if (moveTarget != null && basePosCached)
moveTarget.anchoredPosition = basePos;
{
if (!UI_OrderedEntryAnimator.IsLayoutSensitive(moveTarget))
moveTarget.anchoredPosition = basePos;
}
if (fadeTarget != null)
{
@@ -1027,13 +1027,7 @@ public class btmandtopController : MonoBehaviour, ICancelHandler
settingsInstance.SetActive(true);
EnsureSettingsLastSibling();
RegisterManagedPanel(settingsInstance, () =>
{
if (settingsInstance != null)
{
settingsInstance.SetActive(false);
}
});
RegisterManagedPanel(settingsInstance, CloseSettingsWithExitAnim);
NotifyManagedPanelVisibilityChanged(true);
return;
}
@@ -1043,23 +1037,41 @@ public class btmandtopController : MonoBehaviour, ICancelHandler
settingsInstance.transform.SetParent(GetSettingsParentTransform(), false);
EnsureSettingsLastSibling();
// Toggle active state
bool active = settingsInstance.activeSelf;
settingsInstance.SetActive(!active);
if (active)
{
CloseSettingsWithExitAnim();
return;
}
settingsInstance.SetActive(true);
if (settingsInstance.activeSelf)
{
EnsureSettingsLastSibling();
RegisterManagedPanel(settingsInstance, () =>
{
if (settingsInstance != null)
{
settingsInstance.SetActive(false);
}
});
RegisterManagedPanel(settingsInstance, CloseSettingsWithExitAnim);
}
NotifyManagedPanelVisibilityChanged(true);
}
private void CloseSettingsWithExitAnim()
{
if (settingsInstance == null)
{
NotifyManagedPanelVisibilityChanged(true);
return;
}
UI_PanelExitUtility.PlayExitThen(settingsInstance, () =>
{
if (settingsInstance != null)
{
settingsInstance.SetActive(false);
}
NotifyManagedPanelVisibilityChanged(true);
});
}
public bool IsSettingsPanelVisible
{
get { return settingsInstance != null && settingsInstance.activeInHierarchy; }
@@ -1201,8 +1213,7 @@ public class btmandtopController : MonoBehaviour, ICancelHandler
return;
}
instance.SetActive(false);
BroadcastOverlayPanelsVisibility();
CloseManagedOverlayWithExitAnim(instance);
}
private bool ToggleIfAlreadyOpen(ref GameObject instance)
@@ -1217,8 +1228,7 @@ public class btmandtopController : MonoBehaviour, ICancelHandler
return false;
}
instance.SetActive(false);
BroadcastOverlayPanelsVisibility();
CloseManagedOverlayWithExitAnim(instance);
return true;
}
@@ -1250,12 +1260,34 @@ public class btmandtopController : MonoBehaviour, ICancelHandler
}
AttachManagedPanelVisibilityRelay(instance, false);
EnsurePanelPopupTween(instance);
TryAssignCanvasCamera(instance);
BroadcastOverlayPanelsVisibility();
EnsureTopNavigationFront();
return true;
}
private UI_PanelPopupTween EnsurePanelPopupTween(GameObject instance)
{
if (instance == null)
{
return null;
}
if (instance.GetComponent<UI_SettingsPanelEnterAnim>() != null)
{
return null;
}
UI_PanelPopupTween popupTween = instance.GetComponent<UI_PanelPopupTween>();
if (popupTween == null)
{
popupTween = instance.AddComponent<UI_PanelPopupTween>();
}
return popupTween;
}
private void EnsureSettingsLastSibling()
{
if (settingsInstance == null || GetSettingsParentTransform() == null)
@@ -1296,8 +1328,25 @@ public class btmandtopController : MonoBehaviour, ICancelHandler
private void CloseInstance(ref GameObject instance, GameObject keep)
{
if (instance == null || instance == keep) return;
instance.SetActive(false);
BroadcastOverlayPanelsVisibility();
CloseManagedOverlayWithExitAnim(instance);
}
private void CloseManagedOverlayWithExitAnim(GameObject instance)
{
if (instance == null)
{
return;
}
UI_PanelExitUtility.PlayExitThen(instance, () =>
{
if (instance != null)
{
instance.SetActive(false);
}
BroadcastOverlayPanelsVisibility();
});
}
private GameObject FindExistingInstance(GameObject prefab)
+17 -3
View File
@@ -15,7 +15,20 @@ public class MusicPlayer : MonoBehaviour
public Button Button_List;
public Slider Slider_Progress;
public Music_Data Music_Data => Music_Mgr.Singleton.Music_Cur;
public static AudioSource Music_Source => Music_Mgr.Singleton.AudioSource;
public static AudioSource Music_Source
{
get
{
BgmPlaybackManager bgm = BgmPlaybackManager.Instance;
if (bgm != null && bgm.audioSource != null)
{
return bgm.audioSource;
}
Music_Mgr manager = Music_Mgr.Singleton;
return manager != null ? manager.AudioSource : null;
}
}
private void Start()
{
if (Music_Data != null)
@@ -32,10 +45,11 @@ public class MusicPlayer : MonoBehaviour
private void Update()
{
if (Music_Source.clip != null)
AudioSource source = Music_Source;
if (source != null && source.clip != null)
{
_sb.Clear();
_sb.Append(Music_Mgr.Get_Time_Cur(Music_Source)).Append("/").Append(Music_Mgr.Get_Time_Max(Music_Source.clip));
_sb.Append(Music_Mgr.Get_Time_Cur(source)).Append("/").Append(Music_Mgr.Get_Time_Max(source.clip));
Text_Time.text = _sb.ToString();
}
}
+44 -1
View File
@@ -113,16 +113,30 @@ public class Music_Mgr : Singleton_Mono<Music_Mgr>
public void Play(Music_Data data)
{
if (data == null) return;
Music_Cur = data;
if (!ShouldPlayInScene(SceneManager.GetActiveScene().name))
{
StopMusicPlayback();
return;
}
Music_Cur = data;
if (TryPlayThroughBgmManager(data, true))
{
StopMusicPlayback();
RefreshPlayers(data);
return;
}
AudioSource.clip = data.Clip;
AudioSource.Play();
RefreshPlayers(data);
}
private void RefreshPlayers(Music_Data data)
{
var players = Object.FindObjectsByType<MusicPlayer>(FindObjectsInactive.Include, FindObjectsSortMode.None);
foreach (var player in players)
{
@@ -176,6 +190,18 @@ public class Music_Mgr : Singleton_Mono<Music_Mgr>
return;
}
if (Music_Cur == null && Music_Data_List != null && Music_Data_List.Count > 0)
{
Music_Cur = Music_Data_List[0];
}
if (Music_Cur != null && TryPlayThroughBgmManager(Music_Cur, false))
{
StopMusicPlayback();
RefreshPlayers(Music_Cur);
return;
}
if (AudioSource != null && !AudioSource.isPlaying)
{
if (Music_Cur != null)
@@ -196,4 +222,21 @@ public class Music_Mgr : Singleton_Mono<Music_Mgr>
AudioSource.Stop();
}
}
private bool TryPlayThroughBgmManager(Music_Data data, bool restart)
{
if (data == null || data.Clip == null)
{
return false;
}
BgmPlaybackManager bgm = BgmPlaybackManager.Instance;
if (bgm == null)
{
return false;
}
bgm.PlayExternalClip(data.Clip, restart);
return true;
}
}
@@ -26,7 +26,7 @@ public class UI_Panel_Music : MonoBehaviour
{
if (Input.GetKeyDown(KeyCode.Escape))
{
gameObject.SetActive(false);
ClosePanel();
}
}
private void Start()
@@ -57,12 +57,21 @@ public class UI_Panel_Music : MonoBehaviour
music_Data_List = Get_Music_Page(index);
foreach (var item in music_Data_List)
for (int i = 0; i < music_Data_List.Count; i++)
{
var item = music_Data_List[i];
var slot = Instantiate(prefab_Music_Slot, group_Music.transform);
UISystemBootstrap.RegisterHierarchy(slot.gameObject);
slot.Refresh(item);
music_Slot_List.Add(slot);
UI_OrderedEntryAnimator.PlayFadeOnly(slot.gameObject, i, 0.16f, 0.018f, true);
}
if (group_Music != null)
{
Canvas.ForceUpdateCanvases();
LayoutRebuilder.ForceRebuildLayoutImmediate(group_Music.transform as RectTransform);
Canvas.ForceUpdateCanvases();
}
}
public List<Music_Data> Get_Music_Page(int index)
@@ -79,4 +88,15 @@ public class UI_Panel_Music : MonoBehaviour
return list;
}
private void ClosePanel()
{
UI_PanelExitUtility.PlayExitThen(gameObject, () =>
{
if (gameObject != null)
{
gameObject.SetActive(false);
}
});
}
}
+185 -8
View File
@@ -6,6 +6,82 @@ using UnityEngine.UI;
public static class UI_OrderedEntryAnimator
{
public static Sequence PlaySingle(
GameObject target,
int orderIndex = 0,
float duration = 0.22f,
float stagger = 0.018f,
float fromYOffset = -18f,
float fromScale = 0.96f,
bool useUnscaledTime = true,
bool forceFadeOnly = false)
{
if (target == null || !target.activeInHierarchy) return null;
RectTransform rect = target.transform as RectTransform;
if (rect == null) rect = target.GetComponent<RectTransform>();
if (rect == null) return null;
DOTween.Kill(target);
CanvasGroup group = target.GetComponent<CanvasGroup>();
if (group == null) group = target.AddComponent<CanvasGroup>();
rect.DOKill();
group.DOKill();
float safeDuration = Mathf.Max(0.01f, duration);
float delay = Mathf.Max(0f, stagger) * Mathf.Max(0, orderIndex);
Vector2 basePos = rect.anchoredPosition;
Vector3 baseScale = rect.localScale;
float targetAlpha = group.alpha <= 0f ? 1f : group.alpha;
bool layoutControlled = forceFadeOnly || IsLayoutSensitive(rect);
if (!layoutControlled)
{
rect.anchoredPosition = basePos + new Vector2(0f, fromYOffset);
rect.localScale = baseScale * Mathf.Max(0.01f, fromScale);
}
group.alpha = 0f;
Sequence sequence = DOTween.Sequence().SetUpdate(useUnscaledTime).SetTarget(target);
sequence.SetDelay(delay);
if (!layoutControlled)
{
sequence.Join(rect.DOAnchorPos(basePos, safeDuration).SetEase(Ease.OutCubic).SetUpdate(useUnscaledTime));
sequence.Join(rect.DOScale(baseScale, safeDuration).SetEase(Ease.OutBack).SetUpdate(useUnscaledTime));
}
sequence.Join(group.DOFade(targetAlpha, safeDuration).SetEase(Ease.OutCubic).SetUpdate(useUnscaledTime));
sequence.OnKill(() => Restore(rect, group, basePos, baseScale, targetAlpha, !layoutControlled));
sequence.OnComplete(() => Restore(rect, group, basePos, baseScale, targetAlpha, !layoutControlled));
return sequence;
}
public static Sequence PlayRefresh(
GameObject target,
float duration = 0.18f,
float fromYOffset = -10f,
float fromScale = 0.985f,
bool useUnscaledTime = true)
{
return PlaySingle(target, 0, duration, 0f, fromYOffset, fromScale, useUnscaledTime);
}
public static Sequence PlayFadeOnly(
GameObject target,
int orderIndex = 0,
float duration = 0.18f,
float stagger = 0.012f,
bool useUnscaledTime = true)
{
return PlaySingle(target, orderIndex, duration, stagger, 0f, 1f, useUnscaledTime, true);
}
public static Sequence PlayRefresh(Component target, float duration = 0.18f, float fromYOffset = -10f, float fromScale = 0.985f, bool useUnscaledTime = true)
{
return target != null ? PlayRefresh(target.gameObject, duration, fromYOffset, fromScale, useUnscaledTime) : null;
}
public static Sequence Play(
Transform root,
float itemDuration,
@@ -24,6 +100,7 @@ public static class UI_OrderedEntryAnimator
float duration = Mathf.Max(0.01f, itemDuration);
float stagger = Mathf.Max(0f, itemStagger);
Sequence sequence = DOTween.Sequence().SetUpdate(useUnscaledTime);
List<AnimState> states = new List<AnimState>(targets.Count);
for (int i = 0; i < targets.Count; i++)
{
@@ -37,19 +114,111 @@ public static class UI_OrderedEntryAnimator
group.DOKill();
Vector2 basePos = rt.anchoredPosition;
Vector3 baseScale = rt.localScale;
float baseAlpha = group.alpha <= 0f ? 1f : group.alpha;
bool layoutControlled = IsLayoutSensitive(rt);
states.Add(new AnimState(rt, group, basePos, baseScale, baseAlpha, !layoutControlled));
rt.anchoredPosition = basePos + fromOffset;
if (!layoutControlled)
{
rt.anchoredPosition = basePos + fromOffset;
}
group.alpha = 0f;
float startAt = i * stagger;
sequence.Insert(startAt, rt.DOAnchorPos(basePos, duration).SetEase(Ease.OutCubic).SetUpdate(useUnscaledTime));
if (!layoutControlled)
{
sequence.Insert(startAt, rt.DOAnchorPos(basePos, duration).SetEase(Ease.OutCubic).SetUpdate(useUnscaledTime));
}
sequence.Insert(startAt, group.DOFade(baseAlpha, duration).SetEase(Ease.OutCubic).SetUpdate(useUnscaledTime));
}
sequence.OnKill(() => RestoreAll(states));
sequence.OnComplete(() => RestoreAll(states));
return sequence;
}
private struct AnimState
{
public RectTransform Rect;
public CanvasGroup Group;
public Vector2 AnchoredPosition;
public Vector3 Scale;
public float Alpha;
public bool RestoreTransform;
public AnimState(RectTransform rect, CanvasGroup group, Vector2 anchoredPosition, Vector3 scale, float alpha, bool restoreTransform)
{
Rect = rect;
Group = group;
AnchoredPosition = anchoredPosition;
Scale = scale;
Alpha = alpha;
RestoreTransform = restoreTransform;
}
}
private static void RestoreAll(List<AnimState> states)
{
if (states == null)
{
return;
}
for (int i = 0; i < states.Count; i++)
{
AnimState state = states[i];
Restore(state.Rect, state.Group, state.AnchoredPosition, state.Scale, state.Alpha, state.RestoreTransform);
}
}
private static void Restore(RectTransform rect, CanvasGroup group, Vector2 anchoredPosition, Vector3 scale, float alpha, bool restoreTransform)
{
if (restoreTransform && rect != null)
{
rect.anchoredPosition = anchoredPosition;
rect.localScale = scale;
}
if (group != null)
{
group.alpha = alpha;
}
}
public static bool IsLayoutSensitive(RectTransform rect)
{
if (rect == null)
{
return false;
}
if (rect.GetComponent<LayoutGroup>() != null || rect.GetComponent<ContentSizeFitter>() != null)
{
return true;
}
Transform current = rect;
while (current != null && current.parent != null)
{
Transform parent = current.parent;
if (parent.GetComponent<LayoutGroup>() != null)
{
return true;
}
RectTransform currentRect = current as RectTransform;
if (currentRect != null && currentRect.GetComponent<LayoutElement>() != null && parent.GetComponent<ContentSizeFitter>() != null)
{
return true;
}
current = parent;
}
return false;
}
public static Sequence PlayKeyDownFlash(
Transform keyDownRoot,
bool useUnscaledTime,
@@ -122,15 +291,23 @@ public static class UI_OrderedEntryAnimator
{
Transform child = parent.GetChild(i);
if (child == null) continue;
stack.Push(child);
RectTransform rt = child as RectTransform;
if (rt == null || !child.gameObject.activeInHierarchy) continue;
if (includePredicate != null && !includePredicate(rt)) continue;
if (!IsPanelLike(child)) continue;
if (!seen.Add(rt)) continue;
bool canConsider = rt != null && child.gameObject.activeInHierarchy;
bool included = false;
if (canConsider
&& (includePredicate == null || includePredicate(rt))
&& IsPanelLike(child)
&& seen.Add(rt))
{
list.Add(rt);
included = true;
}
list.Add(rt);
if (!included || !IsLayoutSensitive(rt))
{
stack.Push(child);
}
}
}
+13 -3
View File
@@ -8,8 +8,13 @@ public class UI_Show_Anim : MonoBehaviour
private void OnEnable()
{
Clear();
transform.localScale = Vector3.zero;
transform.DOScale(1, animTime_Scale).SetUpdate(true);
RectTransform rect = transform as RectTransform;
bool canScale = rect == null || !UI_OrderedEntryAnimator.IsLayoutSensitive(rect);
if (canScale)
{
transform.localScale = Vector3.zero;
transform.DOScale(1, animTime_Scale).SetUpdate(true);
}
if (gameObject.Try_Get_Component(out CanvasGroup canvasGroup))
{
@@ -23,7 +28,12 @@ public class UI_Show_Anim : MonoBehaviour
public void Close()
{
Clear();
transform.DOScale(0, animTime_Scale).SetUpdate(true);
RectTransform rect = transform as RectTransform;
bool canScale = rect == null || !UI_OrderedEntryAnimator.IsLayoutSensitive(rect);
if (canScale)
{
transform.DOScale(0, animTime_Scale).SetUpdate(true);
}
if (gameObject.Try_Get_Component(out CanvasGroup canvasGroup))
{
float a = 1;
@@ -144,7 +144,13 @@ public class UnimplementedFeaturePrompt : MonoBehaviour
flashRoutine = null;
}
if (root != null)
root.SetActive(false);
{
UI_PanelExitUtility.PlayExitThen(root, () =>
{
if (root != null)
root.SetActive(false);
});
}
}
private void BindOkayButton()