81 lines
2.0 KiB
C#
81 lines
2.0 KiB
C#
using CHN;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using WI;
|
|
using TMPro;
|
|
using System;
|
|
using UnityEngine.EventSystems;
|
|
|
|
namespace CHN
|
|
{
|
|
public class UI_MappingButton : UIBase, IPointerEnterHandler, IPointerExitHandler
|
|
{
|
|
public Button button;
|
|
public RawImage Line;
|
|
public TextMeshProUGUI Value;
|
|
|
|
public Action<UI_MappingButton> onClickButton;
|
|
public float duration;
|
|
public bool isClick;
|
|
|
|
public void SetMappingButton()
|
|
{
|
|
button = GetComponentInChildren<Button>();
|
|
button.onClick.AddListener(OnClickMappingButton);
|
|
}
|
|
|
|
void OnClickMappingButton()
|
|
{
|
|
onClickButton?.Invoke(this);
|
|
}
|
|
|
|
public void ExpandLine()
|
|
{
|
|
StopAllCoroutines();
|
|
StartCoroutine(LineAnimation(0.9f));
|
|
}
|
|
public void ReductionLine()
|
|
{
|
|
StopAllCoroutines();
|
|
StartCoroutine(LineAnimation(0f));
|
|
}
|
|
private IEnumerator LineAnimation(float nextValue)
|
|
{
|
|
var originalScale = Line.transform.localScale;
|
|
|
|
var targetScale = new Vector3(nextValue, 1f, 1f);
|
|
|
|
float elapsedTime = 0f;
|
|
|
|
while (elapsedTime < duration)
|
|
{
|
|
var progress = elapsedTime / duration;
|
|
Line.transform.localScale = Vector3.Lerp(originalScale, targetScale, progress);
|
|
elapsedTime += Time.deltaTime;
|
|
yield return null;
|
|
}
|
|
Line.transform.localScale = targetScale;
|
|
}
|
|
|
|
public void OnPointerEnter(PointerEventData eventData)
|
|
{
|
|
if (isClick)
|
|
return;
|
|
|
|
StopAllCoroutines();
|
|
StartCoroutine(LineAnimation(0.3f));
|
|
}
|
|
|
|
public void OnPointerExit(PointerEventData eventData)
|
|
{
|
|
if (isClick)
|
|
return;
|
|
|
|
StopAllCoroutines();
|
|
StartCoroutine(LineAnimation(0f));
|
|
}
|
|
}
|
|
}
|