Пример #1
2
        private static void AddTaskDelay(Action action, int delayInMilliseconds)
        {
            System.Threading.Thread.Sleep(delayInMilliseconds);
            bool bFired;

            if (action != null)
            {
                foreach (Delegate singleCast in action.GetInvocationList())
                {
                    bFired = false;
                    try
                    {
                        ISynchronizeInvoke syncInvoke = (ISynchronizeInvoke)singleCast.Target;
                        if (syncInvoke != null && syncInvoke.InvokeRequired)
                        {
                            bFired = true;
                            syncInvoke.BeginInvoke(singleCast, null);
                        }
                        else
                        {
                            bFired = true;
                            singleCast.DynamicInvoke(null);
                        }
                    }
                    catch (Exception)
                    {
                        if (!bFired)
                            singleCast.DynamicInvoke(null);
                    }
                }
            }
        }
Пример #2
1
    void Update()
    {
        CheckEscape();

        if (_nextFrameCall != null)
        {
            //_nextFrameCall.Invoke();
            Delegate[] list = _nextFrameCall.GetInvocationList();
            if (list != null)
            {
                int count = list.Length;
                for (int i = 0; i < count; i++)
                {
                    System.Action function = (System.Action)list[i];
                    _nextFrameCall -= function;
                    function.Invoke();
                }
                //_nextFrameCall = null;
            }
        }
        if (_updateFrameList != null)
        {
            _updateFrameList.Invoke();
        }

        //StageManager.Update();
    }
        private static void RenderMenu(Action examples)
        {
            Console.WriteLine("Select an example:");
              for (int i = 0; i < examples.GetInvocationList().Count(); i++)
              {
            var action = examples.GetInvocationList().ToArray()[i];
            Console.WriteLine("  {0} - {1}", i, action.Method.DeclaringType.Name);
              }

              Console.Write(">");
        }
Пример #4
0
        static public void AddEditorUpdateAct(System.Action act)
        {
#if UNITY_EDITOR
            m_EditorUpdateAction += act;
            Debug.Log("AddEditorUpdateAct count:" + m_EditorUpdateAction.GetInvocationList().GetLength(0));
#endif
        }
Пример #5
0
 public static void InvokeAction(System.Action action)
 {
     if (action != null && action.GetInvocationList().Length > 0)
     {
         action();
     }
 }
Пример #6
0
 void ClearDelegate(System.Action delegateHandler)
 {
     if (delegateHandler == null)
     {
         return;
     }
     System.Delegate[] list = delegateHandler.GetInvocationList();
     foreach (System.Delegate del in list)
     {
         delegateHandler -= (System.Action)del;
     }
 }
Пример #7
0
        static public void RemoveEditorUpdateAct(System.Action act)
        {
#if UNITY_EDITOR
            m_EditorUpdateAction -= act;
            int count = 0;
            if (m_EditorUpdateAction != null)
            {
                count = m_EditorUpdateAction.GetInvocationList().GetLength(0);
            }
            Debug.Log("RemoveEditorUpdateAct count:" + count);
#endif
        }
        private static int IdentifySelection(Action examples)
        {
            var selection = Console.ReadLine();

              int index;
              if (!int.TryParse(selection, out index))
              {
            // put it out of range
            index = examples.GetInvocationList().Count();
              }

              return index;
        }
Пример #9
0
    static int set_onDestroyEvent(IntPtr L)
    {
        try
        {
            GameFramework.MonoBase obj  = (GameFramework.MonoBase)ToLua.CheckObject(L, 1, typeof(GameFramework.MonoBase));
            EventObject            arg0 = null;

            if (LuaDLL.lua_isuserdata(L, 2) != 0)
            {
                arg0 = (EventObject)ToLua.ToObject(L, 2);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "The event 'GameFramework.MonoBase.onDestroyEvent' can only appear on the left hand side of += or -= when used outside of the type 'GameFramework.MonoBase'"));
            }

            if (arg0.op == EventOp.Add)
            {
                System.Action ev = (System.Action) DelegateTraits <System.Action> .Create(arg0.func);

                obj.onDestroyEvent += ev;
            }
            else if (arg0.op == EventOp.Sub)
            {
                System.Action ev    = (System.Action)LuaMisc.GetEventHandler(obj, typeof(GameFramework.MonoBase), "onDestroyEvent");
                Delegate[]    ds    = ev.GetInvocationList();
                LuaState      state = LuaState.Get(L);

                for (int i = 0; i < ds.Length; i++)
                {
                    ev = (System.Action)ds[i];
                    LuaDelegate ld = ev.Target as LuaDelegate;

                    if (ld != null && ld.func == arg0.func)
                    {
                        obj.onDestroyEvent -= ev;
                        state.DelayDispose(ld.func);
                        break;
                    }
                }

                arg0.func.Dispose();
            }

            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Пример #10
