[CB] unity editor toolbar editor Extension

Source: Internet
Author: User
1. apply to prefab [Apply changes to prefab]

if (GUILayout.Button("Apply Collider To Prefab"))            {                PrefabUtility.ReplacePrefab(simActor.Preview, PrefabUtility.GetPrefabParent(simActor.Preview), ReplacePrefabOptions.ConnectToPrefab);            }
 
 
2. Current sceneview center position: obtains the coordinates of scene.
For example, each new actor appears in the middle of the scene view.

   SceneView.onSceneGUIDelegate -= OnCustomSceneGUI;    void OnCustomSceneGUI(SceneView sceneview)    {        SceneViewPos = sceneview.pivot;    }
// Create an 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 [context menu of scenario view]

For details, refer to uiwidgetcontainereditor. nguieditortools. showspriteselectionmenu (E. mouseposition) of ngui. What I have implemented here is not processed yet.

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

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

See 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

You can also view ngui \ editor \ nguicontextmenu. CS

 

 

 

Asset store recommended tool: https://www.assetstore.unity3d.com/en! /Content/10424

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.