public bool Awakening() { spaar.ModLoader.Game.OnSimulationToggle += GameOnOnSimulationToggle; spaar.ModLoader.Game.OnLevelWon += GameOnOnLevelWon; env = new NLua.Lua(); env.LoadCLRPackage(); env["this"] = this; // Give the script access to the gameobject. env["transform"] = transform; env["gameObject"] = gameObject; env["enabled"] = enabled; env["useAPI"] = new Action(UseAPI); env["disableAPI"] = new Action(DisableAPI); if (Settings.useAPI) { Besiege.SetUp(); env["besiege"] = Besiege._besiege; } try { env.DoString(source); } catch (NLua.Exceptions.LuaException e) { Debug.LogError(FormatException(e), context: gameObject); return(false); } Call("Awake"); return(true); }
void UseAPI() { Settings.useAPI = true; Besiege.SetUp(); env["besiege"] = Besiege._besiege; }
/// <summary> /// Starts the $PythonBehaviour /// </summary> /// <param name="classname">Name of the Script</param> public bool Awakening(String classname) { scope = engine.CreateScope(); scope.SetVariable("this", this); scope.SetVariable("gameObject", gameObject); scope.SetVariable("transform", transform); scope.SetVariable("enabled", enabled); scope.SetVariable("useAPI", new Action(UseAPI)); scope.SetVariable("disableAPI", new Action(DisableAPI)); if (Settings.useAPI) { Besiege.SetUp(); scope.SetVariable("besiege", Besiege._besiege); } spaar.ModLoader.Game.OnSimulationToggle += GameOnOnSimulationToggle; spaar.ModLoader.Game.OnLevelWon += GameOnOnLevelWon; foreach (string @ref in refs.Where(@ref => !String.IsNullOrEmpty(@ref))) { try { #region OBSOLETE /* * Assembly assembly = Assembly.Load(@ref); * var namespaces = assembly.GetTypes() * .Select(t => t.Namespace) * .Distinct(); * String[] lines = Util.splitStringAtNewline(sauce); * for (int i = 0; i < lines.Length; i++) * { * if (!lines[i].Contains("import") && !String.IsNullOrEmpty(lines[i])) * { * foreach (string ns in namespaces) * { * if (!String.IsNullOrEmpty(ns)) * { * if (lines[i].Contains((ns + "."))) * { * lines[i] = Regex.Replace(lines[i], ns + ".", string.Empty); * } * } * } * } * lines[i] += Util.getNewLine(); * } * lines = lines.Where(x => !string.IsNullOrEmpty(x) && !x.Equals("\r\n") && !x.Equals("\r") && !x.Equals("\n") && !String.IsNullOrEmpty(x.Trim())).ToArray(); * sauce = String.Concat(lines); */ #endregion engine.Runtime.LoadAssembly(Assembly.Load(@ref)); } catch (Exception ex) { Debug.LogException(ex); return(false); } } ScriptSource source = engine.CreateScriptSourceFromString(sauce); ErrorListener error = new ErrorSinkProxyListener(ErrorSink.Default); code = source.Compile(error); if (code == null) { Debug.LogError(error); return(false); } code.Execute(scope); pythonClass = engine.Operations.Invoke(scope.GetVariable(classname)); CallMethod("Awake"); return(true); }
public void UseAPI() { Settings.useAPI = true; Besiege.SetUp(); scope.SetVariable("besiege", Besiege._besiege); }