Unity编辑器之inspector处理
2016-04-08 10:57
1051 查看
<pre name="code" class="html">using UnityEngine; using System.Collections; using UnityEditor; [CustomEditor(typeof(MaterialsChangeContainer))] //需要编辑的脚本控件 public class MaterialsChangeContainerEditor : Editor { private static GUIContent deleteContent = new GUIContent("Del"); private static GUIContent addContent = new GUIContent("Add"); private SerializedProperty mList; void OnEnable() { //FindProperty找到类中的某个变量 mList = serializedObject.FindProperty("MaterialsChangeInfoList");//MaterialsChangeInfoList 脚本里面的list变量 } public override void OnInspectorGUI() { serializedObject.Update(); EditorGUILayout.PropertyField(mList.FindPropertyRelative("Array.size"));//显示数组长度 for (int i = 0; i < mList.arraySize; i++) { EditorGUILayout.BeginHorizontal(); SerializedProperty prop = mList.GetArrayElementAtIndex(i); SerializedProperty innerOld = prop.FindPropertyRelative("OldMaterials"); SerializedProperty innerNew = prop.FindPropertyRelative("NewMaterials"); Material matOld = innerOld.objectReferenceValue as Material; Material matNew = innerNew.objectReferenceValue as Material; EditorGUILayout.PropertyField(prop, new GUIContent(string.Format("{0} to {1}", matOld.name, matNew.name)), prop.isExpanded); if (GUILayout.Button(deleteContent, EditorStyles.miniButtonRight, GUILayout.Width(40))) { mList.DeleteArrayElementAtIndex(i); } EditorGUILayout.EndHorizontal(); } EditorGUILayout.BeginHorizontal(); if (GUILayout.Button(addContent)) { mList.InsertArrayElementAtIndex(mList.arraySize); } EditorGUILayout.EndHorizontal(); serializedObject.ApplyModifiedProperties(); } }常用函数
var Obj = serializedObject.targetObject as ClassTest;//获得这个类
相关文章推荐
- Unity3D手游开发日记(8) - 运动残影效果
- 360SDK文档
- unity动态加载Resources.Load方法
- Unity3D游戏开发从零单排(三) - 极速创建狂拽酷炫的游戏地形
- 【Unity3D实战】零基础一步一步教你制作跑酷类游戏(填坑完整版)
- unity 运行 iOS模拟器报错 dyld: Symbol not found: __BeginEventWithLabel
- Unity Shaders and Effects Cookbook (3-3) 创建 BlinnPhong 光照模型
- Unity中Time.deltaTime的使用
- IOC使用Unity 实现依赖注入
- [Unity] transform.Translate vs rigidbody.MovePosition?
- [Unity] unity3d中脚本生命周期(MonoBehaviour lifecycle)
- [Unity] MonoBehaviour lifecycle and leaks explained
- [Unity热更新]tolua# & LuaFramework(五):.proto转换为.lua
- Unity3d 残影效果(狂拽炫酷叼炸天)
- Disunity_V0.5.0 提取Unity生成的Apk的资源
- Unity this.transform.Translate(Vector3.down * moveSpeed * Time.deltaTime)
- Unity做AR
- Unity3D for VR 学习(10): Unity LOD Group 组件
- Unity3D for VR 学习(9): Unity Shader 光照模型 (illumination model)
- Unity3D for VR 学习(8): Unity Shader概述