This repository has been archived on 2026-01-20. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
SH-INT/Assets/Scripts/UI_Button.cs

67 lines
1.9 KiB
C#
Raw Permalink Normal View History

2025-02-20 10:30:18 +09:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
using UnityEngine.EventSystems;
using TMPro;
namespace SHINT.UI
{
public class UI_Button : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
Image buttonBackground;
Color buttonDeactiveColor;
Color buttonActiveColor;
bool isActive;
public float dotweenAnimationDuration;
public override void AfterAwake()
{
buttonBackground = GetComponent<Image>();
buttonDeactiveColor = new Color(42f / 255f, 48f / 255f, 66f / 255f, 1f);
buttonActiveColor = new Color(255f / 255f, 99f / 255f, 23f / 255f, 1f);
buttonBackground.color = buttonDeactiveColor;
}
public void ButtonColorChange_Active()
{
buttonBackground.color = buttonActiveColor;
isActive = true;
}
public void ButtonColorChange_Deactive()
{
buttonBackground.color = buttonDeactiveColor;
isActive = false;
}
void ActiveBackGround()
{
Color backgroundColor = buttonBackground.color;
backgroundColor = buttonActiveColor;
backgroundColor.a = 0.5f;
buttonBackground.color = backgroundColor;
}
public void DeactiveBackGround()
{
if (isActive)
return;
Color backgroundColor = buttonBackground.color;
backgroundColor = buttonDeactiveColor;
backgroundColor.a = 1f;
buttonBackground.color = backgroundColor;
}
public void OnPointerEnter(PointerEventData eventData)
{
ActiveBackGround();
}
public void OnPointerExit(PointerEventData eventData)
{
DeactiveBackGround();
}
}
}