ShanxiKnowledgeBase/SXElectricityInformationAcq.../Assets/Scripts/CharacterEquipWindow/CharacterMirrorManager.cs

69 lines
1.7 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using DefaultNamespace.ProcessMode;
using HighlightPlus;
using MotionFramework;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
/// <summary>
/// 镜子管理器
/// </summary>
public class CharacterMirrorManager : MonoBehaviour
{
[SerializeField] private GameObject text;
[SerializeField] private Image uiImage;
[SerializeField] private GameObject window;
private void OnMouseEnter()
{
text.SetActive(true);
this.GetComponent<HighlightEffect>().highlighted = true;
}
private void OnMouseExit()
{
text.SetActive(false);
this.GetComponent<HighlightEffect>().highlighted = false;
}
private void OnMouseDown()
{
if(EventSystem.current.IsPointerOverGameObject())
return;
MotionEngine.GetModule<AnimationProcessManager>().HandleClick(this.gameObject.name);
StartCoroutine(FadeIn(uiImage, 0.5f));
}
private IEnumerator FadeIn(Image image, float duration)
{
image.gameObject.SetActive(true);
// 初始化透明度为0
Color color = image.color;
color.a = 0f;
image.color = color;
float elapsedTime = 0f;
// 渐变透明度
while (elapsedTime < duration)
{
elapsedTime += Time.deltaTime;
color.a = Mathf.Clamp01(elapsedTime / duration);
image.color = color;
yield return null;
}
// 确保透明度设置为1
color.a = 1f;
image.color = color;
image.raycastTarget = true;
window.SetActive(true);
}
}