using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test1 : MonoBehaviour
{
public Enum4 mEnum;
public int mInt;
public float mFloat;
public string mStr;
public Color mColor;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
public enum Enum4
{
None,
IntVal,
FloatVal,
StrVal,
ColorVal
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(Test1),true)]
public class Test4Editor : Editor
{
public SerializedObject mObj;
public SerializedProperty mEnum;
public SerializedProperty mInt;
public SerializedProperty mFloat;
public SerializedProperty mStr;
public SerializedProperty mColor;
public void OnEnable()
{
this.mObj = new SerializedObject(target);
this.mEnum = this.mObj.FindProperty("mEnum");
this.mInt = this.mObj.FindProperty("mInt");
this.mFloat = this.mObj.FindProperty("mFloat");
this.mStr = this.mObj.FindProperty("mStr");
this.mColor = this.mObj.FindProperty("mColor");
}
public override void OnInspectorGUI()
{
this.mObj.Update();
EditorGUILayout.PropertyField(this.mEnum);
switch (this.mEnum.enumValueIndex)
{
case 1:
EditorGUILayout.PropertyField(this.mInt);
break;
case 2:
EditorGUILayout.PropertyField(this.mFloat);
break;
case 3:
EditorGUILayout.PropertyField(this.mStr);
break;
case 4:
EditorGUILayout.PropertyField(this.mColor);
break;
}
this.mObj.ApplyModifiedProperties();
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class Test2Window : EditorWindow
{
[MenuItem("测试2/ShowWindow")]
public static void ShowWindow()
{
Test2Window.CreateInstance<Test2Window>().Show();
}
}
如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class Test3Window : EditorWindow
{
[MenuItem("测试2/Test3Window")]
public static void ShowWindow()
{
Test3Window.CreateInstance<Test3Window>().ShowUtility();
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class Test4Window : EditorWindow
{
[MenuItem("测试2/Test4Window")]
public static void ShowWindow()
{
Test4Window.CreateInstance<Test4Window>().ShowPopup();
}
public void OnGUI()
{
if(GUILayout.Button("关闭"))
{
this.Close();
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class Test6Window : EditorWindow
{
[MenuItem("测试2/Test6Window")]
public static void ShowWindow()
{
EditorWindow.GetWindow<Test6Window>().Show();
}
public string mText = "默认文本";
public Color mColor = Color.white;
public void OnGUI()
{
if (GUILayout.Button("关闭"))
{
this.Close();
}
this.mText = EditorGUILayout.TextField(this.mText);
this.mText = EditorGUILayout.TextArea(this.mText);
this.mText = EditorGUILayout.PasswordField(this.mText);
this.mColor = EditorGUILayout.ColorField(this.mColor);
//EditorGUILayout 后面的关键字:TextField、TextArea、PasswordField和ColorField。
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class Test7Window : EditorWindow
{
[MenuItem("测试2/Test7Window")]
public static void ShowWindow()
{
EditorWindow.GetWindow<Test7Window>().Show();
}
public string mText = "默认文本";
public Color mColor = Color.white;
public void OnGUI()
{
EditorGUILayout.LabelField("文本输入框");
this.mText = EditorGUILayout.TextField(this.mText);
EditorGUILayout.Space(20);
this.mText = EditorGUILayout.TextArea(this.mText);
EditorGUILayout.SelectableLabel("密码输入框");
this.mText = EditorGUILayout.PasswordField(this.mText);
this.mColor = EditorGUILayout.ColorField(this.mColor);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class Test8Window : EditorWindow
{
[MenuItem("测试2/Test8Window")]
public static void ShowWindow()
{
EditorWindow.GetWindow<Test8Window>().Show();
}
public int mInt;
public float mFloat;
public float mMinFloat;
public float mMaxFloat;
public void OnGUI()
{
EditorGUILayout.LabelField("浮点值滑动条0-100");
this.mFloat = EditorGUILayout.Slider(this.mFloat, 0, 100);
EditorGUILayout.Space(20);
EditorGUILayout.LabelField("整数值滑动条0-100");
this.mInt = EditorGUILayout.IntSlider(this.mInt, 0, 100);
EditorGUILayout.Space(30);
EditorGUILayout.LabelField("最小值和最大值滑动条");
this.mMinFloat = EditorGUILayout.Slider(this.mMinFloat, 0, 100);
this.mMaxFloat = EditorGUILayout.Slider(this.mMaxFloat, 0, 100);
EditorGUILayout.MinMaxSlider(ref this.mMinFloat, ref this.mMaxFloat, 0, 100);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class Test9Window : EditorWindow
{
[MenuItem("测试2/Test9Window")]
public static void ShowWindow()
{
EditorWindow.GetWindow<Test9Window>().Show();
}
public Vector2 mPos2;
public Vector3 mPos3;
public Vector4 mPos4;
public Rect mRect;
public Bounds mBounds;
public void OnGUI()
{
this.mPos2 = EditorGUILayout.Vector2Field("二维数值",this.mPos2);
this.mPos3 = EditorGUILayout.Vector3Field("三维数值",this.mPos3);
this.mPos4 = EditorGUILayout.Vector4Field("四维数值",this.mPos4);
EditorGUILayout.Space(20);
EditorGUILayout.LabelField("矩阵");
this.mRect = EditorGUILayout.RectField(this.mRect);
EditorGUILayout.Space(20);
EditorGUILayout.LabelField("间距");
this.mBounds = EditorGUILayout.BoundsField(this.mBounds);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class Test10Window : EditorWindow
{
[MenuItem("测试2/Test10Window")]
public static void ShowWindow()
{
EditorWindow.GetWindow<Test10Window>().Show();
}
public string mStr;
public int mInt;
public Object mObj1;
public Object mObj2;
public Object mObj3;
public Object mObj4;
public void OnGUI()
{
EditorGUILayout.LabelField("Tag");
this.mStr = EditorGUILayout.TagField(this.mStr);
EditorGUILayout.Space(170);
EditorGUILayout.LabelField("Layer");
this.mInt = EditorGUILayout.LayerField(this.mInt);
EditorGUILayout.Space(150);
EditorGUILayout.LabelField("Camera");
this.mObj1 = EditorGUILayout.ObjectField(this.mObj1, typeof(Camera));
EditorGUILayout.Space();
EditorGUILayout.LabelField("Transform");
this.mObj2 = EditorGUILayout.ObjectField(this.mObj2, typeof(Transform));
EditorGUILayout.Space();
EditorGUILayout.LabelField("Texture");
this.mObj3 = EditorGUILayout.ObjectField(this.mObj3, typeof(Texture));
EditorGUILayout.Space();
EditorGUILayout.LabelField("Object_场景和资源的都可选");
this.mObj4 = EditorGUILayout.ObjectField(this.mObj4, typeof(Object));
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class Test11Window : EditorWindow
{
[MenuItem("测试2/Test11Window")]
public static void ShowWindow()
{
EditorWindow.GetWindow<Test11Window>().Show();
}
public bool mBool1;
public bool mBool2;
public string mStr;
public int mInt;
public Object mObj1;
public Object mObj2;
public Object mObj3;
public Object mObj4;
public void OnGUI()
{
this.mBool1 = EditorGUILayout.Toggle("是否开启", this.mBool1);
if (this.mBool1)
{
EditorGUILayout.LabelField("Tag");
this.mStr = EditorGUILayout.TagField(this.mStr);
EditorGUILayout.Space(20);
EditorGUILayout.LabelField("Layer");
this.mInt = EditorGUILayout.LayerField(this.mInt);
EditorGUILayout.Space(20);
EditorGUILayout.LabelField("Camera");
this.mObj1 = EditorGUILayout.ObjectField(this.mObj1, typeof(Camera));
}
this.mBool2 = EditorGUILayout.Foldout(this.mBool2 , "是否折叠");
if (this.mBool2)
{
EditorGUILayout.Space();
EditorGUILayout.LabelField("Transform");
this.mObj2 = EditorGUILayout.ObjectField(this.mObj2, typeof(Transform));
EditorGUILayout.Space();
EditorGUILayout.LabelField("Texture");
this.mObj3 = EditorGUILayout.ObjectField(this.mObj3, typeof(Texture));
EditorGUILayout.Space();
EditorGUILayout.LabelField("Object_场景和资源的都可选");
this.mObj4 = EditorGUILayout.ObjectField(this.mObj4, typeof(Object));
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class Test11Window : EditorWindow
{
[MenuItem("测试2/Test11Window")]
public static void ShowWindow()
{
EditorWindow.GetWindow<Test11Window>().Show();
}
public bool mBool1;
public bool mBool2;
...
public void OnGUI()
{
this.mBool1 = EditorGUILayout.Toggle("是否开启", this.mBool1);
if (this.mBool1)
{
...
}
this.mBool2 = EditorGUILayout.Foldout(this.mBool2 , "是否折叠");
if (this.mBool2)
{
...
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class Test12Window : EditorWindow
{
[MenuItem("测试2/Test12Window")]
public static void ShowWindow()
{
EditorWindow.GetWindow<Test12Window>().Show();
}
public bool mBool1;
public bool mBool2;
public bool mBool3;
public string mStr;
public int mInt;
public Object mObj1;
public Object mObj2;
public Object mObj3;
public Object mObj4;
public Vector2 mPos;
public void OnGUI()
{
this.mPos = EditorGUILayout.BeginScrollView(this.mPos);
this.mBool1 = EditorGUILayout.Toggle("是否开启", this.mBool1);
if (this.mBool1)
{
EditorGUILayout.LabelField("Tag");
this.mStr = EditorGUILayout.TagField(this.mStr);
EditorGUILayout.Space(20);
EditorGUILayout.LabelField("Layer");
this.mInt = EditorGUILayout.LayerField(this.mInt);
EditorGUILayout.Space(20);
EditorGUILayout.LabelField("Camera");
this.mObj1 = EditorGUILayout.ObjectField(this.mObj1, typeof(Camera));
}
this.mBool2 = EditorGUILayout.Foldout(this.mBool2, "是否折叠");
if (this.mBool2)
{
EditorGUILayout.Space();
EditorGUILayout.LabelField("Transform");
this.mObj2 = EditorGUILayout.ObjectField(this.mObj2, typeof(Transform));
EditorGUILayout.Space();
EditorGUILayout.LabelField("Texture");
this.mObj3 = EditorGUILayout.ObjectField(this.mObj3, typeof(Texture));
EditorGUILayout.Space();
EditorGUILayout.LabelField("Object_场景和资源的都可选");
this.mObj4 = EditorGUILayout.ObjectField(this.mObj4, typeof(Object));
}
this.mBool3 = EditorGUILayout.BeginToggleGroup("是否禁用置灰", this.mBool3);
EditorGUILayout.LabelField("Tag");
this.mStr = EditorGUILayout.TagField(this.mStr);
EditorGUILayout.LabelField("Layer");
this.mInt = EditorGUILayout.LayerField(this.mInt);
EditorGUILayout.LabelField("Camera");
this.mObj1 = EditorGUILayout.ObjectField(this.mObj1, typeof(Camera));
EditorGUILayout.EndToggleGroup();
EditorGUILayout.EndScrollView();
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class Test12Window : EditorWindow
{
[MenuItem("测试2/Test12Window")]
public static void ShowWindow()
{
EditorWindow.GetWindow<Test12Window>().Show();
}
public Object mObj4;
public Vector2 mPos;
public void OnGUI()
{
this.mPos = EditorGUILayout.BeginScrollView(this.mPos);//窗口右侧滑动条开始
...//中间包含的菜单
EditorGUILayout.EndScrollView();//窗口右侧滑动条结束
}
}
this.mBool3 = EditorGUILayout.BeginToggleGroup("是否禁用置灰", this.mBool3);
...
EditorGUILayout.EndToggleGroup();
...