| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using Spine.Unity; |
| | | using UnityEngine; |
| | | using UnityEngine.UI; |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// 特效穿透阻挡器 |
| | |
| | | { |
| | | [Tooltip("是否在UI层级下自动调整排序顺序")] |
| | | public bool autoAdjustSorting = true; |
| | | |
| | | |
| | | [Tooltip("特效渲染器,如果为空则自动获取")] |
| | | public List<Renderer> effectRenderers = new List<Renderer>(); |
| | | |
| | | |
| | | [Tooltip("自定义排序顺序,仅在不自动调整时有效")] |
| | | public int customSortingOrder = 0; |
| | | |
| | | |
| | | [Tooltip("自定义排序层,为空则使用默认UI层")] |
| | | public string customSortingLayer = "UI"; |
| | | |
| | | |
| | | [Tooltip("特效所属的Canvas,如果为空则查找父级Canvas")] |
| | | public Canvas parentCanvas; |
| | | |
| | | |
| | | [Tooltip("特效在Canvas中的排序偏移量")] |
| | | public int sortingOrderOffset = 1; |
| | | |
| | | |
| | | public int canvasSortingOrder = 0; |
| | | |
| | | public int renderQueue = 3000;//默认值 |
| | | |
| | | |
| | | public Action<string, int> onSortingChanged; |
| | | |
| | | private void Awake() |
| | | { |
| | | transform.GetComponentsInChildren(true, effectRenderers); |
| | |
| | | ApplySortingSettings(customSortingOrder, customSortingLayer); |
| | | } |
| | | } |
| | | |
| | | |
| | | private void OnEnable() |
| | | { |
| | | if (autoAdjustSorting) |
| | |
| | | UpdateSortingOrder(); |
| | | } |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 更新排序顺序,确保特效显示在当前UI界面上方 |
| | | /// </summary> |
| | | public void UpdateSortingOrder() |
| | | { |
| | | if (!autoAdjustSorting) return; |
| | | |
| | | |
| | | // 获取父级Canvas的排序顺序 |
| | | if (parentCanvas != null) |
| | | { |
| | |
| | | // 将特效的排序顺序设置为Canvas排序顺序加上偏移量 |
| | | ApplySortingSettings(canvasSortingOrder + sortingOrderOffset, customSortingLayer); |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 应用排序设置到所有渲染器和粒子系统 |
| | | /// </summary> |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | onSortingChanged?.Invoke(sortingLayer, sortingOrder); |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 手动设置排序顺序 |
| | | /// </summary> |
| | |
| | | { |
| | | customSortingLayer = sortingLayer; |
| | | } |
| | | |
| | | |
| | | autoAdjustSorting = false; |
| | | ApplySortingSettings(customSortingOrder, customSortingLayer); |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 设置父级Canvas |
| | | /// </summary> |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | #if UNITY_EDITOR |
| | | [ContextMenu("Apply")] |
| | | public void Apply() |