场景相机初步,日志输出LogWindow

This commit is contained in:
SoulliesOfficial
2025-02-18 10:30:11 -05:00
parent 8d4772532f
commit b36f0469d0
31 changed files with 1497 additions and 721 deletions

View File

@@ -1,7 +1,9 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Ichni.RhythmGame;
using TMPro;
using UniRx;
using UnityEngine;
namespace Ichni.Editor
@@ -14,5 +16,10 @@ namespace Ichni.Editor
{
text.text = content;
}
public void SetUpdatingContent(Func<string> content)
{
Observable.EveryUpdate().Subscribe(_ => text.text = content()).AddTo(gameObject);
}
}
}

View File

@@ -4,6 +4,7 @@ using System.Collections.Generic;
using Ichni.RhythmGame;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
namespace Ichni.Editor
{
@@ -36,5 +37,10 @@ namespace Ichni.Editor
}
connectedBaseElement.Refresh();
}
public void AddListenerFunction(UnityAction<string> action)
{
inputField.onEndEdit.AddListener(action);
}
}
}

View File

@@ -14,7 +14,6 @@ namespace Ichni.Editor
public GameElement connectedGameElement;
public HierarchyTab parentTab;
public List<HierarchyTab> childTabList;
public List<int> IDqueue;
public int tabLayer;
public bool isSelected;
@@ -30,7 +29,6 @@ namespace Ichni.Editor
public void SetTab(GameElement targetElement, GameElement parentElement)
{
connectedGameElement = targetElement;
tabButtonText.text = targetElement.elementName;
targetElement.connectedTab = this;
@@ -49,12 +47,8 @@ namespace Ichni.Editor
this.parentTab = parentElement.connectedTab;
parentElement.connectedTab.childTabList.Add(this);
this.tabLayer = this.parentTab.tabLayer + 1;
this.transform.SetSiblingIndex(this.parentTab.transform.GetSiblingIndex() +
this.parentTab.connectedGameElement.childElementList.Count);
this.transform.SetSiblingIndex(this.parentTab.transform.GetSiblingIndex() + GetAllChildrenCount(this.parentTab));
if (!this.parentTab.isExpanded)
{
this.isExpanded = false;
@@ -63,7 +57,7 @@ namespace Ichni.Editor
for (int i = 1; i <= this.tabLayer; i++)
{
float lineX = 30 * i;
float lineX = 30 * i - 10;
Instantiate(indentationLinePrefab, tabRect).GetComponent<RectTransform>().anchoredPosition = new Vector2(lineX, 0);
}
}
@@ -71,7 +65,6 @@ namespace Ichni.Editor
float posX = -25 +( 30 * tabLayer);
tabMainRect.anchoredPosition = new Vector2(posX, tabMainRect.anchoredPosition.y);
tabButton.onClick.AddListener(SelectGameElement);
expandButton.onClick.AddListener(ExpandOrFold);
}
@@ -104,10 +97,11 @@ namespace Ichni.Editor
if (isExpanded)
{
expandButton.transform.Rotate(new Vector3(0, 0, 180));
foreach (GameElement i in connectedGameElement.childElementList)
for (var index = 0; index < connectedGameElement.childElementList.Count; index++)
{
HierarchyTab a = EditorManager.instance.uiManager.hierarchy.GenerateTab(i, connectedGameElement);
childTabList.Add(a);
var childElement = connectedGameElement.childElementList[index];
EditorManager.instance.uiManager.hierarchy.GenerateTab(childElement, connectedGameElement);
}
}
else

View File

