public Condition(string template, string functionNameRegex = @".*",
                  ConditionMode mode = ConditionMode.CurrentStackFrame)
 {
     Template          = template;
     FunctionNameRegex = functionNameRegex;
     Mode = mode;
 }
Esempio n. 2
0
        public override IGate Decompose(ConditionMode mode)
        {
            var it = Elements.GetEnumerator();
            var r = InitialGate;
            while (it.MoveNext())
            {
                var e = it.Current.Decompose(mode);
                r = Gate.Compose(Type, r, e);
            }

            return r;
        }
Esempio n. 3
0
        public override IGate Decompose(ConditionMode mode)
        {
            var it = Elements.GetEnumerator();
            var r  = InitialGate;

            while (it.MoveNext())
            {
                var e = it.Current.Decompose(mode);
                r = Gate.Compose(Type, r, e);
            }

            return(r);
        }
Esempio n. 4
0
        public void SetModeState(ConditionMode mode)
        {
            invokeIfRequired(new Action(() =>
            {
                var items     = getItems();
                var modeItems = getModeItems();

                if (modeItems != null)
                {
                    var item     = items.FirstOrDefault(x => x.Text == mode.Name);
                    item.Checked = mode.IsActive;
                }
            }));
        }
Esempio n. 5
0
        private IGate DecomposeBoolean(ConditionMode mode)
        {
            var source = GetStateSource(mode).ToArray();

            if (source.Length > 1)
            {
                throw new CompilerException(ErrorCode.ConditionNeverSatisfied, "boolean state condition never satisfied.");
            }

            var c = CreateElementaryCondition(source.First());

            Gate.TraceDecompose(this, c, "decompose " + mode);

            return(c);
        }
Esempio n. 6
0
 public override IGate Decompose(ConditionMode mode)
 {
     if (mode == ConditionMode.Pre)
     {
         //return Left.Decompose(mode);
         return(_lgate);
     }
     else if (mode == ConditionMode.Post)
     {
         //return Right.Decompose(mode);
         return(_rgate);
     }
     else
     {
         throw new NotImplementedException();
     }
 }
Esempio n. 7
0
        /// <summary>
        /// Decomposes the state condition into its elementary parts.
        /// </summary>
        /// <param name="mode"></param>
        /// <returns></returns>
        public override IGate Decompose(ConditionMode mode)
        {
            Freeze();

            if (IsTransition && (mode != ConditionMode.Pre && mode != ConditionMode.Post))
            {
                throw new CompilerException(ErrorCode.BadCondition,
                                            "state transition cannot be decomposed into a static gate.");
            }

            if (Variable.Type.IsBoolean)
            {
                return(DecomposeBoolean(mode));
            }
            else
            {
                return(DecomposeSimple(mode));
            }
        }
Esempio n. 8
0
        private IEnumerable <int> GetStateSource(ConditionMode mode)
        {
            IEnumerable <int> source;
            var post = mode == ConditionMode.Post;

            if (IsTransition && post)
            {
                source = PostStateIndexes;
            }
            else
            {
                source = StateIndexes;
            }

            if (!source.Any())
            {
                throw new Exception("unable to decompose " + this + " empty source (" + mode + ")");
            }

            return(source);
        }
Esempio n. 9
0
        private IGate DecomposeSimple(ConditionMode mode)
        {
            var   source = GetStateSource(mode);
            var   it     = source.GetEnumerator();
            IGate r      = null;

            while (it.MoveNext())
            {
                var e = CreateElementaryCondition(it.Current);
                if (null == r)
                {
                    r = e;
                }
                else
                {
                    r = Gate.ComposeOR(r, e);
                }
            }

            Debug.Assert(null != r);
            Gate.TraceDecompose(this, r, "decompose " + mode);

            return(r);
        }
Esempio n. 10
0
        private IGate DecomposeBoolean(ConditionMode mode)
        {
            var source = GetStateSource(mode).ToArray();

            if (source.Length > 1)
            {
                throw new CompilerException(ErrorCode.ConditionNeverSatisfied, "boolean state condition never satisfied.");
            }

            var c = CreateElementaryCondition(source.First());

            Gate.TraceDecompose(this, c, "decompose " + mode);

            return c;
        }
