unity编辑器

using UnityEditor;
using UnityEditorInternal;


[CustomEditor(typeof(bl_ChatManager))]
public class bl_ChatManagerEditor : Editor {


    ReorderableList GroupList;


    void OnEnable()
    {
        GroupList = new ReorderableList(serializedObject, serializedObject.FindProperty("Groups"), true, true, true, true);
        GroupList.drawElementCallback = OnDrawElementGroups;
        GroupList.drawHeaderCallback = OnHeaderGroup;
    }


    public override void OnInspectorGUI()
    {
        bl_ChatManager myTarget = (bl_ChatManager)target;


        EditorGUILayout.BeginVertical(EditorStyles.helpBox);
        EditorGUILayout.LabelField("Groups Settings",EditorStyles.boldLabel);
        myTarget.GroupID = EditorGUILayout.Popup("My Group:",myTarget.GroupID, myTarget.GetGroupArray);
        myTarget.ShowGroupsEditor = EditorGUILayout.ToggleLeft("Show Groups", myTarget.ShowGroupsEditor, EditorStyles.toolbarButton);
        if (myTarget.ShowGroupsEditor)
        {
            serializedObject.Update();
            GroupList.DoLayoutList();
            serializedObject.ApplyModifiedProperties();
        }
        EditorGUILayout.EndVertical();


        EditorGUILayout.BeginVertical(EditorStyles.helpBox);
        EditorGUILayout.LabelField("Chat Settings", EditorStyles.boldLabel);
        myTarget.useBothSides = EditorGUILayout.ToggleLeft("Use Both Sides",myTarget.useBothSides, EditorStyles.toolbarButton);
        myTarget.useGroupPrefix = EditorGUILayout.ToggleLeft("Use Group Prefix", myTarget.useGroupPrefix, EditorStyles.toolbarButton);
        myTarget.ShowPlayerNameInput = EditorGUILayout.ToggleLeft("Show Player Name Input", myTarget.ShowPlayerNameInput, EditorStyles.toolbarButton);
        myTarget.MaxMessages = EditorGUILayout.IntSlider("Max Messages",myTarget.MaxMessages, 0, 50);
        EditorGUILayout.EndVertical();


        EditorGUILayout.BeginVertical(EditorStyles.helpBox);
        EditorGUILayout.LabelField("Messages Settings", EditorStyles.boldLabel);
        myTarget.FadeMessage = EditorGUILayout.ToggleLeft("Fade Messages", myTarget.FadeMessage, EditorStyles.toolbarButton);
        if (myTarget.FadeMessage)
        {
            myTarget.FadeMessageIn = EditorGUILayout.Slider("Fade In:", myTarget.FadeMessageIn, 3, 60);
            myTarget.FadeMessageSpeed = EditorGUILayout.Slider("Fade Speed:", myTarget.FadeMessageSpeed, 0.5f, 8);
        }
        EditorGUILayout.EndVertical();


        EditorGUILayout.BeginVertical(EditorStyles.helpBox);
        EditorGUILayout.LabelField("Bad Word List", EditorStyles.boldLabel);
        myTarget.ShowBlackListEditor = EditorGUILayout.ToggleLeft("Show Black Words List", myTarget.ShowBlackListEditor, EditorStyles.toolbarButton);
        if (myTarget.ShowBlackListEditor)
        {
            myTarget.BlackList = EditorGUILayout.TextArea(myTarget.BlackList,GUILayout.Height(70));
            EditorGUILayout.HelpBox("Separate words by ',' all words should be in lowercase.", MessageType.Info);
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Replace Char:",GUILayout.Width(100));
            myTarget.ReplaceString = EditorGUILayout.TextField(myTarget.ReplaceString, GUILayout.Width(30));
            GUILayout.EndHorizontal();
        }
        EditorGUILayout.EndVertical();
    }


    void OnDrawElementGroups(Rect rect,int index,bool isActive,bool isFocus)
    {
        SerializedProperty element = GroupList.serializedProperty.GetArrayElementAtIndex(index);
        SerializedProperty thename = element.FindPropertyRelative("Name");
        SerializedProperty thecolor = element.FindPropertyRelative("GroupColor");
        rect.y += 2;
        thename.stringValue = EditorGUI.TextField(new Rect(rect.x,rect.y, 200, EditorGUIUtility.singleLineHeight), thename.stringValue);
        thecolor.colorValue = EditorGUI.ColorField(new Rect(rect.x + 210, rect.y, 100, EditorGUIUtility.singleLineHeight), thecolor.colorValue);
    }


    void OnHeaderGroup(Rect rect)
    {
        EditorGUI.LabelField(rect,"Groups");
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值