How to get access to the class (instance of the class) you where decorating with Property drawer?
I the script below, I want to call the method “Test()” from the PropertyDrawer script. Is it possible?
using UnityEngine;
using UnityEditor;
[System.Serializable]
public class MyClass
{
public string name;
public void Test() => Debug.Log(name);
}
[CustomPropertyDrawer(typeof(MyClass))]
public class MyClassPropertyDrawer : PropertyDrawer
{
MyClass script;
void OnGUI(Rect rect, SerializedProperty property, GUIContent label)
{
if(!script)
script = (MyClass) target; // just an example, like the way we do with "Editor"
script?.Test();
}
}