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