改动与优化
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user