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);
}
}