static public int addClickListener(IntPtr ctx) { try { Button btn = (Button)Bind.RequireThis(ctx); IntPtr callbackptr = Native.duk_get_heapptr(ctx, 0); Native.duk_push_heapptr(ctx, callbackptr); int callbackref = Native.duv_ref(ctx); Context context = Engine.GetContent(ctx); TsDelegate td = new TsDelegate(context, callbackref, 0); UnityAction act = Delegate.CreateDelegate(typeof(UnityAction), td, "Deleg", true, true) as UnityAction; btn.onClick.AddListener(act); if (!_buttonActions.ContainsKey(btn)) { _buttonActions[btn] = new List <UnityAction>(); } _buttonActions[btn].Add(act); return(0); } catch (Exception e) { return(Native.duk_throw_error(ctx, e.ToString())); } }
private static void MediaStateChanged(TsDelegate del) { EventHandler <EventArgs> handler = (s, e) => del.Invoke(); MediaPlayer.MediaStateChanged += handler; _cache.Cache(MediaEventType.MediaStateChanged, del, handler); }
public override bool TryGetDelegate(string scriptName, out TsDelegate del) { if (scriptName == "add_mouse_button") { del = new TsDelegate(add_mouse_button, "add_mouse_button"); return(true); } return(base.TryGetDelegate(scriptName, out del)); }
public void Cache(T key, TsDelegate del, Delegate handler) { if (!_cache.TryGetValue(key, out var list)) { list = new List <KeyValuePair <TsDelegate, Delegate> >(); _cache.Add(key, list); } list.Add(new KeyValuePair <TsDelegate, Delegate>(del, handler)); }
public bool TryRemove(T key, TsDelegate del, out Delegate handler) { if (!_cache.TryGetValue(key, out var list)) { handler = null; return(false); } foreach (var item in list) { if (item.Key == del) { handler = item.Value; return(true); } } handler = null; return(false); }
static public int load(IntPtr ctx) { try { string prefabPath = Native.duk_require_string_s(ctx, 0); IntPtr callbackptr = Native.duk_get_heapptr(ctx, 1); Native.duk_push_heapptr(ctx, callbackptr); int callbackref = Native.duv_ref(ctx); Context context = Engine.GetContent(ctx); TsDelegate td = new TsDelegate(context, callbackref, 1); td.AddArgType(0, ARG_TYPE.CSOBJECT, -1, "GameEngine.CsObject"); AssetLoadedCallback callback = Delegate.CreateDelegate(typeof(AssetLoadedCallback), td, "Deleg", true, true) as AssetLoadedCallback; Global.resLoader.Load(prefabPath, callback); return(0); } catch (Exception e) { return(Native.duk_throw_error(ctx, e.ToString())); } }