Beispiel #1
0
        public BehaviorTreeData Load()
        {
            BehaviorTreeData data = null;

            if (!string.IsNullOrEmpty(XmlData))
            {
                try
                {
                    Skill.Framework.IO.XmlDocument document = new Framework.IO.XmlDocument();
                    document.LoadXml(XmlData);
                    data = new BehaviorTreeData();
                    data.Load(document.FirstChild);
                }
                catch (System.Exception ex)
                {
                    data = null;
                    Debug.LogException(ex, this);
                }
            }
            else
            {
                data = new BehaviorTreeData();
                Save(data);
            }
            data.Name          = this.name;
            data.ExpandMethods = this.ExpandMethods;
            return(data);
        }
Beispiel #2
0
        private void Build()
        {
            BehaviorTreeData bTree = _Data.Load();

            if (bTree != null)
            {
                SharedAccessKeysData[] sharedAccessKeys = new SharedAccessKeysData[_Data.SharedKeys.Length];
                for (int i = 0; i < _Data.SharedKeys.Length; i++)
                {
                    if (_Data.SharedKeys[i] != null)
                    {
                        sharedAccessKeys[i] = _Data.SharedKeys[i].Load();
                    }
                }

                bool compiled = BehaviorTreeCompiler.Compile(bTree, sharedAccessKeys);
                if (compiled)
                {
                    Builder.Build(bTree, _Data.BuildPath, _Data.name);
                }
            }
            else
            {
                Debug.LogError("Invalid SaveData");
            }
        }
        private void Rebuild()
        {
            _RefreshStyles = true;
            Clear();
            if (_Asset != null)
            {
                _BehaviorTree = _Asset.Load();
            }

            if (_BehaviorTree != null)
            {
                _Behaviors.Clear();
                foreach (var state in _BehaviorTree.States)
                {
                    AddToList(state);
                }
                if (_BehaviorTree.ExtraBehaviors != null)
                {
                    foreach (var b in _BehaviorTree.ExtraBehaviors)
                    {
                        AddToList(b);
                    }
                }

                _States.Clear();
                _States.Rebuild();
            }
        }
Beispiel #4
0
 public static void Build(Skill.Editor.AI.BehaviorTreeData tree, string localDir, string name)
 {
     ValidateGenerator();
     _Generator.Reset();
     _Generator.Generate(tree);
     CreateFile(_Generator, localDir, name);
 }
Beispiel #5
0
 public void Save(BehaviorTreeData data)
 {
     if (!this)
     {
         return;        // if deleted
     }
     if (data == null)
     {
         return;
     }
     data.Name = this.name;
     Skill.Framework.IO.XmlDocument document = new Framework.IO.XmlDocument();
     document.AppendChild(data.ToXmlElement());
     XmlData = document.OuterXml;
     UnityEditor.EditorUtility.SetDirty(this);
 }
Beispiel #6
0
        public static bool Compile(BehaviorTreeData data, SharedAccessKeysData[] accessKeys)
        {
            _ErrorFound = false;
            _Tree       = data;
            _AccessKeys = accessKeys;

            if (_Behaviors == null)
            {
                _Behaviors = new List <BehaviorData>();
            }

            CreateBehaviorList();
            CheckDefaultState();
            SearchForBehaviorErrors();
            SearchForBehaviorWarnings();

            _Tree       = null;
            _AccessKeys = null;
            return(!_ErrorFound);
        }