@@ -101,7 +101,7 @@ namespace Ichni.Editor
string title, string parameterName)
{
DynamicUIVector3InputField vector3InputField =
Instantiate(EditorManager.instance.basePrefabs.Vector3inputField, container.rect)
Instantiate(EditorManager.instance.basePrefabs.vector3InputField, container.rect)
.GetComponent<DynamicUIVector3InputField>();
vector3InputField.Initialize(baseElement, title, parameterName);
container.dynamicUIElements.Add(vector3InputField);
@@ -128,20 +128,30 @@ namespace Ichni.Editor
return colorPicker;
}
public DynamicUIHintText GenerateText(IBaseElement baseElement, DynamicUIContainer container, string content)
public DynamicUIHintText GenerateHintText(IBaseElement baseElement, DynamicUIContainer container, string content)
{
DynamicUIHintText parameterText = Instantiate(EditorManager.instance.basePrefabs.text, container.rect)
DynamicUIHintText hintText = Instantiate(EditorManager.instance.basePrefabs.hintText, container.rect)
.GetComponent<DynamicUIHintText>();
parameterText.Initialize(baseElement, string.Empty, string.Empty);
parameterText.SetContent(content);
container.dynamicUIElements.Add(parameterText);
return parameterText;
hintText.Initialize(baseElement, string.Empty, string.Empty);
hintText.SetContent(content);
container.dynamicUIElements.Add(hintText);
return hintText;
}
public DynamicUIHintText GenerateHintText(IBaseElement baseElement, DynamicUIContainer container, Func<string> action)
{
DynamicUIHintText hintText = Instantiate(EditorManager.instance.basePrefabs.hintText, container.rect)
.GetComponent<DynamicUIHintText>();
hintText.Initialize(baseElement, string.Empty, string.Empty);
hintText.SetUpdatingContent(action);
container.dynamicUIElements.Add(hintText);
return hintText;
}
public DynamicUIParameterText GenerateText(IBaseElement baseElement, DynamicUIContainer container, string title,
public DynamicUIParameterText GenerateParameterText(IBaseElement baseElement, DynamicUIContainer container, string title,
string parameterName, bool isAlwaysUpdate = false)
{
DynamicUIParameterText parameterText = Instantiate(EditorManager.instance.basePrefabs.text, container.rect)
DynamicUIParameterText parameterText = Instantiate(EditorManager.instance.basePrefabs.parameterText, container.rect)
.GetComponent<DynamicUIParameterText>();
parameterText.Initialize(baseElement, title, parameterName);
parameterText.isAlwaysUpdated = isAlwaysUpdate;

View File

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

View File

@@ -0,0 +1,25 @@
using System.Collections;
using System.Collections.Generic;
using Lean.Pool;
using TMPro;
using UnityEngine;
namespace Ichni.Editor
{
public class LogText : MonoBehaviour
{
public TMP_Text logText;
public void SetLogText(string text, Color color)
{
logText.text = text;
logText.color = color;
string logFilePath = EditorManager.instance.projectInformation.projectPath + "/Logs/EditorLog.txt";
// if(!ES3.FileExists(logFilePath)) System.IO.File.Create(logFilePath).Dispose();
//
// System.IO.File.AppendAllText(logFilePath, text + "\n");
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c627b09eb0f984c59b55367c47919d38
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,39 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Lean.Pool;
using UnityEngine;
namespace Ichni.Editor
{
public class LogWindow : MonoBehaviour
{
public GameObject logTextPrefab;
public RectTransform textRect;
public Queue<LogText> logTexts;
public int logTextCapacity = 4;
private void Start()
{
logTexts = new Queue<LogText>();
}
public void AddLog(string text, Color color = default)
{
CheckLogTextCapacity();
LogText logText = LeanPool.Spawn(logTextPrefab, textRect).GetComponent<LogText>();
if (color == default) color = Color.white;
logText.SetLogText(text, color);
logTexts.Enqueue(logText);
}
private void CheckLogTextCapacity()
{
if (logTexts.Count >= logTextCapacity)
{
LeanPool.Despawn(logTexts.Dequeue().gameObject);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d537bd381617a4941839f44c04840c28
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -9,5 +9,6 @@ namespace Ichni.Editor
public Canvas mainCanvas;
public ToolBar toolBar;
public ResolutionHints resolutionHints;
public LogWindow logWindow;
}
}

View File

@@ -17,7 +17,10 @@ namespace Ichni.RhythmGame
/// <summary>
/// 用于生成存档
/// </summary>
public void SaveBM();
public void SaveBM()
{
}
/// <summary>
/// 刷新物体的状态
@@ -44,7 +47,11 @@ namespace Ichni.RhythmGame
}
public Inspector inspector => EditorManager.instance.uiManager.inspector;
public void SetUpInspector();
public void SetUpInspector()
{
}
}
// public virtual void SetTimeDuration()

View File

@@ -93,11 +93,11 @@ namespace Ichni.RhythmGame
var originalScaleInputField =
inspector.GenerateVec3InputField(this, container, "Start Scale", nameof(originalScale));
var currentPosText =
inspector.GenerateText(this, container, "Current Position", nameof(currentPosition), true);
inspector.GenerateParameterText(this, container, "Current Position", nameof(currentPosition), true);
var currentRotText =
inspector.GenerateText(this, container, "Current Rotation", nameof(currentEulerAngles), true);
inspector.GenerateParameterText(this, container, "Current Rotation", nameof(currentEulerAngles), true);
var currentScaleText =
inspector.GenerateText(this, container, "Current Scale", nameof(currentScale), true);
inspector.GenerateParameterText(this, container, "Current Scale", nameof(currentScale), true);
}
public override void Refresh()

View File

@@ -149,7 +149,7 @@ namespace Ichni.RhythmGame
{
var container = inspector.GenerateContainer("Element Info");
var nameInputField = inspector.GenerateInputField(this, container, GetType().Name + "'s Name", nameof(elementName));
var guidText = inspector.GenerateText(this, container, "Element GUID", nameof(elementGuid));
var guidText = inspector.GenerateParameterText(this, container, "Element GUID", nameof(elementGuid));
var tagsListButton = inspector.GenerateButton(this, container, "Tags List", () =>
{
inspector.GenerateCompositeParameterWindow(this, "Tags List", nameof(tags)).SetAsStringList();

View File

@@ -79,6 +79,14 @@ namespace Ichni.RhythmGame
{
matchedBM = new Beatmap.PathNode_BM(elementName, elementGuid, tags, parentElement.matchedBM as GameElement_BM);
}
public override void SetUpInspector()
{
base.SetUpInspector();
var container = inspector.GenerateContainer("Path Node");
var indexText = inspector.GenerateHintText(this, container, "Index: " + index);
}
}
namespace Beatmap

View File

@@ -33,11 +33,12 @@ public class BasePrefabsCollection : SerializedScriptableObject
[Title("DynamicUI相关-Simple")] public GameObject dynamicUIContainer;
public GameObject inputField;
public GameObject Vector3inputField;
public GameObject text;
[FormerlySerializedAs("Vector3inputField")] public GameObject vector3InputField;
[FormerlySerializedAs("text")] public GameObject parameterText;
public GameObject hintText;
public GameObject button;
public GameObject toggle;
[FormerlySerializedAs("dropdown")] public GameObject enumDropdown;
public GameObject enumDropdown;
public GameObject stringListDropdown;
public GameObject baseColorPicker;
public GameObject emissionColorPicker;

View File

@@ -0,0 +1,42 @@
using System.Collections;
using System.Collections.Generic;
using Ichni.RhythmGame;
using Ichni.RhythmGame.Beatmap;
using UnityEngine;
namespace Ichni.Editor
{
public class CameraManager : MonoBehaviour, IBaseElement
{
public bool isSceneCameraActive;
public SceneCamera sceneCamera;
public float cameraMoveSpeed;
public GameCamera gameCamera;
private bool haveGameCamera => gameCamera != null;
public BaseElement_BM matchedBM { get; set; }
public void SwitchCamera()
{
if (!haveGameCamera)
{
throw new System.Exception("GameCamera is not assigned");
}
isSceneCameraActive = !isSceneCameraActive;
sceneCamera.camera.enabled = isSceneCameraActive;
gameCamera.camera.enabled = !isSceneCameraActive;
}
public void SetUpInspector()
{
string ShowCameraType() => isSceneCameraActive ? "Scene Camera" : "Game Camera";
var container = EditorManager.instance.uiManager.inspector.GenerateContainer("Camera Manager");
var cameraTypeText = EditorManager.instance.uiManager.inspector.GenerateHintText(this, container, ShowCameraType);
var switchCameraButton = EditorManager.instance.uiManager.inspector.GenerateButton(this, container, "Switch Camera", SwitchCamera);
var cameraMoveSpeedField = EditorManager.instance.uiManager.inspector.GenerateInputField(this, container, "Camera Move Speed", nameof(cameraMoveSpeed));
sceneCamera.SetUpInspector();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 604e2c80e1fb64c2ba9608c11fb2f040
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -7,6 +7,7 @@ using Ichni.RhythmGame.Beatmap;
using Ichni.RhythmGame.ThemeBundles.Basic;
using Sirenix.OdinInspector;
using UnityEngine;
using Random = UnityEngine.Random;
namespace Ichni
{
@@ -18,6 +19,7 @@ namespace Ichni
public EditorUIManager uiManager;
public EditorSettings editorSettings;
public BackgroundController backgroundController;
public CameraManager cameraManager;
public ProjectInformation projectInformation;
public SongInformation songInformation;
@@ -75,6 +77,7 @@ namespace Ichni
"basic", "Skybox", "Background"));
projectInformation.SetUpInspector();
songInformation.SetUpInspector();
cameraManager.SetUpInspector();
}
private void CreateNew()

View File

@@ -10,6 +10,37 @@ namespace Ichni.Editor
{
private void Update()
{
if (EditorManager.instance.cameraManager.isSceneCameraActive)
{
float cameraSpeed = EditorManager.instance.cameraManager.cameraMoveSpeed * Time.deltaTime;
Transform sceneCameraTransform = EditorManager.instance.cameraManager.sceneCamera.transform;
if (Keyboard.current.wKey.isPressed)
{
sceneCameraTransform.position += sceneCameraTransform.forward * cameraSpeed;
}
if (Keyboard.current.sKey.isPressed)
{
sceneCameraTransform.position -= sceneCameraTransform.forward * cameraSpeed;
}
if (Keyboard.current.dKey.isPressed)
{
sceneCameraTransform.position += sceneCameraTransform.right * cameraSpeed;
}
if (Keyboard.current.aKey.isPressed)
{
sceneCameraTransform.position -= sceneCameraTransform.right * cameraSpeed;
}
if (Keyboard.current.spaceKey.isPressed)
{
sceneCameraTransform.position += sceneCameraTransform.up * cameraSpeed;
}
if (Keyboard.current.leftShiftKey.isPressed)
{
sceneCameraTransform.position -= sceneCameraTransform.up * cameraSpeed;
}
}
if (Keyboard.current.leftCtrlKey.isPressed)
{
if (Keyboard.current.sKey.wasPressedThisFrame)
@@ -20,7 +51,9 @@ namespace Ichni.Editor
{
EditorManager.instance.projectManager.exportManager.Export();
}
else if (Keyboard.current.digit1Key.wasPressedThisFrame)
if (Keyboard.current.digit1Key.wasPressedThisFrame)
{
EditorManager.instance.uiManager.mainPage.resolutionHints.SetPhoneFrame();
}

View File

@@ -0,0 +1,54 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Ichni.RhythmGame;
using Ichni.RhythmGame.Beatmap;
using UnityEngine;
namespace Ichni.Editor
{
public class SceneCamera : MonoBehaviour, IBaseElement
{
public Camera camera;
public GameCamera.CameraViewType viewType;
public float perspectiveAngle;
public float orthographicSize;
public BaseElement_BM matchedBM { get; set; }
public void SetUpInspector()
{
Inspector inspector = EditorManager.instance.uiManager.inspector;
var container = inspector.GenerateContainer("Scene Camera");
var viewTypeDropdown = inspector.GenerateDropdown(this, container, "View Type", typeof(GameCamera.CameraViewType), nameof(viewType));
var perspectiveAngleField = inspector.GenerateInputField(this, container, "Perspective Angle", nameof(perspectiveAngle));
var orthographicSizeField = inspector.GenerateInputField(this, container, "Orthographic Size", nameof(orthographicSize));
viewTypeDropdown.AddListenerFunction(_ =>
{
camera.orthographic = viewType == GameCamera.CameraViewType.Orthographic;
});
perspectiveAngleField.AddListenerFunction(_ =>
{
camera.fieldOfView = perspectiveAngle;
});
orthographicSizeField.AddListenerFunction(_ =>
{
camera.orthographicSize = orthographicSize;
});
string GetPosition() => $"Position: {camera.transform.position}";
var positionText = inspector.GenerateHintText(this, container, GetPosition);
string GetEulerAngles() => $"Euler Angles: {camera.transform.eulerAngles}";
var eulerAnglesText = inspector.GenerateHintText(this, container, GetEulerAngles);
}
public void MoveCamera(Vector3 delta)
{
camera.transform.position += delta;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 63e7ac45befe54908ba6c691211fcbfa
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: