예제 #1
0
    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;
    }
예제 #2
0
    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"));
    }
예제 #3
0
    void Start()
    {
        stoppable = true;
        engine    = UnityPython.CreateEngine();

        StartCoroutine(UpdatingUnityVariables());
        StartCoroutine(SyncPythonVariablesAndUnityVariables());
    }
예제 #4
0
 // Start is called before the first frame update
 void Start()
 {
     engine = UnityPython.CreateEngine();
 }