Exemple #1
0
        public static bool Load(string relativePath, bool bForce)
        {
            BehaviorTree behaviorTree = null;

            if (Workspace.BehaviorTrees.ContainsKey(relativePath))
            {
                if (!bForce)
                {
                    return(true);
                }
                behaviorTree = Workspace.BehaviorTrees.get_Item(relativePath);
            }
            string text = Workspace.WorkspaceExportPath;

            text += relativePath;
            string ext = string.Empty;

            Workspace.EFileFormat eFileFormat = Workspace.FileFormat;
            switch (eFileFormat)
            {
            case Workspace.EFileFormat.EFF_xml:
                ext = ".xml";
                break;

            case Workspace.EFileFormat.EFF_default:
                ext = ".xml";
                if (FileManager.Instance.FileExist(text, ext))
                {
                    eFileFormat = Workspace.EFileFormat.EFF_xml;
                }
                else
                {
                    ext = ".bson";
                    if (FileManager.Instance.FileExist(text, ext))
                    {
                        throw new NotImplementedException("bson support has been removed!!!");
                    }
                    eFileFormat = Workspace.EFileFormat.EFF_cs;
                }
                break;
            }
            bool flag  = false;
            bool flag2 = false;
            bool flag3 = false;

            if (behaviorTree == null)
            {
                flag3        = true;
                behaviorTree = new BehaviorTree();
                Workspace.BehaviorTrees.set_Item(relativePath, behaviorTree);
            }
            if (eFileFormat == Workspace.EFileFormat.EFF_xml)
            {
                byte[] array = Workspace.ReadFileToBuffer(text, ext);
                if (array != null)
                {
                    if (!flag3)
                    {
                        flag2 = true;
                        behaviorTree.Clear();
                    }
                    if (eFileFormat == Workspace.EFileFormat.EFF_xml)
                    {
                        flag = behaviorTree.load_xml(array);
                    }
                    Workspace.PopFileFromBuffer(text, ext, array);
                }
            }
            else if (eFileFormat == Workspace.EFileFormat.EFF_cs)
            {
                if (!flag3)
                {
                    flag2 = true;
                    behaviorTree.Clear();
                }
                try
                {
                    MethodInfo methodInfo = null;
                    if (Workspace.BTCreators.ContainsKey(relativePath))
                    {
                        methodInfo = Workspace.BTCreators.get_Item(relativePath);
                    }
                    else
                    {
                        string typeName = "behaviac.bt_" + relativePath.Replace("/", "_");
                        Type   type     = Utils.GetType(typeName);
                        if (type != null)
                        {
                            methodInfo = type.GetMethod("build_behavior_tree", 24);
                            if (methodInfo != null)
                            {
                                Workspace.BTCreators.set_Item(relativePath, methodInfo);
                            }
                        }
                    }
                    if (methodInfo != null)
                    {
                        object[] array2 = new object[]
                        {
                            behaviorTree
                        };
                        flag = (bool)methodInfo.Invoke(null, array2);
                    }
                }
                catch (Exception ex)
                {
                    string text2 = string.Format("The behavior {0} failed to be loaded : {1}", relativePath, ex.get_Message());
                }
            }
            if (flag)
            {
                if (!flag3)
                {
                }
            }
            else if (flag3)
            {
                bool flag4 = Workspace.BehaviorTrees.Remove(relativePath);
            }
            else if (flag2)
            {
                Workspace.BehaviorTrees.Remove(relativePath);
            }
            return(flag);
        }