示例#1
0
        public static void Wrap(AnimatedParameter animParam, Environment env)
        {
            var wrapper = new ExpressionParameterWrapper(animParam);

            env.AddVariable("parameter", wrapper, wrapper.GetType());
            env.AddVariable(animParam.parameterName, wrapper, wrapper.GetType());
            // env.AddVariable(  new BoundVariable("value", animParam.ResolvedObject(), animParam.GetMemberInfo())  );
        }
示例#2
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;
            }
        }
示例#3
0
 public ExpressionParameterWrapper(AnimatedParameter animParam)
 {
     this.animParam = animParam;
 }