using UnityEngine;
using UnityEngine.UI;
///
/// 特效穿透阻挡器
/// 将此脚本挂在特效游戏对象上,可以防止特效穿透UI界面
///
public class EffectPenetrationBlocker : MonoBehaviour
{
[Tooltip("是否在UI层级下自动调整排序顺序")]
public bool autoAdjustSorting = true;
[Tooltip("特效渲染器,如果为空则自动获取")]
public Renderer[] effectRenderers;
[Tooltip("特效粒子系统,如果为空则自动获取")]
public ParticleSystem[] particleSystems;
[Tooltip("自定义排序顺序,仅在不自动调整时有效")]
public int customSortingOrder = 0;
[Tooltip("自定义排序层,为空则使用默认UI层")]
public string customSortingLayer = "UI";
[Tooltip("特效所属的Canvas,如果为空则查找父级Canvas")]
public Canvas parentCanvas;
[Tooltip("特效在Canvas中的排序偏移量")]
public int _sortingOrderOffset = 0;
public int canvasSortingOrder = 0;
private void Awake()
{
// 如果没有指定渲染器,则自动获取
if (effectRenderers == null || effectRenderers.Length == 0)
{
effectRenderers = GetComponentsInChildren(true);
}
// 如果没有指定粒子系统,则自动获取
if (particleSystems == null || particleSystems.Length == 0)
{
particleSystems = GetComponentsInChildren(true);
}
// 查找父级Canvas
if (parentCanvas == null)
{
parentCanvas = GetComponentInParent