Beispiel #1
0
        public static bool SetWorkspaceSettings(string workspaceExportPath, Workspace.EFileFormat format)
        {
            bool flag = string.IsNullOrEmpty(Workspace.ms_workspaceExportPath);

            Workspace.ms_workspaceExportPath = workspaceExportPath;
            if (!Workspace.ms_workspaceExportPath.EndsWith("/"))
            {
                Workspace.ms_workspaceExportPath += '/';
            }
            Workspace.fileFormat_ = format;
            if (string.IsNullOrEmpty(Workspace.ms_workspaceExportPath))
            {
                return(false);
            }
            Workspace.LoadWorkspaceAbsolutePath();
            Workspace.ms_deltaFrames = 1;
            if (flag)
            {
                Details.RegisterCompareValue();
                Details.RegisterComputeValue();
                Workspace.RegisterBehaviorNode();
                Workspace.RegisterMetas();
            }
            return(true);
        }
Beispiel #2
0
        public static void SendWorkspaceSettings()
        {
#if !BEHAVIAC_RELEASE
            if (Config.IsSocketing)
            {
                if (!s_tracer.IsWorkspaceSent() && s_tracer.IsConnected())
                {
                    string wksAbsPath = Workspace.GetWorkspaceAbsolutePath();

                    if (!string.IsNullOrEmpty(wksAbsPath))
                    {
                        Workspace.EFileFormat format = Workspace.FileFormat;
                        string formatString          = (format == Workspace.EFileFormat.EFF_xml ? "xml" : "bson");

                        string msg = string.Format("[workspace] {0} \"{1}\"\n", formatString, wksAbsPath);
                        behaviac.Debug.Log(msg);

                        //behaviac.Socket.SendText(msg);
                        LogManager.LogWorkspace(msg);

                        s_tracer.SetWorkspaceSent(true);
                    }
                }
            }
#endif
        }
Beispiel #3
0
        private static bool loadBB()
        {
            string relativePath = "behaviac.bb";
            string fullPath     = Path.Combine(Workspace.Instance.FilePath, relativePath);

            bool bLoadResult = false;

            Workspace.EFileFormat f = Workspace.Instance.FileFormat;
            string ext = "";

            Workspace.Instance.HandleFileFormat(fullPath, ref ext, ref f);

            switch (f)
            {
            case Workspace.EFileFormat.EFF_bson:
            {
                byte[] pBuffer = Workspace.Instance.ReadFileToBuffer(fullPath, ext);

                if (pBuffer != null)
                {
                    bLoadResult = load_bson(pBuffer);

                    Workspace.Instance.PopFileFromBuffer(fullPath, ext, pBuffer);
                }
                else
                {
                    Debug.LogError(string.Format("'{0}' doesn't exist!, Please override Workspace and its GetWorkspaceExportPath()", fullPath));
                    Debug.Check(false);
                }
            }
            break;

            //case Workspace.EFileFormat.EFF_xml:
            default:
            {
                byte[] pBuffer = Workspace.Instance.ReadFileToBuffer(fullPath, ext);

                if (pBuffer != null)
                {
                    bLoadResult = load_xml(pBuffer);

                    Workspace.Instance.PopFileFromBuffer(fullPath, ext, pBuffer);
                }
                else
                {
                    Debug.LogError(string.Format("'{0}' doesn't exist!, Please override Workspace and its GetWorkspaceExportPath()", fullPath));
                    Debug.Check(false);
                }
            }
            break;
            }

            return(bLoadResult);
        }
Beispiel #4
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);
        }