- 치유/보호막 스킬을 즉발 자가시전에서 투사체형 아군 1인 타겟팅으로 전환 - TargetType.SingleAlly 추가, targetOverride 매개변수로 외부 타겟 주입 지원 - PlayerSkillInput: 카메라 레이캐스트 기반 아군 탐지, 서버 검증, RPC 타겟 ID 전달 - AllyTargetIndicator: 호버 아군 위에 디스크 인디케이터 표시, 사거리/초과 색상 변경 - SpawnEffect: 타겟 방향 회전 보정 - 투사체 스폰 이펙트 에셋 생성 (치유/보호막 각각) - 인디케이터 프리팹 + URP/Unlit 머티리얼 생성 - Player 프리팹에 AllyTargetIndicator 컴포넌트 추가 및 설정 - Input.mousePosition → Mouse.current.position.ReadValue() 수정 (Input System 호환)
113 lines
4.5 KiB
C#
113 lines
4.5 KiB
C#
using UnityEngine;
|
|
using Unity.Netcode;
|
|
|
|
using Colosseum.Enemy;
|
|
|
|
namespace Colosseum.Skills.Effects
|
|
{
|
|
/// <summary>
|
|
/// 프리팹 스폰 효과 (투사체, 파티클 등)
|
|
/// </summary>
|
|
[CreateAssetMenu(fileName = "SpawnEffect", menuName = "Colosseum/Skills/Effects/Spawn")]
|
|
public class SpawnEffect : SkillEffect
|
|
{
|
|
[Header("Spawn Settings")]
|
|
[SerializeField] private GameObject prefab;
|
|
[SerializeField] private SpawnLocation spawnLocation = SpawnLocation.Caster;
|
|
[SerializeField] private Vector3 spawnOffset = Vector3.zero;
|
|
[SerializeField] private bool parentToCaster = false;
|
|
[Min(0f)] [SerializeField] private float autoDestroyTime = 3f;
|
|
[Tooltip("전투 컨텍스트의 현재 타겟을 스폰 방향 계산에 사용할지 여부")]
|
|
[SerializeField] private bool useCombatContextTarget = false;
|
|
|
|
[Header("Hit Settings")]
|
|
[Tooltip("투사체가 대상에 명중했을 때 적용할 효과. 미설정 시 명중 효과 없음.")]
|
|
[SerializeField] private SkillEffect hitEffect;
|
|
|
|
protected override void ApplyEffect(GameObject caster, GameObject target)
|
|
{
|
|
if (prefab == null || caster == null) return;
|
|
|
|
GameObject resolvedTarget = ResolveTarget(caster, target);
|
|
Vector3 spawnPos = GetSpawnPosition(caster, resolvedTarget) + spawnOffset;
|
|
Quaternion spawnRot = GetSpawnRotation(caster, resolvedTarget);
|
|
|
|
var networkObject = prefab.GetComponent<NetworkObject>();
|
|
if (networkObject != null)
|
|
{
|
|
// 네트워크 오브젝트: 서버에서 스폰 후 전파
|
|
// (OnEffect 가드에 의해 이미 서버에서만 호출됨)
|
|
GameObject instance = Object.Instantiate(prefab, spawnPos, spawnRot);
|
|
var spawnedNet = instance.GetComponent<NetworkObject>();
|
|
spawnedNet.Spawn(destroyWithScene: true);
|
|
|
|
var projectile = instance.GetComponent<SkillProjectile>();
|
|
if (projectile != null)
|
|
projectile.Initialize(caster, hitEffect);
|
|
}
|
|
else
|
|
{
|
|
// 로컬 오브젝트 (파티클 등): 기존 방식 유지
|
|
Transform parent = parentToCaster ? caster.transform : null;
|
|
GameObject instance = Object.Instantiate(prefab, spawnPos, spawnRot, parent);
|
|
|
|
var projectile = instance.GetComponent<SkillProjectile>();
|
|
if (projectile != null)
|
|
projectile.Initialize(caster, hitEffect);
|
|
|
|
if (autoDestroyTime > 0f)
|
|
Object.Destroy(instance, autoDestroyTime);
|
|
}
|
|
}
|
|
|
|
private GameObject ResolveTarget(GameObject caster, GameObject target)
|
|
{
|
|
if (!useCombatContextTarget)
|
|
return target;
|
|
|
|
if (target != null && target != caster)
|
|
return target;
|
|
|
|
BossCombatBehaviorContext context = caster.GetComponent<BossCombatBehaviorContext>();
|
|
return context != null && context.CurrentTarget != null
|
|
? context.CurrentTarget
|
|
: target;
|
|
}
|
|
|
|
private Vector3 GetSpawnPosition(GameObject caster, GameObject target)
|
|
{
|
|
return spawnLocation switch
|
|
{
|
|
SpawnLocation.Caster => caster.transform.position,
|
|
SpawnLocation.CasterForward => caster.transform.position + caster.transform.forward * 2f,
|
|
SpawnLocation.Target => target != null ? target.transform.position : caster.transform.position,
|
|
_ => caster.transform.position
|
|
};
|
|
}
|
|
|
|
private Quaternion GetSpawnRotation(GameObject caster, GameObject target)
|
|
{
|
|
// target이 있으면 항상 target 방향 우선 (SingleAlly 타게팅 지원)
|
|
if (target != null && target != caster)
|
|
{
|
|
Vector3 lookDirection = target.transform.position - caster.transform.position;
|
|
if (lookDirection.sqrMagnitude > 0.0001f)
|
|
return Quaternion.LookRotation(lookDirection);
|
|
}
|
|
|
|
// target이 없으면 spawnLocation 기준
|
|
if (spawnLocation == SpawnLocation.Target)
|
|
return caster.transform.rotation;
|
|
|
|
return caster.transform.rotation;
|
|
}
|
|
}
|
|
|
|
public enum SpawnLocation
|
|
{
|
|
Caster,
|
|
CasterForward,
|
|
Target
|
|
}
|
|
}
|