[cb]Unity 关卡编辑器 开发

简介:



关卡编辑器

关卡编辑器插件开发日记

1. Apply to Prefab [替换Prefab]

image

if (GUILayout.Button("Apply Collider To Prefab"))
            {
                PrefabUtility.ReplacePrefab(simActor.Preview, PrefabUtility.GetPrefabParent(simActor.Preview), ReplacePrefabOptions.ConnectToPrefab);
            }

 

2. 获取Scene的中间坐标

比如每次 New Actor时,都出现在Scene视图的中间

   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

image

[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


本文转自赵青青博客园博客,原文链接:http://www.cnblogs.com/zhaoqingqing/p/3812368.html,如需转载请自行联系原作者

相关文章
|
2月前
|
JSON 数据可视化 图形学
Graphix: 轻量级、可插拔、OOP 式图形编辑器开发引擎
A lightweight, pluggable, object-oriented programming (OOP) style graphic editor development engine / 一个轻量级、可插拔、OOP 式图形编辑器开发引擎
57 2
|
2天前
|
图形学
【#Unity Shader#Amplify Shader Editor(ASE)_第八篇】
【#Unity Shader#Amplify Shader Editor(ASE)_第八篇】
|
2天前
|
图形学
【#Unity Shader#Amplify Shader Editor(ASE)_第三篇】
【#Unity Shader#Amplify Shader Editor(ASE)_第三篇】
|
3月前
|
算法 安全 图形学
Unity Hololens2开发|(十一)MRTK3 Solver(求解器)
Unity Hololens2开发|(十一)MRTK3 Solver(求解器)
|
3月前
|
API 图形学
Unity Hololens2开发|(十)MRTK3空间操作 ObjectManipulator (对象操控器)
Unity Hololens2开发|(十)MRTK3空间操作 ObjectManipulator (对象操控器)
|
3月前
|
Go 图形学
Unity Hololens2开发|(九)MRTK3空间操作 ConstraintManager(约束)
Unity Hololens2开发|(九)MRTK3空间操作 ConstraintManager(约束)
|
3月前
|
算法 图形学 UED
Unity Hololens2开发|(八)MRTK3空间操作 BoundsControl(边界控制)
Unity Hololens2开发|(八)MRTK3空间操作 BoundsControl(边界控制)
|
3月前
|
图形学
Unity Hololens2开发|(七)MRTK3子系统 TextToSpeechSubsystem(文本转语音)
Unity Hololens2开发|(七)MRTK3子系统 TextToSpeechSubsystem(文本转语音)
|
3月前
|
图形学
Unity Hololens2开发|(六)MRTK3子系统 DictationSubsystem(听写功能)
Unity Hololens2开发|(六)MRTK3子系统 DictationSubsystem(听写功能)
|
3月前
|
图形学
Unity Hololens2开发|(五)MRTK3子系统 KeywordRecognitionSubsystem(关键字识别)
Unity Hololens2开发|(五)MRTK3子系统 KeywordRecognitionSubsystem(关键字识别)