Beispiel #1
0
        public override void Initialize()
        {
            // Register object in Lua.
            ScriptManager.SetGlobal("Game", this);

            var mainLuaFile = Path.Combine(Core.ContentRoot, @"Scripts\main.lua");

            if (File.Exists(mainLuaFile))
            {
                Camera.SetPosition(Core.Settings.StartupCameraPosition);
                Camera.SetLookAt(Core.Settings.StartupCameraLookAt);

                if (File.Exists(Path.Combine(Application.StartupPath, Core.Settings.StartupScene)))
                {
                    ScriptManager.SetGlobal("startupScene", Core.Settings.StartupScene);
                }
                else
                {
                    DebuggingBag.Put(string.Format(CultureInfo.InvariantCulture, "Startup scene {0} doesn't exit.", Core.Settings.StartupScene), null);
                }

                ScriptManager.DoFile(mainLuaFile);
                // Call post initialize for all game objects.
                SceneManager.GetGameObjects().ForEach(i => (i as ObjectBase).PostInitialize());
            }
            else
            {
                return;
            }
        }
Beispiel #2
0
 public void RegisterFunction(string path, object target, MethodBase function)
 {
     try
     {
         lua.RegisterFunction(path, target, function);
     }
     catch (Exception e)
     {
         DebuggingBag.Put("RegisterFunction error:", e.Message);
     }
 }
Beispiel #3
0
 public void DoString(string value)
 {
     try
     {
         lua.DoString(value);
     }
     catch (Exception e)
     {
         DebuggingBag.Put("DoString error:", e.Message);
     }
 }
Beispiel #4
0
 public void DoFile(string target)
 {
     try
     {
         lua.DoFile(target);
     }
     catch (Exception e)
     {
         DebuggingBag.Put("ScriptManager.DoFile error:", e.Message);
     }
 }
Beispiel #5
0
 public LuaFunction FindFunc(string name)
 {
     try
     {
         LuaFunction retfunc = lua.GetFunction(name);
         return(retfunc);
     }
     catch (Exception e)
     {
         DebuggingBag.Put("FindFunc error:", e.Message);
         return(null);
     }
 }
Beispiel #6
0
 public void CallFunction(string name)
 {
     if (FindFunc(name) == null)
     {
         return;
     }
     try
     {
         LuaFunction retfunc = lua.GetFunction(name);
         retfunc.Call();
     }
     catch (Exception e)
     {
         DebuggingBag.Put(string.Format(CultureInfo.InvariantCulture, "{0} error:", name), e.Message);
     }
 }
Beispiel #7
0
 public void dbg(string name, object item)
 {
     DebuggingBag.Put(name, item);
 }