UiStyle.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. namespace SoftKitty.InventoryEngine
  6. {
  7. public class UiStyle : MonoBehaviour
  8. {
  9. #region Variables
  10. [HideInInspector]
  11. public bool ApplyStyle = false;
  12. public GraphicsSet[] References;
  13. public RectSetting[] Rects;
  14. #endregion
  15. #region Internal Methods
  16. public void UpdatePrefab()
  17. {
  18. #if UNITY_EDITOR
  19. UnityEditor.EditorUtility.SetDirty(this);
  20. #endif
  21. }
  22. public void SetColor(int _index, Color _color)
  23. {
  24. //if (Application.isPlaying) return;
  25. References[_index].color = _color;
  26. foreach (MaskableGraphic obj in References[_index].graphics) {
  27. obj.color = new Color(_color.r, _color.g, _color.b,obj.color.a);
  28. }
  29. }
  30. public void SetVisible(int _index,bool _visible)
  31. {
  32. //if (Application.isPlaying) return;
  33. if (References[_index].visibleAdjustable)
  34. {
  35. References[_index].visible = _visible;
  36. foreach (MaskableGraphic obj in References[_index].graphics)
  37. {
  38. obj.gameObject.SetActive(_visible);
  39. }
  40. }
  41. }
  42. public void SetWidth(int _index, float _value)
  43. {
  44. if (_index >= Rects.Length) return;
  45. Rects[_index].widthLerp = _value;
  46. foreach (RectSet obj in Rects[_index].set)
  47. {
  48. if (Rects[_index].widthAdjustable) obj.rect.sizeDelta = new Vector2(Mathf.Lerp(obj.widthMinMax.x, obj.widthMinMax.y, Rects[_index].widthLerp), obj.rect.sizeDelta.y);
  49. }
  50. }
  51. public void SetHeight(int _index, float _value)
  52. {
  53. if (_index>=Rects.Length) return;
  54. Rects[_index].heightLerp = _value;
  55. foreach (RectSet obj in Rects[_index].set)
  56. {
  57. if (Rects[_index].heightAdjustable) obj.rect.sizeDelta = new Vector2(obj.rect.sizeDelta.x,Mathf.Lerp(obj.heightMinMax.x, obj.heightMinMax.y, Rects[_index].heightLerp));
  58. }
  59. }
  60. #endregion
  61. }
  62. }