feat: 角色展示v1.2
This commit is contained in:
64
CharacterPreview/HideSelfOnLeisure.cs
Normal file
64
CharacterPreview/HideSelfOnLeisure.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace CharacterPreview
|
||||
{
|
||||
public class HideSelfOnLeisure:MonoBehaviour,IPointerEnterHandler,IPointerExitHandler
|
||||
{
|
||||
private Image image;
|
||||
private Color CurrentColor => ModBehaviour.config.data.canEdit ? Color.green : Color.red;
|
||||
private Color HideColor => ModBehaviour.config.data.canEdit
|
||||
? new Color(Color.green.r, Color.green.g, Color.green.b, 0.1f)
|
||||
: new Color(Color.red.r, Color.red.g, Color.red.b, 0.1f);
|
||||
|
||||
public float hideTime = 3f;
|
||||
public float animationTime = 1f;
|
||||
private float timer = 0;
|
||||
private float animationTimer = 0;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
image = GetComponent<Image>();
|
||||
// if (!image)
|
||||
// gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (timer < hideTime)
|
||||
{
|
||||
timer += Time.deltaTime;
|
||||
if (timer >= hideTime)
|
||||
{
|
||||
animationTimer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (animationTimer < animationTime)
|
||||
{
|
||||
animationTimer += Time.deltaTime;
|
||||
// if(animationTimer >= animationTime)
|
||||
// animationTimer=animationTime;
|
||||
var t = animationTimer / animationTime;
|
||||
t = Mathf.Clamp01(t);
|
||||
image.color = Color.Lerp(CurrentColor, HideColor, t);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
if(!image)return;
|
||||
timer = hideTime;
|
||||
animationTimer = animationTime;
|
||||
image.color = CurrentColor;
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
if (!image) return;
|
||||
timer = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user