0
    static int set_OnFinished(IntPtr L)
    {
        try
        {
            EventObject arg0 = null;

            if (LuaDLL.lua_isuserdata(L, 2) != 0)
            {
                arg0 = (EventObject)ToLua.ToObject(L, 2);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "The event 'SceneLoader.OnFinished' can only appear on the left hand side of += or -= when used outside of the type 'SceneLoader'"));
            }

            if (arg0.op == EventOp.Add)
            {
                System.Action ev = (System.Action)DelegateFactory.CreateDelegate(typeof(System.Action), arg0.func);
                SceneLoader.OnFinished += ev;
            }
            else if (arg0.op == EventOp.Sub)
            {
                System.Action ev    = (System.Action)LuaMisc.GetEventHandler(null, typeof(SceneLoader), "OnFinished");
                Delegate[]    ds    = ev.GetInvocationList();
                LuaState      state = LuaState.Get(L);

                for (int i = 0; i < ds.Length; i++)
                {
                    ev = (System.Action)ds[i];
                    LuaDelegate ld = ev.Target as LuaDelegate;

                    if (ld != null && ld.func == arg0.func)
                    {
                        SceneLoader.OnFinished -= ev;
                        state.DelayDispose(ld.func);
                        break;
                    }
                }

                arg0.func.Dispose();
            }

            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Пример #11
0
 public void AddEvent(System.Action completedEvent)
 {
     if (null == EndEvent)
     {
         EndEvent = completedEvent;
     }
     else
     {
         Delegate[] delegates = EndEvent.GetInvocationList();
         if (!Array.Exists(delegates, (v) => { return(v == (Delegate)completedEvent); }))
         {
             EndEvent += completedEvent;
         }
     }
 }
Пример #12
0
        public Running(Action action)
        {
            this.action = action;

            try
            {
                foreach (var action_delegate in action.GetInvocationList())
                {
                    action_delegate.DynamicInvoke();
                }
            }
            catch (Exception e)
            {
                exception = e.InnerException;
            }
        }
Пример #13
0
    private void ClearEvents()
    {
        if (actionYes != null)
        {
            foreach (Delegate d in actionYes.GetInvocationList())
            {
                actionYes -= (System.Action)d;
            }
        }

        if (actionNo != null)
        {
            foreach (Delegate d in actionNo.GetInvocationList())
            {
                actionNo -= (System.Action)d;
            }
        }
    }
        private static void ExecuteDelegateExample(Action examples, int selectedIndex)
        {
            var counter = 0;
              foreach (Action action in examples.GetInvocationList())
              {
            if (counter.Equals(selectedIndex))
            {
              Console.WriteLine("{1}{0}{1}{2}", action.Method.DeclaringType, Environment.NewLine, new string('-', 20));
              try
              {
            action();
              }
              catch (Exception exception)
              {
            Console.WriteLine(exception);
              }

              break;
            }

            counter++;
              }
        }
