47 lines
1.2 KiB
C#
47 lines
1.2 KiB
C#
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
|
|||
|
public class CircleDissolveEffect : MonoBehaviour
|
|||
|
{
|
|||
|
public Material dissolveMaterial;
|
|||
|
public Image targetImage; // ʹ<>õ<EFBFBD>UIͼƬ
|
|||
|
public float transitionSpeed = 1.0f;
|
|||
|
private float radius = 0.0f;
|
|||
|
public bool isTransitioning = false;
|
|||
|
|
|||
|
void Start()
|
|||
|
{
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߱Ȳ<DFB1>Ӧ<EFBFBD>õ<EFBFBD>Shader
|
|||
|
float aspectRatio = (float)targetImage.rectTransform.rect.width / targetImage.rectTransform.rect.height;
|
|||
|
dissolveMaterial.SetFloat("_AspectRatio", aspectRatio);
|
|||
|
}
|
|||
|
|
|||
|
void Update()
|
|||
|
{
|
|||
|
if (isTransitioning)
|
|||
|
{
|
|||
|
if (radius < 1f)
|
|||
|
{
|
|||
|
radius += Time.deltaTime * transitionSpeed;
|
|||
|
dissolveMaterial.SetFloat("_Radius", Mathf.Clamp01(radius));
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
if (radius > 0f)
|
|||
|
{
|
|||
|
radius -= Time.deltaTime * transitionSpeed;
|
|||
|
dissolveMaterial.SetFloat("_Radius", Mathf.Clamp01(radius));
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void StartTransition()
|
|||
|
{
|
|||
|
radius = 0.0f;
|
|||
|
isTransitioning = true;
|
|||
|
}
|
|||
|
}
|