Change Project License to MIT (#700)

* license change

replace unneeded package

* reword this
This commit is contained in:
minenice55
2024-02-16 01:17:16 -05:00
committed by GitHub
parent 172e3850a5
commit dd9a06ad52
153 changed files with 167 additions and 5439 deletions

View File

@ -2,7 +2,6 @@ using UnityEngine;
using UnityEngine.UI;
using TMPro;
using Starpelly;
public class ColorPreview : MonoBehaviour
{
@ -21,18 +20,18 @@ public class ColorPreview : MonoBehaviour
public void ChangeColor(Color c)
{
colorPicker.color = c;
hex.text = c.Color2Hex();
hex.text = Color2Hex(c);
}
public void OnColorChanged(Color c)
{
previewGraphic.color = c;
hex.text = c.Color2Hex();
hex.text = Color2Hex(c);
}
public void SetColorFromHex(string hex)
{
colorPicker.color = Starpelly.Colors.Hex2RGB(hex);
colorPicker.color = Hex2RGB(hex);
}
private void OnDestroy()
@ -45,4 +44,38 @@ public class ColorPreview : MonoBehaviour
{
SetColorFromHex(hex.text);
}
static string Color2Hex(Color color)
{
Color32 col = (Color32)color;
string hex = col.r.ToString("X2") + col.g.ToString("X2") + col.b.ToString("X2");
return hex;
}
/// <summary>
/// Converts a Hexadecimal Color to an RGB Color.
/// </summary>
static Color Hex2RGB(string hex)
{
if (hex is null or "") return Color.black;
try
{
hex = hex.Replace("0x", "");//in case the string is formatted 0xFFFFFF
hex = hex.Replace("#", "");//in case the string is formatted #FFFFFF
byte a = 255;//assume fully visible unless specified in hex
byte r = byte.Parse(hex.Substring(0, 2), System.Globalization.NumberStyles.HexNumber);
byte g = byte.Parse(hex.Substring(2, 2), System.Globalization.NumberStyles.HexNumber);
byte b = byte.Parse(hex.Substring(4, 2), System.Globalization.NumberStyles.HexNumber);
//Only use alpha if the string has enough characters
if (hex.Length >= 8)
{
a = byte.Parse(hex.Substring(6, 2), System.Globalization.NumberStyles.HexNumber);
}
return new Color32(r, g, b, a);
}
catch
{
return Color.black;
}
}
}