Esempio n. 11
0
        private IGate DecomposeSimple(ConditionMode mode)
        {
            var source = GetStateSource(mode);
            var it = source.GetEnumerator();
            IGate r = null;
            while (it.MoveNext())
            {
                var e = CreateElementaryCondition(it.Current);
                if (null == r)
                {
                    r = e;
                }
                else
                {
                    r = Gate.ComposeOR(r, e);
                }
            }

            Debug.Assert(null != r);
            Gate.TraceDecompose(this, r, "decompose " + mode);

            return r;
        }
    public void Initialize(SerializedProperty property)
    {
        _listProp           = property.FindPropertyRelative(nameof(ConditionEvaluator.Items));
        _conditionEvaluator = fieldInfo.GetValue(property.serializedObject.targetObject) as ConditionEvaluator;
        _reorderableList    = new ReorderableList(property.serializedObject, _listProp, true, true, true, true);

        if (_conditionEvaluator.Items == null)
        {
            _conditionEvaluator.Items = new List <AnimationCondition>();
        }

        //_parameters = _conditionEvaluator.Parameters;
        _listHeight = _reorderableList.GetHeight();

        _reorderableList.drawElementCallback = (rect, index, isActive, isFocused) =>
        {
            EditorGUI.PropertyField(rect, _listProp.GetArrayElementAtIndex(index));
        };

        if (IntModes == null)
        {
            IntModes = new List <ConditionMode>
            {
                ConditionMode.Greater,
                ConditionMode.Less,
                ConditionMode.Equals,
                ConditionMode.NotEqual
            };
        }

        if (FloatModes == null)
        {
            FloatModes = new List <ConditionMode>
            {
                ConditionMode.Greater,
                ConditionMode.Less
            };
        }

        _reorderableList.drawHeaderCallback = rect =>
        {
            GUI.Label(rect, "Conditions");
        };

        _reorderableList.onAddCallback = list =>
        {
            var           _parametersCollection = _conditionEvaluator.Parameters;
            string        parameter             = "";
            ConditionMode mode = ConditionMode.Greater;
            if (_parametersCollection != null)
            {
                AnimatorControllerParameter[] parameters = _parametersCollection.Items;
                if (parameters.Length > 0)
                {
                    parameter = parameters[0].name;
                    mode      = parameters[0].type == AnimatorControllerParameterType.Float || parameters[0].type == AnimatorControllerParameterType.Int
                        ? ConditionMode.Greater
                        : ConditionMode.If;
                }
            }

            _conditionEvaluator.Items.Add(new AnimationCondition
            {
                ConditionMode = mode,
                Parameter     = parameter,
                Threshold     = 0f
            });
        };

        _reorderableList.drawElementCallback = (rect, index, active, focused) =>
        {
            var _parametersCollection = _conditionEvaluator.Parameters;
            SerializedProperty arrayElementAtIndex   = _listProp.GetArrayElementAtIndex(index);
            ConditionMode      animatorConditionMode = (ConditionMode)arrayElementAtIndex.FindPropertyRelative(nameof(AnimationCondition.ConditionMode)).intValue;
            int  num1      = 3;
            Rect rect1     = new Rect(rect.x, rect.y + 2f, rect.width, rect.height - 5f);
            Rect position1 = rect1;
            position1.xMax -= rect1.width / 2f + (float)num1;
            Rect position2 = rect1;
            position2.xMin += rect1.width / 2f + (float)num1;
            Rect position3 = position2;
            position3.xMax -= position2.width / 2f + (float)num1;
            Rect position4 = position2;
            position4.xMin += position2.width / 2f + (float)num1;
            string stringValue = arrayElementAtIndex.FindPropertyRelative("Parameter").stringValue;

            int           index1     = _parametersCollection?.IndexOfParameter(stringValue) ?? -1;
            bool          flag       = false;
            List <string> stringList = new List <string>();

            AnimatorControllerParameter[] controllerParameterArray = null;
            if (_parametersCollection != null)
            {
                controllerParameterArray = _parametersCollection.Items;
                for (int index2 = 0; index2 < controllerParameterArray.Length; ++index2)
                {
                    stringList.Add(controllerParameterArray[index2].name);
                }
            }

            string name = DelayedTextFieldDropDown(position1, stringValue, stringList.ToArray());
            if (stringValue != name)
            {
                index1 = _parametersCollection.IndexOfParameter(name);
                arrayElementAtIndex.FindPropertyRelative(nameof(AnimationCondition.Parameter)).stringValue = name;
                animatorConditionMode = ConditionMode.Greater;
                arrayElementAtIndex.FindPropertyRelative(nameof(AnimationCondition.ConditionMode)).intValue = (int)animatorConditionMode;
                flag = true;
            }

            AnimatorControllerParameterType controllerParameterType = index1 == -1
                ? (AnimatorControllerParameterType)(-1)
                : controllerParameterArray[index1].type;

            if (index1 != -1 && (controllerParameterType == AnimatorControllerParameterType.Float || controllerParameterType == AnimatorControllerParameterType.Int))
            {
                List <ConditionMode> animatorConditionModeList = controllerParameterType != AnimatorControllerParameterType.Float
                    ? IntModes
                    : FloatModes;

                string[] displayedOptions = new string[animatorConditionModeList.Count];
                for (int index2 = 0; index2 < displayedOptions.Length; ++index2)
                {
                    displayedOptions[index2] = animatorConditionModeList[index2].ToString();
                }
                int selectedIndex = -1;
                for (int index2 = 0; index2 < displayedOptions.Length; ++index2)
                {
                    if (animatorConditionMode.ToString() == displayedOptions[index2])
                    {
                        selectedIndex = index2;
                    }
                }
                if (selectedIndex == -1)
                {
                    Vector2 vector2   = GUI.skin.label.CalcSize(Styles.ErrorIcon);
                    Rect    position5 = position3;
                    position5.xMax  = position5.xMin + vector2.x;
                    position3.xMin += vector2.x;
                    GUI.Label(position5, Styles.ErrorIcon);
                }
                EditorGUI.BeginChangeCheck();
                int index3 = EditorGUI.Popup(position3, selectedIndex, displayedOptions);
                if (EditorGUI.EndChangeCheck() || flag)
                {
                    arrayElementAtIndex.FindPropertyRelative(nameof(AnimationCondition.ConditionMode)).intValue = (int)animatorConditionModeList[index3];
                }
                EditorGUI.BeginChangeCheck();
                float floatValue = arrayElementAtIndex.FindPropertyRelative(nameof(AnimationCondition.Threshold)).floatValue;
                float num2       = controllerParameterType != AnimatorControllerParameterType.Float ? (float)EditorGUI.IntField(position4, Mathf.FloorToInt(floatValue)) : EditorGUI.FloatField(position4, floatValue);
                if (!EditorGUI.EndChangeCheck() && !flag)
                {
                    return;
                }
                arrayElementAtIndex.FindPropertyRelative(nameof(AnimationCondition.Threshold)).floatValue = num2;
            }
            else if (index1 != -1 && controllerParameterType == AnimatorControllerParameterType.Bool)
            {
                string[] displayedOptions = new string[2]
                {
                    "true",
                    "false"
                };
                int selectedIndex = animatorConditionMode != ConditionMode.IfNot ? 0 : 1;
                EditorGUI.BeginChangeCheck();
                int num2 = EditorGUI.Popup(position2, selectedIndex, displayedOptions);
                if (!EditorGUI.EndChangeCheck() && !flag)
                {
                    return;
                }
                arrayElementAtIndex.FindPropertyRelative(nameof(AnimationCondition.ConditionMode)).intValue = num2 != 0 ? 2 : 1;
            }
            else if (controllerParameterType == AnimatorControllerParameterType.Trigger)
            {
                if (!flag)
                {
                    return;
                }
                arrayElementAtIndex.FindPropertyRelative(nameof(AnimationCondition.ConditionMode)).intValue = 1;
            }
            else
            {
                EditorGUI.LabelField(position2, "Parameter does not exist in Controller");
            }
        };

        _initialized = true;
    }
