AutoCAD 3DMAX C语言 Pro/E UG JAVA编程 PHP编程 Maya动画 Matlab应用 Android
Photoshop Word Excel flash VB编程 VC编程 Coreldraw SolidWorks A Designer Unity3D
 首页 > Unity3D

【Unity C#编程】自定义编辑器(三)

51自学网 2014-05-24 http://www.51zixue.net

只允许列表

多对象编辑

另一个有趣的就是多对象编辑。可以通过复制列表检测对象来测试,做一些区分,之后同时选择即可。

没有多对象编辑

默认自定义的编辑器是不支持多对象编辑的,可以通过在listTesterInspector里添加CanEditMultipleObjects属性来修复。

1
[CustomEditor(typeof(ListTester)), CanEditMultipleObjects]

 

多对象编辑

虽然这很有帮助,但是在编辑那些含有不同尺寸列表的多对象时候,还是有点奇怪的。通常来说这不是很有帮助,有时候甚至能导致出错。因此在含有不同尺寸时候我们不会显示列表。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
public static void Show (SerializedProperty list, EditorListOption options = EditorListOption.Default) {
if (!list.isArray) {
EditorGUILayout.HelpBox(list.name + " is neither an array nor a list!", MessageType.Error);
return;
}
 
bool
showListLabel = (options & EditorListOption.ListLabel) != 0,
showListSize = (options & EditorListOption.ListSize) != 0;
 
if (showListLabel) {
EditorGUILayout.PropertyField(list);
EditorGUI.indentLevel += 1;
}
if (!showListLabel || list.isExpanded) {
SerializedProperty size = list.FindPropertyRelative("Array.size");
if (showListSize) {
EditorGUILayout.PropertyField(size);
}
if (size.hasMultipleDifferentValues) {
EditorGUILayout.HelpBox("Not showing lists with different sizes.", MessageType.Info);
}
else {
ShowElements(list, options);
}
}
if (showListLabel) {
EditorGUI.indentLevel -= 1;
}
}

建议使用电驴(eMule)下载分享的资源。

说明
:本教程来源互联网或网友分享或出版商宣传分享,仅为学习研究或媒体推广,51zixue.net不保证资料的完整性。
 
上一篇:【Unity C#编程】跑动游戏(1):游戏设计  下一篇:【Unity C#编程】自定义编辑器(二)