I am able to get a list of methods from a script but I am unable to actually show each individual method in the editor and I am not really sure how to do so. All I really need to know is how to show an element of an array. Any help is appreciated. Cheers.
I wrote this script on the fly. It creates public list of strings ( the list will be shown in the inspector ), which it subsequently fills with the names of all the methods declared in the script. They are found via reflection.
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
using System.Reflection;
using System;
using System.Linq;
public class MyScript : MonoBehaviour
{
public List<string> methods;
private void OnValidate()
{
this.Foo();
}
private void Foo()
{
Type t = this.GetType();
MethodInfo[] m = t.GetMethods(BindingFlags.Instance|BindingFlags.Static|BindingFlags.NonPublic|BindingFlags.Public).Where(x=>x.DeclaringType==t).OrderBy(x=>x.Name).ToArray();
this.methods = new List<string>();
foreach (var n in m)
{
this.methods.Add(n.Name);
}
}
private void Awake() {}
private IEnumerator Start() {yield return new WaitForSeconds(0.5f);}
protected virtual void Update() {}
public void Foo1(string a, float b) {}
private void Foo2() {}
private static void Foo3() {}
protected int Foo4(int a) {return a;}
private void OnGUI() {}
}