private PaletteColor FindClosestColor() { var colors = ColorPaletteManager.GetPaletteColors(); PaletteColor closestColor = null; float closestDistance = 1000; foreach (var color in colors) { if (closestColor == null) { closestColor = color; continue; } float distance = Mathf.Sqrt(Mathf.Pow(color.r - currentRed, 2) + Mathf.Pow(color.g - currentGreen, 2) + Mathf.Pow(color.b - currentBlue, 2)); if (distance <= closestDistance) { closestColor = color; closestDistance = distance; } } return(closestColor); }
public static void SetColor(int x, int y) { if (Singleton == null) { return; } Singleton.closestColor = ColorPaletteManager.GetColorFromPalette(x, y); Singleton.UpdateUI(); }
// ----------------------------- // private datamember // ----------------------------- #region privateMember #endregion privateMember // ----------------------------- // monobehaviour // ----------------------------- #region MonoBehaviour void Awake() { //////////////////////////////////////////////////////////////////// /// SINGLETON ////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// // First we check if there are any other instances conflicting if (Instance != null && Instance != this) { // If that is the case, we destroy other instances Destroy(gameObject); } // Here we save our singleton instance Instance = this; //////////////////////////////////////////////////////////////////// /// SINGLETON ////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// }