GQ_Communicate/GQ_URP/GQ/Assets/script/UI/UI_Twinkle.cs

165 lines
5.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class UI_Twinkle : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
#region UI
private Button button;
private TextMeshProUGUI textMeshProUGUI;
private Image image;
private Dropdown dropdown;
private Text text;
#endregion
public string hexColor;
private Color normalColor;
public Color highlightedColor;
public Sprite highlightedSprite;
private Sprite normalSprite;
public MyEnum myEnum;
public Settype settype = Settype.;
private void Start()
{
//Debug.Log("版本号 1.1.1");
#region UI
button = GetComponent<Button>();
textMeshProUGUI = GetComponent<TextMeshProUGUI>();
image = GetComponent<Image>();
dropdown = GetComponent<Dropdown>();
#endregion
if (ColorUtility.TryParseHtmlString(hexColor, out Color color))
{
highlightedColor = color;
}
#region \
if (button && myEnum == MyEnum.)
{
normalColor = button.colors.normalColor;
}
else if (textMeshProUGUI && myEnum == MyEnum.TextMeshProUGUI)
{
normalColor = textMeshProUGUI.color;
}
else if (image && myEnum == MyEnum.)
{
image.color = new Color(image.color.r, image.color.g, image.color.b, 0.7f);
}
else if (dropdown && myEnum == MyEnum.)
{
normalSprite = dropdown.image.sprite;
}
#endregion
//Debug.Log("版本号 1.1.1");
}
public void OnPointerEnter(PointerEventData eventData)
{
if (myEnum == MyEnum. && settype == Settype. && button.transition == Selectable.Transition.ColorTint)
{
if (button.interactable)
{
ColorBlock colors = button.colors;
colors.highlightedColor = highlightedColor;
button.colors = colors;
}
else
{
ColorBlock colors = button.colors;
colors.disabledColor = highlightedColor;
button.colors = colors;
}
}
else if (myEnum == MyEnum. && settype == Settype. && button.transition == Selectable.Transition.SpriteSwap)
{
if (button.interactable)
{
SpriteState spriteState = button.spriteState;
spriteState.highlightedSprite = highlightedSprite;
button.spriteState = spriteState;
}
else
{
SpriteState spriteState = button.spriteState;
spriteState.disabledSprite = highlightedSprite;
button.spriteState = spriteState;
}
}
else if (myEnum == MyEnum.TextMeshProUGUI && settype == Settype.)
{
textMeshProUGUI.color = highlightedColor;
}
else if (myEnum == MyEnum. && settype == Settype.)
{
image.color = new Color(image.color.r, image.color.g, image.color.b, 1);
}
}
public void OnPointerExit(PointerEventData eventData)
{
if (myEnum == MyEnum. && settype == Settype. && button.transition == Selectable.Transition.ColorTint)
{
if (button.interactable)
{
ColorBlock colors = button.colors;
colors.normalColor = normalColor;
button.colors = colors;
}
else
{
ColorBlock colors = button.colors;
colors.disabledColor = normalColor;
button.colors = colors;
}
}
else if (myEnum == MyEnum. && settype == Settype. && button.transition == Selectable.Transition.SpriteSwap)
{
if (!button.interactable)
{
Image image = button.image;
Sprite sprite = image.sprite;
SpriteState spriteState = button.spriteState;
spriteState.disabledSprite = sprite;
button.spriteState = spriteState;
}
}
else if (myEnum == MyEnum.TextMeshProUGUI && settype == Settype.)
{
textMeshProUGUI.color = normalColor;
}
else if (myEnum == MyEnum. && settype == Settype.)
{
image.color = new Color(image.color.r, image.color.g, image.color.b, 0.7f);
}
}
public enum MyEnum
{
,
TextMeshProUGUI,
,
}
public enum Settype
{
,
,
}
[ContextMenu("Text名字同步")]
public void syncTextName()
{
text = GetComponent<Text>();
if (!text) { Debug.LogError("无Text组件"); return; }
text.text = transform.name+": ";
}
}