Example #1
0
        //--------------------------------------------------------------------------------------------/
        // Methods
        //--------------------------------------------------------------------------------------------/
        /// <summary>
        /// Shows/hides this window
        /// </summary>
        /// <param name="show"></param>
        /// <param name="onFinished"></param>
        public void Transition(bool show, System.Action onFinished = null)
        {
            if (debug)
            {
                StratusDebug.Log(show, this);
            }

            if (!show)
            {
                eventSystem.SetSelectedGameObject(null);
            }

            canvas.blocksRaycasts = show;
            canvas.interactable   = show;
            pollingInput          = show;

            currentSeq?.Cancel();
            currentSeq = StratusActions.Sequence(this);



            // Fade the canvas
            StratusActions.Property(currentSeq, () => canvas.alpha, show ? 1f : 0f, transitionSpeed, Ease.Linear);
            StratusActions.Call(currentSeq, () => { visible = false; });

            // Optionally, select the default button
            if (defaultSelected)
            {
                //Trace.Script($"Selecting {defaultSelected.name}", this);
                if (show)
                {
                    StratusActions.Call(currentSeq, () => eventSystem.SetSelectedGameObject(defaultSelected.gameObject));
                }
            }

            // Optionally, reset the state of all other selectables
            if (controlSelectables)
            {
                foreach (var selectable in selectables)
                {
                    if (selectable == defaultSelected)
                    {
                        continue;
                    }

                    selectable.OnDeselect(null);
                }
            }

            // Now invoke any callbacks
            if (onFinished != null)
            {
                StratusActions.Call(currentSeq, () => { onFinished(); });
            }
        }
        /// <summary>
        /// Adds a function to be invoked as part of the action set, alongside any arguments.
        /// Optionally, it also can add a delay before the function is invoked.
        /// </summary>
        /// <param name="set">A reference to the action set.</param>
        /// <param name="func">The function to which to call.</param>
        public static StratusAction Call(StratusActionSet set, StratusActionCall.Delegate func, float delay = 0.0f)
        {
            StratusAction call = new StratusActionCall(func);

            // Optionally, add a delay
            if (delay != 0.0f)
            {
                Delay(set, delay);
            }
            set.Add(call);
            return(call);
        }
        /// <summary>
        /// Adds a property change to the action set.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="set">A reference to the set.</param>
        /// <param name="varExpr">A lambda expression encapsulating a reference to the property which will be modified</param>
        /// <param name="value">The new value for the property</param>
        /// <param name="duration">Over how long should the property be changed</param>
        /// <param name="ease">What interpolation algorithm to use</param>
        public static void Property <T>(StratusActionSet set, Expression <Func <T> > varExpr, T value, float duration, Ease ease)
        {
            var memberExpr   = varExpr.Body as MemberExpression;
            var inst         = memberExpr.Expression;
            var variableName = memberExpr.Member.Name;
            var targetObj    = Expression.Lambda <Func <object> >(inst).Compile()();

            // Construct an action then branch depending on whether the member to be
            // interpolated is a property or a field
            StratusAction action = null;

            // Property
            var property = targetObj.GetType().GetProperty(variableName, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);

            if (property != null)
            {
                var propertyType = property.PropertyType;

                if (propertyType == typeof(float))
                {
                    action = new StratusActionPropertyFloat(targetObj, property, Convert.ToSingle(value), duration, ease);
                }
                else if (propertyType == typeof(int))
                {
                    action = new StratusActionPropertyInt(targetObj, property, Convert.ToInt32(value), duration, ease);
                }
                else if (propertyType == typeof(bool))
                {
                    action = new StratusActionPropertyBool(targetObj, property, Convert.ToBoolean(value), duration, ease);
                }
                else if (propertyType == typeof(Vector2))
                {
                    action = new StratusActionPropertyVector2(targetObj, property, (Vector2)Convert.ChangeType(value, typeof(Vector2)), duration, ease);
                }
                else if (propertyType == typeof(Vector3))
                {
                    action = new StratusActionPropertyVector3(targetObj, property, (Vector3)Convert.ChangeType(value, typeof(Vector3)), duration, ease);
                }
                else if (propertyType == typeof(Vector4))
                {
                    action = new StratusActionPropertyVector4(targetObj, property, (Vector4)Convert.ChangeType(value, typeof(Vector4)), duration, ease);
                }
                else if (propertyType == typeof(Color))
                {
                    action = new StratusActionPropertyColor(targetObj, property, (Color)Convert.ChangeType(value, typeof(Color)), duration, ease);
                }
                else if (propertyType == typeof(Quaternion))
                {
                    action = new StratusActionPropertyQuaternion(targetObj, property, (Quaternion)Convert.ChangeType(value, typeof(Quaternion)), duration, ease);
                }
                else
                {
                    Stratus.StratusDebug.Log("Couldn't find the property!");
                }
            }
            // Field
            else
            {
                var field     = targetObj.GetType().GetField(variableName, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
                var fieldType = field.FieldType;

                if (fieldType == typeof(float))
                {
                    action = new StratusActionPropertyFloat(targetObj, field, Convert.ToSingle(value), duration, ease);
                }
                else if (fieldType == typeof(int))
                {
                    action = new StratusActionPropertyInt(targetObj, field, Convert.ToInt32(value), duration, ease);
                }
                else if (fieldType == typeof(bool))
                {
                    action = new StratusActionPropertyBool(targetObj, field, Convert.ToBoolean(value), duration, ease);
                }
                else if (fieldType == typeof(Vector2))
                {
                    action = new StratusActionPropertyVector2(targetObj, field, (Vector2)Convert.ChangeType(value, typeof(Vector2)), duration, ease);
                }
                else if (fieldType == typeof(Vector3))
                {
                    action = new StratusActionPropertyVector3(targetObj, field, (Vector3)Convert.ChangeType(value, typeof(Vector3)), duration, ease);
                }
                else if (fieldType == typeof(Vector4))
                {
                    action = new StratusActionPropertyVector4(targetObj, field, (Vector4)Convert.ChangeType(value, typeof(Vector4)), duration, ease);
                }
                else if (fieldType == typeof(Color))
                {
                    action = new StratusActionPropertyColor(targetObj, field, (Color)Convert.ChangeType(value, typeof(Color)), duration, ease);
                }
                else if (fieldType == typeof(Quaternion))
                {
                    action = new StratusActionPropertyQuaternion(targetObj, field, (Quaternion)Convert.ChangeType(value, typeof(Quaternion)), duration, ease);
                }
                else
                {
                    Stratus.StratusDebug.Log("Couldn't find the field!");
                }
            }
            // Now add it!
            set.Add(action);
        }
 /// <summary>
 /// Destroys the specified object after a set amount of time
 /// </summary>
 /// <param name="set"></param>
 /// <param name="obj"></param>
 /// <param name="delay"></param>
 public static void Destroy(StratusActionSet set, UnityEngine.Object obj, float delay = 0.0f)
 {
     Call(set, () => GameObject.Destroy(obj, delay));
 }