Esempio n. 1
0
        public void Edit <T>(IAssetData asset)
        {
            if (asset.AssetNameEquals("Data\\ObjectInformation"))
            {
                var data = asset.AsDictionary <int, string>().Data;

                foreach (BugModel bugModel in BugCatchingMod.AllBugs)
                {
                    data.Add(bugModel.ParentSheetIndex, bugModel.QuickItemDataString);
                }
            }
            if (asset.AssetNameEquals("TileSheets\\tools"))
            {
                Texture2D toolSpriteSheet = asset.AsImage().Data;
                Color[]   originalTools   = new Color[toolSpriteSheet.Width * toolSpriteSheet.Height];
                toolSpriteSheet.GetData <Color>(originalTools);

                Texture2D bugNetToolSpriteSheet = ToolsSprites;
                Color[]   addonTools            = new Color[bugNetToolSpriteSheet.Width * bugNetToolSpriteSheet.Height];
                bugNetToolSpriteSheet.GetData <Color>(addonTools);

                Texture2D newSpriteSheet = new Texture2D(Game1.game1.GraphicsDevice, toolSpriteSheet.Width, toolSpriteSheet.Height + bugNetToolSpriteSheet.Height, false, SurfaceFormat.Color);
                var       allTools       = new Color[originalTools.Length + addonTools.Length];
                originalTools.CopyTo(allTools, 0);
                addonTools.CopyTo(allTools, originalTools.Length);
                newSpriteSheet.SetData(allTools);
                asset.ReplaceWith(newSpriteSheet);
            }
        }
Esempio n. 2
0
        public static Texture2D RotateTextureCCW(Texture2D tex, int quarterSteps)
        {
            if (tex == null)
            {
                return(null);
            }
            tex = UnityEngine.Object.Instantiate(tex);
            int width = tex.width, height = tex.height;

            Color[] col        = tex.GetPixels();
            Color[] rotatedCol = new Color[width * height];
            for (int itCnt = 0; itCnt < quarterSteps; itCnt++)
            {
                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        rotatedCol[x * width + y] = col[(width - y - 1) * width + x];
                    }
                }
                rotatedCol.CopyTo(col, 0);
            }
            tex.SetPixels(col);
            tex.Apply();
            return(tex);
        }
Esempio n. 3
0
        public Texture2D MakeTexture(Texture2D source, int targetRowIndex, Painter painter)
        {
            var sourceData = new Color[source.Width * source.Height];
            var newData    = new Color[source.Width * source.Height];

            sourceData.CopyTo(newData, 0);
            source.GetData(sourceData);
            var match         = FindBestMatch(new TextureColors(source));
            var sourcePalette = new List <Color>(match != null ? match : new Color[0]);
            var targetPalette = new List <Color>(GetRow(targetRowIndex));

            var paletteIndex = 0;

            foreach (var currentSourceColor in sourcePalette)
            {
                var currentDestColor = targetPalette[paletteIndex];
                for (var i = 0; i < source.Width * source.Height; i++)
                {
                    var oldColor = sourceData[i];
                    if (oldColor == currentSourceColor)
                    {
                        newData[i] = currentDestColor;
                    }
                }

                paletteIndex++;
            }

            var outputTexture = painter.CreateTexture(new Point(source.Width, source.Height));

            outputTexture.SetData(newData);
            return(outputTexture);
        }
Esempio n. 4
0
 public RagePixelBitmap(Color[] _pixels, int width, int height)
 {
     W = width;
     H = height;
     pixels = new Color[_pixels.Length];
     _pixels.CopyTo(pixels, 0);
 }
Esempio n. 5
0
        /// <summary>
        /// Rotates the texture Counter-Clockwise, 'quarterSteps' specifying the times
        /// </summary>
        public static Texture2D RotateTextureCCW(Texture2D tex, int quarterSteps)
        {
            if (tex == null)
            {
                return(null);
            }
            // Copy and setup working arrays
            tex = UnityEngine.Object.Instantiate(tex);
            int width = tex.width, height = tex.height;

            Color[] col        = tex.GetPixels();
            Color[] rotatedCol = new Color[width * height];
            for (int itCnt = 0; itCnt < quarterSteps; itCnt++)
            {             // For each iteration, perform rotation of 90 degrees
                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        rotatedCol[x * width + y] = col[(width - y - 1) * width + x];
                    }
                }
                rotatedCol.CopyTo(col, 0);                  // Push rotation for next iteration
            }
            // Apply rotated working arrays
            tex.SetPixels(col);
            tex.Apply();
            return(tex);
        }
Esempio n. 6
0
        protected override void Initialize()
        {
            Initialized = true;
            Batch       = new SpriteBatch(GraphicsDevice);
            Pixel1x1    = new Texture2D(GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
            Pixel1x1.SetData(new Color[] { Color.White });
            using (Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream("QTRHacker.NewDimension.Res.Image.Numbers.png"))
                NumbersTexture = Texture2D.FromStream(GraphicsDevice, s);

            {
                Color[] raw_color = new Color[NumbersTexture.Width * NumbersTexture.Height];
                Color[] color     = new Color[NumbersTexture.Width * NumbersTexture.Height];
                NumbersTexture.GetData(raw_color);
                raw_color.CopyTo(color, 0);

                for (int i = 0; i < raw_color.Length; i++)
                {
                    if (color[i] == Color.Transparent)
                    {
                        continue;
                    }
                    color[i].R = (byte)(255 - raw_color[i].R);
                    color[i].G = (byte)(255 - raw_color[i].G);
                    color[i].B = (byte)(255 - raw_color[i].B);
                    color[i].A = raw_color[i].A;
                }
                NumbersTexture.SetData(color);
            }

            {
                SlotBackgroudFramework = new Texture2D(GraphicsDevice, 32, 32, false, SurfaceFormat.Color);
                Color[] color = new Color[32 * 32];
                for (int i = 0; i < 32; i++)
                {
                    color[i] = color[31 * 32 + i] = color[32 * i] = color[32 * i + 31] = Color.Purple;
                }
                for (int i = 1; i < 31; i++)
                {
                    for (int j = 1; j < 31; j++)
                    {
                        color[i * 32 + j] = new Color(1f, 1f, 1f, 1f);                        //132,101,219
                    }
                }
                SlotBackgroudFramework.SetData(color);
            }
            Root.Initialize();
            foreach (var root in NodesFrom)
            {
                root.Initialize();
            }
            foreach (var root in NodesTo)
            {
                root.Initialize();
            }
            Application.Idle += Application_Idle;
        }
Esempio n. 7
0
        public void CopyToByteArray()
        {
            var array = new byte[4];
            var color = new Color(-1.0f, 0.5f, 2.0f);

            color.CopyTo(array, 1);

            array[1].Should().Be(0);
            array[2].Should().Be(128);
            array[3].Should().Be(255);
        }
Esempio n. 8
0
        public void CopyToFloatArray()
        {
            var array = new float[4];
            var color = new Color(1, 2, 3);

            color.CopyTo(array, 1);

            array[1].Should().Be(1);
            array[2].Should().Be(2);
            array[3].Should().Be(3);
        }
Esempio n. 9
0
        private Color getLineColor(Int16 lineId, DATA_TYPE type)
        {
            if (LINE_BASE_COLORS.Length <= lineId)
            {
                // Random color
                Random rnd = new Random();

                Color[] tempColors = new Color[LINE_BASE_COLORS.Length + 1];
                LINE_BASE_COLORS.CopyTo(tempColors, 0);
                LINE_BASE_COLORS = new Color[tempColors.Length];
                tempColors[LINE_BASE_COLORS.Length - 1] = Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256));
                tempColors.CopyTo(LINE_BASE_COLORS, 0);

                LINE_TRANSPARENT_COLORS.CopyTo(tempColors, 0);
                LINE_TRANSPARENT_COLORS = new Color[tempColors.Length];
                tempColors[LINE_TRANSPARENT_COLORS.Length - 1] = Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256));
                tempColors.CopyTo(LINE_TRANSPARENT_COLORS, 0);
            }

            return((type == DATA_TYPE.BASE) ? LINE_BASE_COLORS[lineId] : LINE_TRANSPARENT_COLORS[lineId]);
        }
