How to execute a method from a PropertyDrawer?


How can i execute a method that belong to a script that attached to some GameObject from a PropertyDrawer?

for example i have these classes:

    using UnityEngine;
    public class Data{
    	public Vector3 size =;
    	public float speed;
    using UnityEngine;
    using System.Collections;
    public class Test: MonoBehaviour {
    	public Data data;
    	public void DoSomething(){/*..*/}
    using UnityEngine;
    using UnityEditor;
    public class DataDrawer : PropertyDrawer {
    	public override void OnGUI (Rect pos, SerializedProperty prop, GUIContent label)
    		SerializedProperty size  = prop.FindPropertyRelative ("size");
    		SerializedProperty speed = prop.FindPropertyRelative ("speed");
    		if( GUI.Button(new Rect ( 0 , 0,100, 20),"Click Me" ) ){
    			//HOW TO EXECUTE DoSomething() method from this point?	

I need to call “DoSomething” method that belong to “Test” class from the PropertyDrawer that decorate the “Data” class.

Help Please…

Well, I guess that normally it is actually bad practice to use something of the class you attatch your data to (Beecause then Data can only be added to that specific class.

If you don’t mind though, the following line will execute your method.

(prop.serializedObject.targetObject as Test).DoSomething();