Exemplo n.º 1
0
        private void CreateProgramAndBind()
        {
            BehaviourTree._current = this;

            _program = BTLAssetManager.CreateBehaviourProgram(btSources);

            var objects = this.GetComponents <Component>();

            try
            {
                _program.Bind(objects);
                _exceptions = _program.exceptions;

                foreach (var ex in _program.exceptions)
                {
                    Debug.LogException(ex, this);
                }
            }
            catch (System.Exception e)
            {
                Debug.LogException(e, this);
                _program = null;
            }

            if (_program != null)
            {
                _program.Reset();
            }
        }
Exemplo n.º 2
0
        private void DebugLogCompilationExceptions()
        {
            _exceptions      = BTLAssetManager.GetCompilationExceptions(btSources);
            _pandaExceptions = null;
            _program         = new BTProgram(pandaExceptions);

            if (Application.isPlaying)
            {
                DebugLogErrors();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Compile the BT from the attached scripts.
        /// </summary>
        public void Compile()
        {
            _exceptions      = null;
            _pandaExceptions = null;

            if (_program != null)
            {
                _program.Dispose();
                _program = null;
            }

            if (btSources.Length > 0)
            {
                bool hasSource = false;
                foreach (var t in btSources)
                {
                    if (t != null)
                    {
                        hasSource = true;
                        break;
                    }
                }

                if (hasSource)
                {
                    bool hasCompiled = false;
                    hasCompiled = !BTLAssetManager.HasCompilationErrors(btSources);
                    if (hasCompiled)
                    {
                        CreateProgramAndBind();
                    }
                    else
                    {
                        DebugLogCompilationExceptions();
                    }
                }

                if (OnInitialized != null)
                {
                    OnInitialized();
                }
            }
        }
        public static SourceDisplay[] MapGUILines(BTSource[] btlSources, BTProgram program, PandaScriptException[] pandaExceptions)
        {
            if (btlSources == null || program == null)
            {
                return(null);
            }

            var sourceDisplays = new SourceDisplay[btlSources.Length];

            for (int i = 0; i < btlSources.Length; i++)
            {
                if (btlSources[i] == null)
                {
                    continue;
                }

                SourceDisplay sourceDisplay = null;
                var           tokens        = BTLAssetManager.GetBTLTokens(btlSources, btlSources[i]);
                sourceDisplay = BTLGUILine.Analyse(tokens, i);

                sourceDisplays[i] = sourceDisplay;

                CodeMap codemap = null;
                if (program.codemaps != null && i < program.codemaps.Length)
                {
                    codemap = program.codemaps[i];
                }

                if (codemap != null)
                {
                    BTLGUILine.MapNodes(sourceDisplay.lines, codemap);

                    var lines = sourceDisplay.flattenLines;
                    foreach (var line in lines)
                    {
                        foreach (var n in line.btnodes)
                        {
                            var task = n as BTTask;
                            if (task != null && task.boundState != BoundState.Bound)
                            {
                                line.hasErrors = true;
                            }
                        }
                    }
                }

                if (sourceDisplay != null)
                {
                    var lines = sourceDisplay.flattenLines;
                    foreach (var line in lines)
                    {
                        foreach (var pandaException in pandaExceptions)
                        {
                            if (pandaException != null)
                            {
                                if (pandaException.filePath == btlSources[i].url && line.lineNumber == pandaException.lineNumber)
                                {
                                    line.hasErrors = true;
                                }
                            }
                        }
                    }
                }
            }

            return(sourceDisplays);
        }