you need to defined as Serializable
[Serializable]
class MyClass: ScriptableObject{
public int prop;
}
Behind the scene Unity use SerializedObject(UnityEngine.Object), that you can use to find SerializedProperty and show in OnGUI. Or if you just use it in Behaviour, Unity would do it automatically for u.
class MyBehaviour:Behaviour{
public MyClass myObject; // Unity will show its public properties in Foldout. }
But what If I've lot of serializable classes objects and I want to be able to switch and see its properties.
You can create runtime ScriptableObjectTemplate class, object in memory,
using UnityEngine;
public class ScriptableObjectTemplate:ScriptableObject{
public MyClass value;
}
with only one property(named:value) of type MyClass. Serialize by use of SerializedObject and FindProperty "value" as SerializedProperty.
__serializedProperty=SerializeVariable().FindProperty("value");
Then you can create your default drawer:
UnityDefaultPropertyDrawer drawer=new UnityDefaultPropertyDrawer();
drawer.OnGUI(rect,__serializedProperty,label)
No comments:
Post a Comment