您当前的位置: 首页 >  unity

苍狼王unity学院

暂无认证

  • 7浏览

    0关注

    305博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

unity的编辑器扩展功能

苍狼王unity学院 发布时间:2019-01-10 12:43:13 ,浏览量:7

unity的编辑器扩展功能 1.在Project下面创建新文件夹Editor 2.使用menuItem添加菜单栏按钮。 using System.Collections; using System.Collections.Generic; using UnityEditor; using UnityEngine; public class Tools { [MenuItem(“Tools/test”)] static void Test() { Debug.Log(“Test”); } } 在这里插入图片描述亲测有效。 3.关于MenuItem的路径设置和显示的先后顺序设置。* 3.1菜单栏下添加一个子菜单 [MenuItem(“Window/mytools/test1”)] static void Test3() { Debug.Log(“Test1”); } 在这里插入图片描述亲测有效。 3.2在Hierarchy右键里面添加一个按钮。

[MenuItem ("GameObject/mytools",false,10)]//设置成10左右即可打开。
static void Test4()
{
    Debug.Log("test4");
}

亲测有效 3.3在Project面板右键里面添加一个按钮。

[MenuItem ("Assets/assetButton")]
static void Test5()
{
    Debug.Log("Test5");
}

亲测有效。

5.给组件的右键菜单栏添加按钮; 1、新建一个脚本PlayerHealth.cs,挂在Player上。 [MenuItem(“CONTEXT/PlayerHealth/InitHealthAndSpeed”)] static void InitHealthAndSpeed() { Debug.Log(“Init”); } 可以看到PlayerHealth上面已经带有InitHealthAndSpeed按钮。在这里插入图片描述 可以看到PlayerHealth上面已经带有InitHealthAndSpeed按钮。 6.关于MenuCommand的使用; 6.1修改组件上的一个脚本上的一个属性。 (1).PlayerHealth.cs上面原始带有一个属性health=100; [MenuItem(“CONTEXT/PlayerHealth/InitHealthAndSpeed”)] static void InitHealthAndSpeed(MenuCommand cmd)//MenuCommand是当前正在操作的组件。 { PlayerHealth health = cmd.context as PlayerHealth; health.health = 1; Debug.Log(“I it”); } 点击InitHealthAndSpeed按钮后PlayerHealth.cs属性health=1; 亲测有效。 7、使用SeLection获取选择的游戏物体。 7.1、通过字节设置的按钮去删除某些游戏物体。 // 制作自己的删除功能按钮 [MenuItem(“GameObject/my delete”, false, 10)] static void MyDelete() { //无法撤回的删除功能 //foreach(Object o in Selection.objects) //{ // GameObject.DestroyImmediate(o); //} //要想撤回删除,需要把删除操作记录到操作记录里 foreach (Object o in Selection.objects) { Undo.DestroyObjectImmediate(o); } } 7.2如何给菜单项添加快捷键。 [MenuItem(“Tools/test %q”,false ,100)] static void Test2() { Debug.Log(“Test2”); } 在这里插入图片描述 今天先写到这里,后面再补充剩余的。

关注
打赏
1665389160
查看更多评论
立即登录/注册

微信扫码登录

0.1571s