/* func */
        public void AppendSprite(Sprite sprite, SpriteInfo spriteInfo)
        {
            if (sprite == null)
            {
                throw new ArgumentNullException(nameof(sprite));
            }
            if (spriteInfo is null)
            {
                throw new ArgumentNullException(nameof(spriteInfo));
            }
            if (sprite.texture == null)
            {
                throw new ArgumentNullException(nameof(sprite.texture));
            }
            Texture2D texture2D = GetEnableTexture2D(sprite.texture);

            if (spriteInfo.ColorDataLength > int.MaxValue)
            {
                throw new ArgumentOutOfRangeException($"{nameof(spriteInfo)}.{nameof(SpriteInfo.ColorDataLength)} : {spriteInfo.ColorDataLength} is greater than {int.MaxValue}");
            }

            spriteInfo.ColorDataStartPosition = Stream.Position;
            int shiftX = spriteInfo.TexturePosX;
            int shiftY = spriteInfo.TexturePosY;

            byte[] buffer     = new byte[spriteInfo.ColorDataLength];
            int    startIndex = 0;

            for (int y = 0; y < spriteInfo.Height; y++)
            {
                for (int x = 0; x < spriteInfo.Width; x++)
                {
                    Color color = texture2D.GetPixel(x + shiftX, y + shiftY);
                    Color.RGBToHSV(color, out float h, out float s, out float v);
                    buffer[startIndex++] = (byte)(color.r * 255);
                    buffer[startIndex++] = (byte)(color.g * 255);
                    buffer[startIndex++] = (byte)(color.b * 255);
                    buffer[startIndex++] = (byte)(color.a * 255);
                    buffer[startIndex++] = (byte)(h * 255);
                }
            }
            Stream.Write(buffer, 0, buffer.Length);
        }
Exemplo 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);
        }
Exemplo 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);
        }
 /* inter */
 public JPColor[, ] this[SpriteInfo spriteInfo] => SpriteColorData[spriteInfo];