Esempio n. 10
0
        private Color getChannelColor(Int16 channelId, DATA_TYPE type)
        {
            if (CHANNEL_BASE_COLORS.Length <= channelId)
            {
                // Random color
                Random rnd = new Random();

                Color[] tempColors = new Color[CHANNEL_BASE_COLORS.Length + 1];
                CHANNEL_BASE_COLORS.CopyTo(tempColors, 0);
                CHANNEL_BASE_COLORS = new Color[tempColors.Length];
                tempColors[CHANNEL_BASE_COLORS.Length - 1] = Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256));
                tempColors.CopyTo(CHANNEL_BASE_COLORS, 0);

                CHANNEL_TRANSPARENT_COLORS.CopyTo(tempColors, 0);
                CHANNEL_TRANSPARENT_COLORS = new Color[tempColors.Length];
                tempColors[CHANNEL_TRANSPARENT_COLORS.Length - 1] = Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256));
                tempColors.CopyTo(CHANNEL_TRANSPARENT_COLORS, 0);
            }

            return((type == DATA_TYPE.BASE) ? CHANNEL_BASE_COLORS[channelId] : CHANNEL_TRANSPARENT_COLORS[channelId]);
        }
Esempio n. 11
0
    public void ChangeColors()
    {
        ChartGenerator chartgen = this.GetComponent <ChartGenerator>();

        Color[] tempcolors = new Color[chartgen.numcolors()];

        chartgen.colors.CopyTo(tempcolors, 0);
        newcolors.CopyTo(chartgen.colors, 0);
        tempcolors.CopyTo(newcolors, 0);

        chartgen.getchart();
    }
Esempio n. 12
0
    static void CalculColors(GifData gifData)
    {
        Color[] previousFrame    = new Color[gifData.canvasWidth * gifData.canvasHeight];
        Color[] currentFrame     = new Color[gifData.canvasWidth * gifData.canvasHeight];
        Color[] transparentFrame = new Color[gifData.canvasWidth * gifData.canvasHeight];

        // Create sprites
        for (int i = 0; i < gifData.graphicsControlExtensions.Count; i++)
        {
            GifGraphicsControlExtension graphicsControlExt = gifData.graphicsControlExtensions[i];
            GifImageDescriptor          imageDescriptor    = graphicsControlExt.imageDescriptor;
            GifImageData imageData      = imageDescriptor.imageData;
            int          top            = imageDescriptor.imageTop;
            int          left           = imageDescriptor.imageLeft;
            int          disposalMethod = graphicsControlExt.disposalMethod;

            int     transparencyIndex = graphicsControlExt.transparentColorFlag ? graphicsControlExt.transparentColorIndex : -1;
            Color[] colorTabel        = imageData.imageDescriptor.localColorTableFlag ? imageData.imageDescriptor.localColorTable : gifData.globalColorTable;

            for (int j = 0; j < imageDescriptor.imageWidth; j++)
            {
                for (int k = 0; k < imageDescriptor.imageHeight; k++)
                {
                    int x           = left + j;
                    int y           = (gifData.canvasHeight - 1) - (top + k);
                    int colorIndex  = imageData.colorIndices[j + k * imageDescriptor.imageWidth];
                    int pixelOffset = x + y * gifData.canvasWidth;

                    if (colorIndex != transparencyIndex)
                    {
                        currentFrame[pixelOffset] = colorTabel[colorIndex];//imageData.getColor(colorIndex);
                    }
                }
            }
            // Set texture pixels and create sprite
            // Store current frame as previous before continuing, and reset current frame
            currentFrame.CopyTo(previousFrame, 0);
            if (disposalMethod == 0 || disposalMethod == 2)
            {
                currentFrame     = new Color[currentFrame.Length];
                imageData.colors = currentFrame;
            }
            else
            {
                imageData.colors = new Color[currentFrame.Length];
                currentFrame.CopyTo(imageData.colors, 0);
            }
        }
    }
Esempio n. 13
0
        public void Edit <T>(IAssetData asset)
        {
            // Create a texture of the original spritesheet, and collect its data.
            Texture2D spriteSheet = asset.AsImage().Data;
            int       sheetHeight = spriteSheet.Height;
            int       sheetWidth  = spriteSheet.Width;

            Color[] originalData = new Color[sheetHeight * sheetWidth];
            spriteSheet.GetData(originalData);

            // Create a texture of the csvm spritesheet, and collect its data.
            Texture2D csvmSpriteSheet = this.helper.Content.Load <Texture2D>("Res/csvmTileSheet.png", ContentSource.ModFolder);
            int       csvmSheetHeight = csvmSpriteSheet.Height;
            int       csvmSheetWidth  = csvmSpriteSheet.Width;

            Color[] csvmData = new Color[csvmSheetHeight * csvmSheetWidth];
            csvmSpriteSheet.GetData(csvmData);

            // Combine the original and the csvm spritesheets
            Texture2D combinedSpriteSheet = new Texture2D(Game1.game1.GraphicsDevice, sheetWidth, sheetHeight + csvmSheetHeight, false, SurfaceFormat.Color);

            Color[] combinedData = new Color[originalData.Length + csvmData.Length];
            originalData.CopyTo(combinedData, 0);
            csvmData.CopyTo(combinedData, originalData.Length);
            combinedSpriteSheet.SetData(combinedData);

            // Replace the game's spritesheet with the newly created one.
            asset.ReplaceWith(combinedSpriteSheet);

            // Assign an index to each new texture added in the itemPairs dictionary.
            // The key is set to the name from textures, and the index is its item
            // index that will be recognized in game.
            for (int i = 0; i < (textures.Length / 16) + 1; i++)
            {
                int remainingTextures = i == (textures.Length / 16) ? textures.Length % 16 : 16;
                for (int j = 0; j < remainingTextures; j++)
                {
                    // Current texture is the number texture we're on. 16 * the row + the column.
                    int currentTexture = (16 * i) + j;

                    // Create the key value pair of texture_name: texture's index.
                    // Note, currentTexture is not incremented by one as this is an index (Started from 0) and
                    // not an absolute position (started from 1.)
                    this.itemPairs[textures[currentTexture]] = ((sheetHeight / 16) * (sheetWidth / 16)) + (currentTexture);
                }
            }
        }
