改动与优化

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)