Eldoir / Array2DEditor

Use 2-dimensional arrays in Unity's Inspector.
MIT License
173 stars 11 forks source link

Serializable class #16

Open chebedzic opened 1 year ago

chebedzic commented 1 year ago

Hey there,

Amazing plugin and I'm really happy with it.

I've managed to create an Array 2d of custom scriptable object classes, but I have a problem if I try to create Array2d of a serializable class.

Basically is this possible?


[Serializable]
public class Array2DTest : Array2D<Test>

[Serializable]
public class Test

[CustomPropertyDrawer(typeof(Array2DTest))]
    public class Array2DTestDrawer : Array2DDrawer
    {
        protected override object GetDefaultCellValue() => new Test();

        protected override object GetCellValue(SerializedProperty cell) => cell.managedReferenceValue;
        protected override void SetValue(SerializedProperty cell, object obj)
        {
            cell.managedReferenceValue = (Test) obj;
        }
    }
Eldoir commented 1 year ago

Hi @chebedzic, thank you for your comment, really! 😃 I apologize for the delay. I'm back on this plugin so I will look into this and let you know if I find something. I have tried something like your example and indeed, it doesn't seem to work, I can't display my custom class. I've seen the doc about managedReferenceValue, which I didn't know about: https://docs.unity3d.com/ScriptReference/SerializedProperty-managedReferenceValue.html It looks like we're gonna need a [SerializeReference] attribute somewhere...