Пример #1
0
    void ExecuteCommand(string command)
    {
        if (input.wasCanceled)
        {
            input.ActivateInputField();
            return;
        }
        input.text = "";
        input.ActivateInputField();
        if (command.Length != 0)
        {
            m_previousCommands.Insert(0, command);
        }
        m_previousCommandSelected = -1;

        bool exception = false;

        try{
            PythonUtils.GetEngine().Execute(command, m_scope);
        }catch (Exception e) {
            exception = true;
//			Debug.LogException (e);
            write(e.Message);
        }

        text.text += "\n<b>" + (exception ? "<color=#d22>" : "") + command + (exception ?"</color=#f66>" : "") + "</b> ";
        text.text += log;
        log        = "";

        scroll.verticalNormalizedPosition = 0f;
    }
    void RecreateScope()
    {
        m_scope = PythonUtils.GetEngine().CreateScope();
        m_scope.SetVariable("console", this);
        var fullScript = PythonUtils.defaultPythonConsoleHeader + GlobalAssemblyImport();

        PythonUtils.GetEngine().Execute(fullScript, m_scope);
    }
Пример #3
0
 void InitScope()
 {
     if (m_scope == null)
     {
         m_scope = PythonUtils.GetEngine().CreateScope();
     }
     m_scope.SetVariable("owner", this);
     m_scope.SetVariable("gameObject", gameObject);
     m_scope.SetVariable("transform", transform);
     scopeInitializedWithScript = false;
 }
    void Compile()
    {
        var engine = PythonUtils.GetEngine();
        var source = engine.CreateScriptSourceFromString(PythonUtils.defaultPythonBehaviourHeader + text);

        try {
            m_compiled = source.Compile();
        } catch (System.Exception ex) {
            compiledWithError = true;
            m_updateCount++;
            m_dirty = false;
            throw ex;
        }
        m_updateCount++;
        m_dirty = false;
    }
Пример #5
0
    private void Awake()
    {
        if (script == null)
        {
            Debug.LogError("There is no script on this object: " + gameObject.name);
            return;
        }
        if (scope == null)
        {
            ScriptEngine scriptEngine = PythonUtils.GetEngine();
            scope = scriptEngine.CreateScope();
            scope.SetVariable("owner", this);
            scope.SetVariable("gameObject", gameObject);
            scope.SetVariable("transform", transform);

            source = scriptEngine.CreateScriptSourceFromString(script.text);
            source.Compile();
            source.Execute(scope);
            CallMethod("Awake");
        }
    }
    void ExecuteCommand(string command)
    {
        if (input.wasCanceled)
        {
            input.ActivateInputField();
            return;
        }
        input.text = "";
        input.ActivateInputField();
        if (command.Length != 0)
        {
            m_previousCommands.Insert(0, command);
        }
        m_previousCommandSelected = -1;

        m_commandExecutionInProgress = true;
        bool exception = false;

        try{
            PythonUtils.GetEngine().Execute(command, m_scope);
        }catch (Exception e) {
            exception = true;
            write(e.Message);
        }
        m_commandExecutionInProgress = false;

        var commandLog = "<b>" + (exception ? "<color=#d22>" : "") + command + (exception ? "</color=#f66>" : "") + "</b>";

        if (string.IsNullOrEmpty(m_log))
        {
            m_log = commandLog;
        }
        else
        {
            m_log = commandLog + "\n" + m_log;
        }

        FlushLog();
        scroll.verticalNormalizedPosition = 0f;
    }
Пример #7
0
    void OnEnable()
    {
        input.onSubmit.AddListener(ExecuteCommand);

        if (m_scope == null)
        {
            m_scope = PythonUtils.GetEngine().CreateScope();
            //		m_scope.SetVariable ("_pythonConsole", this);
            PythonUtils.GetEngine().Execute(PythonUtils.defaultPythonConsoleHeader + GlobalAssemblyImport() +
                                            @"
import sys
sys.stdout=PythonConsole
Select = PythonConsole.Select

import UnityEngine
Destroy = UnityEngine.Object.Destroy
FindObjectOfType = UnityEngine.Object.FindObjectOfType
FindObjectsOfType = UnityEngine.Object.FindObjectsOfType
Instantiate = UnityEngine.Object.Instantiate

"
                                            , m_scope);
        }
    }