Пример #1
0
    private void Start()
    {
        var engine = PythonEnvironment.CreateEngine();
        var scope  = engine.CreateScope();
        var source = "print('Hello World')";

        engine.Execute(source, scope);
    }
    private void Start()
    {
        var engine = PythonEnvironment.CreateEngine();
        var scope  = engine.CreateScope();
        var source = "import UnityEngine\nUnityEngine.Debug.Log('Unity Hello World')";

        engine.IncludeUnityLibraries();
        engine.Execute(source, scope);
    }
Пример #3
0
    private void Start()
    {
        var engine = PythonEnvironment.CreateEngine();
        var scope  = engine.CreateScope();
        var source = "import random\nvalue = random.choice([1, 2, 3, 4, 5, 6, 7])";

        engine.IncludeNativeLibrary();
        engine.IncludeUnityLibraries();
        engine.Execute(source, scope);
        Debug.Log(scope.GetVariable <int>("value"));
    }
    private void Awake()
    {
        engine = PythonEnvironment.CreateEngine();
        scope  = engine.CreateScope();
        engine.IncludeNativeLibrary();
        engine.IncludeUnityLibraries();
        var script = engine.CreateScriptSourceFromString(ScriptSource.text);
        var binary = script.Compile();

        binary.Execute(scope);
        scope.GetVariable <function>(FunctionInitialize != null ? FunctionInitialize: "OnInitialize")?.Invoke(this);
        scope.GetVariable <function>(FunctionAwake != null ? FunctionAwake : "OnAwake")?.Invoke(this);
    }