ColorPresetItem.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. [RequireComponent(typeof(UITexture))]
  5. [RequireComponent(typeof(UIButton))]
  6. public class ColorPresetItem : MonoBehaviour
  7. {
  8. public int slotNo
  9. {
  10. get
  11. {
  12. return this.slotNo_;
  13. }
  14. set
  15. {
  16. if (this.slotNo_ != value)
  17. {
  18. this.slotNo_ = value;
  19. this.UpdateData();
  20. }
  21. }
  22. }
  23. private void Start()
  24. {
  25. this.UpdateData();
  26. }
  27. private void Awake()
  28. {
  29. if (this.uiTex == null)
  30. {
  31. this.uiTex = base.GetComponent<UITexture>();
  32. }
  33. this.grayTexArray = UTY.GetPixelArray(this.greyTex);
  34. this.colorChangeTex = new Texture2D(this.greyTex.width, this.greyTex.height, TextureFormat.RGBA32, false, true);
  35. EventDelegate.Add(base.GetComponent<UIButton>().onClick, new EventDelegate.Callback(this.OnButtonClick));
  36. }
  37. public void UpdateData()
  38. {
  39. Dictionary<string, int> editColorPresetData = GameMain.Instance.CMSystem.GetEditColorPresetData(this.slotNo);
  40. if (editColorPresetData == null)
  41. {
  42. this.uiTex.mainTexture = this.emptyTex;
  43. }
  44. else
  45. {
  46. ColorPaletteManager.ColorData colorData = ColorPaletteManager.ColorData.RestoreData(MaidParts.PARTS_COLOR.EYE_L, editColorPresetData);
  47. UTY.ConvertColor(new MaidParts.PartsColor
  48. {
  49. m_nMainHue = colorData.main.hue,
  50. m_nMainChroma = colorData.main.chroma,
  51. m_nMainBrightness = colorData.main.brightness,
  52. m_nMainContrast = colorData.main.contrast,
  53. m_nShadowHue = colorData.shadow.hue,
  54. m_nShadowChroma = colorData.shadow.chroma,
  55. m_nShadowBrightness = colorData.shadow.brightness,
  56. m_nShadowContrast = colorData.shadow.contrast,
  57. m_nShadowRate = colorData.shadowRate
  58. }, this.grayTexArray, ref this.colorChangeTex);
  59. this.uiTex.mainTexture = this.colorChangeTex;
  60. }
  61. this.uiTex.SetDimensions(this.uiTex.mainTexture.width, this.uiTex.mainTexture.height);
  62. }
  63. private void OnButtonClick()
  64. {
  65. int num = -1;
  66. int num2 = -2;
  67. if (UICamera.currentTouchID == num2)
  68. {
  69. GameMain.Instance.CMSystem.RemoveEditColorPresetData(this.slotNo);
  70. this.UpdateData();
  71. }
  72. else if (UICamera.currentTouchID == num)
  73. {
  74. if (this.uiTex.mainTexture == this.emptyTex)
  75. {
  76. if (this.onSaveColorPresetEvent != null)
  77. {
  78. Dictionary<string, int> storeData = this.onSaveColorPresetEvent().GetStoreData();
  79. GameMain.Instance.CMSystem.SetEditColorPresetData(this.slotNo, storeData);
  80. this.UpdateData();
  81. }
  82. }
  83. else if (this.onLoadColorPresetEvent != null)
  84. {
  85. this.onLoadColorPresetEvent(GameMain.Instance.CMSystem.GetEditColorPresetData(this.slotNo));
  86. }
  87. }
  88. }
  89. [SerializeField]
  90. private Texture2D emptyTex;
  91. [SerializeField]
  92. private Texture2D greyTex;
  93. public Func<ColorPaletteManager.ColorData> onSaveColorPresetEvent;
  94. public Action<Dictionary<string, int>> onLoadColorPresetEvent;
  95. private Texture2D colorChangeTex;
  96. private UITexture uiTex;
  97. private int slotNo_;
  98. private byte[] grayTexArray;
  99. }