Example #1
0
    public void SetParams(string aID, double aMaxSecs, double aMaxMins, double aMaxHours, double aMaxDays, double aMaxMonths, List <string> aMonths, FunctionToCall aFunc, int aTimescale)
    {
        id = aID;

        maxSeconds = aMaxSecs;
        maxMinutes = aMaxMins;
        maxHours   = aMaxHours;
        maxDays    = aMaxDays;
        maxMonths  = aMaxMonths;

        months = aMonths;

        timeScale = aTimescale;

        functionToCall = aFunc;

        month  = 1;
        hour   = 39;
        minute = 0;
        day    = 40;
        year   = 0001;

        isPaused = true;

        Debug.Log("Params Set");
    }
Example #2
0
    static void Main()
    {
        FunctionToCall <string> functionDelegate = PrintString;

        functionDelegate += PrintUpperString;
        functionDelegate("Hi There.");
    }
Example #3
0
        virtual public void run_loop()
        {
            lock (i)
            {
                if (i.ContainsKey("running"))
                {
                    return;
                }
                i["running"] = true;
            }
            for (; ;)
            {
                lock (q)
                {
                    while (q.Count > 0)
                    {
                        FunctionToCall f = (FunctionToCall)q.Dequeue();
                        f();

                        /*{
                         *  Thread thread = new Thread(delegate() { f(); });
                         *  thread.IsBackground = true;
                         *  thread.SetApartmentState(System.Threading.ApartmentState.STA);
                         *  thread.Start();
                         * }*/
                    }
                    Monitor.Wait(q);
                }
            }
            lock (i)
            {
                i.Remove("running");
            }
        }
Example #4
0
 public UserAction(string _DisplayString, FunctionToCall _UserActionFunctionStart, FunctionToCall _UserActionFunctionWhile, FunctionToCall _UserActionFunctionEnd, string _AnimBool)
 {
     DisplayString           = _DisplayString;
     UserActionFunctionStart = _UserActionFunctionStart;
     UserActionFunctionWhile = _UserActionFunctionWhile;
     UserActionFunctionEnd   = _UserActionFunctionEnd;
     AnimBool = _AnimBool;
 }
Example #5
0
    static void Main()
    {
        FunctionToCall functionDelegate = Add2;

        functionDelegate += Add3;
        functionDelegate += Add2;

        Console.WriteLine("Value: {0}", functionDelegate());
    }
Example #6
0
    static void Main()
    {
        FunctionToCall del = delegate(int x) {
            return(x + 20);
        };

        Console.WriteLine("{0}", del(5));
        Console.WriteLine("{0}", del(6));
    }
        [TestMethod] // -----------------------------------------------------------------------
        public void TestMethod3()
        {
            FunctionToCall functionDelegate = Add2;     // 5+2

            functionDelegate += Add3;                   // 7+3
            functionDelegate += Add2;                   // 10+2

            HLog.print("Value: {0}", functionDelegate); // result= 12
        }
Example #8
0
        /// <summary>
        /// Removes a delegate from an IGameEvent list, if it exists.
        /// Example:
        /// GlobalEventHandler.Unregister<PlayerDeathEvent>(OnPlayerDeathEvent)
        /// ...
        /// public void OnPlayerDeathEvent(PlayerDeathEvent evt){}
        /// </summary>
        /// <param name="evt"></param>
        /// <param name="f"></param>
        public static void Unregister <T>(FunctionToCall <T> f) where T : IGameEvent
        {
            // Grab the Type and make a temporary Tuple containing all the necessary data
            Type type = typeof(T);

            // Don't bother looking if it doesn't exist
            if (eventList.ContainsKey(type))
            {
                eventList[type].RemoveAll(x => (FunctionToCall <T>)x.Item2 == f);
            }
        }
Example #9
0
        /// <summary>
        /// Cria Um botão e associa a uma função
        /// </summary>
        /// <param name="func: ">Passar a função a ser associada.</param>
        /// <param name="pos: ">(Opcional)Posição que o botão vai ser instanciado X, y  (0 ~ 100).</param>

        public static void DebbugerButton(FunctionToCall func, Vector2?pos = null)
        {
            Vector2 localPositionConverted = pos ?? new Vector2(0, 0);

            localPositionConverted = ConvertCanvasPositionToScale(localPositionConverted);

            GameObject buttonToInstantiate = Instantiate(Resources.Load("DebbugButton") as GameObject);

            buttonToInstantiate.GetComponentInChildren <Text>().text = func.Method.Name;
            buttonToInstantiate.GetComponentInChildren <Button>().onClick.AddListener(delegate { func(); });
            buttonToInstantiate.GetComponentInChildren <RectTransform>().pivot = new Vector2(0, 1);
            buttonToInstantiate.GetComponentInChildren <RectTransform>().GetChild(0).localPosition = localPositionConverted;
        }
Example #10
0
    static void Main(string[] args)
    {
        FunctionToCall functionDelegate = Add2;

        functionDelegate += Add3;
        functionDelegate += Add2;

        int x = 5;

        functionDelegate(ref x);

        Console.WriteLine("Value: {0}", x);
    }
Example #11
0
        /// <summary>
        /// Attaches a delegate to a specific IGameEvent.
        /// Example:
        /// GlobalEventHandler.Register<PlayerDeathEvent>(OnPlayerDeathEvent)
        /// ...
        /// public void OnPlayerDeathEvent(PlayerDeathEvent evt){}
        /// </summary>
        /// <param name="evt"></param>
        /// <param name="f"></param>
        public static void Register <T>(FunctionToCall <T> f) where T : IGameEvent
        {
            // First, get the class Type
            Type type = typeof(T);

            // If it doesn't exist, add an entry for it
            if (!eventList.ContainsKey(type))
            {
                eventList.Add(type, new List <Tuple <GameObject, object> >());
            }
            // Add the delegate to the list. The Target is cast explicitly to MonoBehaviour in order to retrieve the GameObject instance
            eventList[type].Add(new Tuple <GameObject, object>(
                                    ((MonoBehaviour)f.Target).gameObject,
                                    (object)f
                                    ));
        }
Example #12
0
        virtual public void go_to(FunctionToCall f)
        {
            lock (i)
            {
                if ((bool)i["slave"])
                {
                    ((FunctionQueue)i["queue"])(f);
                    return;
                }
            }

            lock (q)
            {
                q.Enqueue(f);

                lock (q) Monitor.Pulse(q);
            }
        }
Example #13
0
 // ReSharper restore InconsistentNaming
 public static void SetDelegate(FunctionToCall function)
 {
     GetPosFromDelegate = function;
 }
Example #14
0
 // ReSharper restore InconsistentNaming
 public static void SetDelegate(FunctionToCall function)
 {
     GetPosFromDelegate = function;
 }