Esempio n. 14
0
        public void patchCraftablesTilesheetAsset(IAssetData craftableTilesheetAsset)
        {
            //Modifying default Craftables tilesheet of the game
            Texture2D CraftablesSheet = craftableTilesheetAsset.AsImage().Data;
            int       originalWidth   = CraftablesSheet.Width;
            int       originalHeight  = CraftablesSheet.Height;

            int startingId = (originalWidth / 16) * (originalHeight / 32);

            IBigCraftableWrapper.getWrapper("Seed Machine").itemID = startingId; //First free id for the mod injecting
            IBigCraftableWrapper.getWrapper("Seed Bandit").itemID  = startingId + 6;

            //Getting original color array
            Color[] originalData = new Color[originalWidth * originalHeight];
            CraftablesSheet.GetData <Color>(originalData);

            //Getting mod's color array
            int customWidth  = SeedMachinesSprite.Width;
            int customHeight = SeedMachinesSprite.Height;

            Color[] customData = new Color[customWidth * customHeight];
            SeedMachinesSprite.GetData <Color>(customData);

            //Preparing new clear tilesheet
            Texture2D newTileSheet = new Texture2D(Game1.game1.GraphicsDevice, originalWidth, originalHeight + customHeight, false, SurfaceFormat.Color);

            //Join default and custom color arrays
            var mixedData = new Color[originalData.Length + customData.Length];

            originalData.CopyTo(mixedData, 0);
            customData.CopyTo(mixedData, originalData.Length);

            //Push joined array of colors to prepared new tilesheet
            newTileSheet.SetData(0, new Rectangle(0, 0, originalWidth, originalHeight + customHeight), mixedData, 0, mixedData.Length);

            //Replace default tilesheet with joined one
            craftableTilesheetAsset.ReplaceWith(newTileSheet);

            this.craftablesTilesheetWasPatched = true;
        }
Esempio n. 15
0
    private void createAnimator(GifData gifData)
    {
        List <Sprite>     sprites        = new List <Sprite>();
        GifAnimatorScript animatorScript = gameObject.AddComponent <GifAnimatorScript>();

        Color[] previousFrame    = new Color[gifData.canvasWidth * gifData.canvasHeight];
        Color[] currentFrame     = new Color[gifData.canvasWidth * gifData.canvasHeight];
        Color[] transparentFrame = new Color[gifData.canvasWidth * gifData.canvasHeight];

        // Create sprites
        for (int i = 0; i < gifData.graphicsControlExtensions.Count; i++)
        {
            GifGraphicsControlExtension graphicsControlExt = gifData.graphicsControlExtensions[i];
            GifImageDescriptor          imageDescriptor    = graphicsControlExt.imageDescriptor;
            GifImageData imageData         = imageDescriptor.imageData;
            int          top               = imageDescriptor.imageTop;
            int          left              = imageDescriptor.imageLeft;
            int          disposalMethod    = graphicsControlExt.disposalMethod;
            Texture2D    texture           = new Texture2D(gifData.canvasWidth, gifData.canvasHeight);
            int          transparencyIndex = graphicsControlExt.transparentColorFlag ? graphicsControlExt.transparentColorIndex : -1;

            // Determine base pixels
            if (i == 0)
            {
                texture.SetPixels(transparentFrame);
            }
            else
            {
                if (disposalMethod == 1)
                {
                    texture.SetPixels(previousFrame);
                }
                else if (disposalMethod == 2)
                {
                    texture.SetPixels(transparentFrame);
                }
                else if (disposalMethod == 3)
                {
                    throw new NotImplementedException("Disposal method 3 is not implemented.");
                }
            }

            // Set pixels from image data
            for (int j = 0; j < imageDescriptor.imageWidth; j++)
            {
                for (int k = 0; k < imageDescriptor.imageHeight; k++)
                {
                    int x           = left + j;
                    int y           = (gifData.canvasHeight - 1) - (top + k);
                    int colorIndex  = imageData.colorIndices[j + k * imageDescriptor.imageWidth];
                    int pixelOffset = x + y * gifData.canvasWidth;

                    if (colorIndex != transparencyIndex)
                    {
                        GifColor gifColor = imageData.getColor(colorIndex);

                        currentFrame[pixelOffset] = new Color(gifColor.r / 255f, gifColor.g / 255f, gifColor.b / 255f);
                    }
                }
            }

            //float bgMax = 50f / 255;
            //var transparent = currentFrame.Where(p => p.a == 0);
            //var bgMeanSum = currentFrame.Aggregate(new float[8], (curSum, color) =>
            //{
            //    curSum[4] += color.a;
            //    ++curSum[5];

            //    if (color.a > 0)
            //    {
            //        curSum[6] += color.a;
            //        ++curSum[7];
            //    }

            //    if (color.r >= bgMax || color.g >= bgMax || color.b >= bgMax)
            //        return curSum; // We are interested on dark colors

            //    curSum[0] += color.r;
            //    curSum[1] += color.g;
            //    curSum[2] += color.b;
            //    ++curSum[3];

            //    return curSum;
            //});

            //var bgMean = new Color32(
            //    (byte)(bgMeanSum[0] * 255 / bgMeanSum[3]),
            //    (byte)(bgMeanSum[1] * 255 / bgMeanSum[3]),
            //    (byte)(bgMeanSum[2] * 255 / bgMeanSum[3]),
            //    (byte)(bgMeanSum[4] * 255 / bgMeanSum[5]));

            //Debug.Log(
            //    $"Frame {i} has transparent colors?: {transparent.Any()} || Count: {transparent.Count()} || Background: {bgMean}" +
            //    Environment.NewLine +
            //    $"Solid transparency mean (must be 255): {(byte)(bgMeanSum[6] * 255 / bgMeanSum[7])}");

            // Set texture pixels and create sprite
            texture.SetPixels(currentFrame);
            texture.Apply();
            texture.filterMode = FilterMode.Point;
            sprites.Add(Sprite.Create(texture, new Rect(0f, 0f, gifData.canvasWidth, gifData.canvasHeight), new Vector2(1f, 1f)));

            // Store current frame as previous before continuing, and reset current frame
            currentFrame.CopyTo(previousFrame, 0);
            if (disposalMethod == 0 || disposalMethod == 2)
            {
                currentFrame = new Color[currentFrame.Length];
            }
        }

        // Setup animator script
        animatorScript.sprites = sprites;
    }
