示例#1
0
 //Setting
 public static bool SetEffect(string name, HeightRender.Effect effect, CSScript script = null)
 {
     if (name != null && name.Length > 0)
     {
         if (script == null)
         {
             script        = new CSScript();
             script.Source = "Photon Apply(int x, int y, Photon color, HeightField heightField)\r\n{\r\n\t//Your code goes here\r\n}";
         }
         EffectScript es;
         if (!effects.TryGetValue(name, out es))
         {
             es = new EffectScript()
             {
                 effect = effect, script = script
             }
         }
         ;
         else
         {
             es.effect = effect;
         }
         effects[name] = es;
         if (effectSet != null)
         {
             effectSet(name, es.effect);
         }
         return(true);
     }
     else
     {
         return(false);
     }
 }
示例#2
0
 //Setting
 public static bool SetEffect(string name, HeightRender.Effect effect, CSScript script = null)
 {
     if (name != null)
     {
         if (script == null)
         {
             script = new CSScript();
         }
         EffectScript es;
         if (!effects.TryGetValue(name, out es))
         {
             es = new EffectScript()
             {
                 effect = effect, script = script
             }
         }
         ;
         else
         {
             es.effect = effect;
         }
         effects[name] = es;
         if (effectSet != null)
         {
             effectSet(name, es.effect);
         }
         return(true);
     }
     else
     {
         return(false);
     }
 }
示例#3
0
 private void Document_EffectSet(string name, HeightRender.Effect effect)
 {
     effectNameBox.Items.Clear();
     foreach (string s in Document.EffectNames)
     {
         effectNameBox.Items.Add(s);
     }
 }
示例#4
0
        private void compileButton_Click(object sender, EventArgs e)
        {
            script.RequiredTypes.Add(typeof(Color));
            script.RequiredTypes.Add(typeof(HeightField));
            script.RequiredTypes.Add(typeof(Photon));
            script.RequiredTypes.Add(typeof(Numerics));
            script.RequiredTypes.Add(typeof(Math));
            script.RequiredTypes.Add(typeof(PerlinNoise));
            script.Source = scriptBox.Text;

            string errors;

            if (script.Compile(out errors))
            {
                MethodInfo applyInfo;
                if (script.TryGetMember <MethodInfo>("Apply", out applyInfo))
                {
                    try
                    {
                        HeightRender.Effect effect = (HeightRender.Effect)applyInfo.CreateDelegate(typeof(HeightRender.Effect), script.ScriptObject);
                        Document.SetEffect(effectName, effect);
                    }
                    catch
                    {
                        MessageBox.Show("The method signature for the \"Apply\" function should be:\n\nfloat[] Apply(int x, int y, float[] color, dynamic heightField)", "Script Error");
                    }
                }
                else
                {
                    MessageBox.Show("The \"Apply\" function is missing from your script.");
                }
            }
            else
            {
                MessageBox.Show("There was a compilation error in your script:\n\n" + errors.Split('\n')[0], "Script Error");
            }
        }
示例#5
0
 private void Document_EffectSet(string name, HeightRender.Effect effect)
 {
     EffectName = name;
 }