您的位置:首页 > 移动开发 > Unity3D

[cb]Unity Editor Toolbar 编辑器扩展

2014-06-27 17:09 701 查看
1、ApplytoPrefab[把改动应用到Prefab]




if(GUILayout.Button("ApplyColliderToPrefab"))
{
PrefabUtility.ReplacePrefab(simActor.Preview,PrefabUtility.GetPrefabParent(simActor.Preview),ReplacePrefabOptions.ConnectToPrefab);
}



2、CurrentSceneViewCenterPosition:获取Scene中间坐标
比如每次NewActor时,都出现在Scene视图的中间




SceneView.onSceneGUIDelegate-=OnCustomSceneGUI;
voidOnCustomSceneGUI(SceneViewsceneview)
{
SceneViewPos=sceneview.pivot;
}

//创建Actor
publicvoidCreateMapActor()

{
GameObjectgameLogic=GameObject.Find("MapLogic");
GameObjectnewActor=GameObject.CreatePrimitive(PrimitiveType.Sphere);

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

newActor.transform.position=SceneViewPos;
}


3、SceneContextMenu[场景视图右键菜单]
可以参考NGUI的UIWidgetContainerEditor.NGUIEditorTools.ShowSpriteSelectionMenu(e.mousePosition);我这儿实现的,还没有做处理

usingUnityEngine;
usingUnityEditor;

[InitializeOnLoad]
[ExecuteInEditMode]
publicclassMySceneContext:MonoBehaviour
{

voidUpdate()
{
SceneView.onSceneGUIDelegate=SceneContext;
}

voidSceneContext(SceneViewsceneview)
{
if(Selection.activeTransform==null)return;
TransformselectTrans=Selection.activeTransform;
Vector3curPos=selectTrans.position;

Eventevt=Event.current;
if(evt.type==EventType.ContextClick)
{
GenericMenumenu=newGenericMenu();
menu.AddItem(newGUIContent("MenuItem1"),false,CallBack,"item1");
menu.AddItem(newGUIContent("MenuItem2"),false,CallBack,"item2");
menu.ShowAsContext();
evt.Use();
}
}

voidCallBack(objectuserData)
{

}
}


4、InspectorContextMenu




[MenuItem("CONTEXT/Transform/MyContext1")]
publicstaticvoidMyContext(MenuCommandcommand)
{
CBase.Log("contextmenu");
}


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

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

TheCONTEXT/{string}seemstoworkforcomponentswithintheInspector

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

AssetStore工具推荐:https://www.assetstore.unity3d.com/en/#!/content/10424
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: