コード例 #1
0
        public static VariableBase GetVariable(this Environment environment, string name)
        {
            VariableBase result = null;

            environment.Variables.TryGetValue(name, out result);
            return(result);
        }
コード例 #2
0
        public static object GetConstant(this Environment environment, string name)
        {
            object result = null;

            environment.Constants.TryGetValue(name, out result);
            return(result);
        }
コード例 #3
0
        ///Wrap an object if wrapper available, within provided environment
        public static void Wrap(object o, Environment env)
        {
            var wrapper = DecoratorFactory.GetDecorator <IExpressionDecorator>(o);

            if (wrapper != null)
            {
                wrapper.Wrap(env);
            }
        }
コード例 #4
0
 static GlobalEnvironment()
 {
     env = new StagPoint.Eval.Environment();
     env.AddConstant("Mathf", typeof(Mathf));
     env.AddConstant("Vector2", typeof(Vector2));
     env.AddConstant("Vector3", typeof(Vector3));
     env.AddConstant("Quaternion", typeof(Quaternion));
     env.AddConstant("Color", typeof(Color));
     env.AddConstant("Slate", typeof(GlobalEnvironment));
 }
コード例 #5
0
        public static void AddBoundProperty(this Environment environment, string name, object target, string propertyName)
        {
            var property = target.GetType().RTGetProperty(propertyName);

            if (property != null && !property.RTIsStatic())
            {
                var boundVariable = new BoundVariable(name, target, property);
                environment.AddVariable(boundVariable);
            }
        }
コード例 #6
0
        public static void AddStaticMethod(this Environment environment, string name, System.Type type, string methodName)
        {
            var method = type.RTGetMethod(methodName);

            if (method != null && method.IsStatic)
            {
                var boundVariable = new BoundVariable(name, null, method);
                environment.AddVariable(boundVariable);
            }
        }
コード例 #7
0
        public static void AddStaticProperty(this Environment environment, string name, System.Type type, string propertyName)
        {
            var property = type.RTGetProperty(propertyName);

            if (property != null && property.RTIsStatic())
            {
                var boundVariable = new BoundVariable(name, null, property);
                environment.AddVariable(boundVariable);
            }
        }
コード例 #8
0
        public static void AddBoundMethod(this Environment environment, string name, object target, string methodName)
        {
            var method = target.GetType().RTGetMethod(methodName);

            if (method != null && !method.IsStatic)
            {
                var boundVariable = new BoundVariable(name, target, method);
                environment.AddVariable(boundVariable);
            }
        }
コード例 #9
0
        ///Compile an expression within target environment
        public static void CompileExpression(string scriptExpression, Environment environment, AnimatedParameter animParam, out Exception compileException, out Expression compiledExpression)
        {
            compiledExpression = null;
            compileException   = null;
            if (string.IsNullOrEmpty(scriptExpression))
            {
                return;
            }

            var expectedType = animParam.animatedType;

            try
            {
                compiledExpression = StagPoint.Eval.EvalEngine.Compile(scriptExpression, environment);
                if (compiledExpression.Type == typeof(void))
                {
                    throw new System.Exception(string.Format("Expression must return a value of type '{0}'", expectedType.FriendlyName()));
                }
                var value = compiledExpression.Execute();
                if (value is object[])
                {
                    var arr            = (value as object[]).Cast <float>().ToArray();
                    var requiredLength = animParam.parameterModel.RequiredCurvesCount();
                    if (arr.Length != requiredLength)
                    {
                        throw new System.Exception(string.Format("Result Expression Array returns '{0}' values, but '{1}' values are required.", arr.Length, requiredLength));
                    }
                }
                else
                {
                    var valueType = value.GetType();
                    if (!expectedType.RTIsAssignableFrom(valueType))
                    {
                        throw new System.Exception(string.Format("Result Expression Type is '{0}', but '{1}' is required.", valueType.FriendlyName(), expectedType.FriendlyName()));
                    }
                }
            }
            catch (System.Exception exc)
            {
                compileException   = exc;
                compiledExpression = null;
            }
        }
コード例 #10
0
        public static void AddStaticMethod(this Environment environment, string name, System.Type type, MethodInfo method)
        {
            var boundVariable = new BoundVariable(name, null, method);

            environment.AddVariable(boundVariable);
        }
コード例 #11
0
        public static void AddStaticProperty(this Environment environment, string name, System.Type type, PropertyInfo property)
        {
            var boundVariable = new BoundVariable(name, null, property);

            environment.AddVariable(boundVariable);
        }
コード例 #12
0
        public static void AddBoundMethod(this Environment environment, string name, object target, MethodInfo method)
        {
            var boundVariable = new BoundVariable(name, target, method);

            environment.AddVariable(boundVariable);
        }
コード例 #13
0
        public static void AddBoundProperty(this Environment environment, string name, object target, PropertyInfo property)
        {
            var boundVariable = new BoundVariable(name, target, property);

            environment.AddVariable(boundVariable);
        }
コード例 #14
0
 public static void AddDelegateMethod <T1, T2, T3, T4>(this Environment environment, string name, Action <T1, T2, T3, T4> callback)
 {
     environment.AddBoundMethod(name, callback.Target, callback.Method);
 }
コード例 #15
0
        ///----------------------------------------------------------------------------------------------

        public static void AddVariable(this Environment environment, string name, object target)
        {
            environment.AddVariable(name, target, target.GetType());
        }
コード例 #16
0
 public static void AddDelegateMethod <TResult, T1, T2, T3, T4>(this Environment environment, string name, Func <T1, T2, T3, T4, TResult> callback)
 {
     environment.AddBoundMethod(name, callback.Target, callback.Method);
 }
コード例 #17
0
 public static void AddBoundMethod(this Environment environment, string name, object target, string methodName)
 {
     AddBoundMethod(environment, name, target, target.GetType().RTGetMethod(methodName));
 }
コード例 #18
0
 public static void AddBoundProperty(this Environment environment, string name, object target, string propertyName)
 {
     AddBoundProperty(environment, name, target, target.GetType().RTGetProperty(propertyName));
 }