Custom Editors - Array of Custom Classes
Hey All,
I've been unable to find a proper answer to this (apologies if there is one and I'm just blind).
I'm trying to make a custom inspector for a scriptableobject. The scriptable object has a list of type HelpTab. Help tab has two strings inside of it (code example below).
public class HelpTabsScriptableObject : ScriptableObject
{
[Serializable]
public class HelpTab
{
[SerializeField]
private string _title;
public string Title { get { return _title; } }
[SerializeField]
private string _description;
public string Description { get { return _description; } }
}
[SerializeField]
private List<HelpTab> _helpTabs = new List<HelpTab>();
public List<HelpTab> Tabs { get { return _helpTabs; } }
}
The issue is trying to access _title and _description from _helpTabs. The GetArrayElementAtIndex function doesn't help much, because this returns a SerializedProperty, and to be able to get the _title and _description we need access to a SerializedObject.
This is as far as I've been able to get. Does anyone have any solution or something to look at?
Answer by nathanlink169 · Sep 05, 2018 at 12:40 PM
I found out by talking to one of my buddies. The method I was looking for was FindPropertyRelative.
For example: _helpTabs.GetArrayElementAtIndex(0).FindPropertyRelative("_title").stringValue
Answer by JVene · Sep 04, 2018 at 08:35 PM
The property SeriealizedProperty.serializedObject gives you the object you need
From what I understand, SerializedProperty.serializedObject gives me the Serialized Object that owns the Serialized Property, not changing the current Serialized Property to a Serialized Object.
For example, if I went _helpTabs.GetArrayElementAtIndex(0).serializedObject - I would end up at _helpTabs once more, making no progress.
Your answer
Follow this Question
Related Questions
[Simple question] Adding a new SerializedProperty to a SerializedObject 1 Answer
How to Have a ReoderableList in a Custom Editor Window 1 Answer
DrawGizmo - Accessing Editor script in DrawGizmo 1 Answer
How to read from editor preferences? 0 Answers
Custom Editor: Changing isExpanded from another editor 0 Answers