Exemple #1
0
        public static void TestRefReturn()
        {
            GetRef <c1> refa = () => ref a;

            refa().a[0] = "c";

            Assert.AreEqual("c", refa().a[0], "Changing array elements' values works.");

            var score = new Score();

            score.Get() = 10;
            Assert.AreEqual(10, score.Get(), "Changing value of reference to variable returned by ref method works.");

            var s = score.Get();

            int i = 1;

            Set(ref i);
            Assert.AreEqual(11, i, "Ref method can change the value of the target pointed by a reference passed in.");

            Set(ref s);
            Assert.AreEqual(11, s, "Ref method can change the value of an indirect target reference passed in.");
            Assert.AreEqual(10, score.Get(), "Changing the value of a variable which reference has been replaced does not affect the value of the former reference.");

            Set(ref score.Get());
            Assert.AreEqual(11, score.Get(), "Passing a reference to a ref return method to another ref return method works as expected.");

            score.Get() = 10;
            Set1(score.Get());
            Assert.AreEqual(10, score.Get(), "Non-ref method will not change the passed value outside its scope.");
        }
Exemple #2
0
        public static void WaitForHandle(GetRef <Action> Action, Action Handle)
        {
            var    Task     = new Task(() => { });
            Action MyAction = null;

            MyAction = () => {
                Handle();
                Action() -= MyAction;
            };
            Action() += MyAction;
        }
        /// <summary>
        /// Tween a field of an object to a certain value.
        /// </summary>
        /// <param name="item">Object to tween a field from.</param>
        /// <param name="selector">Selector that returns a ref to the field given the object.</param>
        /// <param name="from">Start value of the tween.</param>
        /// <param name="to">End value of the tween.</param>
        /// <param name="duration">Duration of the tween.</param>
        /// <param name="easingFunction">Easing function to apply for the tween.</param>
        /// <param name="lerp">Linear interpolation function to use.</param>
        /// <typeparam name="TItem">Type of the object.</typeparam>
        /// <typeparam name="TProperty">Type of the field.</typeparam>
        public void Tween <TItem, TProperty>(TItem item, GetRef <TItem, TProperty> selector, TProperty from, TProperty to, TimeSpan duration, Ease easingFunction, Lerp <TProperty> lerp)
        {
            var tween = ObjectPool <Tween <TItem, TProperty> > .Shared.Get();

            tween.Item           = item;
            tween.Selector       = selector;
            tween.Lerp           = lerp;
            tween.From           = from;
            tween.To             = to;
            tween.EasingFunction = easingFunction;
            Tween(tween, duration);
        }
Exemple #4
0
        public static Task WaitForHandle(GetRef <Action> Action)
        {
            var    Task     = new Task(() => { });
            Action MyAction = null;

            MyAction = () => {
                Task.Start();
                Action() -= MyAction;
            };
            Action() += MyAction;
            return(Task);
        }
Exemple #5
0
        public static Task <t> WaitForHandle <t>(GetRef <Action <t> > Action)
        {
            t          Result   = default(t);
            var        Task     = new Task <t>(() => Result);
            Action <t> MyAction = null;

            MyAction = (v) => {
                Result = v;
                Task.Start();
                Action() -= MyAction;
            };
            Action() += MyAction;
            return(Task);
        }
Exemple #6
0
        public static void WaitForHandle(GetRef <Action> Action, Action Handle)
        {
            var    Locker   = new object();
            var    Runned   = false;
            Action MyAction = null;

            MyAction = () => {
                lock (Locker)
                {
                    if (Runned == false)
                    {
                        Action() -= MyAction;
                        Runned    = true;
                        Handle();
                    }
                }
            };
            Action() += MyAction;
        }
