unity3D自定义菜单项
2015-10-16 14:25
435 查看
有时候 我们想在菜单项中添加自己定义的快速添加组件的选项
其实方法很简单只要在脚本中添加
以下语句就可以
一定要记住加的命名空间 using UnityEditor;
[MenuItem("第一级菜单/第二级菜单")]
在我们的菜单中就有了这个选项
那么该如何添加需要的组件呢??
private static void EnableRotate(MenuCommand command)
{
Debug.Log("测试");
GameObject obj = Selection.activeGameObject;
if (obj==null)
{
Debug.log("null ");
}
else
{
obj.AddComponent<ParticleSystem>();
obj.GetComponent<ParticleSystem>().startColor = Color.red;
}
}
我们就顺利的添加了想要的组件 粒子
完整代码:
using System.Collections;
using UnityEditor;
using UnityEngine;
public class ConfigTest :MonoBehaviour {
[MenuItem("第一/第二")]
private static void EnableRotate(MenuCommand command)
{
Debug.Log("测试");
GameObject obj = Selection.activeGameObject;
if (obj==null)
{
Debug.Log("null");
}
else
{
obj.AddComponent<ParticleSystem>();
obj.GetComponent<ParticleSystem>().startColor = Color.red;
}
}
}
其实方法很简单只要在脚本中添加
以下语句就可以
一定要记住加的命名空间 using UnityEditor;
[MenuItem("第一级菜单/第二级菜单")]
在我们的菜单中就有了这个选项
那么该如何添加需要的组件呢??
private static void EnableRotate(MenuCommand command)
{
Debug.Log("测试");
GameObject obj = Selection.activeGameObject;
if (obj==null)
{
Debug.log("null ");
}
else
{
obj.AddComponent<ParticleSystem>();
obj.GetComponent<ParticleSystem>().startColor = Color.red;
}
}
我们就顺利的添加了想要的组件 粒子
完整代码:
using System.Collections;
using UnityEditor;
using UnityEngine;
public class ConfigTest :MonoBehaviour {
[MenuItem("第一/第二")]
private static void EnableRotate(MenuCommand command)
{
Debug.Log("测试");
GameObject obj = Selection.activeGameObject;
if (obj==null)
{
Debug.Log("null");
}
else
{
obj.AddComponent<ParticleSystem>();
obj.GetComponent<ParticleSystem>().startColor = Color.red;
}
}
}
相关文章推荐
- Unity导出切割后的Sprite图片
- Unity 内存管理——手机调试Profiler
- Unity 3d脚本加密方案
- Cg per-vertex lighting with texture
- Unity笔记 Surface Shader
- Unity Terrain Optimze
- Cg shader with single texture
- Unity Shader Example 1 : Texture
- Cg per-pixel lighting with vertex lights
- Unity卡牌循环滚动点击
- Cg two-sided per-pixel lighting
- Cg per-pixel lighting
- Unity 3d脚本加密方案
- Cg two-sided per-vertex lighting
- unity警告“Tiled GPU perf. warning: RenderTexture color surface (0x0) was not cleared/discarded, doin”
- Unity项目开发准则(转)
- unity游戏与我
- Unity_NGUI原理机制
- Unity3D中级开发工程师面试指导
- Unity初级工程师面试指导