Advertisement
TwinFrame

ColorChanger

Jan 22nd, 2022
789
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.U2D;
  5.  
  6. public class ColorChanger : MonoBehaviour
  7. {
  8.     [SerializeField] private List<ColorPalette> _palettes;
  9.     [Space]
  10.     [SerializeField] private Material _material1;
  11.     [SerializeField] private Material _material2;
  12.     [SerializeField] private Material _material3;
  13.     [Space]
  14.     [SerializeField] private SpriteShapeRenderer[] _audioShapes;
  15.     [SerializeField] private SpriteShapeRenderer[] _audioMaskShapes;
  16.     [Space]
  17.     [SerializeField] private Material _mainBarMaterial;
  18.     [Space]
  19.     [SerializeField] private Material[] _fontMaterials;
  20.     [Space]
  21.     [SerializeField] private Camera _mainCamera;
  22.     [SerializeField] private Camera _previewCamera;
  23.  
  24.     private int _currentNumPalette = 0;
  25.  
  26.     public int CurrentNumPalette => _currentNumPalette;
  27.  
  28.     public List<ColorPalette> Palettes => _palettes;
  29.  
  30.     private void Awake()
  31.     {
  32.         ChangeGameColor();
  33.     }
  34.  
  35.     public void ChangePalette(int numPalette)
  36.     {
  37.         _currentNumPalette = numPalette;
  38.  
  39.         ChangeGameColor();
  40.     }
  41.  
  42.     public void ChangeColorInPalette(int numPalette, GameColor gameColor, Color color)
  43.     {
  44.         _palettes[numPalette].ChangeColor(gameColor, color);
  45.  
  46.         ChangeGameColor();
  47.     }
  48.  
  49.     public List<ColorPalette> GetPalettes(out List<string> paletteNames, out int currentNumPalette)
  50.     {
  51.         List<string> names = new List<string>(_palettes.Count);
  52.  
  53.         foreach (var palette in _palettes)
  54.         {
  55.             names.Add(palette.name);
  56.         }
  57.  
  58.         currentNumPalette = _currentNumPalette;
  59.         paletteNames = names;
  60.         return _palettes;
  61.     }
  62.  
  63.     public List<string> GetPaletteNames()
  64.     {
  65.         List<string> names = new List<string>(_palettes.Count);
  66.  
  67.         foreach (var palette in _palettes)
  68.         {
  69.             names.Add(palette.name.Replace("Palette", string.Empty));
  70.         }
  71.  
  72.         return names;
  73.     }
  74.  
  75.     private void ChangeGameColor()
  76.     {
  77.         ChangeMainColor(_palettes[_currentNumPalette].MainColor);
  78.         ChangeSlaveColor(_palettes[_currentNumPalette].SlaveColor);
  79.         ChangeAdd1Color(_palettes[_currentNumPalette].Add1Color);
  80.         ChangeAdd2Color(_palettes[_currentNumPalette].Add2Color);
  81.         ChangeTextColor(_palettes[_currentNumPalette].TextColor);
  82.     }
  83.  
  84.     private void ChangeMainColor(Color color)
  85.     {
  86.         _material1.SetColor("_MainColor", color);
  87.  
  88.         _mainBarMaterial.SetColor("_MainColor", color);
  89.  
  90.         _mainCamera.backgroundColor = color;
  91.         _previewCamera.backgroundColor = color;
  92.     }
  93.  
  94.     private void ChangeSlaveColor(Color color)
  95.     {
  96.         _material3.SetColor("_SecondColor", color);
  97.  
  98.         ChangeAudioMaskShapeColor(color);
  99.     }
  100.  
  101.     private void ChangeAdd1Color(Color color)
  102.     {
  103.         _material1.SetColor("_SecondColor", color);
  104.  
  105.         _material2.SetColor("_SecondColor", color);
  106.     }
  107.  
  108.     private void ChangeAdd2Color(Color color)
  109.     {
  110.         _material2.SetColor("_MainColor", color);
  111.  
  112.         _material3.SetColor("_MainColor", color);
  113.     }
  114.  
  115.     private void ChangeTextColor(Color color)
  116.     {
  117.         foreach (var material in _fontMaterials)
  118.             material.SetColor("_FaceColor", color);
  119.  
  120.         ChangeAudioShapeColor(color);
  121.     }
  122.  
  123.     private void ChangeAudioShapeColor(Color color)
  124.     {
  125.         foreach (var shape in _audioShapes)
  126.             shape.color = color;
  127.     }
  128.  
  129.     private void ChangeAudioMaskShapeColor(Color color)
  130.     {
  131.         foreach (var shape in _audioMaskShapes)
  132.             shape.color = color;
  133.     }
  134. }
  135.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement