Esempio n. 1
0
        public static void OverrideInfoData(string name, byte[] binData)
        {
            Directory.CreateDirectory(AssetDirectory);
            if (binData is null)
            {
                return;
            }
            File.WriteAllBytes($"{AssetDirectory}/{name}.json", binData);
            JigsawPuzzleAsset    asset    = AssetDatabase.LoadAssetAtPath <JigsawPuzzleAsset>($"{AssetDirectory}/{name}.asset");
            JigsawPuzzleInfoData infoData = JsonFuck.FromJsonToObject <JigsawPuzzleInfoData>(Encoding.UTF8.GetString(binData));

            asset.InfoData = infoData;
            EditorUtility.SetDirty(asset);
        }
Esempio n. 2
0
        private bool TryReloadDataAncCheck()
        {
            // check
            string infoData = File.ReadAllText(InfoDataFile.FullName);

            JPInfoData = JsonFuck.FromJsonToObject <JigsawPuzzleInfoData>(infoData);
            byte[] binData = File.ReadAllBytes(BinDataFile.FullName);

            if (binData.Length != JPInfoData.BinDataLength)
            {
                throw new Exception($"binData.Length != JPInfoData.BinDataLength, {binData.Length}{JPInfoData.BinDataLength}");
            }

            SpriteColorContainer = new SpriteColorContainer();
            EffectSpriteInfo     = null;
            SpritesInfo          = new List <SpriteInfo>();
            foreach (SpriteInfo spriteInfo in JPInfoData.SpriteInfos)
            {
                SpriteColorContainer.Add(spriteInfo, binData);
                if (spriteInfo.IsEffect)
                {
                    if (EffectSpriteInfo is null)
                    {
                        EffectSpriteInfo = spriteInfo;
                    }
                    else
                    {
                        throw new Exception("Effect 2.");
                    }
                }
                else
                {
                    SpritesInfo.Add(spriteInfo);
                }
            }
            return(true);
        }
Esempio n. 3
0
        public void CreateDataFiles()
        {
            RemoveInvalidData();
            if (!Check)
            {
                Debug.LogError("Not pass check!");
                return;
            }

            InfoData = new JigsawPuzzleInfoData()
            {
                SpriteInfos = new SpriteInfo[Sprites.Length + 1],
                DataName    = DataName,
            };
            SpriteInfo[] spriteInfos = InfoData.SpriteInfos;
            spriteInfos[0] = new SpriteInfo(Effect, true);
            for (int index = 0; index < Sprites.Length; index++)
            {
                spriteInfos[index + 1] = new SpriteInfo(Sprites[index], false);
            }

            using (SpriteColorBuilder spriteColorBuilder = new SpriteColorBuilder())
            {
                spriteColorBuilder.AppendSprite(Effect, spriteInfos[0]);
                for (int index = 1; index < spriteInfos.Length; index++)
                {
                    spriteColorBuilder.AppendSprite(Sprites[index - 1], spriteInfos[index]);
                }
                File.WriteAllBytes(BinDataFullName, spriteColorBuilder.ToArray());
            }

            InfoData.UpdateTime();

            string content = JsonUtility.ToJson(InfoData, true);

            File.WriteAllText(InfoDataFullName, content);
        }