diff --git a/Runtime/Scripts/Controls/ColorPicker/ColorLabel.cs b/Runtime/Scripts/Controls/ColorPicker/ColorLabel.cs index adbb806..0b92364 100644 --- a/Runtime/Scripts/Controls/ColorPicker/ColorLabel.cs +++ b/Runtime/Scripts/Controls/ColorPicker/ColorLabel.cs @@ -6,82 +6,82 @@ namespace UnityEngine.UI.Extensions.ColorPicker { [RequireComponent(typeof(Text))] -public class ColorLabel : MonoBehaviour -{ - public ColorPickerControl picker; - - public ColorValues type; - - public string prefix = "R: "; - public float minValue = 0; - public float maxValue = 255; - - public int precision = 0; - - private Text label; - - private void Awake() + public class ColorLabel : MonoBehaviour { - label = GetComponent(); + public ColorPickerControl picker; - } + public ColorValues type; - private void OnEnable() - { - if (Application.isPlaying && picker != null) + public string prefix = "R: "; + public float minValue = 0; + public float maxValue = 255; + + public int precision = 0; + + private Text label; + + private void Awake() { - picker.onValueChanged.AddListener(ColorChanged); - picker.onHSVChanged.AddListener(HSVChanged); - } - } + label = GetComponent(); - private void OnDestroy() - { - if (picker != null) - { - picker.onValueChanged.RemoveListener(ColorChanged); - picker.onHSVChanged.RemoveListener(HSVChanged); } - } + + private void OnEnable() + { + if (Application.isPlaying && picker != null) + { + picker.onValueChanged.AddListener(ColorChanged); + picker.onHSVChanged.AddListener(HSVChanged); + } + } + + private void OnDestroy() + { + if (picker != null) + { + picker.onValueChanged.RemoveListener(ColorChanged); + picker.onHSVChanged.RemoveListener(HSVChanged); + } + } #if UNITY_EDITOR - private void OnValidate() - { - label = GetComponent(); - UpdateValue(); - } + private void OnValidate() + { + label = GetComponent(); + UpdateValue(); + } #endif - private void ColorChanged(Color color) - { - UpdateValue(); - } - - private void HSVChanged(float hue, float sateration, float value) - { - UpdateValue(); - } - - private void UpdateValue() - { - if (picker == null) + private void ColorChanged(Color color) { - label.text = prefix + "-"; + UpdateValue(); } - else - { - float value = minValue + (picker.GetValue(type) * (maxValue - minValue)); - label.text = prefix + ConvertToDisplayString(value); + private void HSVChanged(float hue, float sateration, float value) + { + UpdateValue(); + } + + private void UpdateValue() + { + if (picker == null) + { + label.text = prefix + "-"; + } + else + { + float value = minValue + (picker.GetValue(type) * (maxValue - minValue)); + + label.text = prefix + ConvertToDisplayString(value); + } + } + + private string ConvertToDisplayString(float value) + { + if (precision > 0) + return value.ToString("f " + precision); + else + return Mathf.FloorToInt(value).ToString(); } } - - private string ConvertToDisplayString(float value) - { - if (precision > 0) - return value.ToString("f " + precision); - else - return Mathf.FloorToInt(value).ToString(); - } -} } \ No newline at end of file diff --git a/Runtime/Scripts/Controls/ColorPicker/ColorSliderImage.cs b/Runtime/Scripts/Controls/ColorPicker/ColorSliderImage.cs index 11bbc8c..3835bb9 100644 --- a/Runtime/Scripts/Controls/ColorPicker/ColorSliderImage.cs +++ b/Runtime/Scripts/Controls/ColorPicker/ColorSliderImage.cs @@ -59,7 +59,9 @@ namespace UnityEngine.UI.Extensions.ColorPicker private void OnDestroy() { if (image.texture != null) + { DestroyImmediate(image.texture); + } } #if UNITY_EDITOR diff --git a/Runtime/Scripts/Controls/ColorPicker/HexColorField.cs b/Runtime/Scripts/Controls/ColorPicker/HexColorField.cs index ba43ac5..e21df39 100644 --- a/Runtime/Scripts/Controls/ColorPicker/HexColorField.cs +++ b/Runtime/Scripts/Controls/ColorPicker/HexColorField.cs @@ -7,95 +7,95 @@ namespace UnityEngine.UI.Extensions.ColorPicker { [RequireComponent(typeof(InputField))] -public class HexColorField : MonoBehaviour -{ - public ColorPickerControl ColorPicker; - - public bool displayAlpha; - - private InputField hexInputField; - - private const string hexRegex = "^#?(?:[0-9a-fA-F]{3,4}){1,2}$"; - - private void Awake() + public class HexColorField : MonoBehaviour { - hexInputField = GetComponent(); + public ColorPickerControl ColorPicker; - // Add listeners to keep text (and color) up to date - hexInputField.onEndEdit.AddListener(UpdateColor); - ColorPicker.onValueChanged.AddListener(UpdateHex); - } + public bool displayAlpha; - private void OnDestroy() - { - hexInputField.onValueChanged.RemoveListener(UpdateColor); - ColorPicker.onValueChanged.RemoveListener(UpdateHex); - } + private InputField hexInputField; - private void UpdateHex(Color newColor) - { - hexInputField.text = ColorToHex(newColor); - } + private const string hexRegex = "^#?(?:[0-9a-fA-F]{3,4}){1,2}$"; - private void UpdateColor(string newHex) - { - Color32 color; - if (HexToColor(newHex, out color)) - ColorPicker.CurrentColor = color; - else - Debug.Log("hex value is in the wrong format, valid formats are: #RGB, #RGBA, #RRGGBB and #RRGGBBAA (# is optional)"); - } - - private string ColorToHex(Color32 color) - { - if (displayAlpha) - return string.Format("#{0:X2}{1:X2}{2:X2}{3:X2}", color.r, color.g, color.b, color.a); - else - return string.Format("#{0:X2}{1:X2}{2:X2}", color.r, color.g, color.b); - } - - public static bool HexToColor(string hex, out Color32 color) - { - // Check if this is a valid hex string (# is optional) - if (System.Text.RegularExpressions.Regex.IsMatch(hex, hexRegex)) + private void Awake() { - int startIndex = hex.StartsWith("#") ? 1 : 0; + hexInputField = GetComponent(); - if (hex.Length == startIndex + 8) //#RRGGBBAA - { - color = new Color32(byte.Parse(hex.Substring(startIndex, 2), NumberStyles.AllowHexSpecifier), - byte.Parse(hex.Substring(startIndex + 2, 2), NumberStyles.AllowHexSpecifier), - byte.Parse(hex.Substring(startIndex + 4, 2), NumberStyles.AllowHexSpecifier), - byte.Parse(hex.Substring(startIndex + 6, 2), NumberStyles.AllowHexSpecifier)); - } - else if (hex.Length == startIndex + 6) //#RRGGBB - { - color = new Color32(byte.Parse(hex.Substring(startIndex, 2), NumberStyles.AllowHexSpecifier), - byte.Parse(hex.Substring(startIndex + 2, 2), NumberStyles.AllowHexSpecifier), - byte.Parse(hex.Substring(startIndex + 4, 2), NumberStyles.AllowHexSpecifier), - 255); - } - else if (hex.Length == startIndex + 4) //#RGBA - { - color = new Color32(byte.Parse("" + hex[startIndex] + hex[startIndex], NumberStyles.AllowHexSpecifier), - byte.Parse("" + hex[startIndex + 1] + hex[startIndex + 1], NumberStyles.AllowHexSpecifier), - byte.Parse("" + hex[startIndex + 2] + hex[startIndex + 2], NumberStyles.AllowHexSpecifier), - byte.Parse("" + hex[startIndex + 3] + hex[startIndex + 3], NumberStyles.AllowHexSpecifier)); - } - else //#RGB - { - color = new Color32(byte.Parse("" + hex[startIndex] + hex[startIndex], NumberStyles.AllowHexSpecifier), - byte.Parse("" + hex[startIndex + 1] + hex[startIndex + 1], NumberStyles.AllowHexSpecifier), - byte.Parse("" + hex[startIndex + 2] + hex[startIndex + 2], NumberStyles.AllowHexSpecifier), - 255); - } - return true; + // Add listeners to keep text (and color) up to date + hexInputField.onEndEdit.AddListener(UpdateColor); + ColorPicker.onValueChanged.AddListener(UpdateHex); } - else + + private void OnDestroy() { - color = new Color32(); - return false; + hexInputField.onValueChanged.RemoveListener(UpdateColor); + ColorPicker.onValueChanged.RemoveListener(UpdateHex); + } + + private void UpdateHex(Color newColor) + { + hexInputField.text = ColorToHex(newColor); + } + + private void UpdateColor(string newHex) + { + Color32 color; + if (HexToColor(newHex, out color)) + ColorPicker.CurrentColor = color; + else + Debug.Log("hex value is in the wrong format, valid formats are: #RGB, #RGBA, #RRGGBB and #RRGGBBAA (# is optional)"); + } + + private string ColorToHex(Color32 color) + { + if (displayAlpha) + return string.Format("#{0:X2}{1:X2}{2:X2}{3:X2}", color.r, color.g, color.b, color.a); + else + return string.Format("#{0:X2}{1:X2}{2:X2}", color.r, color.g, color.b); + } + + public static bool HexToColor(string hex, out Color32 color) + { + // Check if this is a valid hex string (# is optional) + if (System.Text.RegularExpressions.Regex.IsMatch(hex, hexRegex)) + { + int startIndex = hex.StartsWith("#") ? 1 : 0; + + if (hex.Length == startIndex + 8) //#RRGGBBAA + { + color = new Color32(byte.Parse(hex.Substring(startIndex, 2), NumberStyles.AllowHexSpecifier), + byte.Parse(hex.Substring(startIndex + 2, 2), NumberStyles.AllowHexSpecifier), + byte.Parse(hex.Substring(startIndex + 4, 2), NumberStyles.AllowHexSpecifier), + byte.Parse(hex.Substring(startIndex + 6, 2), NumberStyles.AllowHexSpecifier)); + } + else if (hex.Length == startIndex + 6) //#RRGGBB + { + color = new Color32(byte.Parse(hex.Substring(startIndex, 2), NumberStyles.AllowHexSpecifier), + byte.Parse(hex.Substring(startIndex + 2, 2), NumberStyles.AllowHexSpecifier), + byte.Parse(hex.Substring(startIndex + 4, 2), NumberStyles.AllowHexSpecifier), + 255); + } + else if (hex.Length == startIndex + 4) //#RGBA + { + color = new Color32(byte.Parse("" + hex[startIndex] + hex[startIndex], NumberStyles.AllowHexSpecifier), + byte.Parse("" + hex[startIndex + 1] + hex[startIndex + 1], NumberStyles.AllowHexSpecifier), + byte.Parse("" + hex[startIndex + 2] + hex[startIndex + 2], NumberStyles.AllowHexSpecifier), + byte.Parse("" + hex[startIndex + 3] + hex[startIndex + 3], NumberStyles.AllowHexSpecifier)); + } + else //#RGB + { + color = new Color32(byte.Parse("" + hex[startIndex] + hex[startIndex], NumberStyles.AllowHexSpecifier), + byte.Parse("" + hex[startIndex + 1] + hex[startIndex + 1], NumberStyles.AllowHexSpecifier), + byte.Parse("" + hex[startIndex + 2] + hex[startIndex + 2], NumberStyles.AllowHexSpecifier), + 255); + } + return true; + } + else + { + color = new Color32(); + return false; + } } } -} } \ No newline at end of file diff --git a/Runtime/Scripts/Controls/ColorPicker/SVBoxSlider.cs b/Runtime/Scripts/Controls/ColorPicker/SVBoxSlider.cs index 3c26ac8..ced2a91 100644 --- a/Runtime/Scripts/Controls/ColorPicker/SVBoxSlider.cs +++ b/Runtime/Scripts/Controls/ColorPicker/SVBoxSlider.cs @@ -52,7 +52,9 @@ namespace UnityEngine.UI.Extensions.ColorPicker private void OnDestroy() { if (image.texture != null) + { DestroyImmediate(image.texture); + } } #if UNITY_EDITOR diff --git a/Runtime/Scripts/Effects/ShineEffector.cs b/Runtime/Scripts/Effects/ShineEffector.cs index 11a4b3e..bcb7278 100644 --- a/Runtime/Scripts/Effects/ShineEffector.cs +++ b/Runtime/Scripts/Effects/ShineEffector.cs @@ -96,10 +96,8 @@ namespace UnityEngine.UI.Extensions { effectRoot.SetActive(true); } - { - - } } + void OnDestroy() { if (!Application.isPlaying) diff --git a/Runtime/Scripts/Effects/UIParticleSystem.cs b/Runtime/Scripts/Effects/UIParticleSystem.cs index 3a7ddbf..6c1f468 100644 --- a/Runtime/Scripts/Effects/UIParticleSystem.cs +++ b/Runtime/Scripts/Effects/UIParticleSystem.cs @@ -388,6 +388,7 @@ namespace UnityEngine.UI.Extensions { currentMaterial = null; currentTexture = null; + base.OnDestroy(); } public void StartParticleEmission()