[Unity UGUI]卡卡西大法
我一直以为我发过了,结果收到评论才发现是自己老年痴呆了 ;>
=================================================================
做这个就是仿NGUI的UIGridManager
先上脚本
1 using System.Collections; 2 using System.Collections.Generic; 3 using UnityEngine; 4 5 public class CopyObjs : MonoBehaviour 6 { 7 public GameObject tempObj; 8 9 public List<GameObject> copyObjList = new List<GameObject>(); 10 11 //[HideInInspector] 12 [SerializeField] 13 private int mCount; 14 15 public int MaxCount 16 { 17 get { return mCount; } 18 set 19 { 20 if (mCount == value) return; 21 mCount = value; 22 copyObjList.RemoveAll(obj=>obj == null); 23 tempObj.SetActive(false); 24 25 for (int i = mCount - copyObjList.Count; i > 0; i--) 26 { 27 copyObjList.Add(GameObject.Instantiate(tempObj,transform)); 28 } 29 30 for (int i = 0; i < copyObjList.Count; i++) 31 { 32 if (Application.isPlaying || i < mCount) 33 { 34 copyObjList[i].SetActive(i < mCount); 35 } 36 else 37 { 38 DestroyImmediate(copyObjList[i]); 39 } 40 } 41 42 copyObjList.RemoveAll(obj => obj == null); 43 44 } 45 } 46 }
搭配这个带土使用更香哦
1 using System.Collections; 2 using System.Collections.Generic; 3 using UnityEditor; 4 using UnityEngine; 5 6 [CanEditMultipleObjects] 7 [CustomEditor(typeof(CopyObjs),true)] 8 public class CopyObjsEditor : Editor 9 { 10 CopyObjs mUICopy; 11 private void OnEnable() 12 { 13 mUICopy = target as CopyObjs; 14 } 15 16 public override void OnInspectorGUI() 17 { 18 EditorGUILayout.LabelField("克隆的最大数量"); 19 mUICopy.MaxCount = EditorGUILayout.IntField("MaxCount",mUICopy.MaxCount); 20 base.DrawDefaultInspector(); 21 } 22 }
=================================================================
好了大结局。。。。啊哈哈