示例#1
0
 public StagPoint.Eval.Environment GetExpressionEnvironment()
 {
     if (expressionEnvironment != null)
     {
         return(expressionEnvironment);
     }
     expressionEnvironment = keyable.GetExpressionEnvironment().Push();
     Slate.Expressions.ExpressionParameterWrapper.Wrap(this, expressionEnvironment);
     return(expressionEnvironment);
 }
 public StagPoint.Eval.Environment GetExpressionEnvironment()
 {
     if (env != null)
     {
         return(env);
     }
     env = keyable.GetExpressionEnvironment().Push();
     Slate.Expressions.ExpressionsUtility.Wrap(this, env);
     return(env);
 }
        StagPoint.Eval.Environment IDirectable.GetExpressionEnvironment()
        {
            if (expressionEnvironment != null)
            {
                return(expressionEnvironment);
            }

            expressionEnvironment = parent.GetExpressionEnvironment().Push();
            Slate.Expressions.ExpressionActionClipWrapper.Wrap(this, expressionEnvironment);
            return(expressionEnvironment);
        }
        StagPoint.Eval.Environment IDirector.GetExpressionEnvironment()
        {
            if (expressionEnvironment != null)
            {
                return(expressionEnvironment);
            }

            expressionEnvironment = Slate.Expressions.GlobalEnvironment.Get().Push();
            Slate.Expressions.ExpressionCutsceneWrapper.Wrap(this, expressionEnvironment);
            return(expressionEnvironment);
        }
 static GlobalEnvironment()
 {
     env = new Environment();
     env.AddConstant("Slate", typeof(GlobalEnvironment));
     env.AddConstant("Mathf", typeof(Mathf));
     env.AddConstant("Vector2", typeof(Vector2));
     env.AddConstant("Vector3", typeof(Vector3));
     env.AddConstant("Vector4", typeof(Vector4));
     env.AddConstant("Color", typeof(Color));
     env.AddConstant("EaseType", typeof(EaseType));
 }
        void IExpressionDecorator.Wrap(Environment env)
        {
            if (target.animatedType == typeof(bool))
            {
                env.AddBoundProperty("value", this, "value_bool");
            }
            if (target.animatedType == typeof(int))
            {
                env.AddBoundProperty("value", this, "value_int");
            }
            if (target.animatedType == typeof(float))
            {
                env.AddBoundProperty("value", this, "value_float");
            }
            if (target.animatedType == typeof(Vector2))
            {
                env.AddBoundProperty("value", this, "value_vector2");
            }
            if (target.animatedType == typeof(Vector3))
            {
                env.AddBoundProperty("value", this, "value_vector3");
            }
            if (target.animatedType == typeof(Color))
            {
                env.AddBoundProperty("value", this, "value_color");
            }

            if (target.animatedType == typeof(bool))
            {
                env.AddBoundMethod("Eval", this, "Eval_Bool");
            }
            if (target.animatedType == typeof(int))
            {
                env.AddBoundMethod("Eval", this, "Eval_Int");
            }
            if (target.animatedType == typeof(float))
            {
                env.AddBoundMethod("Eval", this, "Eval_Float");
            }
            if (target.animatedType == typeof(Vector2))
            {
                env.AddBoundMethod("Eval", this, "Eval_Vector2");
            }
            if (target.animatedType == typeof(Vector3))
            {
                env.AddBoundMethod("Eval", this, "Eval_Vector3");
            }
            if (target.animatedType == typeof(Color))
            {
                env.AddBoundMethod("Eval", this, "Eval_Color");
            }

            env.AddVariable("Parameter", this);
        }
        ///Compile the expression if any
        void CompileExpression()
        {
            env = null;
            Exception exception = null;

            StagPoint.Eval.Expression expression = null;
            if (hasActiveExpression)
            {
                Slate.Expressions.ExpressionsUtility.CompileExpression(scriptExpression, GetExpressionEnvironment(), this, out exception, out expression);
                compileException   = exception;
                compiledExpression = expression;
            }
        }
