- Home /
Question by
gonzalolog · Jan 11, 2014 at 07:43 PM ·
arrayindexmethodstable
Multi-Arrays help
Hello everybody, i have a doubt, i'm trying to make hook system, and i'm not able to build it...
My theory:
Create a global table>That table have multiple items with events>Each item have functions
What is the problem, i don't know how create a string indexed table for see if it's the correct item, here is my code
I took the idea from gmod about how it handle hooks
public delegate void _Hook(UnityEngine.Object[] args);
public class hook : MonoBehaviour {
_Hook[,] hookTable;
public void Start()
{
hookTable = new _Hook[1,1];
}
public void Run( string event_name, UnityEngine.Object[] args)
{
foreach (var hook in hookTable) {
hook(args);
}
}
public void Add( string event_name,string name,_Hook func,UnityEngine.Object[] args)
{
hookTable[event_name][name] = func(args);
}
public hookObject[] GetHooks()
{
return hookTable;
}
public void Remove(string event_name,string name)
{
hookTable[event_name][ name ] = null;
}
}
But i have problems with the hookTable because i can't do it multiarray and make it handle methods...So
How can make a table handle methods or index tables with strings
Thanks for see
Comment
You can use a Dictionary to have a key-value pair. Other than that, I'm not really sure what you're getting at...