Esempio n. 16
0
        private LinearGradientBrush GetBrush(SvgLinearGradientElement res, RectangleF bounds)
        {
            //LinearGradientBrush brush = new LinearGradientBrush(new RectangleF(fEffectiveLeft - 1,
            //    fEffectiveTop - 1, fEffectiveWidth + 2, fEffectiveHeight + 2),
            //    Color.White, Color.White, mode);

            XmlNodeList stops = res.Stops;

            ColorBlend cb = new ColorBlend();

            //List<Color> adjcolors = new List<Color>();
            //List<float> adjpositions = new List<float>();
            //GetColorsAndPositions(stops, adjpositions, adjcolors);
            var gradientStops = this.GetGradientStops(stops);

            if (gradientStops == null || gradientStops.Count == 0)
            {
                return(null);
            }

            float fLeft   = (float)res.X1.AnimVal.Value;
            float fRight  = (float)res.X2.AnimVal.Value;
            float fTop    = (float)res.Y1.AnimVal.Value;
            float fBottom = (float)res.Y2.AnimVal.Value;

            bool bForceUserSpaceOnUse = (fLeft > 1 || fRight > 1 || fTop > 1 || fBottom > 1);

            float fEffectiveLeft   = fLeft;
            float fEffectiveRight  = fRight;
            float fEffectiveTop    = fTop;
            float fEffectiveBottom = fBottom;

            if (res.GradientUnits.AnimVal.Equals((ushort)SvgUnitType.ObjectBoundingBox) && !bForceUserSpaceOnUse)
            {
                if (res.SpreadMethod.AnimVal.Equals((ushort)SvgSpreadMethod.Pad))
                {
                    fEffectiveRight = bounds.Right;
                    fEffectiveLeft  = bounds.Left;
                }
                else
                {
                    fEffectiveLeft  = bounds.Left + fLeft * (bounds.Width);
                    fEffectiveRight = bounds.Left + fRight * (bounds.Width);
                }

                fEffectiveTop    = bounds.Top + fTop * (bounds.Height);
                fEffectiveBottom = bounds.Top + fBottom * (bounds.Height);
            }

            LinearGradientMode mode = LinearGradientMode.Horizontal;

            if (fTop == fBottom)
            {
                mode = LinearGradientMode.Horizontal;
            }
            else
            {
                if (fLeft == fRight)
                {
                    mode = LinearGradientMode.Vertical;
                }
                else
                {
                    if (fLeft < fRight)
                    {
                        mode = LinearGradientMode.ForwardDiagonal;
                    }
                    else
                    {
                        mode = LinearGradientMode.BackwardDiagonal;
                    }
                }
            }

            float fEffectiveWidth = fEffectiveRight - fEffectiveLeft;

            if (fEffectiveWidth <= 0)
            {
                fEffectiveWidth = bounds.Width;
            }

            float fEffectiveHeight = fEffectiveBottom - fEffectiveTop;

            if (fEffectiveHeight <= 0)
            {
                fEffectiveHeight = bounds.Height;
            }

            int stopCount = gradientStops.Count;
            var colors    = new Color[stopCount];
            var positions = new float[stopCount];

            for (int i = 0; i < stopCount; i++)
            {
                var gradientStop = gradientStops[i];
                colors[i]    = gradientStop.Color;
                positions[i] = gradientStop.Offset;
            }
            //LinearGradientBrush brush = new LinearGradientBrush(new PointF(fLeft, fTop),
            //    new PointF(fRight, fBottom), gradientStops[0].Color, gradientStops[stopCount - 1].Color);
            LinearGradientBrush brush = new LinearGradientBrush(new RectangleF(fEffectiveLeft - 1,
                                                                               fEffectiveTop - 1, fEffectiveWidth + 2, fEffectiveHeight + 2),
                                                                Color.Transparent, Color.Transparent, mode);

            if (res.GradientUnits.AnimVal.Equals((ushort)SvgUnitType.ObjectBoundingBox) && !bForceUserSpaceOnUse)
            {
                if (res.SpreadMethod.AnimVal.Equals((ushort)SvgSpreadMethod.Pad))
                {
                    for (int i = 0; i < stopCount; i++)
                    {
                        if (fLeft == fRight)
                        {
                            positions[i] = fTop + positions[i] * (fBottom - fTop);
                        }
                        else
                        {
                            positions[i] = fLeft + positions[i] * (fRight - fLeft);
                        }
                    }

                    // this code corrects the values again... fix
                    int nSize = colors.Length;

                    if (positions[0] > 0.0)
                    {
                        ++nSize;
                    }

                    if (positions[colors.Length - 1] < 1)
                    {
                        ++nSize;
                    }

                    Color[] readjcolors    = new Color[nSize];
                    float[] readjpositions = new float[nSize];

                    if (positions[0] > 0.0)
                    {
                        positions.CopyTo(readjpositions, 1);
                        colors.CopyTo(readjcolors, 1);

                        readjcolors[0]    = readjcolors[1];
                        readjpositions[0] = 0;
                    }
                    else
                    {
                        positions.CopyTo(readjpositions, 0);
                        colors.CopyTo(readjcolors, 0);
                    }

                    if (positions[colors.Length - 1] < 1)
                    {
                        readjcolors[nSize - 1]    = readjcolors[nSize - 2];
                        readjpositions[nSize - 1] = 1;
                    }

                    cb.Colors    = readjcolors;
                    cb.Positions = readjpositions;
                }
                else
                {
                    cb.Colors    = colors;
                    cb.Positions = positions;
                }
            }
            else
            {
                cb.Colors    = colors;
                cb.Positions = positions;
            }

            brush.InterpolationColors = cb;

            if (res.SpreadMethod.AnimVal.Equals((ushort)SvgSpreadMethod.Reflect))
            {
                brush.WrapMode = WrapMode.TileFlipXY;
            }
            else if (res.SpreadMethod.AnimVal.Equals((ushort)SvgSpreadMethod.Repeat))
            {
                brush.WrapMode = WrapMode.Tile;
            }
            else if (res.SpreadMethod.AnimVal.Equals((ushort)SvgSpreadMethod.Pad))
            {
                brush.WrapMode = WrapMode.Tile;
            }

            brush.Transform = GetTransformMatrix(res);

            if (string.Equals(res.GetPropertyValue("color-interpolation"),
                              CssConstants.ValLinearRgb, StringComparison.OrdinalIgnoreCase))
            {
                brush.GammaCorrection = true;
            }
            else
            {
                brush.GammaCorrection = false;
            }

            return(brush);
        }
Esempio n. 17
0
    public void mbAddToRenderBuffer(ref Vector3[] vertices, ref Vector2[] uvs, ref Color[] colors)
    {
        if (mBufferPtr == mVertices.Length)
            mbEnlargeBuffers(LayerBlocksize);

        vertices.CopyTo(mVertices, mBufferPtr);
        uvs.CopyTo(mUVs, mBufferPtr);
        colors.CopyTo(mColors, mBufferPtr);

        int i = (mBufferPtr / 4) * 6;
        mTriangles[i++] = mBufferPtr;
        mTriangles[i++] = mBufferPtr + 1;
        mTriangles[i++] = mBufferPtr + 2;
        mTriangles[i++] = mBufferPtr + 2;
        mTriangles[i++] = mBufferPtr + 3;
        mTriangles[i++] = mBufferPtr;

        mBufferPtr += 4;
    }
