public void ExecuteScript() { ReleaseAnyVariable(); if (engine == null) { engine = UnityPython.CreateEngine(); } runtime = engine.Runtime; scope = runtime.CreateScope(); scripts.ForEach(script => { var scriptContent = script.GetScriptHeader(); scriptContent += script.script; // create script source from content var source = engine.CreateScriptSourceFromString(scriptContent); try { // execute python script source.Execute(scope); } catch (System.Exception exc) { Debug.LogError(exc); } }); runtime.Shutdown(); this.stoppable = false; }
void Start() { var engine = UnityPython.CreateEngine(); var scope = engine.CreateScope(); scope.SetVariable("name", name); scope.SetVariable("this", this); string code = @" import sys print 'Hello {}! Python version: {}'.format(name, sys.version) print repr(this.s), this.x print this.GetComponent('Transform') str = 'output' "; var source = engine.CreateScriptSourceFromString(code); try { source.Execute(scope); } catch (Microsoft.Scripting.SyntaxErrorException e) { Debug.LogError(e); } catch (System.Exception e) { Debug.LogError(e); } Debug.Log(scope.GetVariable <string>("str")); }
void Start() { stoppable = true; engine = UnityPython.CreateEngine(); StartCoroutine(UpdatingUnityVariables()); StartCoroutine(SyncPythonVariablesAndUnityVariables()); }
// Start is called before the first frame update void Start() { engine = UnityPython.CreateEngine(); }