Ejemplo n.º 1
0
        void UpdateSpriteTexture(CSPalette palette, SpriteRenderer r)
        {
            if (r.sprite == null || r.sprite.texture == null)
            {
                return;
            }
            Sprite    sprite     = r.sprite;
            Texture2D newTexture = palette.GetNearestTexture(sprite.texture, colorMatch, threshold, colorOperations, enableColorAdjustments, colorAdjustments);
            Sprite    newSPrite  = Sprite.Create(newTexture, sprite.rect, new Vector2(sprite.pivot.x / sprite.rect.width, sprite.pivot.y / sprite.rect.height), sprite.pixelsPerUnit);

            newSPrite.name = sprite.name + CS_NAME_SUFFIX;
            r.sprite       = newSPrite;
        }
Ejemplo n.º 2
0
        public void Refresh()
        {
            RestoreMaterialsBackup();
            MakeMaterialsBackup();

            Renderer renderer = GetComponent <Renderer>();

            if (renderer == null)
            {
                return;
            }
            Material[] mats = renderer.sharedMaterials;
            if (mats == null || materialIndex >= mats.Length)
            {
                return;
            }
            Material mat = Instantiate(mats[materialIndex]);

            mat.name = mats[materialIndex].name + CS_NAME_SUFFIX;

            CSPalette palette = (applyPalette && this.palette != null) ? this.palette : CSPalette.CreateEmptyPalette();

            switch (mode)
            {
            case RecolorMode.MainColorOnly:
                mat.color = palette.GetNearestColor(mat.color, colorMatch, threshold, colorOperations, enableColorAdjustments, colorAdjustments);
                break;

            case RecolorMode.Texture:
                if (isSprite)
                {
                    SpriteRenderer spr = (SpriteRenderer)renderer;
                    UpdateSpriteTexture(palette, spr);
                    return;
                }
                else if (mat.mainTexture != null)
                {
                    mat.mainTexture = palette.GetNearestTexture(mat.mainTexture, colorMatch, threshold, colorOperations, enableColorAdjustments, colorAdjustments);
                }
                break;

            case RecolorMode.MainColorAndTexture:
                mat.color = palette.GetNearestColor(mat.color, colorMatch, threshold, colorOperations, enableColorAdjustments, colorAdjustments);
                if (isSprite)
                {
                    SpriteRenderer spr = (SpriteRenderer)renderer;
                    UpdateSpriteTexture(palette, spr);
                }
                else if (mat.mainTexture != null)
                {
                    mat.mainTexture = palette.GetNearestTexture(mat.mainTexture, colorMatch, threshold, colorOperations, enableColorAdjustments, colorAdjustments);
                }
                break;

            case RecolorMode.VertexColors:
                if (isMeshFilter || isSkinnedMesh)
                {
                    UpdateMeshColors(palette);
                }
                break;
            }

            mats[materialIndex]      = mat;
            renderer.sharedMaterials = mats;
        }