c# - Finding instance of method -


this question utility script unity3d, problem in c#;

i providing script string (onclickcallbackpath) looks "gameobjectname.componenttypename.callbackdelegatename".

finding gameobject , component not problem, take @ code:

    string[] ss = onclickcallbackpath.split ("." [0]);     transform onclicktarget = tools.finddeepchild (transform.root, ss [0]);     monobehaviour[] allcomponentsontarget = onclicktarget.getcomponents<monobehaviour> ();      foreach (monobehaviour mb in allcomponentsontarget)      {         if (mb.gettype ().name == ss [1])          {             methodinfo[] methods = mb.gettype ().getmethods (bindingflags.public);              foreach (methodinfo mi in methods)              {                 if (mi.name == ss [2])                  {                     // , here how imagine work, , similar...                     // of course there no getinstance method in methodinfo                     action = (action) mi.getinstance(mb);                     break;                 }             }              break;         }     }  

as can see need find object of action type (i making sure method correct signature), within monobehaviour found.

i tried take @ methodinfo properties have looking for, tried find solution in net (also here on so) without success. bet problem finding solution wrong naming problem.

but hope understand problem.

any appreciated.

what you're looking is

(action)delegate.createdelegate(typeof(action), mb, mi) 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -