I have problem with nested array where I cannot add or remove it on editor window.
This is Card Resources class derived from Resources class
public class CardResources : BaseResources<GameObject>
{
}
This is Base Resources class
[System.Serializable]
public class NamedResource<T> where T : Object
{
public string Path;
public T[] Resources;
}
public abstract class BaseResources : ScriptableObject
{
}
public abstract class BaseResources<TObject> : BaseResources where TObject : Object
{
[SerializeField] private NamedResource<TObject>[] _resources;
public NamedResource<TObject>[] Resources { get => _resources; }
}
This is Resources editor window
public class CardResourecesEditor : ResourcesEditor
{
[MenuItem("Resources/Cards")]
protected static void OpenWindow()
{
var window = GetWindow<CardResourecesEditor>();
window.Show();
window.Init<CardResources>();
}
}
public class ResourcesEditor : EditorWindow
{
protected SerializedObject serializedObject;
protected SerializedProperty serializedProperty;
private BaseResources resources;
protected string selectedPropertyPach;
protected string selectedProperty;
protected virtual void Init<T>() where T : BaseResources
{
resources = GetInstances<T>();
}
protected virtual void OnGUI()
{
if (resources == null)
return;
serializedObject = new SerializedObject(resources);
SerializedProperty stringsProperty = serializedObject.FindProperty("_resources");
serializedObject.Update();
EditorGUILayout.PropertyField(stringsProperty, true);
Apply();
}
public static T GetInstances<T>() where T : BaseResources
{
string[] guids = AssetDatabase.FindAssets("t:" + typeof(T).Name);
T[] a = new T[guids.Length];
for (int i = 0; i < guids.Length; i++)
{
string path = AssetDatabase.GUIDToAssetPath(guids[i]);
a[i] = AssetDatabase.LoadAssetAtPath<T>(path);
}
return a[0];
}
protected void Apply()
{
serializedObject.ApplyModifiedProperties();
}
}