123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- [RequireComponent(typeof(UITexture))]
- [RequireComponent(typeof(UIButton))]
- public class ColorPresetItem : MonoBehaviour
- {
- public int slotNo
- {
- get
- {
- return this.slotNo_;
- }
- set
- {
- if (this.slotNo_ != value)
- {
- this.slotNo_ = value;
- this.UpdateData();
- }
- }
- }
- private void Start()
- {
- this.UpdateData();
- }
- private void Awake()
- {
- if (this.uiTex == null)
- {
- this.uiTex = base.GetComponent<UITexture>();
- }
- this.grayTexArray = UTY.GetPixelArray(this.greyTex);
- this.colorChangeTex = new Texture2D(this.greyTex.width, this.greyTex.height, TextureFormat.RGBA32, false, true);
- EventDelegate.Add(base.GetComponent<UIButton>().onClick, new EventDelegate.Callback(this.OnButtonClick));
- }
- public void UpdateData()
- {
- Dictionary<string, int> editColorPresetData = GameMain.Instance.CMSystem.GetEditColorPresetData(this.slotNo);
- if (editColorPresetData == null)
- {
- this.uiTex.mainTexture = this.emptyTex;
- }
- else
- {
- ColorPaletteManager.ColorData colorData = ColorPaletteManager.ColorData.RestoreData(MaidParts.PARTS_COLOR.EYE_L, editColorPresetData);
- UTY.ConvertColor(new MaidParts.PartsColor
- {
- m_nMainHue = colorData.main.hue,
- m_nMainChroma = colorData.main.chroma,
- m_nMainBrightness = colorData.main.brightness,
- m_nMainContrast = colorData.main.contrast,
- m_nShadowHue = colorData.shadow.hue,
- m_nShadowChroma = colorData.shadow.chroma,
- m_nShadowBrightness = colorData.shadow.brightness,
- m_nShadowContrast = colorData.shadow.contrast,
- m_nShadowRate = colorData.shadowRate
- }, this.grayTexArray, ref this.colorChangeTex);
- this.uiTex.mainTexture = this.colorChangeTex;
- }
- this.uiTex.SetDimensions(this.uiTex.mainTexture.width, this.uiTex.mainTexture.height);
- }
- private void OnButtonClick()
- {
- int num = -1;
- int num2 = -2;
- if (UICamera.currentTouchID == num2)
- {
- GameMain.Instance.CMSystem.RemoveEditColorPresetData(this.slotNo);
- this.UpdateData();
- }
- else if (UICamera.currentTouchID == num)
- {
- if (this.uiTex.mainTexture == this.emptyTex)
- {
- if (this.onSaveColorPresetEvent != null)
- {
- Dictionary<string, int> storeData = this.onSaveColorPresetEvent().GetStoreData();
- GameMain.Instance.CMSystem.SetEditColorPresetData(this.slotNo, storeData);
- this.UpdateData();
- }
- }
- else if (this.onLoadColorPresetEvent != null)
- {
- this.onLoadColorPresetEvent(GameMain.Instance.CMSystem.GetEditColorPresetData(this.slotNo));
- }
- }
- }
- [SerializeField]
- private Texture2D emptyTex;
- [SerializeField]
- private Texture2D greyTex;
- public Func<ColorPaletteManager.ColorData> onSaveColorPresetEvent;
- public Action<Dictionary<string, int>> onLoadColorPresetEvent;
- private Texture2D colorChangeTex;
- private UITexture uiTex;
- private int slotNo_;
- private byte[] grayTexArray;
- }
|