예제 #1
0
        public ControlOutput Enter(Flow flow)
        {
            var    data         = flow.stack.GetElementData <Data>(this);
            object currentValue = flow.GetValue <object>(input);


            if (!OperatorUtility.Equal(data.lastValue, currentValue))
            {
                data.lastValue = currentValue;
                flow.SetValue(lastValue, currentValue);
                return(onChange);
            }

            return(null);
        }
예제 #2
0
 private bool GenericComparison(object a, object b)
 {
     return(OperatorUtility.Equal(a, b));
 }
예제 #3
0
        private bool GetValue(Flow flow)
        {
            switch (BranchingType)
            {
            case BranchType.And:
                foreach (var item in arguments)
                {
                    if (!flow.GetValue <bool>(item))
                    {
                        return(false);
                    }
                }
                return(true);

            case BranchType.Or:
                foreach (var item in arguments)
                {
                    if (flow.GetValue <bool>(item))
                    {
                        return(true);
                    }
                }
                return(false);

            case BranchType.GreaterThan:
            {
                bool NumericComparison(float a, float b, bool allowEquals)
                {
                    return((a > b) || (allowEquals && Mathf.Approximately(a, b)));
                }

                return(NumericComparison(flow.GetValue <float>(arguments[0]), flow.GetValue <float>(arguments[1]), AllowEquals));
            }

            case BranchType.LessThan:
            {
                bool NumericComparison(float a, float b, bool allowEquals)
                {
                    return((a < b) || (allowEquals && Mathf.Approximately(a, b)));
                }

                return(NumericComparison(flow.GetValue <float>(arguments[0]), flow.GetValue <float>(arguments[1]), AllowEquals));
            }

            case BranchType.Equal:
                if (Numeric)
                {
                    var target = flow.GetValue <float>(arguments[0]);

                    for (int i = 1; i < arguments.Count; i++)
                    {
                        Debug.Log(flow.GetValue <float>(arguments[i]));
                        if (!Mathf.Approximately(target, flow.GetValue <float>(arguments[i])))
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
                else
                {
                    var target = flow.GetValue <object>(arguments[0]);

                    for (int i = 1; i < arguments.Count; i++)
                    {
                        if (!OperatorUtility.Equal(target, flow.GetValue <object>(arguments[i])))
                        {
                            return(false);
                        }
                    }
                    return(true);
                }

            default:
                return(false);
            }
        }
 private bool Equal(Flow flow)
 {
     return(OperatorUtility.Equal(flow.GetValue(a), flow.GetValue(b)));
 }
예제 #5
0
 protected override bool GenericComparison(object a, object b)
 {
     return(OperatorUtility.Equal(a, b));
 }
        protected override bool ShouldTrigger(Flow flow, EmptyEventArgs args)
        {
            var data = flow.stack.GetElementData <Data>(this);

            if (!data.isListening)
            {
                return(false);
            }

            var name = flow.GetValue <string>(this.name);

            VariableDeclarations variables;

            switch (kind)
            {
            case VariableKind.Flow:
                variables = flow.variables;
                break;

            case VariableKind.Graph:
                variables = Variables.Graph(flow.stack);
                break;

            case VariableKind.Object:
                variables = Variables.Object(flow.GetValue <GameObject>(@object));
                break;

            case VariableKind.Scene:
                variables = Variables.Scene(flow.stack.scene);
                break;

            case VariableKind.Application:
                variables = Variables.Application;
                break;

            case VariableKind.Saved:
                variables = Variables.Saved;
                break;

            default:
                throw new UnexpectedEnumValueException <VariableKind>(kind);
            }
            var val = variables.Get(name);

            if (data.firstExecution)
            {
                if (provideInitial)
                {
                    data._previousValue = flow.GetValue <object>(Initial);
                }
                else
                {
                    data._previousValue = val;
                }
            }



            bool equal = OperatorUtility.Equal(data._previousValue, val);

            if (!equal)
            {
                data._previousValue = val;
                flow.SetValue(value, val);
            }

            data.firstExecution = false;

            return(!equal);
        }
        public override void Visit(BinaryExpression binary)
        {
            // Simulate Lazy<Func<>> behavior for late evaluation
            object        leftValue = null;
            Func <object> left      = () =>
            {
                if (leftValue == null)
                {
                    binary.LeftExpression.Accept(this);
                    leftValue = Result;
                }
                return(leftValue);
            };

            // Simulate Lazy<Func<>> behavior for late evaluation
            object        rightValue = null;
            Func <object> right      = () =>
            {
                if (rightValue == null)
                {
                    binary.RightExpression.Accept(this);
                    rightValue = Result;
                }
                return(rightValue);
            };

            switch (binary.Type)
            {
            case BinaryExpressionType.And:
                Result = ConversionUtility.Convert <bool>(left()) && ConversionUtility.Convert <bool>(right());
                break;

            case BinaryExpressionType.Or:
                Result = ConversionUtility.Convert <bool>(left()) || ConversionUtility.Convert <bool>(right());
                break;

            case BinaryExpressionType.Div:
                Result = OperatorUtility.Divide(left(), right());
                break;

            case BinaryExpressionType.Equal:
                Result = OperatorUtility.Equal(left(), right());
                break;

            case BinaryExpressionType.Greater:
                Result = OperatorUtility.GreaterThan(left(), right());
                break;

            case BinaryExpressionType.GreaterOrEqual:
                Result = OperatorUtility.GreaterThanOrEqual(left(), right());
                break;

            case BinaryExpressionType.Lesser:
                Result = OperatorUtility.LessThan(left(), right());
                break;

            case BinaryExpressionType.LesserOrEqual:
                Result = OperatorUtility.LessThanOrEqual(left(), right());
                break;

            case BinaryExpressionType.Minus:
                Result = OperatorUtility.Subtract(left(), right());
                break;

            case BinaryExpressionType.Modulo:
                Result = OperatorUtility.Modulo(left(), right());
                break;

            case BinaryExpressionType.NotEqual:
                Result = OperatorUtility.NotEqual(left(), right());
                break;

            case BinaryExpressionType.Plus:
                Result = OperatorUtility.Add(left(), right());
                break;

            case BinaryExpressionType.Times:
                Result = OperatorUtility.Multiply(left(), right());
                break;

            case BinaryExpressionType.BitwiseAnd:
                Result = OperatorUtility.And(left(), right());
                break;

            case BinaryExpressionType.BitwiseOr:
                Result = OperatorUtility.Or(left(), right());
                break;

            case BinaryExpressionType.BitwiseXOr:
                Result = OperatorUtility.ExclusiveOr(left(), right());
                break;

            case BinaryExpressionType.LeftShift:
                Result = OperatorUtility.LeftShift(left(), right());
                break;

            case BinaryExpressionType.RightShift:
                Result = OperatorUtility.RightShift(left(), right());
                break;
            }
        }