I am not really sure that i am picked right title. But here i will try to explain the details what i want to do.
Currently I am developing simple 2d game engine for my own game. Let's say i have 4 classes:
Scene
andSceneObject
: There isSceneObject[] Objects
variable inScene
class which represent Objects in Scene (SceneObject could be a text, image, button etc. For text it will be SceneObject.Text, for image it will be SceneObject.Image and so on).ContentManager
: The class that handle image source forSceneObject.Image
, all Image is stored in this class (Where "Image" isSystem.Drawing.Image
type)Log
: Simple Class to logging
What i want is Loading the SceneObject
from C# Script, but in that script, i want to allow the script writer to interact with ContentManager
(and all classes that may i made in my project, like the Log
class)
Here the example of C# Code that to be compiled in Run-time (let's say its called "ExampleScript.cs"):
using System;
using System.Collections.Generic;
using System.Text;
using Engine.Graphics;
using Engine.UI;
namespace Engine
{
public class Example : Scene
{
public SceneObject.Button BtnExample;
public SceneObject.Text LblExample;
public Example()
{
// This will throw an exception if Example.png isn't exist in the ContentManager
BtnExample = new SceneObject.Button(ContentManager.GetImage("Example.png"));
LblExample = new SceneObject.Text("Hello World!");
// This is the plus for C# Run-Time Code
// Allow writer to add customization for each SceneObject
BtnExample.Rotate(10);
BtnExample.Color = Color.White;
// and so on
// I believe complicated effect / customization can be done easier than loading from plain text file (and it's somehow look cooler LOL)
// Add it to "Objects" variable
Add(LblExample, BtnExample);
Log.WriteLine("SceneLoaded!");
}
}
}
and then i compile and get all SceneObject
like this:
try
{
Script SceneScript = new Script("ExampleScript.cs");
Scene Example = SceneScript.Compile();
SceneObject[] Objects = Example.Objects;
}
catch (Exception ex)
{
// Compile Error here
// Something like "'Example.png' isn't exist in content manager"
}
So how can i do this?
I tried to search on Google, but what i found is just something like compiling console application in run-time, that's not enough for me :\
Thanks in advance! :D