ThreeKingdomsSlingshot/Assets/Scripts/Runtime/Skills/FxOwnerLift.cs

52 lines
2.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections.Generic;
using UnityEngine;
namespace TKS
{
/// <summary>
/// 표 skill_vfx.csv 의 b_lift 1 인 행(2026-11-11 PD 「조운의 찌르기 이펙트가 몬스터보다 레이어 순서가 하단에 있어서 어색해 · 공격 이펙트는 몬스터보다 상단에 배치」):
/// 이펙트는 다른 유닛 위(n_order −2 이하 = 그리는 순서 10 이하 · 유닛 그림 0 · HP 바·이름 2~6 보다 위)에 그리고,
/// 이 이펙트가 살아 있는 동안 쓴 유닛의 그림만 그 위(<see cref="OwnerOrder"/>)로 올린다 — 공격 이펙트가 적을 덮되 쓴 캐릭터는 가리지 않게.
/// 이펙트가 지워지면(남은 입자까지 사라진 뒤) 원래 순서로 되돌린다 · 같은 유닛에 여러 개가 걸리면 마지막 것이 지워질 때 되돌림.
/// </summary>
public class FxOwnerLift : MonoBehaviour
{
/// <summary>올린 유닛 그림의 그리는 순서(유닛 위 이펙트 SortingBase 바로 아래).</summary>
public const int OwnerOrder = SkillVfx.SortingBase - 1;
static readonly Dictionary<int, int> counts = new Dictionary<int, int>();
static readonly Dictionary<int, int> origin = new Dictionary<int, int>();
SpriteRenderer target;
int id;
public static void Attach(GameObject fx, SpriteRenderer owner)
{
if (fx == null || owner == null) return;
var l = fx.AddComponent<FxOwnerLift>();
l.target = owner;
l.id = owner.GetInstanceID();
int n;
counts.TryGetValue(l.id, out n);
if (n == 0) origin[l.id] = owner.sortingOrder;
counts[l.id] = n + 1;
owner.sortingOrder = OwnerOrder;
}
void OnDestroy()
{
int n;
if (!counts.TryGetValue(id, out n)) return;
if (n > 1)
{
counts[id] = n - 1;
return;
}
counts.Remove(id);
int o;
if (origin.TryGetValue(id, out o) && target != null) target.sortingOrder = o;
origin.Remove(id);
}
}
}