Http://www.cnblogs.com/zhaoqingqing/p/3812368.html
1, apply to Prefab [apply the 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: Get Scene Center coordinates
For example, each time the New actor appears in the middle of the scene view
Sceneview.onsceneguidelegate-= Oncustomscenegui; void Oncustomscenegui (Sceneview sceneview) { sceneviewpos = Sceneview.pivot; }
Create actor void Createmapactor ()
{ Gameobject gamelogic = Gameobject.find ("maplogic"); Gameobject newactor = gameobject.createprimitive (primitivetype.sphere); "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[scenes view right-click menu]
You can refer to Ngui's uiwidgetcontainereditor. Nguieditortools.showspriteselectionmenu (e.mouseposition); What I've done here has not been dealt with.
Using Unityengine;Using Unityeditor; [Initializeonload] [Executeineditmode]PublicClass 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")] void Mycontext (MenuCommand command) { CBase.Log ("context menu"); }
See also: 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 Tool Recommendation: https://www.assetstore.unity3d.com/en/#!/content/10424
Unity Editor Toolbar compiler extension