Created
November 29, 2017 09:50
-
-
Save klkucan/98ba2c355dff4c35b1c2620db58e5dfe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEditor; | |
using UnityEngine; | |
[CustomPropertyDrawer(typeof(MessageBoxBehaviour))] | |
public class MessageBoxDrawer : PropertyDrawer | |
{ | |
Vector2 scrollPos; | |
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) | |
{ | |
int fieldCount = 0; | |
return fieldCount * EditorGUIUtility.singleLineHeight; | |
} | |
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) | |
{ | |
SerializedProperty type = property.FindPropertyRelative("messageType"); | |
SerializedProperty DialogueTextDisplay = property.FindPropertyRelative("DialogueTextDisplay"); | |
SerializedProperty CanvasObject = property.FindPropertyRelative("CanvasObject"); | |
SerializedProperty DialogueTextColor = property.FindPropertyRelative("DialogueTextColor"); | |
SerializedProperty DialogueString = property.FindPropertyRelative("DialogueString"); | |
SerializedProperty OptionText = property.FindPropertyRelative("OptionText"); | |
SerializedProperty OptionContent = property.FindPropertyRelative("OptionContent"); | |
SerializedProperty OptionEvent = property.FindPropertyRelative("OptionEvent"); | |
EditorGUI.BeginProperty(position, label, property); | |
var indent = EditorGUI.indentLevel; | |
EditorGUI.indentLevel = 0; | |
var typeRect = new Rect(position.x, position.y, 500, EditorGUIUtility.singleLineHeight); | |
var DialogueTextDisplayRect = new Rect(position.x, position.y + EditorGUIUtility.singleLineHeight + 8, position.width, EditorGUIUtility.singleLineHeight); | |
var CanvasObjectRect = new Rect(position.x, position.y + (EditorGUIUtility.singleLineHeight + 8) * 2, position.width, EditorGUIUtility.singleLineHeight); | |
var DialogueTextColorRect = new Rect(position.x, position.y + (EditorGUIUtility.singleLineHeight + 8) * 3, position.width, EditorGUIUtility.singleLineHeight); | |
var DialogueStringRect = new Rect(position.x, position.y + (EditorGUIUtility.singleLineHeight + 8) * 4, position.width, EditorGUIUtility.singleLineHeight); | |
EditorGUI.PropertyField(typeRect, type, new GUIContent("Message Type")); | |
EditorGUILayout.Space(); | |
EditorGUI.PropertyField(DialogueTextDisplayRect, DialogueTextDisplay, new GUIContent("DialogueTextDisplay")); | |
EditorGUI.PropertyField(CanvasObjectRect, CanvasObject, new GUIContent("CanvasObject")); | |
EditorGUI.PropertyField(DialogueTextColorRect, DialogueTextColor, new GUIContent("DialogueTextColor")); | |
EditorGUI.PropertyField(DialogueStringRect, DialogueString, new GUIContent("DialogueString")); | |
switch ((UIMessageType)type.enumValueIndex) | |
{ | |
case UIMessageType.Notify: | |
break; | |
case UIMessageType.Option: | |
float offset = string.IsNullOrEmpty(DialogueString.stringValue) ? EditorGUIUtility.singleLineHeight * 2 : 0; | |
//int maxT = OptionText.arraySize; | |
int maxC = OptionContent.arraySize; | |
//EditorGUI.indentLevel += 1; | |
//for (int i = 0; i < max; i++) | |
//{ | |
// EditorGUI.PropertyField(OptionTextRect, OptionText.GetArrayElementAtIndex(i)); | |
//} | |
//scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Width(position.width), GUILayout.Height(1000)); | |
//var OptionTextRect = new Rect(position.x, position.y + (EditorGUIUtility.singleLineHeight + 8) * 5, position.width, EditorGUIUtility.singleLineHeight * maxT); | |
//EditorGUI.PropertyField(OptionTextRect, OptionText, new GUIContent("OptionText"), true); | |
var OptionContentRect = new Rect(position.x, | |
position.y + (EditorGUIUtility.singleLineHeight + 8) * 5 + offset, | |
position.width, | |
EditorGUIUtility.singleLineHeight * maxC); | |
EditorGUI.PropertyField(OptionContentRect, OptionContent, new GUIContent("OptionContent"), true); | |
var OptionEventRect = new Rect(position.x, | |
OptionContentRect.y + (EditorGUIUtility.singleLineHeight + 8) * (maxC + 2), | |
position.width, | |
EditorGUIUtility.singleLineHeight * maxC); | |
EditorGUI.PropertyField(OptionEventRect, OptionEvent, new GUIContent("OptionEvent"), true); | |
//EditorGUILayout.EndScrollView(); | |
break; | |
case UIMessageType.Model: | |
break; | |
default: | |
break; | |
} | |
EditorGUI.indentLevel = indent; | |
EditorGUI.EndProperty(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment