• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

码起来

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

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 }

 

 

代码用来测试用的,不规范请见谅。

 

posted on 2019-11-28 17:02  码起来  阅读(1042)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3