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

Commit ea21a84

Browse files
Added error handling for typed variables
1 parent c4b7ee1 commit ea21a84

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
using System.Collections;
1+
using System.Reflection;
2+
using System.Collections;
23
using System.Collections.Generic;
34
using UnityEngine;
45
using UnityEditor;
56

67
[CustomEditor(typeof(BaseVariable<>), true)]
78
public class BaseVariableEditor : Editor
89
{
10+
private IBaseVariable Target { get { return (IBaseVariable)target; } }
11+
912
private SerializedProperty _valueProperty;
1013
private SerializedProperty _developerDescription;
1114

@@ -16,7 +19,16 @@ private void OnEnable()
1619
}
1720
public override void OnInspectorGUI()
1821
{
19-
EditorGUILayout.PropertyField(_valueProperty);
22+
if (SOArchitecture_EditorUtility.HasPropertyDrawer(Target.Type))
23+
{
24+
EditorGUILayout.PropertyField(_valueProperty);
25+
}
26+
else
27+
{
28+
EditorGUILayout.LabelField("Cannot display value. No PropertyDrawer for " + Target.Type);
29+
}
30+
31+
2032
EditorGUILayout.PropertyField(_developerDescription);
2133
}
2234
}

Assets/SO Architecture/Variables/BaseVariable.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
using UnityEngine;
22

3-
public abstract class BaseVariable<T> : SOArchitectureBaseObject
3+
public interface IBaseVariable
4+
{
5+
System.Type Type { get; }
6+
}
7+
public abstract class BaseVariable<T> : SOArchitectureBaseObject, IBaseVariable
48
{
59
public T Value { get { return _value; } set { _value = value; } }
10+
public System.Type Type { get { return typeof(T); } }
611

712
[SerializeField]
813
protected T _value;

0 commit comments

Comments
 (0)