Files
ichni_Creator_Studio/Assets/Scripts/EditorGame/Grids/GridController.cs

77 lines
2.6 KiB
C#
Raw Normal View History

2025-04-04 15:29:03 -04:00
using System.Collections.Generic;
using Ichni.RhythmGame;
using Ichni.RhythmGame.Beatmap;
using UnityEngine;
namespace Ichni.Editor
{
public class GridController : MonoBehaviour, IBaseElement
{
public BaseElement_BM matchedBM { get; set; }
2025-06-14 20:47:45 +08:00
2025-04-04 15:29:03 -04:00
public EditorGrid yPlaneGrid;
public EditorGrid xPlaneGrid;
public EditorGrid zPlaneGrid;
[Header("State")]
public bool yPlaneEnabled = true;
public bool xPlaneEnabled = false;
public bool zPlaneEnabled = false;
public bool isYPlaneShowingPositionText = true;
public float fixedTextSizeFactor = 0.1f;
2025-04-04 15:29:03 -04:00
2025-04-16 08:33:34 -04:00
2025-04-04 15:29:03 -04:00
private void Start()
{
RefreshPlanes();
}
public void SetUpInspector()
{
IHaveInspection inspector = EditorManager.instance.uiManager.inspector;
var container = inspector.GenerateContainer("Grid Controller");
2025-06-14 20:47:45 +08:00
2025-04-14 17:49:47 -04:00
var gridSettings = container.GenerateSubcontainer(3);
inspector.GenerateToggle(this, gridSettings, "Y Plane (XZ)", nameof(yPlaneEnabled))
2025-04-14 17:49:47 -04:00
.AddListenerFunction(RefreshPlanes);
inspector.GenerateToggle(this, gridSettings, "X Plane (YZ)", nameof(xPlaneEnabled))
2025-04-14 17:49:47 -04:00
.AddListenerFunction(RefreshPlanes);
2025-04-16 08:33:34 -04:00
inspector.GenerateToggle(this, gridSettings, "Z Plane (XY)", nameof(zPlaneEnabled))
.AddListenerFunction(RefreshPlanes);
inspector.GenerateToggle(this, gridSettings, "Show Y Plane Pos", nameof(isYPlaneShowingPositionText))
.AddListenerFunction(RefreshPlanes);
inspector.GenerateInputField(this, gridSettings, "Fixed Text Size Factor", nameof(fixedTextSizeFactor))
.AddListenerFunction(RefreshPlanes);
2025-04-04 15:29:03 -04:00
}
private void RefreshPlanes()
{
SetGridState(yPlaneGrid, yPlaneEnabled, isYPlaneShowingPositionText);
SetGridState(xPlaneGrid, xPlaneEnabled, false); // 假设其他平面暂时不显示文字
SetGridState(zPlaneGrid, zPlaneEnabled, false);
}
private void SetGridState(EditorGrid grid, bool active, bool showText)
{
if (grid == null) return;
2025-06-14 20:47:45 +08:00
grid.gameObject.SetActive(active);
if (active)
2025-04-16 08:33:34 -04:00
{
grid.canShowPositionText = showText;
grid.isShowingPositionText = showText;
// 如果关闭了文字显示,立刻清理
if (!showText)
2025-04-16 08:33:34 -04:00
{
grid.ClearAllTexts();
2025-04-16 08:33:34 -04:00
}
}
2025-04-04 15:29:03 -04:00
}
}
}