示例#1
0
        private static void setValue(Value property, TextBox textBox)
        {
            bool result = float.TryParse(textBox.Text, out float val);

            if (result)
            {
                property.Setter(val);
            }
            else
            {
                ScriptEngine engine = EditorKernel.GetService(typeof(ScriptEngine)) as ScriptEngine;
                Script       script = new Script {
                    SourceCode = "float main(){return " + textBox.Text + ";}",
                    EntryPoint = "float main()"
                };
                if (script.Build(engine) == Status.OK && script.Execute() == Status.OK)
                {
                    property.Setter(script.GetFloatResult());
                    script.Release();
                }
                else
                {
                    property.Setter(property.Getter());
                }
            }
        }
示例#2
0
        private static void setValue(Value property, TextBox textBox)
        {
            var values = textBox.Text.Split(',');

            if (values.Length == 3 &&
                float.TryParse(textBox.Text, out float x) &&
                float.TryParse(textBox.Text, out float y) &&
                float.TryParse(textBox.Text, out float z))
            {
                property.Setter(new Float3(x, y, z));
            }
            else
            {
                ScriptEngine engine = EditorKernel.GetService(typeof(ScriptEngine)) as ScriptEngine;
                Script       script = new Script {
                    SourceCode = "float3 main(){return float3(" + textBox.Text + ");}",
                    EntryPoint = "float3 main()"
                };
                if (script.Build(engine) == Status.OK && script.Execute() == Status.OK)
                {
                    property.Setter(script.GetFloat3Result());
                    script.Release();
                }
                else
                {
                    property.Setter(property.Getter());
                }
            }
            textBox.Text = property.Getter().ToString();
        }