Esempio n. 18
0
    public void GenerateMesh()
    {
        Vector3[] AllPos    = { };
        int[]     AllTras   = { };
        Color[]   AllColors = { };

        for (int p = 0; p < points.Length; p++)
        {
            if (points[p].size <= 0)
            {
                points[p].size = 0;
                Debug.Log("Size value is out of range " + this.name);
            }
            float b = 7.8f - ((points[p].LandingTime - TimeManager.time) * 7.8f);//最終地点を1とする
            if (points[p].EnableAnimationCurve)
            {
                b = points[p].Curve.Evaluate(TimeManager.time - points[p].LandingTime) * 7.8f;//最終地点を1とした曲線を参照する
            }

            Vector3[] pos  = new Vector3[2 + (points[p].size * 2)];
            int[]     tras = new int[points[p].size * 6];

            //頂点の座標の生成
            var rad   = Math.PI / 180;
            var angle = 180.0f / 16.0f;
            if (b >= 0)
            {
                pos[0] = b * 1.00f * new Vector2((float)Math.Cos(((angle * (points[p].line + 0)) + 180) * rad), (float)Math.Sin(((angle * (points[p].line + 0)) + 180) * rad)) + new Vector2(0, 5);
                pos[1] = b * 1.01f * new Vector2((float)Math.Cos(((angle * (points[p].line + 0)) + 180) * rad), (float)Math.Sin(((angle * (points[p].line + 0)) + 180) * rad)) + new Vector2(0, 5);
                for (int i = 0; i < points[p].size * 2; i += 2)
                {
                    pos[2 + i] = b * 1.00f * new Vector2((float)Math.Cos(((angle * (points[p].line + 1 + (i / 2))) + 180) * rad), (float)Math.Sin(((angle * (points[p].line + 1 + (i / 2))) + 180) * rad)) + new Vector2(0, 5);
                    pos[3 + i] = b * 1.01f * new Vector2((float)Math.Cos(((angle * (points[p].line + 1 + (i / 2))) + 180) * rad), (float)Math.Sin(((angle * (points[p].line + 1 + (i / 2))) + 180) * rad)) + new Vector2(0, 5);
                }
            }
            else
            {
                pos[0] = new Vector2(0, 5);
                pos[1] = new Vector2(0, 5);
                for (int i = 0; i < points[p].size * 2; i += 2)
                {
                    pos[2 + i] = new Vector2(0, 5);
                    pos[3 + i] = new Vector2(0, 5);
                }
            }


            //頂点の順序
            for (int i = 0; i < points[p].size; i++)
            {
                int x = i * 2;
                tras[i * 6]     = x + AllPos.Length;
                tras[i * 6 + 1] = x + 2 + AllPos.Length;
                tras[i * 6 + 2] = x + 1 + AllPos.Length;
                tras[i * 6 + 3] = x + 1 + AllPos.Length;
                tras[i * 6 + 4] = x + 2 + AllPos.Length;
                tras[i * 6 + 5] = x + 3 + AllPos.Length;
            }

            Color[] colors = new Color[pos.Length];
            float   a;
            a = GetComponent <HoldNoteEvent>().holding ? 1 : 0.5f;
            for (int i = 0; i < colors.Length; i++)
            {
                colors[i] = new Color(0.5f, 0.5f, 1) * a;
            }
            colors[0] = Color.blue * a;
            colors[1] = Color.blue * a;
            colors[points[p].size * 2]     = Color.blue * a;
            colors[points[p].size * 2 + 1] = Color.blue * a;



            Vector2[] cpos = new Vector2[pos.Length];
            for (int i = 0; i < cpos.Length; i += 2)
            {
                cpos[i / 2] = new Vector2(pos[i].x, pos[i].y);
                cpos[(i / 2) + (cpos.Length / 2)] = new Vector2(pos[(pos.Length - i) - 1].x, pos[(pos.Length - i) - 1].y);
            }
            PolygonCollider2D polygon = gameObject.GetComponent <PolygonCollider2D>();
            polygon.pathCount = p + 1;
            polygon.SetPath(p, cpos);

            Array.Resize(ref AllPos, AllPos.Length + pos.Length);
            Array.Resize(ref AllTras, AllTras.Length + tras.Length);
            Array.Resize(ref AllColors, AllColors.Length + colors.Length);
            pos.CopyTo(AllPos, AllPos.Length - pos.Length);
            tras.CopyTo(AllTras, AllTras.Length - tras.Length);
            colors.CopyTo(AllColors, AllColors.Length - colors.Length);
        }
        Mesh mesh = new Mesh();

        mesh.vertices  = AllPos;
        mesh.triangles = AllTras;
        mesh.colors    = AllColors;
        GetComponent <MeshFilter>().mesh = mesh;

        GenerateTrail(mesh);
        GenerateTrailCollider(mesh);
    }
        /// <summary>
        /// Thread Methode with AnimationLogic
        /// </summary>
        /// <param name="paramArray"></param>
        private static void Animating(object paramArray)
        {
            #region Read Parameter

            var param = (object[])paramArray;
            //ControleSize
            var controlSize = (Size)param[0];
            //Drawmode (Lines, Dots, Circle)
            var drawmode = (DrawMode)param[2];
            //Penwidth to Draw
            var penWidth = (int)param[3];
            //Outer Circle Radius
            var outerCircle = (int)param[4];
            //Inner Circle Radius
            var innerCircle = (int)param[5];
            //DrawBufferSize
            var bufferSize = (outerCircle + penWidth) * 2;
            //Clockwise Rotation
            var clockwise = (bool)param[7];

            #endregion

            #region Set Enviromente

            //Get DeviceContex from Handle
            var ding = Win32Support.GetDCEx((IntPtr)param[1]);

            //Get Graphics from DeviceContext
            var g = Graphics.FromHdc(ding);
            g.SmoothingMode     = SmoothingMode.AntiAlias;
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;

            //Make BackBuffer
            Image buffer  = new Bitmap(bufferSize, bufferSize);
            var   gBuffer = Graphics.FromImage(buffer);
            gBuffer.SmoothingMode = SmoothingMode.AntiAlias;

            #endregion

            #region Set ColorArray

            var colors = new Color[12];
            for (var i = 0; i < 12; i++)
            {
                colors[i] = Color.FromArgb((255 - (i * 20)), (Color)param[6]);
            }

            #endregion

            #region Translate ZeroPoint to Middle of Control

            gBuffer.TranslateTransform(dx: bufferSize / 2, dy: bufferSize / 2);
            g.TranslateTransform(dx: controlSize.Width / 2, dy: controlSize.Height / 2);

            #endregion

            #region GetControlBackground

            Image background = new Bitmap(bufferSize, bufferSize);
            var   gTmp       = Graphics.FromImage(background);
            Win32Support.BitBlt(gTmp.GetHdc(), 0, 0, bufferSize, bufferSize, g.GetHdc(), (controlSize.Width / 2) - (bufferSize / 2), (controlSize.Height / 2) - (bufferSize / 2), Win32Support.TernaryRasterOperations.SRCCOPY);
            g.ReleaseHdc();
            gTmp.ReleaseHdc();

            #endregion

            #region AnimationLoop

            while (true)
            {
                //Catch Handle Exception
                try
                {
                    #region Draw Background

                    gBuffer.DrawImage(background, -(bufferSize / 2), -(bufferSize / 2));

                    #endregion

                    #region Draw Animation

                    for (int i = 0; i < 12; i++)
                    {
                        switch (drawmode)
                        {
                        case DrawMode.Dots:
                            gBuffer.FillEllipse(new SolidBrush(colors[i]), 0, outerCircle - penWidth, penWidth * 2, penWidth * 2);
                            break;

                        case DrawMode.Lines:
                            var pen = new Pen(new SolidBrush(colors[i]), penWidth)
                            {
                                StartCap = LineCap.Round,
                                EndCap   = LineCap.Round
                            };
                            gBuffer.DrawLine(pen, new Point(0, innerCircle), new Point(0, outerCircle));
                            break;

                        case DrawMode.Circle:
                            gBuffer.DrawArc(new Pen(colors[i], penWidth * 2), new Rectangle(-(outerCircle), -(outerCircle), outerCircle * 2, outerCircle * 2), 0, 31);
                            break;
                        }
                        if (clockwise)
                        {
                            gBuffer.RotateTransform(-30);
                        }
                        else
                        {
                            gBuffer.RotateTransform(30);
                        }
                    }

                    #endregion

                    #region Draw BackBuffer

                    //Draw Buffer
                    g.DrawImage(buffer, new Point(-(bufferSize / 2), -(bufferSize / 2)));

                    #endregion

                    #region Colorrotation

                    //Array Rotation
                    var tmp = new Color[12];
                    colors.CopyTo(tmp, 0);
                    colors[0]  = tmp[1];
                    colors[1]  = tmp[2];
                    colors[2]  = tmp[3];
                    colors[3]  = tmp[4];
                    colors[4]  = tmp[5];
                    colors[5]  = tmp[6];
                    colors[6]  = tmp[7];
                    colors[7]  = tmp[8];
                    colors[8]  = tmp[9];
                    colors[9]  = tmp[10];
                    colors[10] = tmp[11];
                    colors[11] = tmp[0];

                    #endregion

                    //Interval
                    Thread.Sleep(100);
                }
                catch (Exception)
                {
                    #region Release from Threadpool

                    //Release from Threadpool
                    _findThreadParameter = ((IntPtr)param[1]).ToString();
                    Threadpool.RemoveAt(Threadpool.FindIndex(FindThread));

                    #endregion
                }

                #region Test Thread in Threadpool

                //If not in Threadpool end Thread
                _findThreadParameter = ((IntPtr)param[1]).ToString();
                if (!Threadpool.Exists(FindThread))
                {
                    break;
                }

                #endregion
            }

            #endregion

            #region Resourcen freigeben

            //Resourcen freigeben
            background.Dispose();
            buffer.Dispose();
            gBuffer.Dispose();
            g.Dispose();
            Win32Support.DeleteDC(ding);
            ding = IntPtr.Zero;

            #endregion
        }
