Skip to content
This repository was archived by the owner on May 9, 2025. It is now read-only.

Commit c1e1f3f

Browse files
Improved developer description API
1 parent 5d63fff commit c1e1f3f

10 files changed

+149
-64
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using UnityEngine;
5+
6+
[Serializable]
7+
public class DeveloperDescription : IEquatable<DeveloperDescription>, IEquatable<string>
8+
{
9+
public DeveloperDescription() { }
10+
public DeveloperDescription(string value)
11+
{
12+
_value = value;
13+
}
14+
15+
[SerializeField]
16+
private string _value = string.Empty;
17+
18+
public static implicit operator string(DeveloperDescription description)
19+
{
20+
return description._value;
21+
}
22+
public static implicit operator DeveloperDescription(string value)
23+
{
24+
return new DeveloperDescription(value);
25+
}
26+
27+
public override bool Equals(object obj)
28+
{
29+
return _value.Equals(obj);
30+
}
31+
public bool Equals(DeveloperDescription other)
32+
{
33+
if (other == null)
34+
return false;
35+
36+
return _value == other._value;
37+
}
38+
public bool Equals(string other)
39+
{
40+
if (other == null)
41+
return false;
42+
43+
return _value == other;
44+
}
45+
public override int GetHashCode()
46+
{
47+
return _value.GetHashCode();
48+
}
49+
public override string ToString()
50+
{
51+
return _value;
52+
}
53+
}
Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
using UnityEditor;
5+
6+
[CustomPropertyDrawer(typeof(DeveloperDescription))]
7+
public class DeveloperDescriptionDrawer : PropertyDrawer
8+
{
9+
private SerializedProperty property;
10+
11+
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
12+
{
13+
this.property = property;
14+
15+
DrawTitle();
16+
DrawTextArea();
17+
}
18+
private void DrawTitle()
19+
{
20+
EditorGUILayout.LabelField(new GUIContent("Description", "Click below this field to add a description"));
21+
}
22+
private void DrawTextArea()
23+
{
24+
SerializedProperty stringValue = property.FindPropertyRelative("_value");
25+
26+
Vector2 fieldSize = Styles.TextAreaStyle.CalcSize(new GUIContent(stringValue.stringValue));
27+
Rect textAreaRect = GUILayoutUtility.GetRect(fieldSize.x, fieldSize.y);
28+
29+
30+
EditorGUI.indentLevel++;
31+
32+
stringValue.stringValue = EditorGUI.TextArea(textAreaRect, stringValue.stringValue, Styles.TextAreaStyle);
33+
34+
EditorGUI.indentLevel--;
35+
36+
37+
HandleInput(textAreaRect);
38+
}
39+
private void HandleInput(Rect textAreaRect)
40+
{
41+
Event e = Event.current;
42+
43+
if(e.type == EventType.MouseDown)
44+
{
45+
if (!textAreaRect.Contains(e.mousePosition))
46+
RemoveFocus();
47+
}
48+
else if(e.type == EventType.KeyDown || e.type == EventType.KeyUp)
49+
{
50+
if (Event.current.keyCode == (KeyCode.Escape))
51+
{
52+
RemoveFocus();
53+
}
54+
}
55+
}
56+
private void RemoveFocus()
57+
{
58+
GUI.FocusControl(null);
59+
Repaint();
60+
}
61+
private void Repaint()
62+
{
63+
EditorUtility.SetDirty(property.serializedObject.targetObject);
64+
}
65+
private static class Styles
66+
{
67+
public static GUIStyle TextAreaStyle;
68+
69+
static Styles()
70+
{
71+
TextAreaStyle = new GUIStyle(EditorStyles.textArea);
72+
TextAreaStyle.normal = EditorStyles.label.normal;
73+
}
74+
}
75+
}

Assets/SO Architecture/Editor/Drawers/DeveloperDescriptionDrawer.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/SO Architecture/Editor/Inspectors/BaseGameEventEditor.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
public abstract class BaseGameEventEditor : Editor
55
{
66
private IStackTraceObject Target { get { return (IStackTraceObject)target; } }
7-
private SerializedProperty DeveloperDescrption { get { return serializedObject.FindProperty("DeveloperDescription"); } }
7+
private SerializedProperty DeveloperDescription { get { return serializedObject.FindProperty("DeveloperDescription"); } }
88

99
private StackTrace _stackTrace;
1010

@@ -17,12 +17,10 @@ protected virtual void OnEnable()
1717
}
1818
public override void OnInspectorGUI()
1919
{
20-
//EditorGUI.BeginDisabledGroup(!Application.isPlaying);
2120
DrawRaiseButton();
22-
//EditorGUI.EndDisabledGroup();
2321

2422
_stackTrace.Draw();
2523

26-
SOArchitectureBaseObjectEditor.DrawDescription(DeveloperDescrption);
24+
EditorGUILayout.PropertyField(DeveloperDescription);
2725
}
2826
}

Assets/SO Architecture/Editor/Inspectors/BaseGameEventListenerEditor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
public abstract class BaseGameEventListenerEditor : Editor
55
{
66
private IStackTraceObject Target { get { return (IStackTraceObject)target; } }
7-
private SerializedProperty DeveloperDescrption { get { return serializedObject.FindProperty("DeveloperDescription"); } }
7+
private SerializedProperty DeveloperDescription { get { return serializedObject.FindProperty("DeveloperDescription"); } }
88

99
private StackTrace _stackTrace;
1010
private SerializedProperty _event;
@@ -32,8 +32,8 @@ public override void OnInspectorGUI()
3232
DrawRaiseButton();
3333

3434
_stackTrace.Draw();
35-
36-
SOArchitectureBaseObjectEditor.DrawDescription(DeveloperDescrption);
35+
36+
EditorGUILayout.PropertyField(DeveloperDescription);
3737

3838
serializedObject.ApplyModifiedProperties();
3939
}

Assets/SO Architecture/Editor/Inspectors/RuntimeSetEditor.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ public override void OnInspectorGUI()
2121
_reorderableList.DoLayoutList();
2222

2323
_reorderableList.serializedProperty.serializedObject.ApplyModifiedProperties();
24-
25-
Target.DeveloperDescription = SOArchitectureBaseObjectEditor.DrawDescription(Target.DeveloperDescription);
2624
}
2725
private void DrawElement(Rect rect, int index, bool isActive, bool isFocused)
2826
{

Assets/SO Architecture/Editor/Inspectors/SOArchitectureBaseObjectEditor.cs

Lines changed: 0 additions & 52 deletions
This file was deleted.

Assets/SO Architecture/SOArchitectureBaseMonobehaviour.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
public abstract class SOArchitectureBaseMonobehaviour : MonoBehaviour
88
{
99
#if UNITY_EDITOR
10-
public string DeveloperDescription = string.Empty;
10+
[SerializeField]
11+
private DeveloperDescription DeveloperDescription = new DeveloperDescription();
1112
#endif
1213
}

Assets/SO Architecture/SOArchitectureBaseObject.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
public abstract class SOArchitectureBaseObject : ScriptableObject
88
{
99
#if UNITY_EDITOR
10-
public string DeveloperDescription = string.Empty;
10+
[SerializeField]
11+
private DeveloperDescription DeveloperDescription = new DeveloperDescription();
1112
#endif
1213
}

0 commit comments

Comments
 (0)