Esempio n. 13
0
        /// <summary>
        /// Decomposes the state condition into its elementary parts.
        /// </summary>
        /// <param name="mode"></param>
        /// <returns></returns>
        public override IGate Decompose(ConditionMode mode)
        {
            Freeze();

            if(IsTransition && (mode != ConditionMode.Pre && mode != ConditionMode.Post))
            {
                throw new CompilerException(ErrorCode.BadCondition,
                    "state transition cannot be decomposed into a static gate.");
            }

            if (Variable.Type.IsBoolean)
            {
                return DecomposeBoolean(mode);
            }
            else
            {
                return DecomposeSimple(mode);
            }
        }
Esempio n. 14
0
 public override IGate Decompose(ConditionMode mode)
 {
     return this;
 }
Esempio n. 15
0
 public ModeChangedEventArgs(string message, ConditionMode mode)
 {
     Message   = message;
     Mode      = mode;
     TimeStamp = DateTime.Now;
 }
Esempio n. 16
0
 public void AddMode(ConditionMode mode)
 {
     _modes.Add(mode);
 }
Esempio n. 17
0
 public override IGate Decompose(ConditionMode mode)
 {
     return Gate.Invert(_b.Decompose(mode));
 }
Esempio n. 18
0
 public override IGate Decompose(ConditionMode mode)
 {
     return(this);
 }
