85 lines
2.6 KiB
C#
85 lines
2.6 KiB
C#
using System;
|
|
using Sirenix.OdinInspector;
|
|
using UnityEngine;
|
|
|
|
#if UNITY_EDITOR
|
|
using Sirenix.Utilities.Editor;
|
|
using UnityEditor;
|
|
#endif
|
|
|
|
namespace Cielonos.MainGame.Map
|
|
{
|
|
public partial class SpawnPoint : MonoBehaviour
|
|
{
|
|
[HorizontalGroup("SpawnPointInfo", 0.5f)]
|
|
[LabelText("Identification")]
|
|
public string groupName = "Default";
|
|
|
|
[HorizontalGroup("SpawnPointInfo", 0.2f, MarginLeft = 0.05f), ReadOnly, HideLabel]
|
|
[SerializeField] private int index = -1;
|
|
public int Index => index;
|
|
|
|
[HorizontalGroup("SpawnPointInfo", 0.1f, MarginLeft = 0.05f), Button(Icon = SdfIconType.Command), HideLabel]
|
|
public void Refresh()
|
|
{
|
|
ZoneManager.Instance.RebuildMapData();
|
|
}
|
|
|
|
private void OnDrawGizmos()
|
|
{
|
|
Color color = Color.white;
|
|
if (MapBaseCollection.Instance != null)
|
|
{
|
|
color = MapBaseCollection.Instance.GetGroupColor(groupName);
|
|
}
|
|
|
|
Gizmos.color = color;
|
|
Gizmos.DrawSphere(transform.position, 0.25f);
|
|
|
|
//Draw Direction
|
|
Vector3 forward = transform.forward * 0.25f;
|
|
Gizmos.DrawCube(transform.position + forward, new Vector3(0.1f, 0.1f, 0.25f));
|
|
|
|
#if UNITY_EDITOR
|
|
// Draw text label using Handles - automatically faces camera
|
|
string text = $"{groupName}_{index}";
|
|
|
|
// Create a custom style if needed, or use default skin
|
|
GUIStyle style = new GUIStyle();
|
|
style.normal.textColor = color;
|
|
|
|
float distance = Vector3.Distance(SceneView.lastActiveSceneView.camera.transform.position, transform.position);
|
|
|
|
if (distance > 100f)
|
|
{
|
|
return; // 太远了不显示
|
|
}
|
|
|
|
float sizeFactor = Mathf.Clamp(100 / distance, 0.2f, 1f);
|
|
style.fontSize = Mathf.RoundToInt(10 * sizeFactor);
|
|
style.fontStyle = FontStyle.Bold;
|
|
style.alignment = TextAnchor.MiddleCenter;
|
|
Handles.Label(transform.position + Vector3.up * 0.5f, text, style);
|
|
#endif
|
|
}
|
|
|
|
// 被 Manager 调用
|
|
public void SetData(int newIndex)
|
|
{
|
|
index = newIndex;
|
|
|
|
#if UNITY_EDITOR
|
|
UnityEditor.EditorUtility.SetDirty(this);
|
|
#endif
|
|
}
|
|
}
|
|
|
|
public partial class SpawnPoint
|
|
{
|
|
public void GetTransform(out Vector3 position, out Quaternion rotation)
|
|
{
|
|
position = transform.position;
|
|
rotation = transform.rotation;
|
|
}
|
|
}
|
|
} |