using System; using System.Collections; using System.Collections.Generic; using System.Linq; using TMPro; using UnityEngine; using Random = UnityEngine.Random; // WTF, C# is awesome! Fuck Python public class CharecterCreationManager : MonoBehaviour { // Yes, I am using a vector to store RGB values. You can't stop me! public Vector3 SelectedColor; // RGB GameObjects [SerializeField] private TMP_InputField[] RGB_GOs; public SpriteRenderer charecterPreview; private void OnEnable() { SelectedColor = new Vector3(Random.Range(0, 256), Random.Range(0, 256), Random.Range(0, 256)); for (int i = 0; i < 3; i++) { RGB_GOs[i].text = SelectedColor[i].ToString(); } RerenderCharecterPreview(); } public void TextChange(string rawType) { Enum.TryParse(rawType, out RGBType type); // Unity events compatible FilterInputs(type); SelectedColor[(int)type] = Convert.ToByte(RGB_GOs[(int)type].text); RerenderCharecterPreview(); } void RerenderCharecterPreview() { charecterPreview.color = new Color(SelectedColor.x / 255, SelectedColor.y / 255, SelectedColor.z / 255); } // Cry about it public void FilterInputs(RGBType type) => RGB_GOs[(int)type].text = (Convert.ToInt16(RGB_GOs[(int)type].text) < 0) ? Math.Abs(Convert.ToInt16(RGB_GOs[(int)type].text)).ToString() : RGB_GOs[(int)type].text; } public enum RGBType { R, G, B }