239 lines
9.0 KiB
C#
239 lines
9.0 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Dreamteck.Splines.Primitives;
|
|
using Ichni.Editor;
|
|
using Ichni.RhythmGame;
|
|
using Ichni.RhythmGame.Beatmap;
|
|
using Ichni.RhythmGame.ThemeBundles.Basic;
|
|
using Sirenix.OdinInspector;
|
|
using TMPro;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
|
|
namespace Ichni
|
|
{
|
|
public class EditorManager : GameElement
|
|
{
|
|
public static EditorManager instance;
|
|
|
|
public bool isLoaded;
|
|
|
|
public ProjectManager projectManager;
|
|
public AudioManager audioManager;
|
|
public MusicPlayer musicPlayer;
|
|
public EditorUIManager uiManager;
|
|
public EditorSettings editorSettings;
|
|
public OperationManager operationManager;
|
|
public BackgroundController backgroundController;
|
|
public GridController gridController;
|
|
public CameraManager cameraManager;
|
|
public Ichni.Editor.PostProcessingManager postProcessingManager;
|
|
public Canvas judgeHintCanvas;
|
|
public Canvas inspectorCanvas;
|
|
public Timeline timeline;
|
|
|
|
public ProjectInformation projectInformation;
|
|
public SongInformation songInformation;
|
|
public BeatmapContainer beatmapContainer;
|
|
public CommandScripts commandScripts;
|
|
|
|
public NoteBase.NoteJudgeType currentJudgeType;
|
|
public bool useClickSelect;
|
|
public bool useNotePrefab;
|
|
public bool ExpandWhileClick;
|
|
public bool useQuickMove;
|
|
public BasePrefabsCollection basePrefabs;
|
|
public Dictionary<string, CustomPrefabsCollection> customPrefabs;
|
|
|
|
|
|
public NoteAudioCollection noteAudioCollection;
|
|
|
|
[Title("Runtime Global Elements")]
|
|
public VariablesContainer variablesContainer;
|
|
public BackgroundSetter backgroundSetter;
|
|
|
|
private void Awake()
|
|
{
|
|
instance = this;
|
|
isLoaded = false;
|
|
projectManager = new ProjectManager();
|
|
operationManager = new OperationManager();
|
|
|
|
if (!ES3.FileExists(Application.streamingAssetsPath + "/EditorSettings.es3"))
|
|
{
|
|
editorSettings = new EditorSettings(300, 3, 100, 100, 60);
|
|
EditorSettings.SaveSettings(editorSettings);
|
|
Application.targetFrameRate = editorSettings.frameRate;
|
|
}
|
|
else
|
|
{
|
|
EditorSettings.LoadSettings(ref editorSettings);
|
|
Application.targetFrameRate = editorSettings.frameRate;
|
|
}
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
StartCoroutine(StartFrameRate());
|
|
|
|
|
|
this.elementName = "EditorManager";
|
|
this.elementGuid = Guid.Empty;
|
|
uiManager.hierarchy.GenerateTab(this, null);
|
|
this.connectedTab.deleteButton.gameObject.SetActive(false);
|
|
if (InformationTransistor.instance.isLoadedProject)
|
|
{
|
|
LoadProject(InformationTransistor.instance.loadedProjectName);
|
|
}
|
|
else
|
|
{
|
|
projectManager.GenerateEmptyProject(InformationTransistor.instance.projectInfo_BM, InformationTransistor.instance.songInfo_BM);
|
|
projectManager.saveManager.Save();
|
|
musicPlayer.audioSource.clip = songInformation.song;
|
|
}
|
|
|
|
StartCoroutine(beatmapContainer.AfterLoadSet());
|
|
isLoaded = true;
|
|
songInformation.songTime = musicPlayer.audioSource.time - songInformation.offset;
|
|
|
|
}
|
|
public float CurrentFrameRate;
|
|
public TMP_Text FPStext;
|
|
public TMP_Text UIText;
|
|
private IEnumerator StartFrameRate()
|
|
{
|
|
int frameCount = 0;
|
|
while (true)
|
|
{
|
|
CurrentFrameRate = 1f / Time.deltaTime;
|
|
if (frameCount == 2)
|
|
{
|
|
frameCount = 0;
|
|
FPStext.text = string.Format("FPS: {0:N2}", CurrentFrameRate);
|
|
}
|
|
frameCount++;
|
|
yield return null;
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (isLoaded) projectManager.autoSaveManager.UpdateAutoSave();
|
|
}
|
|
|
|
public void LoadProject(string projectName)
|
|
{
|
|
if (!InformationTransistor.instance.isRecovery)
|
|
{
|
|
projectManager.loadManager.Load(projectName);
|
|
Debug.Log("Loaded");
|
|
}
|
|
else
|
|
{
|
|
projectManager.loadManager.LoadExport(projectName);
|
|
}
|
|
|
|
musicPlayer.audioSource.clip = songInformation.song;
|
|
beatmapContainer.gameElementList.ForEach(gameElement =>
|
|
{
|
|
gameElement.AfterInitialize();
|
|
gameElement.Refresh();
|
|
});
|
|
}
|
|
|
|
public override void SetUpInspector()
|
|
{
|
|
IHaveInspection inspector = uiManager.inspector;
|
|
|
|
var container = inspector.GenerateContainer("Editor Manager");
|
|
|
|
var inGameSettings = container.GenerateSubcontainer(3);
|
|
var judgeTypeDropdown = inspector.GenerateDropdown(this, inGameSettings, "Judge Type",
|
|
typeof(NoteBase.NoteJudgeType), nameof(currentJudgeType)).AddListenerFunction(() =>
|
|
{
|
|
foreach (GameElement gameElement in beatmapContainer.gameElementList)
|
|
{
|
|
if (gameElement is NoteVisualBase noteVisual)
|
|
{
|
|
noteVisual.Recover();
|
|
}
|
|
}
|
|
});
|
|
var useNotePrefabToggle =
|
|
inspector.GenerateToggle(this, inGameSettings, "Use Note Prefab", nameof(useNotePrefab));
|
|
var useClickSelectToggle =
|
|
inspector.GenerateToggle(this, inGameSettings, "Use Click Select", nameof(useClickSelect));
|
|
var ExpandWhileClickToggle =
|
|
inspector.GenerateToggle(this, inGameSettings, "Expand Tab While Click", nameof(ExpandWhileClick));
|
|
|
|
var useQuickMoveToggle =
|
|
inspector.GenerateToggle(this, inGameSettings, "Use Quick Move", nameof(useQuickMove));
|
|
|
|
var generation = container.GenerateSubcontainer(3);
|
|
var generateFolderButton =
|
|
inspector.GenerateButton(this, generation, "Generate Folder",
|
|
() => ElementFolder.GenerateElement("Folder", Guid.NewGuid(),
|
|
new List<string>(), true, null));
|
|
var generateBackgroundSetterButton =
|
|
inspector.GenerateButton(this, generation, "Generate Background Setter",
|
|
() => BackgroundSetter.GenerateElement("Background Setter", Guid.NewGuid(),
|
|
new List<string>(), true, null, false,
|
|
"basic", "Skybox", "Background"));
|
|
var generateVariablesContainerButton =
|
|
inspector.GenerateButton(this, generation, "Generate Variables Container",
|
|
() => VariablesContainer.GenerateElement("Variables Container", Guid.NewGuid(),
|
|
new List<string>(), true, null, new Dictionary<string, int>()));
|
|
|
|
projectInformation.SetUpInspector();
|
|
songInformation.SetUpInspector();
|
|
cameraManager.SetUpInspector();
|
|
gridController.SetUpInspector();
|
|
}
|
|
|
|
|
|
private bool isQuit = false;
|
|
[Obsolete]
|
|
public void OnApplicationQuit()
|
|
{
|
|
if (isQuit) return;
|
|
|
|
Application.CancelQuit();//退出拦截
|
|
GeneralSecondaryWindow QuitWindow =
|
|
Instantiate(EditorManager.instance.basePrefabs.generalSecondaryWindow,
|
|
EditorManager.instance.uiManager.mainPage.mainCanvas.GetComponent<RectTransform>()).GetComponent<GeneralSecondaryWindow>();
|
|
|
|
QuitWindow.Initialize("Do You Want To Save?", () =>
|
|
{
|
|
Destroy(QuitWindow.gameObject);
|
|
});
|
|
|
|
|
|
var container = QuitWindow.GenerateContainer("Save confirm");
|
|
var beatmapToolsSettings = container.GenerateSubcontainer(3);
|
|
var yesButton = QuitWindow.GenerateButton(beatmapToolsSettings, "Yes", () =>
|
|
{
|
|
isQuit = true;
|
|
EditorManager.instance.projectManager.saveManager.Save();
|
|
Application.Quit();
|
|
|
|
});
|
|
var noButton = QuitWindow.GenerateButton(beatmapToolsSettings, "No", () =>
|
|
{
|
|
isQuit = true;
|
|
Application.Quit();
|
|
});
|
|
|
|
// if (isQuit)
|
|
// {
|
|
// Application.CancelQuit();//退出拦截
|
|
// MessageCtrl.Instance.OpenConfirmView("关闭界面将终止,确认关闭?", "", () =>
|
|
// {
|
|
// isQuit = false;
|
|
// Application.Quit();
|
|
// });
|
|
// }
|
|
|
|
}
|
|
}
|
|
} |