码迷,mamicode.com
首页 > 其他好文 > 详细

[cb]Unity Editor Toolbar 编辑器扩展

时间:2014-07-10 00:24:37      阅读:744      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   width   os   

1、Apply to Prefab [把改动应用到Prefab]

bubuko.com,布布扣

if (GUILayout.Button("Apply Collider To Prefab"))
            {
                PrefabUtility.ReplacePrefab(simActor.Preview, PrefabUtility.GetPrefabParent(simActor.Preview), ReplacePrefabOptions.ConnectToPrefab);
            }
 
 
2、Current SceneView Center Position :获取Scene中间坐标
比如每次 New Actor时,都出现在Scene视图的中间

bubuko.com,布布扣

   SceneView.onSceneGUIDelegate -= OnCustomSceneGUI;
    void OnCustomSceneGUI(SceneView sceneview)
    {
        SceneViewPos = sceneview.pivot;
    }
//创建Actor
    public void CreateMapActor()
   {
        GameObject gameLogic = GameObject.Find("MapLogic");
        GameObject newActor = GameObject.CreatePrimitive(PrimitiveType.Sphere);

        newActor.name = "Actor-" + UnityEngine.Random.Range(1, 999999);
        CBaseTool.SetChild(newActor.transform, gameLogic.transform);
        Selection.activeGameObject = newActor;
        CSimActor simActor = newActor.AddComponent<CSimActor>();

        newActor.transform.position = SceneViewPos;
    }

 

3、Scene Context Menu[场景视图右键菜单]

可以参考NGUI的 UIWidgetContainerEditor. NGUIEditorTools.ShowSpriteSelectionMenu(e.mousePosition); 我这儿实现的,还没有做处理

using UnityEngine;
using UnityEditor;

[InitializeOnLoad]
[ExecuteInEditMode]
public class MySceneContext : MonoBehaviour
{

    void Update()
    {
        SceneView.onSceneGUIDelegate = SceneContext;
    }

    void SceneContext(SceneView sceneview)
    {
        if (Selection.activeTransform == null) return;
        Transform selectTrans = Selection.activeTransform;
        Vector3 curPos = selectTrans.position;

        Event evt = Event.current;
        if (evt.type == EventType.ContextClick)
        {
            GenericMenu menu = new GenericMenu();
            menu.AddItem(new GUIContent("MenuItem1"), false, CallBack, "item 1");
            menu.AddItem(new GUIContent("MenuItem2"), false, CallBack, "item 2");
            menu.ShowAsContext();
            evt.Use();
        }
    }

    void CallBack(object userData)
    {

    }
}
4、Inspector Context Menu

bubuko.com,布布扣

[MenuItem("CONTEXT/Transform/MyContext1")]
    public static void MyContext(MenuCommand command)
    {
        CBase.Log("context menu");
    }

参见:http://docs.unity3d.com/ScriptReference/MenuCommand-context.html

http://answers.unity3d.com/questions/22947/adding-to-the-context-menu-of-the-hierarchy-tab.html

The CONTEXT/{string} seems to work for components within the Inspector

同时可查看 NGUI\Editor\NGUIContextMenu.cs

 

 

 

Asset Store工具推荐:https://www.assetstore.unity3d.com/en/#!/content/10424

[cb]Unity Editor Toolbar 编辑器扩展,布布扣,bubuko.com

[cb]Unity Editor Toolbar 编辑器扩展

标签:style   blog   http   color   width   os   

原文地址:http://www.cnblogs.com/zhaoqingqing/p/3812368.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!