Пример #15
0
        private void Awake()
        {
            if (LuaScript == null)
            {
                return;
            }
            if (!LuaManager.Inited)
            {
                return;
            }
            scriptData = LuaManager.LuaVM.NewTable();
            LuaTable meta = LuaManager.LuaVM.NewTable();

            meta.Set("__index", LuaManager.LuaVM.Global);
            scriptData.SetMetaTable(meta);
            meta.Dispose();

            scriptData.Set("self", this);
            //scriptData.Set<LuaFunction>("", EventRegister);

            if (Injections != null && Injections.Length > 0)
            {
                foreach (var item in Injections)
                {
                    if (item.Name != "" && item.Name != null && item.Object != null)
                    {
                        scriptData.Set(item.Name, item.Object);
                    }
                }
            }

            if (Injections_str != null && Injections_str.Length > 0)
            {
                foreach (var item in Injections_str)
                {
                    if (item.Name != "" && item.Name != null && item.str != null)
                    {
                        scriptData.Set(item.Name, item.str);
                    }
                }
            }

            //Debug.Log("文件名:" + LuaScript.name);
            LuaManager.LuaVM.DoString(LuaScript.text, LuaScript.name, scriptData);
            Action luaAwake = scriptData.Get <Action>("Awake");

            scriptData.Get("Start", out luaStart);
            scriptData.Get("Update", out luaUpdate);
            scriptData.Get("OnDestroy", out luaOnDestroy);
            scriptData.Get("LateUpdate", out luaLateUpdate);
            scriptData.Get("OnUIOpenMessage", out luaOnUIOpenMessage);
            scriptData.Get("OnUICloseMessage", out luaOnUICloseMessage);
            //luaOnUIOpenMessage = scriptData.Get<LuaFunction>("OnUIOpenMessage");


            if (luaAwake != null)
            {
                luaAwake();
            }
            if (luaUpdate != null)
            {
                if (luaUpdate.GetInvocationList().Length >= 1)
                {
                    enable_update = true;
                    TimeMachine.I.AddUpdate(xUpdate, UpdateOrder);
                }
            }
            if (luaLateUpdate != null)
            {
                if (luaLateUpdate.GetInvocationList().Length >= 1)
                {
                    enable_lateupdate = true;
                    TimeMachine.I.AddUpdate(xLateUpdate, UpdateOrder);
                }
            }


            lua_runed = true;
            mUIEntity = gameObject.GetComponent <UIEntity>();
            if (mUIEntity == null)
            {
                UIBehaviour = false;
            }
        }
 private void RaiseEvent(Action<string, byte[]> handler, string key, RedisResult value)
 {
     if (handler == null) return;
     foreach (Action<string, byte[]> child in handler.GetInvocationList())
     {
         try
         {
             child(key, value.ValueBytes);
         }
         catch (Exception ex)
         {
             OnError("Subscriber callback", ex, false);
         }
     }
 }
Пример #17
0
 private Action AddUnique(Action listeners, Action callback)
 {
     if (!listeners.GetInvocationList().Contains(callback))
     {
         listeners += callback;
     }
     return listeners;
 }
Пример #18
0
        private static MethodBehaviors InvokeDuringEventWithBehaviorDecision(Action<DuringCallbackEventArgs> call, DuringCallbackEventArgs args)
        {
            if (call == null) {
                return MethodBehaviors.IDontCare;
            }
            bool wasLastOptionChangedAtLeastOnce = false;
            MethodBehaviors lastOption = args.MethodBehavior;
            Aspect lastAspect = null;

            Delegate[] list = call.GetInvocationList();
            foreach (Delegate d2 in list) {
                try {
                    Action<DuringCallbackEventArgs> invokeEvent = d2 as Action<DuringCallbackEventArgs>;
                    args.MethodBehavior = MethodBehaviors.IDontCare;
                    args.WasBehaviorSet = false;

                    invokeEvent(args);
                    bool wasRealBehaviorSet = args.WasBehaviorSet && args.MethodBehavior != MethodBehaviors.IDontCare;
                    bool isNewBehaviorConflictingWithOlderBehaviorRequest = wasRealBehaviorSet && lastOption != MethodBehaviors.IDontCare;
                    bool isThisTheFirstRealBehaviorSelection = wasRealBehaviorSet && !wasLastOptionChangedAtLeastOnce;

                    //var aspect = GetAspectHandledBy(invokeEvent);

                    if (isThisTheFirstRealBehaviorSelection) {
                        wasLastOptionChangedAtLeastOnce = true;
                        lastAspect = GetAspectHandledBy(invokeEvent);
                        lastOption = args.MethodBehavior;
                        continue;
                    }

                    if (isNewBehaviorConflictingWithOlderBehaviorRequest) {
                        Aspect currentAspect = GetAspectHandledBy(invokeEvent);
                        string msg = BuildConflictMessage(args, lastOption, lastAspect, currentAspect);
                        throw new ConflictingBehaviorException(msg);
                    }
                    if (args.MethodBehavior != MethodBehaviors.IDontCare) {
                        lastAspect = GetAspectHandledBy(invokeEvent);
                        lastOption = args.MethodBehavior;
                    }
                }

                catch (Exception e) {
                    args.MethodBehavior = MethodBehaviors.ThrowException;
                    args.ReturnValueOrException = e;
                    return MethodBehaviors.ThrowException;
                }
            }

            return lastOption;
        }
Пример #19
0
		void AddUnique(ref Action listeners, Action callback) //ref because it's initially null
		{
			if (listeners == null || !listeners.GetInvocationList().Contains(callback)) {
				listeners += callback;
			}
		}
Пример #20
0
 public static Action<Danmaku> RemoveAll(this Action<Danmaku> source, Action<Danmaku> toRemove) {
     Delegate[] elements = toRemove.GetInvocationList();
     foreach (var element in elements)
         source = Delegate.Remove(source, element) as Action<Danmaku>;
     return source;
 }