- Home /
Question by
MAGTAR · Feb 06, 2020 at 02:20 PM ·
scriptableobjectpropertydrawer
ScriptableObject drawing error
Hi, i made a simple PropertyDrawer for a ScriptableObject
Code:
[CustomPropertyDrawer(typeof(ScriptableObject), true)]
public class ScriptableObjectDrawer : PropertyDrawer
{
// Cached scriptable object editor
private Editor editor = null;
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
Debug.Log("Drawing " + property.objectReferenceValue);
Rect rectNorm = position;
if (property.objectReferenceValue != null)
{
EditorGUI.LabelField(position, (property.objectReferenceValue as ScriptableObject).name);
}
else
{
//EditorGUI.PropertyField(position, property, true);
//return;
EditorGUI.PropertyField(position, property,true);
return;
//EditorGUI.LabelField(position, (property).displayName);
}
//position.height = EditorGUIUtility.singleLineHeight;
// Draw foldout arrow
property.isExpanded = EditorGUI.Foldout(position, property.isExpanded, GUIContent.none);
// Draw foldout properties
if (property.isExpanded)
{
// Make child fields be indented
EditorGUI.indentLevel++;
if ((property.objectReferenceValue == null))
{
position.y += EditorGUIUtility.singleLineHeight;
position.height = EditorGUIUtility.singleLineHeight;
EditorGUI.PropertyField(position, property);
position = rectNorm;
}
if (property.objectReferenceValue != null)
{
//(property.objectReferenceValue as ScriptableObject).name = EditorGUI.TextField(position, "name", (property.objectReferenceValue as ScriptableObject).name);
// Draw object properties
if (!editor)
{
Editor.CreateCachedEditor(property.objectReferenceValue, null, ref editor);
}
if (editor != null)
{
editor.OnInspectorGUI();
}
}
// Set indent back to what it was
EditorGUI.indentLevel--;
}
}
}
And i also made to Scriptable Object children: 1) GameRule :
[CreateAssetMenu(fileName = "Game rule", menuName = "Game rules/game rule")]
public class GameRule : ScriptableObject
{
[System.Serializable]
public enum TriggerMode
{
//TBD
OneToTrigger,
AllToTrigger
}
[System.Serializable]
public enum ActionMode
{
//TBD
OneToDo,
AllToDo
}
//Triggers : List<EventTrigger> TriggerMode : Enum Actions : List<GameAction> ActionMode : Enum
//Maybe TriggerAction pair is better
public TriggerMode triggerMode;
public ActionMode actionMode;
}
2) Level :
[CreateAssetMenu(fileName = "levelSO", menuName = "Levels/Level")]
public class Level : ScriptableObject
{
public string Name;
public List<GameRule> Rules;
}
Now , when i try to edit my SO level i get this error: ArgumentException: Getting control 1's position in a group with only 1 controls when doing repaint And it stops drawing...
Can somebody pls explain me why this kind of error appears and is this a good practice to store SO inside others So. Thanks
снимок.png
(12.1 kB)
Comment
Even if i inherit Level from $$anonymous$$onoBehaviour a get the same error
I also figured out that for some reason Layout event is not called at alll..... Only repaint is called.... Is it my fault or it is a bug????
снимок.png
(14.8 kB)