Esempio n. 20
0
		void SetForcedStateVerts(Vector3[] verts, Color[] cols)
		{
			if(m_forced_state_verts == null || m_forced_state_verts.Length != verts.Length)
				m_forced_state_verts = new Vector3[verts.Length];
			verts.CopyTo(m_forced_state_verts, 0);

			if(m_forced_state_cols == null || m_forced_state_cols.Length != cols.Length)
				m_forced_state_cols = new Color[cols.Length];
			cols.CopyTo(m_forced_state_cols, 0);

		}
Esempio n. 21
0
    public override void SpriteLoad()
    {
        //subIDを決定
        SetSubIDAndRotation();

        var meshRenderer = GetComponentInChildren <SkinnedMeshRenderer>();

        meshRenderer.material     = ResourceLoader.GetMaterial(R_MaterialType.TentaclePiece);
        meshRenderer.sortingOrder = GetOrderInLayer(id);
        //meshRenderer.transform.rotation = Quaternion.AngleAxis(rotAngle, Vector3.forward);

        Sprite spr = null;

        if (subId == 0)
        {
            spr = ResourceLoader.GetChips(R_MapChipType.MainChip)[id];
        }
        else
        {
            spr = ResourceLoader.GetChips(R_MapChipType.Sub1_Tentacle)[subId - 1];
        }

        Texture2D tex = new Texture2D((int)spr.rect.width, (int)spr.rect.height);

        var pixels = spr.texture.GetPixels(
            (int)spr.textureRect.x,
            (int)spr.textureRect.y,
            (int)spr.textureRect.width,
            (int)spr.textureRect.height);

        var distPixels = new Color[pixels.Length];
        int width      = (int)spr.textureRect.width;
        int height     = (int)spr.textureRect.height;

        //ピクセルを回転
        int rotCount = (int)(rotAngle / 90);

        Debug.Log(rotCount);

        for (int i = 0; i < rotCount; i++)
        {
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    distPixels[(width - 1 - y) + x * width] =
                        pixels[x + y * width];
                }
            }
            //回転の適用
            distPixels.CopyTo(pixels, 0);
        }

        //裏から見てるので反転
        for (int y = 0; y < height; y++)
        {
            for (int x = 0; x < width; x++)
            {
                distPixels[(width - 1 - x) + y * width] =
                    pixels[x + y * width];
            }
        }
        //反転の適用
        distPixels.CopyTo(pixels, 0);

        /*
         * 0  1  2  3  4
         * 5  6  7  8  9
         * 10 11 12 13 14
         * 15 16 17 18 19
         * 20 21 22 23 24
         *
         * j
         * i 0 1 2 3 4
         * 1 3 4 3 2
         * 2 1 1 1 1
         * 3 2 4 6 8
         * 4 2 3 4 5
         *
         * 4 3 2 1 0
         *        1
         *                2
         *                3
         *                4
         *
         * [i, j]
         * [0, 0] => [0, 4]
         * [0, 1] => [1, 4]
         * [1, 0] => [0, 3]
         *
         * [i, j] => [j, width - 1 - i]
         * [x + y*width] -> [(width - 1 - y) + x * width]
         *
         * //時計回り
         * [x + y*width] -> [(width - 1 - y) + x * width]
         * //逆
         * [x + y*width] -> [y + ((width - 1) - x) * width]
         *
         */

        tex.SetPixels(pixels);
        tex.Apply();

        meshRenderer.material.SetTexture("_MainTex", tex);


        //パーティクル生成
        SetParticle();

        //更新
        UpdateParticle();
    }
Esempio n. 22
0
        private void Feedback(int col, Color[] _currentCode)
        {
            Ellipse ellipse1 = _ellipses[0, col];
            Color   color1   = ((SolidColorBrush)ellipse1.Fill).Color;
            Ellipse ellipse2 = _ellipses[1, col];
            Color   color2   = ((SolidColorBrush)ellipse2.Fill).Color;
            Ellipse ellipse3 = _ellipses[2, col];
            Color   color3   = ((SolidColorBrush)ellipse3.Fill).Color;
            Ellipse ellipse4 = _ellipses[3, col];
            Color   color4   = ((SolidColorBrush)ellipse4.Fill).Color;

            if (color1 != _selectionButtonGray && color2 != _selectionButtonGray && color3 != _selectionButtonGray && color4 != _selectionButtonGray)
            {
                _tries            += 1;
                _moveOnToNextGuess = true;
                Color[] attempt = new Color[4] {
                    color1, color2, color3, color4
                };
                Color[] duplicateAttempt = new Color[4];
                attempt.CopyTo(duplicateAttempt, 0);

                Color[] duplicateCurrentCode = new Color[4];
                _currentCode.CopyTo(duplicateCurrentCode, 0);

                int rightColorAndPlace      = 0;
                int rightColorButWrongPlace = 0;
                for (int i = 0; i < 4; i++)
                {
                    if (duplicateAttempt[i] == duplicateCurrentCode[i])
                    {
                        rightColorAndPlace     += 1;
                        duplicateCurrentCode[i] = Colors.White;
                        duplicateAttempt[i]     = Colors.White;
                    }
                }
                for (int i = 0; i < 4; i++)
                {
                    if (duplicateAttempt[i] != Colors.White)
                    {
                        if (duplicateCurrentCode.Contains(duplicateAttempt[i]))
                        {
                            int codeIndex = Array.IndexOf(duplicateCurrentCode, duplicateAttempt[i]);
                            duplicateAttempt[i]             = Colors.White;
                            duplicateCurrentCode[codeIndex] = Colors.White;
                            rightColorButWrongPlace        += 1;
                        }
                    }
                }
                TextBlock textbox1 = _textboxes1[_tries - 1];
                TextBlock textbox2 = _textboxes2[_tries - 1];
                textbox1.VerticalAlignment = VerticalAlignment.Center;
                textbox2.VerticalAlignment = VerticalAlignment.Center;

                string rightColorWrongPlaceString = "";
                string rightColorPlaceString      = "";
                for (int i = 0; i < rightColorButWrongPlace; i++)
                {
                    rightColorWrongPlaceString += "\uE734 ";
                }
                for (int i = 0; i < rightColorAndPlace; i++)
                {
                    rightColorPlaceString += "\uE735 ";
                }

                textbox1.Text = rightColorPlaceString;
                textbox2.Text = rightColorWrongPlaceString;

                if (rightColorAndPlace == 4)
                {
                    _isSolved = true;
                    EndScreen(true);

                    Ellipse         e1       = _ellipses[0, _maxAttempts];
                    SolidColorBrush CodePeg1 = new SolidColorBrush(_currentCode[0]);
                    e1.Fill = CodePeg1;

                    Ellipse         e2       = _ellipses[1, _maxAttempts];
                    SolidColorBrush CodePeg2 = new SolidColorBrush(_currentCode[1]);
                    e2.Fill = CodePeg2;

                    Ellipse         e3       = _ellipses[2, _maxAttempts];
                    SolidColorBrush CodePeg3 = new SolidColorBrush(_currentCode[2]);
                    e3.Fill = CodePeg3;

                    Ellipse         e4       = _ellipses[3, _maxAttempts];
                    SolidColorBrush CodePeg4 = new SolidColorBrush(_currentCode[3]);
                    e4.Fill = CodePeg4;

                    _isSolutionVisibleOnBoard = true;
                }
                else if (_tries == _maxAttempts)
                {
                    _isSolved = true;
                    Ellipse         e1       = _ellipses[0, _maxAttempts];
                    SolidColorBrush CodePeg1 = new SolidColorBrush(_currentCode[0]);
                    e1.Fill = CodePeg1;

                    Ellipse         e2       = _ellipses[1, _maxAttempts];
                    SolidColorBrush CodePeg2 = new SolidColorBrush(_currentCode[1]);
                    e2.Fill = CodePeg2;

                    Ellipse         e3       = _ellipses[2, _maxAttempts];
                    SolidColorBrush CodePeg3 = new SolidColorBrush(_currentCode[2]);
                    e3.Fill = CodePeg3;

                    Ellipse         e4       = _ellipses[3, _maxAttempts];
                    SolidColorBrush CodePeg4 = new SolidColorBrush(_currentCode[3]);
                    e4.Fill = CodePeg4;
                    EndScreen(false);
                }
            }
        }
