找回密码
 立即注册

unity3d 编辑器编程

热度 2已有 947 次阅读2012-11-29 17:14 |个人分类:U3D| 导航, private, public, 编辑器

在使用Unity3d来开发大型的项目中,我们通常会自己开发一些适合自己的编辑器来便于一些非程序人员对游戏内容进行编辑。U3d给我们开放了这样的一些接口:

一 导航条

加入我们需要在导航条中增加一些我们自己的小工具。我们可以如下使用:

using UnityEditor;

static public class WayPointTool

{

private static int index = 0 ;

private static Dictionary<string,NvWayPoint> m_WayPointJasonTable;

private static Dictionary<int,WayPoint> m_WayPointTable;

[MenuItem("Game Tool Chain/WayPoint Tool/Reload WayPoint")]

static void ReloadWayPoint()

{

}

}

因为在导航条中的工具类没有被编辑器或者使用者实例化,所以,类和对象以及函数都需要是静态的。

 

二 编辑器窗口

我们也可以在编辑器中添加一些我们想要的窗口,所创建的窗口会像3.5中的Navigation窗口一样。

具体窗口中的内容需要定义的话,要使用U3D提供的类:EditorWindow

此类窗口的特点是没有对象的概念,是全局使用的窗口类。

 

using UnityEngine;

using UnityEditor;

public class MyWindow : EditorWindow

{

// Add menu named "My Window" to the Window menu

[MenuItem ("Window/My Window")]

static void Init () {

// Get existing open window or if none, make a new one:

MyWindow window = (MyWindow)EditorWindow.GetWindow (typeof (MyWindow));

void OnGUI ()

{

GUILayout.Label ("Base Settings", EditorStyles.boldLabel);myString

EditorGUILayout.TextField ("Text Field", myString);groupEnabled

EditorGUILayout.BeginToggleGroup ("Optional Settings", groupEnabled);

myBool = EditorGUILayout.Toggle ("Toggle", myBool);

myFloat = EditorGUILayout.Slider ("Slider", myFloat, -3, 3);

EditorGUILayout.EndToggleGroup ();

EditorGUIUtility.LookLikeInspector ();

EditorGUILayout.TextField ("Text Field:", "Hello There");

EditorGUILayout.IntField("Int Field:", integer1);

EditorGUILayout.FloatField("Float Field:", float1);

EditorGUILayout.Space();

EditorGUIUtility.LookLikeControls();

EditorGUILayout.TextField ("Text Field", "Hello There");

EditorGUILayout.IntField("Int Field:", integer1);

EditorGUILayout.FloatField("Float Field:", float1);

}

}

 

三 自定义对象的编辑窗口

你可能需要对自己定义的类对象暴露一些接口给使用编辑器的开发人员。比如你想让他编辑一个UI控件之类的对象,你可以使用下面的方法来实现:

using UnityEngine;

using UnityEditor;

[CustomEditor(typeof(UIWidget))] // 对UIWidget 对象编辑窗进行的重构

public class UIWidgetInspector : Editor

{

protected UIWidget mWidget;

static protected bool mUseShader = false;

bool mInitialized = false;

protected bool mAllowPreview = true;

public override void OnInspectorGUI ()

{

}

}

 

原文链接:http://blog.sina.com.cn/s/blog_6ad33d350100yqz5.html

1

路过

雷人
1

握手

鲜花

鸡蛋

刚表态过的朋友 (2 人)

发表评论 评论 (1 个评论)

回复 false 2012-11-29 20:59
路过学习 学习

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 立即注册

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-5-19 22:19 , Processed in 0.046226 second(s), 17 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

返回顶部