48 lines
1.9 KiB
C#
48 lines
1.9 KiB
C#
using UnityEngine;
|
||
|
||
namespace BaseGames.World
|
||
{
|
||
/// <summary>
|
||
/// 玩家出生点标记。RoomController 通过 transitionId 查找匹配的出生点。
|
||
/// </summary>
|
||
public class PlayerSpawnPoint : MonoBehaviour
|
||
{
|
||
[SerializeField] private string _transitionId;
|
||
|
||
[Tooltip("+1 = 朝右出生,-1 = 朝左出生")]
|
||
[SerializeField] private int _facingDirection = 1;
|
||
|
||
[Tooltip("(可选)此出生点对应的出口门。\n" +
|
||
"玩家在此出生后,调用 TriggerExitDoor() 播放门的进入动画(玩家从门里走出)。\n" +
|
||
"仅在使用 DoorTransition 的场景中需要配置。")]
|
||
[SerializeField] private DoorTransition _exitDoor;
|
||
|
||
public string TransitionId => _transitionId;
|
||
public Vector2 SpawnPosition => transform.position;
|
||
/// <summary>玩家出生时的朝向(+1 右,-1 左)。</summary>
|
||
public int FacingDirection => _facingDirection;
|
||
/// <summary>此出生点关联的出口门(可为 null)。</summary>
|
||
public DoorTransition ExitDoor => _exitDoor;
|
||
|
||
/// <summary>
|
||
/// 触发出口门的进入动画(玩家从门内侧走出)。
|
||
/// 无关联门时静默跳过。由负责放置玩家的系统在玩家落点后调用。
|
||
/// </summary>
|
||
public void TriggerExitDoor() => _exitDoor?.PlayEnterAnimation();
|
||
|
||
private void OnDrawGizmos()
|
||
{
|
||
Gizmos.color = Color.green;
|
||
Gizmos.DrawWireSphere(transform.position, 0.3f);
|
||
Gizmos.DrawLine(transform.position, transform.position + Vector3.up * 0.5f);
|
||
|
||
// 门关联指示线
|
||
if (_exitDoor != null)
|
||
{
|
||
Gizmos.color = new Color(0.7f, 0.3f, 1f, 0.6f);
|
||
Gizmos.DrawLine(transform.position, _exitDoor.transform.position);
|
||
}
|
||
}
|
||
}
|
||
}
|