예제 #1
0
        public bool Save(Node node, string targetLocation)
        {
            ArchiveType at = ArchiveUtil.FindCompatibleArchiveType(targetLocation);

            if (at == ArchiveType.None)
            {
                return(false);
            }

            IArchive arc = ArchiveUtil.CreateArchive(at);

            if (arc == null)
            {
                return(false);
            }

            return(arc.SaveTo(node, targetLocation));
        }
예제 #2
0
        public Node Load(string targetLocation)
        {
            ArchiveType at = ArchiveUtil.FindCompatibleArchiveType(targetLocation);

            if (at == ArchiveType.None)
            {
                Logging.Instance.Log("No compatible archive found.");
                return(null);
            }

            Logging.Instance.Log("Creating archive '{0}'", at);
            IArchive arc = ArchiveUtil.CreateArchive(at);

            if (arc == null)
            {
                Logging.Instance.Log("CreateArchive() failed.");
                return(null);
            }

            return(arc.LoadFrom(targetLocation));
        }
예제 #3
0
        public bool Init(BootParams bp)
        {
            // 请理性工作
            if (Scene.Instance != null)
            {
                Scene.Instance.Dispose();
            }
            if (ResourceManager.Instance != null)
            {
                ResourceManager.Instance.Clear();
            }

            ArchiveUtil.ClearCreators();
            NodeNameUtil.ResetIDAllocLut();

            // 初始化工厂
            ArchiveUtil.RegisterCreator(ArchiveType.Json, typeof(Archive_Json));

            // 初始化资源系统
            if (!ResourceManager.Instance.LoadDefault(Path.Combine(bp.ReourcePath, bp.DefaultReourceImage)))
            {
                Logging.Instance.Log("加载默认资源 ('{0}') 失败.", bp.DefaultReourceImage);
                return(false);
            }
            if (bp.ReourceImages != null)
            {
                foreach (string resFile in bp.ReourceImages)
                {
                    string resCombined = Path.Combine(bp.ReourcePath, resFile);
                    if (!ResourceManager.Instance.LoadFile(resCombined))
                    {
                        Logging.Instance.Log("加载资源 ('{0}') 失败.", resCombined);
                        return(false);
                    }
                }
            }

            // 用户 atlas 加载
            if (bp.ScenePath.Length > 0)
            {
                string userAtlasName = Path.GetFileNameWithoutExtension(bp.ScenePath);
                string userAtlasPath = Path.Combine(Path.GetDirectoryName(bp.ScenePath), userAtlasName);
                if (!ResourceManager.Instance.LoadFile(userAtlasPath, userAtlasName))
                {
                    Logging.Instance.Log("加载用户资源 ('{0}') 失败.", userAtlasPath);
                }
                else
                {
                    Logging.Instance.Log("加载用户资源 ('{0}') 成功.", userAtlasPath);
                }
            }

            // 初始化场景
            Scene.Instance = new Scene();
            if (!Scene.Instance.Init(bp.DesignTimeResolution))
            {
                return(false);
            }
            if (bp.ScenePath.Length != 0 && !Scene.Instance.Load(bp.ScenePath))
            {
                return(false);
            }
            Logging.Instance.Log("场景初始化成功.");

            return(true);
        }