@@ -5,6 +5,7 @@ using Ichni.RhythmGame;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Ichni.Editor
|
||||
@@ -71,14 +72,17 @@ namespace Ichni.Editor
|
||||
inputFieldBaseA.text = sliderA.value.ToString();
|
||||
ApplyParameters();
|
||||
}
|
||||
public void SliderChangeWithoutNofication(Color color)
|
||||
public void SliderChangeWithoutNotification(Color color)
|
||||
{
|
||||
// 仅更新UI,不触发事件
|
||||
sliderR.SetValueWithoutNotify(color.r);
|
||||
sliderG.SetValueWithoutNotify(color.g);
|
||||
sliderB.SetValueWithoutNotify(color.b);
|
||||
sliderA.SetValueWithoutNotify(color.a);
|
||||
|
||||
inputFieldBaseR.SetTextWithoutNotify(color.r.ToString());
|
||||
inputFieldBaseG.SetTextWithoutNotify(color.g.ToString());
|
||||
inputFieldBaseB.SetTextWithoutNotify(color.b.ToString());
|
||||
inputFieldBaseA.SetTextWithoutNotify(color.a.ToString());
|
||||
// 不调用ApplyParameters以避免重复更新
|
||||
colorPreview.color = new Color(sliderR.value, sliderG.value, sliderB.value, sliderA.value);
|
||||
}
|
||||
@@ -97,5 +101,36 @@ namespace Ichni.Editor
|
||||
|
||||
return this;
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
if (RectTransformUtility.RectangleContainsScreenPoint(colorPreview.rectTransform, Mouse.current.position.ReadValue())
|
||||
|| RectTransformUtility.RectangleContainsScreenPoint(hsvDrawer?.previewImage.rectTransform, Mouse.current.position.ReadValue()))
|
||||
{
|
||||
if (Mouse.current.leftButton.wasPressedThisFrame)//快速复制粘贴颜色
|
||||
{
|
||||
// 复制颜色到剪贴板
|
||||
GUIUtility.systemCopyBuffer = ColorUtility.ToHtmlStringRGBA(new Color(sliderR.value, sliderG.value, sliderB.value, sliderA.value));
|
||||
LogWindow.Log("Color copied to clipboard: " + GUIUtility.systemCopyBuffer);
|
||||
}
|
||||
else if (Mouse.current.rightButton.wasPressedThisFrame)
|
||||
{
|
||||
if (GUIUtility.systemCopyBuffer != null && GUIUtility.systemCopyBuffer != "")
|
||||
{
|
||||
// 从剪贴板粘贴颜色
|
||||
Color pastedColor;
|
||||
if (ColorUtility.TryParseHtmlString("#" + GUIUtility.systemCopyBuffer, out pastedColor))
|
||||
{
|
||||
SliderChangeWithoutNotification(pastedColor);
|
||||
ApplyParameters();
|
||||
LogWindow.Log("Color pasted from clipboard: " + pastedColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Failed to parse color from clipboard: " + GUIUtility.systemCopyBuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using Ichni.RhythmGame;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.Serialization;
|
||||
using UnityEngine.UI;
|
||||
|
||||
@@ -13,7 +14,7 @@ namespace Ichni.Editor
|
||||
{
|
||||
private string emissionEnabledName, colorParameterName, emissionIntensityName;
|
||||
private bool canDisableEmission;
|
||||
|
||||
|
||||
public Toggle toggleEnableEmission;
|
||||
public TMP_InputField inputFieldEmissionR;
|
||||
public TMP_InputField inputFieldEmissionG;
|
||||
@@ -22,21 +23,21 @@ namespace Ichni.Editor
|
||||
public Slider sliderR;
|
||||
public Slider sliderG;
|
||||
public Slider sliderB;
|
||||
|
||||
|
||||
public Image colorPreview;
|
||||
|
||||
public void Initialize(IBaseElement baseElement, string title,
|
||||
|
||||
public void Initialize(IBaseElement baseElement, string title,
|
||||
string emissionEnabledName, string colorParameterName, string emissionIntensityName)
|
||||
{
|
||||
base.Initialize(baseElement, title, colorParameterName);
|
||||
|
||||
canDisableEmission = emissionEnabledName != "NULL"; //如果对应的EmissionColor强制开启,那么其enabledName为"NULL",不需要显示Toggle
|
||||
|
||||
|
||||
this.emissionEnabledName = emissionEnabledName;
|
||||
this.colorParameterName = colorParameterName;
|
||||
this.emissionIntensityName = emissionIntensityName;
|
||||
|
||||
if(canDisableEmission)
|
||||
|
||||
if (canDisableEmission)
|
||||
{
|
||||
bool enableEmission = (bool)connectedBaseElement.GetType().GetField(emissionEnabledName).GetValue(connectedBaseElement);
|
||||
toggleEnableEmission.isOn = enableEmission;
|
||||
@@ -49,24 +50,24 @@ namespace Ichni.Editor
|
||||
|
||||
Color emissionColor = (Color)connectedBaseElement.GetType().GetField(colorParameterName).GetValue(connectedBaseElement);
|
||||
float emissionIntensity = (float)connectedBaseElement.GetType().GetField(emissionIntensityName).GetValue(connectedBaseElement);
|
||||
|
||||
|
||||
inputFieldEmissionR.text = emissionColor.r.ToString();
|
||||
inputFieldEmissionG.text = emissionColor.g.ToString();
|
||||
inputFieldEmissionB.text = emissionColor.b.ToString();
|
||||
inputFieldEmissionI.text = emissionIntensity.ToString();
|
||||
|
||||
sliderR.value=emissionColor.r;
|
||||
sliderG.value=emissionColor.g;
|
||||
sliderB.value=emissionColor.b;
|
||||
|
||||
sliderR.value = emissionColor.r;
|
||||
sliderG.value = emissionColor.g;
|
||||
sliderB.value = emissionColor.b;
|
||||
sliderR.onValueChanged.AddListener(SliderChange);
|
||||
sliderG.onValueChanged.AddListener(SliderChange);
|
||||
sliderB.onValueChanged.AddListener(SliderChange);
|
||||
|
||||
|
||||
inputFieldEmissionR.onEndEdit.AddListener(_ => ApplyParameters());
|
||||
inputFieldEmissionG.onEndEdit.AddListener(_ => ApplyParameters());
|
||||
inputFieldEmissionB.onEndEdit.AddListener(_ => ApplyParameters());
|
||||
inputFieldEmissionI.onEndEdit.AddListener(_ => ApplyParameters());
|
||||
|
||||
|
||||
colorPreview.color = emissionColor;
|
||||
}
|
||||
|
||||
@@ -111,8 +112,50 @@ namespace Ichni.Editor
|
||||
sliderR.onValueChanged.AddListener(_ => action());
|
||||
sliderG.onValueChanged.AddListener(_ => action());
|
||||
sliderB.onValueChanged.AddListener(_ => action());
|
||||
|
||||
|
||||
return this;
|
||||
}
|
||||
public void SliderChangeWithoutNotification(Color color)
|
||||
{
|
||||
sliderR.SetValueWithoutNotify(color.r);
|
||||
sliderG.SetValueWithoutNotify(color.g);
|
||||
sliderB.SetValueWithoutNotify(color.b);
|
||||
inputFieldEmissionI.SetTextWithoutNotify(color.a.ToString());
|
||||
inputFieldEmissionB.SetTextWithoutNotify(color.b.ToString());
|
||||
inputFieldEmissionG.SetTextWithoutNotify(color.g.ToString());
|
||||
inputFieldEmissionR.SetTextWithoutNotify(color.r.ToString());
|
||||
// 不调用ApplyParameters以避免重复更新
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
if (RectTransformUtility.RectangleContainsScreenPoint(colorPreview.rectTransform, Mouse.current.position.ReadValue())
|
||||
)
|
||||
{
|
||||
if (Mouse.current.leftButton.wasPressedThisFrame)//快速复制粘贴颜色
|
||||
{
|
||||
// 复制颜色到剪贴板
|
||||
GUIUtility.systemCopyBuffer = ColorUtility.ToHtmlStringRGBA(new Color(sliderR.value, sliderG.value, sliderB.value, inputFieldEmissionI.text != "" ? float.Parse(inputFieldEmissionI.text) : 1f));
|
||||
LogWindow.Log("Color copied to clipboard: " + GUIUtility.systemCopyBuffer);
|
||||
}
|
||||
else if (Mouse.current.rightButton.wasPressedThisFrame)
|
||||
{
|
||||
if (GUIUtility.systemCopyBuffer != null && GUIUtility.systemCopyBuffer != "")
|
||||
{
|
||||
// 从剪贴板粘贴颜色
|
||||
Color pastedColor;
|
||||
if (ColorUtility.TryParseHtmlString("#" + GUIUtility.systemCopyBuffer, out pastedColor))
|
||||
{
|
||||
SliderChangeWithoutNotification(pastedColor);
|
||||
ApplyParameters();
|
||||
LogWindow.Log("Color pasted from clipboard: " + pastedColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Failed to parse color from clipboard: " + GUIUtility.systemCopyBuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user