Esempio n. 23
0
    private void createAnimator(GifData gifData)
    {
        List <Sprite>     sprites        = new List <Sprite>();
        GifAnimatorScript animatorScript = gameObject.AddComponent <GifAnimatorScript>();

        Color[] previousFrame    = new Color[gifData.canvasWidth * gifData.canvasHeight];
        Color[] currentFrame     = new Color[gifData.canvasWidth * gifData.canvasHeight];
        Color[] transparentFrame = new Color[gifData.canvasWidth * gifData.canvasHeight];

        // Create sprites
        for (int i = 0; i < gifData.graphicsControlExtensions.Count; i++)
        {
            GifGraphicsControlExtension graphicsControlExt = gifData.graphicsControlExtensions[i];
            GifImageDescriptor          imageDescriptor    = graphicsControlExt.imageDescriptor;
            GifImageData imageData         = imageDescriptor.imageData;
            int          top               = imageDescriptor.imageTop;
            int          left              = imageDescriptor.imageLeft;
            int          disposalMethod    = graphicsControlExt.disposalMethod;
            Texture2D    texture           = new Texture2D(gifData.canvasWidth, gifData.canvasHeight);
            int          transparencyIndex = graphicsControlExt.transparentColorFlag ? graphicsControlExt.transparentColorIndex : -1;

            // Determine base pixels
            if (i == 0)
            {
                texture.SetPixels(transparentFrame);
            }
            else
            {
                if (disposalMethod == 1)
                {
                    texture.SetPixels(previousFrame);
                }
                else if (disposalMethod == 2)
                {
                    texture.SetPixels(transparentFrame);
                }
                else if (disposalMethod == 3)
                {
                    throw new NotImplementedException("Disposal method 3 is not implemented.");
                }
            }

            // Set pixels from image data
            for (int j = 0; j < imageDescriptor.imageWidth; j++)
            {
                for (int k = 0; k < imageDescriptor.imageHeight; k++)
                {
                    int x           = left + j;
                    int y           = (gifData.canvasHeight - 1) - (top + k);
                    int colorIndex  = imageData.colorIndices[j + k * imageDescriptor.imageWidth];
                    int pixelOffset = x + y * gifData.canvasWidth;

                    if (colorIndex != transparencyIndex)
                    {
                        GifColor gifColor = imageData.getColor(colorIndex);

                        currentFrame[pixelOffset] = new Color(gifColor.r / 255f, gifColor.g / 255f, gifColor.b / 255f);
                    }
                }
            }

            // Set texture pixels and create sprite
            texture.SetPixels(currentFrame);
            texture.Apply();
            texture.filterMode = FilterMode.Point;
            sprites.Add(Sprite.Create(texture, new Rect(0f, 0f, gifData.canvasWidth, gifData.canvasHeight), new Vector2(1f, 1f)));

            // Store current frame as previous before continuing, and reset current frame
            currentFrame.CopyTo(previousFrame, 0);
            if (disposalMethod == 0 || disposalMethod == 2)
            {
                currentFrame = new Color[currentFrame.Length];
            }
        }

        // Setup animator script
        animatorScript.sprites = sprites;
    }
Esempio n. 24
0
        public virtual void DrawColors(Color[] colors, Vector2 size, Vector2 location)
        {
            if (colors == null) throw new ArgumentNullException("colors");

            Color[] copiedColors = new Color[colors.Length];
            colors.CopyTo(copiedColors, 0);
            this._commands.Enqueue(new ContextCommand { CommandType = CommandType.DrawColors, Vectors = new Vector2[] { size, location }, Addtions = new object[] { copiedColors } });
        }
Esempio n. 25
0
        public void Edit <T>(IAssetData asset)
        {
            if (asset.AssetNameEquals("TileSheets\\tools"))
            {
                Texture2D toolSpriteSheet = asset.AsImage().Data;
                int       originalWidth   = toolSpriteSheet.Width;
                int       originalHeight  = toolSpriteSheet.Height;
                Color[]   data1           = new Color[originalWidth * originalHeight];
                toolSpriteSheet.GetData <Color>(data1);
                Texture2D customToolsSpriteSheet = _toolsSpriteSheet;
                int       meatCleaverWidth       = customToolsSpriteSheet.Width;
                int       meatCleaverlHeight     = customToolsSpriteSheet.Height;
                Color[]   data2 = new Color[meatCleaverWidth * meatCleaverlHeight];
                customToolsSpriteSheet.GetData <Color>(data2);
                Texture2D newSpriteSheet = new Texture2D(Game1.game1.GraphicsDevice, originalWidth, originalHeight + meatCleaverlHeight, false, SurfaceFormat.Color);

                var data3 = new Color[data1.Length + data2.Length];
                data1.CopyTo(data3, 0);
                data2.CopyTo(data3, data1.Length);

                newSpriteSheet.SetData(data3);

                asset.ReplaceWith(newSpriteSheet);

                var newToolInitialParentIdex = (originalWidth / 16) * (originalHeight / 16);

                int offset = 0;
                if (DataLoader.ModConfig.Softmode)
                {
                    offset = 7;
                }

                MeatCleaver.initialParentTileIndex         = newToolInitialParentIdex + offset;
                MeatCleaver.indexOfMenuItemView            = newToolInitialParentIdex + 26 + offset;
                InseminationSyringe.InitialParentTileIndex = newToolInitialParentIdex + 14;
                InseminationSyringe.IndexOfMenuItemView    = newToolInitialParentIdex + 14;
                FeedingBasket.InitialParentTileIndex       = newToolInitialParentIdex + 15;
                FeedingBasket.IndexOfMenuItemView          = newToolInitialParentIdex + 15;
                LoadMail();
            }
            else if (asset.AssetNameEquals("Maps\\MenuTiles"))
            {
                Texture2D menuTilesSpriteSheet = asset.AsImage().Data;
                int       originalWidth        = menuTilesSpriteSheet.Width;
                int       originalHeight       = menuTilesSpriteSheet.Height;
                Color[]   data1 = new Color[originalWidth * originalHeight];
                menuTilesSpriteSheet.GetData <Color>(data1);
                Texture2D customMenuTilesSpriteSheet = _menuTilesSpriteSheet;
                int       customMenuTilesWidth       = customMenuTilesSpriteSheet.Width;
                int       customMenuTileslHeight     = customMenuTilesSpriteSheet.Height;
                Color[]   data2 = new Color[customMenuTilesWidth * customMenuTileslHeight];
                customMenuTilesSpriteSheet.GetData <Color>(data2);
                Texture2D newSpriteSheet = new Texture2D(Game1.game1.GraphicsDevice, originalWidth, originalHeight + customMenuTileslHeight, false, SurfaceFormat.Color);

                var data3 = new Color[data1.Length + data2.Length];
                data1.CopyTo(data3, 0);
                data2.CopyTo(data3, data1.Length);

                newSpriteSheet.SetData(data3);

                asset.ReplaceWith(newSpriteSheet);

                var newMenuTitlesInitialParentIdex = (originalWidth / 64) * (originalHeight / 64);

                InseminationSyringe.AttachmentMenuTile = newMenuTitlesInitialParentIdex;
                FeedingBasket.AttachmentMenuTile       = newMenuTitlesInitialParentIdex + 1;
            }
        }
