Beispiel #1
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="path"></param>
    /// <param name="extraPackagePath"></param>
    /// <param name="pretty"></param>
    public void Save(string path, string extraPackagePath, bool pretty = true)
    {
        if (string.IsNullOrEmpty(path))
        {
            path = System.IO.Path.Combine(Application.persistentDataPath, typeof(XSheet).Name.ToLower());
        }

        List <XPack> xpacks = new List <XPack>();

        foreach (XPack pack in packs.Values)
        {
            xpacks.Add(pack);
        }

        List <XFile> xfiles = new List <XFile>();

        foreach (XFile file in files.Values)
        {
            xfiles.Add(file);
        }

        List <XScene> xscenes = new List <XScene>();

        foreach (XScene scene in scenes.Values)
        {
            xscenes.Add(scene);
        }

#if UNITY_EDITOR
        XBundleExtraCacheInfo cacheInfo    = null;
        List <string>         cacheInScene = null;
        List <string>         cacheAllTime = null;

        string infoText = XBundleExtraInfoUtils.GetBundleExtraCacheInfoText();
        if (!string.IsNullOrEmpty(infoText))
        {
            cacheInfo = LitJson.JsonMapper.ToObject <XBundleExtraCacheInfo>(infoText);
            if (cacheInfo != null)
            {
                cacheInScene = XBundleExtraInfoUtils.ArrayToList <string>(cacheInfo.CacheInScene);
                if (cacheInScene == null)
                {
                    cacheInScene = new List <string>();
                }
                cacheAllTime = XBundleExtraInfoUtils.ArrayToList <string>(cacheInfo.CacheAllTime);
                if (cacheAllTime == null)
                {
                    cacheAllTime = new List <string>();
                }

                foreach (XPack pack in xpacks)
                {
                    SetupBundleCacheType(pack, cacheInScene, cacheAllTime);
                }

                foreach (XScene scene in xscenes)
                {
                    SetupBundleCacheType(scene, cacheInScene, cacheAllTime);
                }
            }
        }

        if (!string.IsNullOrEmpty(extraPackagePath))
        {
            XBundleExtraPackageInfo packageInfo = null;
            List <string>           package1    = new List <string>();
            List <string>           package2    = new List <string>();
            List <string>           package3    = new List <string>();
            string packageInfoText = XBundleExtraInfoUtils.GetBundleExtraText(extraPackagePath);
            if (!string.IsNullOrEmpty(packageInfoText))
            {
                packageInfo = LitJson.JsonMapper.ToObject <XBundleExtraPackageInfo>(packageInfoText);
                if (packageInfo != null)
                {
                    package1 = XBundleExtraInfoUtils.ArrayToList <string>(packageInfo.PackgesCategory1);
                    package2 = XBundleExtraInfoUtils.ArrayToList <string>(packageInfo.PackgesCategory2);
                    package3 = XBundleExtraInfoUtils.ArrayToList <string>(packageInfo.PackgesCategory3);

                    foreach (XPack pack in xpacks)
                    {
                        SetupBundlePackageType(pack, package1, package2, package3);
                    }
                    foreach (XScene scene in xscenes)
                    {
                        SetupBundlePackageType(scene, package1, package2, package3);
                    }
                }
            }
        }

        Debug.Log(string.Format("<color=red> XSheet save path {0} extraPackagePath {1} done. </color>", path, extraPackagePath));
#endif

        XSheetInfo fat = new XSheetInfo();
        fat.packs  = xpacks;
        fat.files  = xfiles;
        fat.scenes = xscenes;

        System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Create, System.IO.FileAccess.Write);
        if (fs != null)
        {
            StringBuilder          sb     = new StringBuilder();
            System.IO.StringWriter writer = new System.IO.StringWriter(sb);
            LitJson.JsonMapper.ToJson(fat,
                                      new LitJson.JsonWriter(writer)
            {
                PrettyPrint = pretty
            });

            byte[] buff = Encoding.UTF8.GetBytes(sb.ToString());
            fs.Write(buff, 0, buff.Length);
            fs.Close();
        }
    }
Beispiel #2
0
    public Queue <XEntryDiff> GenerateSheetDiff(XSheetInfo newSheet)
    {
        Queue <XEntryDiff> diffFat = new Queue <XEntryDiff>();

        // pack diff
        for (int i = 0; i < newSheet.packs.Count; i++)
        {
            bool  diff = true;
            XPack pack = newSheet.packs[i];
            XPack localPack;
            if (packs.TryGetValue(pack.name, out localPack))
            {
                if (localPack.checksum == pack.checksum)
                {
                    diff = false;
                }
            }

            if (diff)
            {
                diffFat.Enqueue(new XEntryDiff()
                {
                    entryType = XEntryType.File, local = localPack, remote = pack
                });
            }
        }

        // file diff
        for (int i = 0; i < newSheet.files.Count; i++)
        {
            bool  diff = true;
            XFile file = newSheet.files[i];
            XFile localFile;
            if (files.TryGetValue(file.name, out localFile))
            {
                if (localFile.checksum == file.checksum)
                {
                    diff = false;
                }
            }

            if (diff)
            {
                diffFat.Enqueue(new XEntryDiff()
                {
                    entryType = XEntryType.Pack, local = localFile, remote = file
                });
            }
        }

        // scene diff
        for (int i = 0; i < newSheet.scenes.Count; i++)
        {
            bool   diff  = true;
            XScene scene = newSheet.scenes[i];
            XScene localScene;
            if (scenes.TryGetValue(scene.name, out localScene))
            {
                if (localScene.bundleName == scene.bundleName)
                {
                    diff = false;
                }
            }

            if (diff)
            {
                diffFat.Enqueue(new XEntryDiff()
                {
                    entryType = XEntryType.Scene, local = localScene, remote = scene
                });
            }
        }

        return(diffFat);
    }
Beispiel #3
0
    /// <summary>
    /// Initialize this instance.
    /// </summary>
    public bool Initialize()
    {
        Clearup();

        string data = string.Empty;

#if UNITY_STANDALONE
        string extPath = Path.Combine(Path.Combine(Path.Combine(Application.streamingAssetsPath, GetPlatformFolder()), XBundleManager.BundlePrefix), name);
#else
        string extPath = Path.Combine(Application.persistentDataPath, name);
#endif

#if UNITY_EDITOR
        Debug.Log("Use local resource sheet");
#else
        if (System.IO.File.Exists(extPath))
        {
            data = System.IO.File.ReadAllText(extPath);

            if (string.IsNullOrEmpty(data))
            {
                System.IO.File.Delete(extPath);
            }
        }

        if (string.IsNullOrEmpty(data))
        {
            TextAsset text = Resources.Load <TextAsset> (name);
            if (text)
            {
                data = text.text;
            }
        }
#endif

        if (string.IsNullOrEmpty(data))
        {
            return(false);
        }

        XSheetInfo info = XSheetInfo.Parse(data);
        if (info != null)
        {
            for (int i = 0; i < info.files.Count; i++)
            {
                Add(info.files [i]);
            }

            for (int i = 0; i < info.packs.Count; i++)
            {
                Add(info.packs [i]);
            }

            for (int i = 0; i < info.scenes.Count; i++)
            {
                Add(info.scenes [i]);
            }
        }
        else
        {
            Debug.LogError("XSheet.cs parse sheet failed");
        }

        return(true);
    }