網(wǎng)絡(luò)代理設(shè)置蘇州網(wǎng)站關(guān)鍵字優(yōu)化
我們知道在OnValidate中創(chuàng)建游戲物體會(huì)發(fā)出警告,刪除游戲物體會(huì)報(bào)錯(cuò)。
所以我們使用協(xié)程,將開始動(dòng)作的信號放在OnValidate中,將動(dòng)作的執(zhí)行放在幀結(jié)尾。
參考代碼如下:
using System.Collections;
using UnityEngine;public class VerticalList : MonoBehaviour
{
#if UNITY_EDITOR[SerializeField]private int _childrenAmount = 0;void OnValidate(){_childrenAmount = Mathf.Max(_childrenAmount, 0);StartCoroutine(KeepChildrenAmount());}IEnumerator KeepChildrenAmount(){yield return new WaitForEndOfFrame();for (int i = transform.childCount - 1; i >= _childrenAmount; --i)DestroyImmediate(transform.GetChild(i).gameObject);while (transform.childCount < _childrenAmount){GameObject obj = new();obj.transform.parent = transform;}}
#endif
}