Sample C# code snippet:
enum myEnum
{
aa = 0,
bb,
cc,
}
public delegate void MyDelegate(myEnum _myEnum, params object[] _params);
public Dictionary<myEnum , MyDelegate> dicMyDelegate = new Dictionary<myEnum , MyDelegate>();
public void GameDelegate(myEnum _myEnum, MyDelegate _Func)
{
if(dicMyDelegate.ContainsKey(_myEnum))
{
MyDelegate Func;
dicMyDelegate.TryGetValue(_myEnum, out Func);
Func += _Func;
}
else
{
dicMyDelegate.Add(_myEnum, _Func);
}
}
public void GameCallBack(myEnum _myEnum)
{
if(!dicMyDelegate.ContainsKey(_myEnum)) return;
MyDelegate Func;
dicMyDelegate.TryGetValue(_myEnum, out Func);
if(Func == null) return;
Func(_myEnum);
}
==================================================
Syntax for using delegates and dictionaries in cocos creator TypeScript.
public delegate void MyDelegate(myEnum _myEnum, params object[] _params);
public Dictionary<myEnum , MyDelegate> dicMyDelegate = new Dictionary<myEnum , MyDelegate>();
Attempting to convert the above C# code to TypeScript has been challenging.
I have been researching online resources all day for guidance.
declare module "Delegate"
{
export function MyDelegate(_myEnum: myEnum , args: any[]) : void;
}
import {MyDelegate} from 'Delegate';