DTM Flick,编辑界面网格
This commit is contained in:
@@ -17,7 +17,7 @@ namespace Ichni.RhythmGame
|
||||
public static Flick GenerateElement(string elementName, Guid id, List<string> tags, bool isFirstGenerated,
|
||||
GameElement parentElement, float exactJudgeTime, List<Vector2> directions)
|
||||
{
|
||||
Flick flick = Instantiate(EditorManager.instance.basePrefabs.tapNote, parentElement.transform)
|
||||
Flick flick = Instantiate(EditorManager.instance.basePrefabs.flickNote, parentElement.transform)
|
||||
.GetComponent<Flick>();
|
||||
flick.Initialize(elementName, id, tags, isFirstGenerated, parentElement);
|
||||
flick.exactJudgeTime = exactJudgeTime;
|
||||
|
||||
8
Assets/Scripts/EditorGame/Grids.meta
Normal file
8
Assets/Scripts/EditorGame/Grids.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f4d99b225afe249449c426683cb3e513
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
70
Assets/Scripts/EditorGame/Grids/EditorGrid.cs
Normal file
70
Assets/Scripts/EditorGame/Grids/EditorGrid.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Ichni.Editor
|
||||
{
|
||||
[RequireComponent(typeof(MeshRenderer))]
|
||||
public class EditorGrid : MonoBehaviour
|
||||
{
|
||||
[Tooltip("指定用于计算缩放的摄像机(若为空则使用 Camera.main)")]
|
||||
public Camera sceneCamera;
|
||||
|
||||
[Tooltip("指定网格所在的平面:0 = XZ (y=0), 1 = XY (z=0), 2 = YZ (x=0)")]
|
||||
public int gridPlane = 0;
|
||||
|
||||
[Tooltip("网格基础缩放值,单位 1")] public float baseScale = 1f;
|
||||
|
||||
[Tooltip("调整缩放的影响因子,建议值 1~5")] public float scaleMultiplier = 1f;
|
||||
|
||||
[Tooltip("距离因子,用于计算对数缩放(例如距离大于该值时切换到下一级单位)")]
|
||||
public float distanceFactor = 10f;
|
||||
|
||||
// 内部缓存材质
|
||||
private Material gridMaterial;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (sceneCamera == null)
|
||||
sceneCamera = EditorManager.instance.cameraManager.sceneCamera.sceneCamera;
|
||||
|
||||
// 实例化材质,避免修改共享材质
|
||||
gridMaterial = GetComponent<MeshRenderer>().material;
|
||||
// 同步网格平面的值到材质(方便 Shader 内部判断)
|
||||
gridMaterial.SetFloat("_Plane", gridPlane);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (sceneCamera == null || gridMaterial == null)
|
||||
return;
|
||||
|
||||
// 计算摄像机到网格平面的垂直距离
|
||||
float camDistance = 0f;
|
||||
Vector3 camPos = sceneCamera.transform.position;
|
||||
Vector3 gridPos = transform.position;
|
||||
switch (gridPlane)
|
||||
{
|
||||
case 0: // XZ 平面:垂直方向为 Y
|
||||
camDistance = Mathf.Abs(camPos.y - gridPos.y);
|
||||
break;
|
||||
case 1: // XY 平面:垂直方向为 Z
|
||||
camDistance = Mathf.Abs(camPos.z - gridPos.z);
|
||||
break;
|
||||
case 2: // YZ 平面:垂直方向为 X
|
||||
camDistance = Mathf.Abs(camPos.x - gridPos.x);
|
||||
break;
|
||||
}
|
||||
|
||||
// 利用对数函数计算缩放等级:距离越远,网格越大
|
||||
float logScale = Mathf.Floor(Mathf.Log(camDistance / distanceFactor + 1, 4));
|
||||
float gridScale = baseScale * Mathf.Pow(4, logScale) * scaleMultiplier;
|
||||
|
||||
gridMaterial.SetFloat("_GridScale", 1 / gridScale);
|
||||
}
|
||||
|
||||
// 提供外部接口,用于切换网格显示
|
||||
public void SetGridActive(bool active)
|
||||
{
|
||||
gameObject.SetActive(active);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/EditorGame/Grids/EditorGrid.cs.meta
Normal file
11
Assets/Scripts/EditorGame/Grids/EditorGrid.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dcf702d09b6611648a7df04aa49aa927
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
50
Assets/Scripts/EditorGame/Grids/GridController.cs
Normal file
50
Assets/Scripts/EditorGame/Grids/GridController.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
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; }
|
||||
|
||||
public EditorGrid yPlaneGrid;
|
||||
public EditorGrid xPlaneGrid;
|
||||
public EditorGrid zPlaneGrid;
|
||||
|
||||
public bool yPlaneEnabled;
|
||||
public bool xPlaneEnabled;
|
||||
public bool zPlaneEnabled;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
yPlaneEnabled = true;
|
||||
xPlaneEnabled = false;
|
||||
zPlaneEnabled = false;
|
||||
RefreshPlanes();
|
||||
}
|
||||
|
||||
public void SetUpInspector()
|
||||
{
|
||||
IHaveInspection inspector = EditorManager.instance.uiManager.inspector;
|
||||
|
||||
var container = inspector.GenerateContainer("Grid Controller");
|
||||
var yPlaneToggle = inspector.GenerateToggle(this, container, "Y Plane", nameof(yPlaneEnabled));
|
||||
yPlaneToggle.AddListenerFunction(RefreshPlanes);
|
||||
var xPlaneToggle = inspector.GenerateToggle(this, container, "X Plane", nameof(xPlaneEnabled));
|
||||
xPlaneToggle.AddListenerFunction(RefreshPlanes);
|
||||
var zPlaneToggle = inspector.GenerateToggle(this, container, "Z Plane", nameof(zPlaneEnabled));
|
||||
zPlaneToggle.AddListenerFunction(RefreshPlanes);
|
||||
}
|
||||
|
||||
private void RefreshPlanes()
|
||||
{
|
||||
yPlaneGrid.gameObject.SetActive(yPlaneEnabled);
|
||||
xPlaneGrid.gameObject.SetActive(xPlaneEnabled);
|
||||
zPlaneGrid.gameObject.SetActive(zPlaneEnabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/EditorGame/Grids/GridController.cs.meta
Normal file
11
Assets/Scripts/EditorGame/Grids/GridController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab1e04d0e4926e748895c81bd8791147
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -23,6 +23,7 @@ namespace Ichni
|
||||
public EditorSettings editorSettings;
|
||||
public OperationManager operationManager;
|
||||
public BackgroundController backgroundController;
|
||||
public GridController gridController;
|
||||
public CameraManager cameraManager;
|
||||
public PostProcessingManager postProcessingManager;
|
||||
public Canvas judgeHintCanvas;
|
||||
@@ -125,6 +126,7 @@ namespace Ichni
|
||||
projectInformation.SetUpInspector();
|
||||
songInformation.SetUpInspector();
|
||||
cameraManager.SetUpInspector();
|
||||
gridController.SetUpInspector();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user