Esempio n. 19
0
        public void SetModeState(ConditionMode mode)
        {
            var temp = _modes.FirstOrDefault(x => x.Name == mode.Name);

            temp.IsActive = mode.IsActive;
        }
Esempio n. 20
0
 public ModeOnClickEventArgs(ConditionMode mode)
 {
     Mode = mode;
 }
Esempio n. 21
0
        public static PropertyOption Create(string name, string code, bool conditional = false, ConditionMode mode = ConditionMode.IS, string conditionalTarget = "", string conditionalValue = "")
        {
            PropertyOption prop = new PropertyOption();

            prop.set(name, code, conditional);

            if (conditional)
            {
                prop.ConditionPropertyTarget = conditionalTarget;
                prop.ConditionValue          = conditionalValue;
                prop.mode = mode;
            }

            return(prop);
        }
Esempio n. 22
0
 /// <summary>
 /// Decomposes this condition into a gate.
 /// </summary>
 /// <param name="mode">Selects pre- or postcondition.</param>
 /// <returns>The resulting gate.</returns>
 public abstract IGate Decompose(ConditionMode mode);
Esempio n. 23
0
        private IEnumerable<int> GetStateSource(ConditionMode mode)
        {
            IEnumerable<int> source;
            var post = mode == ConditionMode.Post;

            if (IsTransition && post)
            {
                source = PostStateIndexes;
            }
            else
            {
                source = StateIndexes;
            }

            if (!source.Any())
            {
                throw new Exception("unable to decompose " + this + " empty source (" + mode + ")");
            }

            return source;
        }
Esempio n. 24
0
 public override IGate Decompose(ConditionMode mode)
 {
     if(mode == ConditionMode.Pre)
     {
         //return Left.Decompose(mode);
         return _lgate;
     }
     else if(mode == ConditionMode.Post)
     {
         //return Right.Decompose(mode);
         return _rgate;
     }
     else
     {
         throw new NotImplementedException();
     }
 }
Esempio n. 25
0
 public override IGate Decompose(ConditionMode mode)
 {
     return Gate.Constant(true);
 }
Esempio n. 26
0
 public override IGate Decompose(ConditionMode mode)
 {
     return(Gate.Constant(true));
 }
Esempio n. 27
0
 public override IGate Decompose(ConditionMode mode)
 {
     return(Gate.Invert(_b.Decompose(mode)));
 }
 public static void SetConditionMode(DependencyObject obj, ConditionMode value)
 {
     obj.SetValue(ConditionModeProperty, value);
 }
 public void AddMode(ConditionMode mode)
 {
 }
Esempio n. 30
0
 /// <summary>
 /// Decomposes this condition into a gate.
 /// </summary>
 /// <param name="mode">Selects pre- or postcondition.</param>
 /// <returns>The resulting gate.</returns>
 public abstract IGate Decompose(ConditionMode mode);