forked from zxl/Frame
1
0
Fork 0
Frame/Assets/Scripts/GameGlobalConfig.cs

109 lines
3.1 KiB
C#
Raw Normal View History

2024-04-04 23:51:14 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using Sirenix.OdinInspector;
using UnityEngine;
using UnityEngine.SceneManagement;
2024-04-07 17:20:48 +08:00
namespace Game
2024-04-04 23:51:14 +08:00
{
2024-04-07 17:20:48 +08:00
[ExecuteAlways]
public class GameGlobalConfig : SerializedMonoBehaviour
2024-04-04 23:51:14 +08:00
{
2024-04-07 17:20:48 +08:00
[HideReferenceObjectPicker]
[System.Serializable]
public class NodeMap
{
[ReadOnly] public Vector3 node1;
[ReadOnly] public Vector3 node2;
2024-04-04 23:51:14 +08:00
2024-04-07 17:20:48 +08:00
[ReadOnly] public string node1Name;
[ReadOnly] public string node2Name;
2024-04-05 18:12:04 +08:00
2024-04-07 17:20:48 +08:00
[ShowInInspector]
[HorizontalGroup("Bottom")]
[BoxGroup("Bottom/Node1")]
[HideLabel]
private Transform node1Transform
2024-04-04 23:51:14 +08:00
{
2024-04-07 17:20:48 +08:00
get { return null; }
set
2024-04-05 18:12:04 +08:00
{
2024-04-07 17:20:48 +08:00
if (value)
{
node1 = value.position;
node1Name = value.name;
}
2024-04-05 18:12:04 +08:00
}
2024-04-04 23:51:14 +08:00
}
2024-04-07 17:20:48 +08:00
[ShowInInspector]
[BoxGroup("Bottom/Node2")]
[HideLabel]
private Transform node2Transform
2024-04-04 23:51:14 +08:00
{
2024-04-07 17:20:48 +08:00
get { return null; }
set
2024-04-05 18:12:04 +08:00
{
2024-04-07 17:20:48 +08:00
if (value)
{
node2 = value.position;
node2Name = value.name;
}
2024-04-05 18:12:04 +08:00
}
2024-04-04 23:51:14 +08:00
}
}
2024-04-07 17:20:48 +08:00
[SerializeField] public NodeMap[] nodeMaps;
2024-04-04 23:51:14 +08:00
#if UNITY_EDITOR
2024-04-07 17:20:48 +08:00
private HashSet<string> _names;
private HashSet<Transform> _points;
private GUIStyle _style;
[SerializeField] private bool _showGizmos = true;
[SerializeField] private bool _showPointLabel = true;
2024-04-04 23:51:14 +08:00
#endif
2024-04-07 17:20:48 +08:00
private void OnDrawGizmos()
2024-04-04 23:51:14 +08:00
{
2024-04-07 17:20:48 +08:00
#if UNITY_EDITOR
if (_points == null || _points.Count == 0)
2024-04-04 23:51:14 +08:00
{
2024-04-07 17:20:48 +08:00
var skinLabel = GUI.skin.label;
_style = new GUIStyle(skinLabel);
_style.normal.textColor = Color.red;
_style.fontStyle = FontStyle.Bold;
_points ??= new HashSet<Transform>();
var wayPointFlags = FindObjectsOfType<WayPointFlag>();
foreach (var wayPointFlag in wayPointFlags)
{
_points.Add(wayPointFlag.transform);
}
2024-04-04 23:51:14 +08:00
}
2024-04-07 17:20:48 +08:00
if (_showPointLabel)
2024-04-04 23:51:14 +08:00
{
2024-04-07 17:20:48 +08:00
foreach (var point in this._points)
{
if (point)
UnityEditor.Handles.Label(point.position, point.gameObject.name, _style);
}
2024-04-04 23:51:14 +08:00
}
2024-04-07 17:20:48 +08:00
if (!_showGizmos)
return;
2024-04-04 23:51:14 +08:00
// var color = UnityEditor.Handles.color;
// UnityEditor.Handles.color = Color.red;
// UnityEditor.Handles.color = color;
2024-04-07 17:20:48 +08:00
if (nodeMaps != null)
2024-04-04 23:51:14 +08:00
{
2024-04-07 17:20:48 +08:00
foreach (var nodeMap in this.nodeMaps)
{
UnityEditor.Handles.DrawLine(nodeMap.node1, nodeMap.node2);
}
2024-04-04 23:51:14 +08:00
}
#endif
2024-04-07 17:20:48 +08:00
}
2024-04-04 23:51:14 +08:00
}
}