改动与优化
This commit is contained in:
@@ -15,6 +15,7 @@ public class itemGetPrefab : MonoBehaviour
|
||||
public Button close;
|
||||
|
||||
private readonly List<GameObject> spawnedItems = new List<GameObject>();
|
||||
private Coroutine layoutRefreshRoutine;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -52,6 +53,8 @@ public class itemGetPrefab : MonoBehaviour
|
||||
Destroy(displayParent.GetChild(i).gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
RequestLayoutRebuild();
|
||||
}
|
||||
|
||||
public get_item_prefab AddItem()
|
||||
@@ -63,11 +66,61 @@ public class itemGetPrefab : MonoBehaviour
|
||||
|
||||
GameObject instance = Instantiate(itemPrefab, displayParent);
|
||||
spawnedItems.Add(instance);
|
||||
UI_OrderedEntryAnimator.PlayFadeOnly(instance, spawnedItems.Count - 1, 0.2f, 0.025f, true);
|
||||
RequestLayoutRebuild();
|
||||
return instance.GetComponent<get_item_prefab>();
|
||||
}
|
||||
|
||||
private void RequestLayoutRebuild()
|
||||
{
|
||||
if (displayParent == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (layoutRefreshRoutine != null)
|
||||
{
|
||||
StopCoroutine(layoutRefreshRoutine);
|
||||
layoutRefreshRoutine = null;
|
||||
}
|
||||
|
||||
if (isActiveAndEnabled)
|
||||
{
|
||||
layoutRefreshRoutine = StartCoroutine(RebuildLayoutNextFrame());
|
||||
return;
|
||||
}
|
||||
|
||||
RebuildLayoutNow();
|
||||
}
|
||||
|
||||
private System.Collections.IEnumerator RebuildLayoutNextFrame()
|
||||
{
|
||||
yield return null;
|
||||
RebuildLayoutNow();
|
||||
layoutRefreshRoutine = null;
|
||||
}
|
||||
|
||||
private void RebuildLayoutNow()
|
||||
{
|
||||
RectTransform rect = displayParent as RectTransform;
|
||||
if (rect == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Canvas.ForceUpdateCanvases();
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate(rect);
|
||||
Canvas.ForceUpdateCanvases();
|
||||
}
|
||||
|
||||
public void CloseSelf()
|
||||
{
|
||||
Destroy(gameObject);
|
||||
UI_PanelExitUtility.PlayExitThen(gameObject, () =>
|
||||
{
|
||||
if (gameObject != null)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user