Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Getting parameters from UnityEvent

Discussion in 'Editor & General Support' started by BillDNA, Dec 15, 2020.

  1. BillDNA

    BillDNA

    Joined:
    Jun 3, 2014
    Posts:
    7
    So I have a debug button that i use to test and it would be nice if it could display the parameters I'm setting in the Inspector. Here is the Code:

    Code (CSharp):
    1.  
    2. public class DebugButton : BaseMonoBehaviour {
    3.     //This creates an interface in the inspector to assign functions
    4.     public UnityEvent DebugFunction;
    5.     public TextMeshPro text;
    6.     public virtual void OnClick() {
    7.         DebugFunction.Invoke();
    8.     }
    9.     public virtual void OnMouseDown() {
    10.         OnClick();
    11.     }
    12.     protected override void OnValidate() {
    13.         if(DebugFunction == null) {
    14.             text.text = "No Function";
    15.         } else {
    16.             string parameters = "?"; //How to get parameters from Unity Event
    17.             text.text = DebugFunction.GetPersistentMethodName(0) + parameters;
    18.         }
    19.     }
    20. }
     
    alexr1221 likes this.