尝试优化Inspector的排版

在输数字的地方输入框的输入限制可以改成十进制数,这样就不会因为输了字母然后报错了
This commit is contained in:
2025-02-20 03:15:42 +08:00
parent 5349cde381
commit 28e8d54a7b
27 changed files with 761 additions and 479 deletions

View File

@@ -14,6 +14,7 @@ using Unity.VisualScripting;
using Ichni.RhythmGame;
using Sirenix.Utilities;
using UnityEngine.InputSystem;
using TMPro;
//又在写大粪 ——神币
namespace Ichni.Editor
@@ -22,14 +23,14 @@ namespace Ichni.Editor
{
public Interpreter functionInterpreter;
public InputField InputCommand;
public TMP_InputField InputCommand;
private Dictionary<int,string> historyCommand=new Dictionary<int,string>();
private int historycount=0;
public GameObject ConsoleUI;
public Hierarchy hierarchy;
public Inspector inspector;
bool isHide=false;
bool isHide=true;
public void GetChange(string change){
@@ -47,8 +48,8 @@ namespace Ichni.Editor
}
private void Update(){
if(Keyboard.current.backquoteKey.wasPressedThisFrame){
hierarchy.gameObject.SetActive(isHide);
inspector.gameObject.SetActive(isHide);
ConsoleUI.SetActive(isHide);
isHide=!isHide;
}
if(InputCommand.isFocused){
@@ -79,26 +80,25 @@ namespace Ichni.Editor
SetUpFunctions();
//Test
functionInterpreter.Eval("print(\"Hello World!\")");
functionInterpreter.Eval("log(\"Hello World but debug!\")");
// functionInterpreter.Eval("print(\"Hello World!\")");
// functionInterpreter.Eval("log(\"Hello World but debug!\")");
}
}
public partial class EditorConsole
{
private delegate void Batch(string name,string prop,int loop,string expression);
private Batch _batch;
private void SetUpFunctions()
{
functionInterpreter = new Interpreter();
functionInterpreter.SetFunction("test",(Action)Test);
functionInterpreter.SetFunction("loopg", (Action<string,int>)LoopGenerate);
functionInterpreter.SetFunction("lgp", (Action<string,int>)LGenPathNodes);
functionInterpreter.SetFunction("print", (Action<object>)print);
functionInterpreter.SetFunction("log", (Action<object>)Debug.Log);
_batch=BatchGenerate;
functionInterpreter.SetFunction("BatchGenerate",_batch);
}
@@ -121,33 +121,26 @@ namespace Ichni.Editor
}
}
//TODO duotrack选择菜单
if(obji.IsNullOrEmpty()){
Debug.LogWarning("no find");
return null;}
return obji[0];
}
private void BatchGenerate(string name,string prop,int loop,string expression){//
GameElement[] allObjects = Resources.FindObjectsOfTypeAll(typeof(GameElement)) as GameElement[];
List<int> objs=new();
foreach (GameElement obj in allObjects){
if(obj.elementName==name)objs.Add(obj.GetInstanceID());
}
print(objs);
//TODO: 预制件,属性,循环数,表达式
print("在做了");
}
private void LoopGenerate(string name,int time){
private void LGenPathNodes(string name,int loop){
Track track= (Track)Find(name);
for(int i=0;i<time;i++){
PathNode.GenerateElement("PathNodes", Guid.NewGuid(), new List<string>(), true,track);
for(int i=0;i<loop;i++){
var p=PathNode.GenerateElement("PathNodes", Guid.NewGuid(), new List<string>(), true,track);
}

View File

@@ -1,3 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
@@ -9,9 +10,23 @@ namespace Ichni.Editor
{
public class DynamicUIContainer : MonoBehaviour
{
Inspector Inspector => EditorManager.instance.uiManager.inspector;
public TMP_Text title;
public GridLayoutGroup gridLayoutGroup;
public List<DynamicUIElement> dynamicUIElements = new List<DynamicUIElement>();
[FormerlySerializedAs("container")] public RectTransform rect;
public void SetDeviver(int num){//rect 500
gridLayoutGroup.cellSize=new Vector2(Inspector.inspectorRect.rect.width/num,gridLayoutGroup.cellSize.y);
bool CanCompress=true;//这是是想着如果没有按钮以外的东西就把y值调小一点的
foreach(var i in GetComponentsInChildren<DynamicUIElement>()){
i.DeviverSet(num);
if(i.GetType()!=typeof(DynamicUIButton))CanCompress=false;
}
if(CanCompress)gridLayoutGroup.cellSize=new Vector2(gridLayoutGroup.cellSize.x,gridLayoutGroup.cellSize.y/2);
}
}
}

View File

@@ -1,9 +1,11 @@
using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using Ichni.RhythmGame;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
namespace Ichni.Editor
{
@@ -24,6 +26,7 @@ namespace Ichni.Editor
public virtual void Initialize(IBaseElement baseElement, string title, string parameterName)
{
this.connectedBaseElement = baseElement;
this.parameterName = parameterName;
if (title != string.Empty)
@@ -34,8 +37,23 @@ namespace Ichni.Editor
{
this.title.gameObject.SetActive(false);
}
}
public virtual void DeviverSet(int DeviveNum){
float o=2f/DeviveNum;//因为所有的单UI都是根据2栏来的
Button[] childb=GetComponentsInChildren<Button>();
TMP_Text[] childt=GetComponentsInChildren<TMP_Text>();
foreach (var i in childb){
RectTransform rectTransform = i.GetComponent<RectTransform>();
rectTransform.sizeDelta=new Vector2(rectTransform.sizeDelta.x*o,rectTransform.sizeDelta.y);
}
foreach (var i in childt){
RectTransform rectTransform = i.GetComponent<RectTransform>();
rectTransform.sizeDelta=new Vector2(rectTransform.sizeDelta.x*o,rectTransform.sizeDelta.y);
}
}
//public abstract void ApplyParameters();
}
}

View File

@@ -18,7 +18,7 @@ namespace Ichni.Editor
public TMP_InputField inputFieldEmissionI;
public Image colorPreview;
public new void Initialize(IBaseElement baseElement, string title,
public void Initialize(IBaseElement baseElement, string title,
string emissionEnabledName, string colorParameterName, string emissionIntensityName)
{
base.Initialize(baseElement, title, colorParameterName);

View File

@@ -28,7 +28,9 @@ namespace Ichni.Editor
inputFieldY.onEndEdit.AddListener(_ => ApplyParameters());
inputFieldZ.onEndEdit.AddListener(_ => ApplyParameters());
}
public override void DeviverSet(int i){
//我什么也不做
}
private void ApplyParameters()
{
Vector3 newValue = new Vector3(float.Parse(inputFieldX.text), float.Parse(inputFieldY.text), float.Parse(inputFieldZ.text));

View File

@@ -26,10 +26,11 @@ namespace Ichni.Editor
public void PlayMusic()
{
isPlaying = true;
isPlaying = !isPlaying;
Trail.SetAllTrails(true, false);
EditorManager.instance.songInformation.songTime = audioSource.time;
audioSource.Play();
if( isPlaying)audioSource.Play();
else audioSource.Pause();
}
public void PauseMusic()

View File

@@ -14,4 +14,5 @@ namespace Ichni.Editor
public TimePointerModule timePointerModule;
public MusicPlayer musicPlayer;
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b6eb61dffe3843041b021e96e9c7cb0b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -87,6 +87,7 @@ namespace Ichni.RhythmGame
{
inspector.GenerateCompositeParameterWindow(this, "Position Z", nameof(positionZ)).SetAsFlexibleFloat();
});
container.SetDeviver(1);
}
}

View File

@@ -87,6 +87,7 @@ namespace Ichni.RhythmGame
public override void SetUpInspector()
{
var container = inspector.GenerateContainer("Transform");
var originalPosInputField =
inspector.GenerateVec3InputField(this, container, "Start Position", nameof(originalPosition));
var originalRotInputField =
@@ -103,6 +104,9 @@ namespace Ichni.RhythmGame
originalPosInputField.AddListenerFunction(Refresh);
originalRotInputField.AddListenerFunction(Refresh);
originalScaleInputField.AddListenerFunction(Refresh);
//这玩意得放在最下面
container.SetDeviver(1);
}
public override void Refresh()

View File

@@ -76,6 +76,7 @@ namespace Ichni.RhythmGame
var timeEffectsCollectionButton = inspector.GenerateButton(this, container, "Time Effects Collection",
() => TimeEffectsCollection.GenerateElement("New Time Effects Collection", Guid.NewGuid(),
new List<string>(), true, this, 0f));
container.SetDeviver(1);
}
}

View File

@@ -141,6 +141,7 @@ namespace Ichni.RhythmGame
Swirl.GenerateElement("New Swirl", Guid.NewGuid(), new List<string>(), true, this,
new FlexibleFloat(), new FlexibleFloat(), new FlexibleFloat());
});
container.SetDeviver(1);
}
}