removed a ton of xml comments and such
This commit is contained in:
76
Editor/EncounterDialogOptionDrawer.cs
Normal file
76
Editor/EncounterDialogOptionDrawer.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using Jovian.EncounterSystem;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Jovian.EncounterSystem.Editor {
|
||||
/// <summary>Label list elements with the option's text id (fallback: inline text preview, then default).</summary>
|
||||
[CustomPropertyDrawer(typeof(EncounterDialogOption))]
|
||||
public class EncounterDialogOptionDrawer : PropertyDrawer {
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
|
||||
var displayLabel = ResolveLabel(property, label);
|
||||
|
||||
var foldoutRect = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);
|
||||
property.isExpanded = EditorGUI.Foldout(foldoutRect, property.isExpanded, displayLabel, true);
|
||||
|
||||
if(!property.isExpanded) {
|
||||
return;
|
||||
}
|
||||
|
||||
EditorGUI.indentLevel++;
|
||||
var y = position.y + EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
var iterator = property.Copy();
|
||||
var end = iterator.GetEndProperty();
|
||||
if(iterator.NextVisible(true)) {
|
||||
while(!SerializedProperty.EqualContents(iterator, end)) {
|
||||
var h = EditorGUI.GetPropertyHeight(iterator, true);
|
||||
var r = new Rect(position.x, y, position.width, h);
|
||||
EditorGUI.PropertyField(r, iterator, true);
|
||||
y += h + EditorGUIUtility.standardVerticalSpacing;
|
||||
if(!iterator.NextVisible(false)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) {
|
||||
var height = EditorGUIUtility.singleLineHeight;
|
||||
if(!property.isExpanded) {
|
||||
return height;
|
||||
}
|
||||
|
||||
var iterator = property.Copy();
|
||||
var end = iterator.GetEndProperty();
|
||||
if(iterator.NextVisible(true)) {
|
||||
while(!SerializedProperty.EqualContents(iterator, end)) {
|
||||
height += EditorGUI.GetPropertyHeight(iterator, true) + EditorGUIUtility.standardVerticalSpacing;
|
||||
if(!iterator.NextVisible(false)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return height;
|
||||
}
|
||||
|
||||
private static GUIContent ResolveLabel(SerializedProperty property, GUIContent fallback) {
|
||||
var textProp = property.FindPropertyRelative("text");
|
||||
if(textProp == null) {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
var id = textProp.FindPropertyRelative("id")?.stringValue;
|
||||
if(!string.IsNullOrEmpty(id)) {
|
||||
return new GUIContent(id);
|
||||
}
|
||||
|
||||
var inline = textProp.FindPropertyRelative("inlineText")?.stringValue;
|
||||
if(!string.IsNullOrEmpty(inline)) {
|
||||
var preview = inline.Length > 40 ? inline.Substring(0, 40) + "…" : inline;
|
||||
return new GUIContent(preview);
|
||||
}
|
||||
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user