示例#8
0
        ///Compile the expression if any
        void CompileExpression()
        {
            expressionEnvironment = null;
            compiledExpression    = null;
            compileException      = null;
            if (string.IsNullOrEmpty(scriptExpression))
            {
                return;
            }

            try
            {
                compiledExpression = StagPoint.Eval.EvalEngine.Compile(scriptExpression, GetExpressionEnvironment());
                if (compiledExpression.Type == typeof(void))
                {
                    throw new System.Exception(string.Format("Expression must return a value of type '{0}'", animatedType.FriendlyName()));
                }
                var value     = compiledExpression.Execute();
                var valueType = value.GetType();
                if (valueType == typeof(object[]))
                {
                    if (ArrayToValue((object[])value) == null)
                    {
                        throw new System.Exception("Return array has different number of arguments.");
                    }
                }
                else
                {
                    if (!animatedType.RTIsAssignableFrom(valueType))
                    {
                        throw new System.Exception(string.Format("Result Expression Type is '{0}', but '{1}' is required.", valueType.FriendlyName(), animatedType.FriendlyName()));
                    }
                }
            }
            catch (System.Exception exc)
            {
                compileException   = exc;
                compiledExpression = null;
            }
        }
 //release environment
 void FlushExpressionEnvironment()
 {
     expressionEnvironment = null;
 }
示例#10
0
        ///creates and returns menu of available options in target expression enviroment
        private static GenericMenu GetExpressionEnvirontmentMenu(StagPoint.Eval.Environment env, System.Action <string> callback)
        {
            var menu = new GenericMenu();

            while (env != null)
            {
                foreach (var pair in env.Variables)
                {
                    var boundVariable = pair.Value as StagPoint.Eval.BoundVariable;
                    if (boundVariable != null)
                    {
                        var category = boundVariable.Target.GetType().Name;
                        var name     = pair.Key;
                        menu.AddItem(new GUIContent(category + "/" + name), false, () => { callback(name); });
                    }
                    var variable = pair.Value as StagPoint.Eval.Variable;
                    if (variable != null)
                    {
                        if (variable.IsReadOnly && !(variable.Value is System.Type))
                        {
                            var category = "Constants";
                            var name     = pair.Key;
                            menu.AddItem(new GUIContent(category + "/" + name), false, () => { callback(name); });
                        }
                        else
                        {
                            var target = variable.Value;
                            var type   = target is System.Type? (System.Type)target : variable.Type;
                            foreach (var m in type.GetMembers(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly))
                            {
                                if (m is PropertyInfo || m is FieldInfo)
                                {
                                    var category = pair.Key;
                                    var name     = m.Name;
                                    var template = category + "." + name;
                                    menu.AddItem(new GUIContent(category + "/" + name), false, () => { callback(template); });
                                }
                                if (m is MethodInfo && !((MethodInfo)m).IsSpecialName)
                                {
                                    var method = (MethodInfo)m;
                                    if (method.ReturnType != typeof(void))
                                    {
                                        var category = pair.Key;
                                        var name     = m.Name;
                                        var template = name;
                                        template += "(";
                                        var parameters = method.GetParameters();
                                        for (var i = 0; i < parameters.Length; i++)
                                        {
                                            var parameter = parameters[i];
                                            template += parameter.Name;
                                            if (i != parameters.Length - 1)
                                            {
                                                template += ", ";
                                            }
                                        }
                                        template += ")";
                                        template  = category + "." + template;
                                        menu.AddItem(new GUIContent(category + "/" + name), false, () => { callback(template); });
                                    }
                                }
                            }
                        }
                    }
                }

                env = env.Parent;
            }

            return(menu);
        }
示例#11
0
 void IExpressionDecorator.Wrap(Environment env)
 {
     env.AddVariable("Clip", this);
 }