using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class CircleDissolveEffect : MonoBehaviour { public Material dissolveMaterial; public Image targetImage; // 使用的UI图片 public float transitionSpeed = 1.0f; private float radius = 0.0f; public bool isTransitioning = false; void Start() { // 计算宽高比并应用到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; } }