Exemple #7
0
        public static Task WaitForHandle(GetRef <Action> Action)
        {
            var    Runned   = false;
            var    Waiter   = new Task(() => { });
            Action MyAction = null;

            MyAction = () => {
                lock (Waiter)
                {
                    if (Runned == false)
                    {
                        Action() -= MyAction;
                        Runned    = true;
                        Waiter.Start();
                    }
                }
            };
            Action() += MyAction;
            return(Waiter);
        }
 /// <summary>
 /// Tween a field of an object to a certain value. The current value is used as the start value.
 /// </summary>
 /// <remarks>
 /// This overload dynamically generates and compiles a Lerp method for the type T using Add(T, T),
 /// Subtract(T, T) and Multiply(float, T) operators.
 /// If the type of the field does not implement these operators this function call will fail.
 /// You can add a custom Lerp function as an additional parameter to use another overload and bypass
 /// the dynamic Lerp generation.
 /// </remarks>
 /// <param name="item">Object to tween a field from.</param>
 /// <param name="selector">Selector that returns a ref to the field given the object.</param>
 /// <param name="to">End value of the tween.</param>
 /// <param name="duration">Duration of the tween.</param>
 /// <param name="easingFunction">Easing function to apply for the tween.</param>
 /// <param name="lerp">Linear interpolation function to use.</param>
 /// <typeparam name="TItem">Type of the object.</typeparam>
 /// <typeparam name="TProperty">Type of the field.</typeparam>
 public void Tween <TItem, TProperty>(TItem item, GetRef <TItem, TProperty> selector, TProperty to, TimeSpan duration, Ease easingFunction, Lerp <TProperty> lerp)
 {
     Tween(item, selector, selector(item), to, duration, easingFunction, lerp);
 }
 /// <summary>
 /// Tween a field of an object to a certain value.
 /// </summary>
 /// <remarks>
 /// This overload dynamically generates and compiles a Lerp method for the type T using Add(T, T),
 /// Subtract(T, T) and Multiply(float, T) operators.
 /// If the type of the field does not implement these operators this function call will fail.
 /// You can add a custom Lerp function as an additional parameter to use another overload and bypass
 /// the dynamic Lerp generation.
 /// </remarks>
 /// <param name="item">Object to tween a field from.</param>
 /// <param name="selector">Selector that returns a ref to the field given the object.</param>
 /// <param name="from">Start value of the tween.</param>
 /// <param name="to">End value of the tween.</param>
 /// <param name="seconds">Duration of the tween in seconds.</param>
 /// <param name="easingFunction">Easing function to apply for the tween.</param>
 /// <param name="lerp">Linear interpolation function to use.</param>
 /// <typeparam name="TItem">Type of the object.</typeparam>
 /// <typeparam name="TProperty">Type of the field.</typeparam>
 public void Tween <TItem, TProperty>(TItem item, GetRef <TItem, TProperty> selector, TProperty from, TProperty to, float seconds, Ease easingFunction, Lerp <TProperty> lerp)
 {
     Tween(item, selector, from, to, TimeSpan.FromSeconds(seconds), easingFunction, lerp);
 }
 /// <summary>
 /// Tween a field of an object to a certain value.
 /// </summary>
 /// <remarks>
 /// This overload dynamically generates and compiles a Lerp method for the type T using Add(T, T),
 /// Subtract(T, T) and Multiply(float, T) operators.
 /// If the type of the field does not implement these operators this function call will fail.
 /// You can add a custom Lerp function as an additional parameter to use another overload and bypass
 /// the dynamic Lerp generation.
 /// </remarks>
 /// <param name="item">Object to tween a field from.</param>
 /// <param name="selector">Selector that returns a ref to the field given the object.</param>
 /// <param name="from">Start value of the tween.</param>
 /// <param name="to">End value of the tween.</param>
 /// <param name="duration">Duration of the tween.</param>
 /// <param name="easingFunction">Easing function to apply for the tween.</param>
 /// <typeparam name="TItem">Type of the object.</typeparam>
 /// <typeparam name="TProperty">Type of the field.</typeparam>
 public void Tween <TItem, TProperty>(TItem item, GetRef <TItem, TProperty> selector, TProperty from, TProperty to, TimeSpan duration, Ease easingFunction)
 {
     Tween(item, selector, from, to, duration, easingFunction, LerpGen <TProperty> .Lerp);
 }
Exemple #11
0
 public static Task <t> WaitForHandle <t>(GetRef <Action <t> > Action) =>
 Actions.WaitForHandle(Action);
Exemple #12
0
 public static void WaitForHandle(this GetRef <Action> Action) =>
 Actions.WaitForHandle(Action);
Exemple #13
0
 public static Task WaitForHandle(this GetRef <Action> Action) =>
 DelegateActions.WaitForHandle(Action);