something & 编辑器指南

This commit is contained in:
2025-04-19 18:59:26 +08:00
parent d7ce55cd04
commit a0f7ec7e15
15 changed files with 4567 additions and 3754 deletions

View File

@@ -13,7 +13,7 @@ namespace Ichni.Editor
{
[Tooltip("指定用于计算缩放的摄像机(若为空则使用 Camera.main")]
public Camera sceneCamera;
public float cameraDistance;
[Tooltip("指定网格所在的平面0 = XZ (y=0), 1 = XY (z=0), 2 = YZ (x=0)")]
@@ -41,7 +41,7 @@ namespace Ichni.Editor
void Start()
{
positionTexts = new Dictionary<GameObject, Vector3>();
sceneCamera = EditorManager.instance.cameraManager.sceneCamera.sceneCamera;
// 实例化材质,避免修改共享材质
gridMaterial = GetComponent<MeshRenderer>().material;
@@ -52,7 +52,7 @@ namespace Ichni.Editor
void Update()
{
sceneCamera = EditorManager.instance.cameraManager.currentCamera;
// 计算摄像机到网格平面的垂直距离
cameraDistance = 0f;
Vector3 camPos = sceneCamera.transform.position;
@@ -76,12 +76,12 @@ namespace Ichni.Editor
gridMaterial.SetFloat("_GridScale", 1 / gridScale);
gridMaterial.SetFloat("_DisappearEndDistance", 100 * gridScale);
if (canShowPositionText && isShowingPositionText)
{
GetPoints();
foreach (KeyValuePair<GameObject,Vector3> positionText in positionTexts)
foreach (KeyValuePair<GameObject, Vector3> positionText in positionTexts)
{
positionText.Key.transform.position = positionText.Value + new Vector3(gridScale / 6, 0, gridScale / 12);
float scaleFactor = gridScale * 1.5f;
@@ -98,6 +98,7 @@ namespace Ichni.Editor
if (sceneCameraHit.collider.gameObject == gameObject)
{
Vector3 point = sceneCameraHit.point;
float radius = gridScale * 16f;
float step = gridScale * 4f;
@@ -114,13 +115,16 @@ namespace Ichni.Editor
List<Vector3> newPositions = new List<Vector3>();
// 添加距离检测逻辑
bool withinDistance = Vector3.Distance(sceneCamera.transform.position, point) <= 100f;
for (float x = minX; x <= maxX; x += step)
{
for (float z = minZ; z <= maxZ; z += step)
{
Vector3 position = new Vector3(x, 0, z);
if (!positionTexts.ContainsValue(position))
if (withinDistance && !positionTexts.ContainsValue(position))
{
GameObject posText = LeanPool.Spawn(positionTextPrefab);
posText.transform.position = position + new Vector3(gridScale / 8, 0, gridScale / 16);
@@ -133,7 +137,7 @@ namespace Ichni.Editor
newPositions.Add(new Vector3(x, 0, z));
}
}
List<GameObject> toRemove = new List<GameObject>();
// 清除不在新范围内的Text
foreach (KeyValuePair<GameObject, Vector3> positionText in positionTexts)
@@ -144,7 +148,7 @@ namespace Ichni.Editor
toRemove.Add(positionText.Key);
}
}
foreach (GameObject text in toRemove)
{
positionTexts.Remove(text);