unity 在editor编辑器下创建多个按钮
入坑最后发现就几句话,真是气死人了。发现自己掉坑里,脑子就变笨了,把代码贴给你们,保持大脑清醒。
1 using System.Collections; 2 using System.Collections.Generic; 3 using UnityEngine; 4 using UnityEditor; 5 public class MI : EditorWindow 6 { 7 bool iert; 8 List<string> aa = new List<string>(); 9 [MenuItem("mi/a")] 10 static void Init() 11 { 12 MI mi = (MI)EditorWindow.GetWindowWithRect(typeof(MI), new Rect(30, 30, 500, 500)); 13 mi.Show(); 14 } 15 16 void OnGUI() 17 { 18 if (GUI.Button(new Rect(20, 20, 100, 100), "创建按钮")) 19 { 20 iert = true; 21 aa.Add("未命名"); 22 } 23 24 if (iert) 25 { 26 for (int i = 0; i < aa.Count; i++) 27 { 28 if (GUI.Button(new Rect(20, 150+50*i, 50, 50), aa[i])) 29 { 30 Debug.Log(i); 31 } 32 } 33 34 35 } 36 } 37 }
代码用来测试用的,不规范请见谅。
浙公网安备 33010602011771号