I'm trying to write a scripting engine to my C#/XNA game using IronPython and came across a problem.
public class Game1 : Game, IGFXEnabledGame
{
//stuff
}
In the Game1
constructor I do necessary initialization for script and then run it to create the Camera
object. I try to move the following hard-coded Camera initialization to a script:
CCamera camera = new CFPPCamera(this);
CCamera
is an abstract class and CFPPCamera
inhertits from it. CFPPCamera
has the following constructor:
public CFPPCamera(Game game)
: base(game)
{
}
Script initialization:
InitScriptPath = "InitScript.py";
rootDir = AppDomain.CurrentDomain.BaseDirectory;
scriptDir = Path.Combine(rootDir, "Scripts");
scriptEngine = Python.CreateEngine();
scriptRuntime = scriptEngine.Runtime;
scriptScope = scriptRuntime.CreateScope();
scriptSource = scriptEngine.CreateScriptSourceFromFile(Path.Combine(scriptDir, InitScriptPath));
scriptScope.SetVariable("this", this);
scriptSource.Execute(scriptScope);
Script code:
import clr
clr.AddReference('Microsoft.Xna.Framework')
clr.AddReference('Microsoft.Xna.Framework.Game')
clr.AddReferenceToFile("../../../../../GFXEngine/bin/x86/Debug/GFXEngine.dll")
import Microsoft.Xna.Framework
from GFXEngine.GFX.Camera import *
from GFXEngine.GFX import *
camera = CFPPCamera(this);
The code compiles without warnings or errors, however on script execution I get an error:
Unable to cast object of type 'RenderingStreamTesting.Game1' to type GFXEngine.GFX.IGFXEnabledGame'.
'
If I don't pass the Camera generation to the script, everything works fine.
RenderingStreamTesting
and GFXEngine
are two projects in the same solution, with RenderingStreamTesting
being the base game project that GFXEngine
references.
From what I found the problem might be caused by referencing different assemblies. I double checked and all references are made to native .NET .dlls and all third party libraries are listed in common directory.
What am I missing?