Files
ichni_Creator_Studio/Assets/Scripts/Manager/EditorManager.cs

174 lines
6.6 KiB
C#
Raw Normal View History

using System;
using System.Collections;
using System.Collections.Generic;
2025-02-28 20:08:00 +08:00
using Dreamteck.Splines.Primitives;
2025-02-09 23:47:42 -05:00
using Ichni.Editor;
using Ichni.RhythmGame;
2025-02-07 10:49:26 -05:00
using Ichni.RhythmGame.Beatmap;
using Ichni.RhythmGame.ThemeBundles.Basic;
using Sirenix.OdinInspector;
2025-06-29 21:28:49 +08:00
using TMPro;
using Unity.VisualScripting;
using UnityEngine;
namespace Ichni
{
2025-02-17 14:46:14 -05:00
public class EditorManager : GameElement
{
public static EditorManager instance;
2025-02-28 20:08:00 +08:00
2025-03-01 21:26:16 -05:00
public bool isLoaded;
2025-02-08 23:09:50 -05:00
public ProjectManager projectManager;
2025-05-21 02:23:25 -04:00
public AudioManager audioManager;
public MusicPlayer musicPlayer;
2025-02-09 23:47:42 -05:00
public EditorUIManager uiManager;
2025-02-08 23:09:50 -05:00
public EditorSettings editorSettings;
2025-02-19 19:01:21 -05:00
public OperationManager operationManager;
2025-02-17 14:46:14 -05:00
public BackgroundController backgroundController;
2025-04-04 15:29:03 -04:00
public GridController gridController;
public CameraManager cameraManager;
2025-06-28 03:01:03 -04:00
public Ichni.Editor.PostProcessingManager postProcessingManager;
2025-03-11 17:28:49 -04:00
public Canvas judgeHintCanvas;
2025-05-02 22:34:42 +08:00
public Canvas inspectorCanvas;
public Timeline timeline;
2025-02-28 20:08:00 +08:00
2025-02-08 23:09:50 -05:00
public ProjectInformation projectInformation;
public SongInformation songInformation;
public BeatmapContainer beatmapContainer;
public CommandScripts commandScripts;
2025-02-28 20:08:00 +08:00
2025-02-02 08:34:54 -05:00
public NoteBase.NoteJudgeType currentJudgeType;
2025-06-29 21:28:49 +08:00
public bool useNotePrefab = true;
public bool ExpandWhileClick = false;
public BasePrefabsCollection basePrefabs;
2025-06-28 03:01:03 -04:00
public Dictionary<string, CustomPrefabsCollection> customPrefabs;
2025-05-03 01:08:29 -04:00
public NoteAudioCollection noteAudioCollection;
2025-05-02 22:34:42 +08:00
2025-03-20 19:30:42 -04:00
[Title("Runtime Global Elements")]
public VariablesContainer variablesContainer;
public BackgroundSetter backgroundSetter;
2025-02-02 08:34:54 -05:00
private void Awake()
{
instance = this;
2025-03-01 21:26:16 -05:00
isLoaded = false;
2025-02-08 23:09:50 -05:00
projectManager = new ProjectManager();
2025-02-19 19:01:21 -05:00
operationManager = new OperationManager();
2025-02-28 20:08:00 +08:00
if (!ES3.FileExists(Application.streamingAssetsPath + "/EditorSettings.es3"))
{
2025-06-08 13:04:13 -04:00
editorSettings = new EditorSettings(300, 3, 100, 100, 60);
EditorSettings.SaveSettings(editorSettings);
2025-06-08 13:04:13 -04:00
Application.targetFrameRate = editorSettings.frameRate;
}
else
{
EditorSettings.LoadSettings(ref editorSettings);
2025-06-08 13:04:13 -04:00
Application.targetFrameRate = editorSettings.frameRate;
}
}
private void Start()
{
2025-06-29 21:28:49 +08:00
StartCoroutine(StartFrameRate());
2025-02-17 14:46:14 -05:00
this.elementName = "EditorManager";
this.elementGuid = Guid.Empty;
uiManager.hierarchy.GenerateTab(this, null);
2025-06-30 16:37:34 +08:00
this.connectedTab.deleteButton.gameObject.SetActive(false);
2025-03-08 14:21:10 -05:00
if (InformationTransistor.instance.isLoadedProject)
{
2025-03-08 18:19:32 -05:00
LoadProject(InformationTransistor.instance.loadedProjectName);
2025-03-08 14:21:10 -05:00
}
else
{
projectManager.GenerateEmptyProject(InformationTransistor.instance.projectInfo_BM, InformationTransistor.instance.songInfo_BM);
projectManager.saveManager.Save();
2025-06-21 09:03:45 -04:00
musicPlayer.audioSource.clip = songInformation.song;
2025-03-08 14:21:10 -05:00
}
2025-05-02 22:34:42 +08:00
2025-03-08 14:21:10 -05:00
isLoaded = true;
2025-03-01 21:26:16 -05:00
}
2025-06-29 21:28:49 +08:00
public float CurrentFrameRate;
public TMP_Text FPStext;
private IEnumerator StartFrameRate()
{
int frameCount = 0;
while (true)
{
CurrentFrameRate = 1f / Time.deltaTime;
if (frameCount == 2)
{
frameCount = 0;
2025-06-30 16:37:34 +08:00
FPStext.text = string.Format("FPS: {0:N2}", CurrentFrameRate);
2025-06-29 21:28:49 +08:00
}
frameCount++;
yield return null;
}
}
2025-03-01 21:26:16 -05:00
private void Update()
{
2025-05-02 22:34:42 +08:00
if (isLoaded) projectManager.autoSaveManager.UpdateAutoSave();
2025-02-28 21:12:20 +08:00
}
2025-03-01 21:26:16 -05:00
2025-03-08 14:21:10 -05:00
public void LoadProject(string projectName)
2025-02-28 21:12:20 +08:00
{
2025-03-08 14:21:10 -05:00
projectManager.loadManager.Load(projectName);
musicPlayer.audioSource.clip = songInformation.song;
2025-02-08 23:09:50 -05:00
beatmapContainer.gameElementList.ForEach(gameElement =>
2025-02-07 10:49:26 -05:00
{
2025-02-08 23:09:50 -05:00
gameElement.AfterInitialize();
2025-05-02 22:34:42 +08:00
2025-02-08 23:09:50 -05:00
gameElement.Refresh();
2025-02-07 10:49:26 -05:00
});
2025-02-17 14:46:14 -05:00
}
2025-03-08 14:21:10 -05:00
2025-02-17 14:46:14 -05:00
public override void SetUpInspector()
{
IHaveInspection inspector = uiManager.inspector;
2025-02-28 20:08:00 +08:00
2025-02-17 14:46:14 -05:00
var container = inspector.GenerateContainer("Editor Manager");
2025-05-02 22:34:42 +08:00
2025-04-14 17:49:47 -04:00
var inGameSettings = container.GenerateSubcontainer(3);
var judgeTypeDropdown = inspector.GenerateDropdown(this, inGameSettings, "Judge Type",
2025-04-20 14:30:28 -04:00
typeof(NoteBase.NoteJudgeType), nameof(currentJudgeType)).AddListenerFunction(() =>
{
foreach (GameElement gameElement in beatmapContainer.gameElementList)
{
if (gameElement is NoteVisualBase noteVisual)
{
noteVisual.Recover();
}
}
});
2025-05-02 22:34:42 +08:00
var useNotePrefabToggle =
2025-04-14 17:49:47 -04:00
inspector.GenerateToggle(this, inGameSettings, "Use Note Prefab", nameof(useNotePrefab));
2025-02-19 09:15:51 -05:00
2025-06-29 21:28:49 +08:00
var ExpandWhileClickToggle =
inspector.GenerateToggle(this, inGameSettings, "Expand Tab While Click", nameof(ExpandWhileClick));
2025-04-14 17:49:47 -04:00
var generation = container.GenerateSubcontainer(3);
2025-02-19 09:15:51 -05:00
var generateFolderButton =
2025-04-14 17:49:47 -04:00
inspector.GenerateButton(this, generation, "Generate Folder",
2025-02-28 20:08:00 +08:00
() => ElementFolder.GenerateElement("Folder", Guid.NewGuid(),
2025-02-19 09:15:51 -05:00
new List<string>(), true, null));
var generateBackgroundSetterButton =
2025-04-14 17:49:47 -04:00
inspector.GenerateButton(this, generation, "Generate Background Setter",
2025-02-19 09:15:51 -05:00
() => BackgroundSetter.GenerateElement("Background Setter", Guid.NewGuid(),
new List<string>(), true, null, false,
2025-02-17 14:46:14 -05:00
"basic", "Skybox", "Background"));
2025-03-20 19:30:42 -04:00
var generateVariablesContainerButton =
2025-04-14 17:49:47 -04:00
inspector.GenerateButton(this, generation, "Generate Variables Container",
2025-03-20 19:30:42 -04:00
() => VariablesContainer.GenerateElement("Variables Container", Guid.NewGuid(),
new List<string>(), true, null, new Dictionary<string, int>()));
2025-05-02 22:34:42 +08:00
2025-02-17 14:46:14 -05:00
projectInformation.SetUpInspector();
songInformation.SetUpInspector();
cameraManager.SetUpInspector();
2025-04-04 15:29:03 -04:00
gridController.SetUpInspector();
}
}
}