Hi Friends, no matter what I tried, I could not access the List field from the Scriptible Object converted to SerializedProperty. Does anyone have valuable information on this subject? Example Code snippet below
[CreateAssetMenu(fileName = “new PoolObjectWrapper”, menuName = “Multi Object Pool/Pool Object Wrapper”)]
public class PoolObjectWrapper : ScriptableObject {
public PoolObject poolObject;
public string name = string.Empty;
[Min(1)] public int min = 1;
[Min(1)] public int max = 10;
public bool checkable;
}
[CreateAssetMenu(fileName = “new PoolObjectContainer”, menuName = “Multi Object Pool/Pool Object Container”)]
public class PoolObjectContainerSO : ScriptableObject
{
public List poolObjects;
}
//This is monobehaviour class
public class MultiObjectPoolManager : MonoBehaviour {
public PoolObjectContainerSO poolObjectContainerSO;
[HideInInspector] public List poolObjectWrappers;
}
#if UNITY_EDITOR
[CustomEditor(typeof(MultiObjectPoolManager), true)]
public class MultiObjectPoolManagerEditor : Editor {
Dictionary<PoolObjectWrapper, ObjectPool<PoolObject>> _objectPools;
SerializedProperty _poolObjects;
MultiObjectPoolManager _mopm;
GUIStyle _styleLabel;
private void OnEnable() {
_mopm = (MultiObjectPoolManager)target;
_poolObjects = serializedObject.FindProperty(nameof(_mopm.poolObjectWrappers));
_objectPools = _mopm.objectPools;
}
public override void OnInspectorGUI() {
serializedObject.Update();
base.OnInspectorGUI();
EditorGUI.BeginDisabledGroup(true);
for(int i = 0; i < _poolObjects.arraySize; i++) {
SerializedProperty sp = _poolObjects.GetArrayElementAtIndex(i); EditorGUILayout.PropertyField(sp);
SerializedProperty spName = sp.FindPropertyRelative("min");
if (spName == null) Debug.LogWarning("sp null"); Debug.Log("Test");
//EditorGUILayout.PropertyField(spName);
}
EditorGUI.EndDisabledGroup();
serializedObject.ApplyModifiedProperties();
}
}
#endif
i am trying to fetch local fields from PoolObjectWrapper and PoolObjectWrapper inside PoolObjectContainerSO. Briefly PoolObjectContainerSO has the list of PoolObjectWrapper and PoolObjectContainerSO is a field in monobehaviour. I am trying to access the fields in PoolObjectWrappers in Editor script belongs to MultiObjectPoolManager.