Esempio n. 26
0
 public void SetColor(Color[] iColors)
 {
     _colors = new Color[iColors.Length];
       iColors.CopyTo(_colors, 0);
       Apply();
 }
    static void SeperateRGBAandlphaChannel(string _texPath)
    {
        string assetRelativePath = GetRelativeAssetPath(_texPath);
        SetTextureReadableEx(assetRelativePath);    //set readable flag and set textureFormat TrueColor
        Texture2D sourcetex = AssetDatabase.LoadAssetAtPath(assetRelativePath, typeof(Texture2D)) as Texture2D; //not just the textures under Resources file
        if (!sourcetex)
        {
            Debug.LogError("Load Texture Failed : " + assetRelativePath);
            return;
        }

        TextureImporter ti = null;
        try
        {
            ti = (TextureImporter)TextureImporter.GetAtPath(assetRelativePath);
        }
        catch
        {
            Debug.LogError("Load Texture failed: " + assetRelativePath);
            return;
        }

        if (ti == null)
        {
            return;
        }

        bool bGenerateMipMap = ti.mipmapEnabled;    //same with the texture import setting

        Texture2D rgbTex = new Texture2D(sourcetex.width, sourcetex.height, TextureFormat.RGB24, bGenerateMipMap);
        rgbTex.SetPixels(sourcetex.GetPixels());

        Texture2D mipMapTex = new Texture2D(sourcetex.width, sourcetex.height, TextureFormat.RGBA32, true);  //Alpha Channel needed here
        mipMapTex.SetPixels(sourcetex.GetPixels());
        mipMapTex.Apply();

        Color[] colors2rdLevel = mipMapTex.GetPixels(0);   //Second level of Mipmap
        Color[] colorsAlpha = new Color[colors2rdLevel.Length];

        //if (colors2rdLevel.Length != (mipMapTex.width + 1) / 2 * (mipMapTex.height + 1) / 2)
        //{
        if (colors2rdLevel.Length != mipMapTex.width * mipMapTex.height)
        {
            Debug.LogError("Size Error.");
            return;
        }

        bool bAlphaExist = false;

        for (int i = 0; i < colors2rdLevel.Length; ++i)
        {
            colorsAlpha[i].r = colors2rdLevel[i].a;
            colorsAlpha[i].g = colors2rdLevel[i].a;
            colorsAlpha[i].b = colors2rdLevel[i].a;

            if (!Mathf.Approximately(colors2rdLevel[i].a, 1.0f))
            {
                bAlphaExist = true;
            }
        }

        Texture2D alphaTex = null;

        if (bAlphaExist)
        {
            alphaTex = new Texture2D(sourcetex.width, sourcetex.height * 2, TextureFormat.RGB24, bGenerateMipMap);
        }
        else
        {
            alphaTex = new Texture2D(defaultWhiteTex.width, defaultWhiteTex.height, TextureFormat.RGB24, false);
        }

        Color[] colorsRGBA = new Color[colors2rdLevel.Length + colorsAlpha.Length];
        colors2rdLevel.CopyTo(colorsRGBA, 0);
        colorsAlpha.CopyTo(colorsRGBA, colors2rdLevel.Length);

        alphaTex.SetPixels(colorsRGBA);

        rgbTex.Apply();
        alphaTex.Apply();

        byte[] bytes = rgbTex.EncodeToPNG();
        File.WriteAllBytes(assetRelativePath, bytes);
        byte[] alphabytes = alphaTex.EncodeToPNG();
        string alphaTexRelativePath = GetAlphaTexPath(_texPath);
        File.WriteAllBytes(alphaTexRelativePath, alphabytes);

        ReImportAsset(assetRelativePath, rgbTex.width, rgbTex.height);
        ReImportAsset(alphaTexRelativePath, alphaTex.width, alphaTex.height);
        Debug.Log("Succeed Departing : " + assetRelativePath);
    }
Esempio n. 28
0
        public Bitmap GetFrameBuffer( )
        {
            ushort widthInWords;
            ushort heightInPixels;
            uint[ ] buf;

            Bitmap bmp = null;


            PixelFormat pixelFormat = PixelFormat.DontCare;

            if( GetFrameBuffer( out widthInWords, out heightInPixels, out buf ) )
            {
                CLRCapabilities.LCDCapabilities lcdCaps = Capabilities.LCD;

                int pixelsPerWord = 32 / ( int )lcdCaps.BitsPerPixel;

                Debug.Assert( heightInPixels == lcdCaps.Height );
                Debug.Assert( widthInWords == ( lcdCaps.Width + pixelsPerWord - 1 ) / pixelsPerWord );

                Color[ ] colors = null;

                switch( lcdCaps.BitsPerPixel )
                {
                case 1:
                    pixelFormat = PixelFormat.Format1bppIndexed;
                    colors = new Color[ ] { Color.White, Color.Black };
                    Adjust1bppOrientation( buf );
                    break;
                case 4:
                case 8:
                    //Not tested
                    int cColors = 1 << ( int )lcdCaps.BitsPerPixel;

                    pixelFormat = ( lcdCaps.BitsPerPixel == 4 ) ? PixelFormat.Format4bppIndexed : PixelFormat.Format8bppIndexed;

                    colors = new Color[ cColors ];

                    for( int i = 0; i < cColors; i++ )
                    {
                        int intensity = 256 / cColors * i;
                        colors[ i ] = Color.FromArgb( intensity, intensity, intensity );
                    }

                    break;
                case 16:
                    pixelFormat = PixelFormat.Format16bppRgb565;
                    break;
                default:
                    Debug.Assert( false );
                    return null;
                }

                BitmapData bitmapData = null;

                try
                {
                    bmp = new Bitmap( ( int )lcdCaps.Width, ( int )lcdCaps.Height, pixelFormat );
                    Rectangle rect = new Rectangle( 0, 0, ( int )lcdCaps.Width, ( int )lcdCaps.Height );

                    if( colors != null )
                    {
                        ColorPalette palette = bmp.Palette;
                        colors.CopyTo( palette.Entries, 0 );
                        bmp.Palette = palette;
                    }

                    bitmapData = bmp.LockBits( rect, ImageLockMode.WriteOnly, pixelFormat );
                    IntPtr data = bitmapData.Scan0;

                    unsafe
                    {
                        fixed( uint* pbuf = buf )
                        {
                            uint* src = ( uint* )pbuf;
                            uint* dst = ( uint* )data.ToPointer( );

                            for( int i = buf.Length; i > 0; i-- )
                            {
                                *dst = *src;
                                dst++;
                                src++;
                            }

                        }
                    }
                }

                finally
                {
                    if( bitmapData != null )
                    {
                        bmp.UnlockBits( bitmapData );
                    }
                }
            }

            return bmp;
        }