修复一些内容

This commit is contained in:
2025-11-25 12:00:00 +08:00
parent 5d6acc1001
commit 1dc2109a18
142 changed files with 48762 additions and 43124 deletions

View File

@@ -46,172 +46,172 @@ namespace Demo.Game
public IEnumerator GameInit()
{
GameContent content = GameContent.instance;
yield return new WaitUntil(() => content != null);
try
{
RootSourcePath = content.RootSourceDir;
MainConfig = new(content.RootSourceDir, content.IsCreateNewProject, true);
Debug.Log($"{content.RootSourceDir} loading", this);
}
catch (Exception ex)
{
Debug.LogException(ex, this);
Debug.LogError($"{content.RootSourceDir} is not a valid project", this);
StartCoroutine(GameExit());
yield break;
}
GameContent content = GameContent.instance;
yield return new WaitUntil(() => content != null);
// Load Song
if (Editor.EditorController.instance.MainGameController == this)
{
string clipPath = (string)MainConfig.FindItem("song", "");
AudioType audioType = (AudioType)MainConfig.FindItem("audioType", BasicAudioSystem.GetAudioType(clipPath));
if (string.IsNullOrEmpty(clipPath))
try
{
foreach (var file in MainConfig.ConfigFile.BackToParentDir().DirToolFileIter())
{
if (file.IsFile() && !file.IsFileEmpty())
{
if (BasicAudioSystem.GetAudioType(file.GetExtension()) != AudioType.UNKNOWN)
{
clipPath = file.GetFullPath();
break;
}
}
}
RootSourcePath = content.RootSourceDir;
MainConfig = new(content.RootSourceDir, content.IsCreateNewProject, true);
Debug.Log($"{content.RootSourceDir} loading", this);
}
if (string.IsNullOrEmpty(clipPath) == false)
catch (Exception ex)
{
IEnumerator Run()
{
#if ENABLE_CLASS_Interaction
var clipFile = new Interaction(clipPath);
#else
var clipFile = new ToolFile(clipPath);
#endif
if (clipFile.Exists() == false)
clipFile = new(MainConfig.GetFile(clipPath).GetFullPath());
if (clipFile.Exists() == false)
{
Debug.LogError($"Cannt load {clipPath}", this);
yield break;
}
yield return MainAudio.LoadAudio(clipFile, audioType);
content.SongLoadOverCallback(MainAudio);
yield return GameAudioSystemInit();
}
StartCoroutine(Run());
}
}
else
{
MainAudio = Editor.EditorController.instance.MainGameController.MainAudio;
yield return GameAudioSystemInit();
}
yield return null;
// Setup Game Rules (Main)
if (Editor.EditorController.instance.MainGameController == this)
{
// Config ScriptableObject
{
ScriptableObject.FastScriptableObjectTypen = content.ScriptableObjectTypen;
ScriptableObject.IsAutoPlay = content.IsAutoPlay;
ScriptableObject.OneBarTime = 60.0f / (float)MainConfig.FindItem(nameof(Editor.EditorController.BPM), Editor.EditorController.instance.BPM);
}
// Default IInteraction
{
IInteraction.DefaultInteractableIntervalLengthThatCanScoreBest = (float)MainConfig.FindItem(
nameof(IInteraction.DefaultInteractableIntervalLengthThatCanScoreBest),
IInteraction.DefaultInteractableIntervalLengthThatCanScoreBest);
IInteraction.DefaultInteractableScoreIntervalLength = (float)MainConfig.FindItem(
nameof(IInteraction.DefaultInteractableScoreIntervalLength),
IInteraction.DefaultInteractableScoreIntervalLength);
IInteraction.DefaultInteractiveLength = (float)MainConfig.FindItem(
nameof(IInteraction.DefaultInteractiveLength),
IInteraction.DefaultInteractiveLength);
IInteraction.DefaultVisibleLength = (float)MainConfig.FindItem(
nameof(IInteraction.DefaultVisibleLength),
IInteraction.DefaultVisibleLength);
}
// Config Game
{
SongOffset = (float)MainConfig.FindItem(nameof(SongOffset), SongOffset);
SetupSongDuration = GameContent.instance.SetupSongDuration;
SetSongCurrentTime = GameContent.instance.SetSongCurrentTime;
}
}
// Setup Game Rules
{
foreach (var ab in ((string)MainConfig.FindItem(nameof(AssetBundle), "")).Split(';'))
{
if (string.IsNullOrEmpty(ab))
continue;
StartCoroutine(AssetBundlesLoadHelper.LoadAssetBundleAsync(ab.Trim(), null));
}
IsAutoPlay = GameContent.instance.IsAutoPlay;
WhichOpenScript = (string)MainConfig.FindItem(nameof(WhichOpenScript), WhichOpenScript);
// Open Project
WhichOpenProject = (string)MainConfig.FindItem(nameof(WhichOpenProject), WhichOpenProject);
if (string.IsNullOrEmpty(WhichOpenProject) == false)
{
string path = string.Format($"{WhichOpenProject}", $"\"{Editor.EditorController.instance.PersistentDataPath}\"");
try
{
System.Diagnostics.Process.Start(path);
}
catch (Exception ex)
{
Debug.LogError($"Cannt open {path}", this);
Debug.LogException(ex, this);
}
}
}
MainConfig.SaveProperties();
yield return null;
// Load Root Object
{
while (MainConfig.Contains("root") == false)
{
string defaultRootPath = "root.rscript";
if (content.IsCreateNewProject)
{
MainConfig["root"] = defaultRootPath;
if (MainConfig.CreateFile(defaultRootPath))
{
MainConfig.SaveProperties();
break;
}
}
Debug.LogError($"{nameof(defaultRootPath)} is cannt create or config's root property is not exist", this);
Debug.LogException(ex, this);
Debug.LogError($"{content.RootSourceDir} is not a valid project", this);
StartCoroutine(GameExit());
yield break;
}
var rootFileName = (string)MainConfig.FindItem("root");
var rootObject = new ToolFile(Path.Combine(content.RootSourceDir, rootFileName));
rootObject.MustExistsPath();
var rootGameObject = new GameObject(rootObject.GetName(true)).AddComponent<RootObject>();
rootGameObject.transform.SetParent(transform);
rootGameObject.ScriptName = rootObject.GetName(true);
rootGameObject.audioSystem = MainAudio;
rootGameObject.EnableScript(content.RootSourceDir, this);
try
// Load Song
if (Editor.EditorController.instance.MainGameController == this)
{
yield return rootGameObject.ParseScript2Expr(rootObject.LoadAsText());
yield return rootGameObject.ApplyScript();
string clipPath = (string)MainConfig.FindItem("song", "");
AudioType audioType = (AudioType)MainConfig.FindItem("audioType", BasicAudioSystem.GetAudioType(clipPath));
if (string.IsNullOrEmpty(clipPath))
{
foreach (var file in MainConfig.ConfigFile.BackToParentDir().DirToolFileIter())
{
if (file.IsFile() && !file.IsFileEmpty())
{
if (BasicAudioSystem.GetAudioType(file.GetExtension()) != AudioType.UNKNOWN)
{
clipPath = file.GetFullPath();
break;
}
}
}
}
if (string.IsNullOrEmpty(clipPath) == false)
{
IEnumerator Run()
{
#if ENABLE_CLASS_Interaction
var clipFile = new Interaction(clipPath);
#else
var clipFile = new ToolFile(clipPath);
#endif
if (clipFile.Exists() == false)
clipFile = new(MainConfig.GetFile(clipPath).GetFullPath());
if (clipFile.Exists() == false)
{
Debug.LogError($"Cannt load {clipPath}", this);
yield break;
}
yield return MainAudio.LoadAudio(clipFile, audioType);
content.SongLoadOverCallback(MainAudio);
yield return GameAudioSystemInit();
}
StartCoroutine(Run());
}
}
finally
else
{
MainObject = rootGameObject;
MainAudio = Editor.EditorController.instance.MainGameController.MainAudio;
yield return GameAudioSystemInit();
}
yield return null;
// Setup Game Rules (Main)
if (Editor.EditorController.instance.MainGameController == this)
{
// Config ScriptableObject
{
ScriptableObject.FastScriptableObjectTypen = content.ScriptableObjectTypen;
ScriptableObject.IsAutoPlay = content.IsAutoPlay;
ScriptableObject.OneBarTime = 60.0f / (float)MainConfig.FindItem(nameof(Editor.EditorController.BPM), Editor.EditorController.instance.BPM);
}
// Default IInteraction
{
IInteraction.DefaultInteractableIntervalLengthThatCanScoreBest = (float)MainConfig.FindItem(
nameof(IInteraction.DefaultInteractableIntervalLengthThatCanScoreBest),
IInteraction.DefaultInteractableIntervalLengthThatCanScoreBest);
IInteraction.DefaultInteractableScoreIntervalLength = (float)MainConfig.FindItem(
nameof(IInteraction.DefaultInteractableScoreIntervalLength),
IInteraction.DefaultInteractableScoreIntervalLength);
IInteraction.DefaultInteractiveLength = (float)MainConfig.FindItem(
nameof(IInteraction.DefaultInteractiveLength),
IInteraction.DefaultInteractiveLength);
IInteraction.DefaultVisibleLength = (float)MainConfig.FindItem(
nameof(IInteraction.DefaultVisibleLength),
IInteraction.DefaultVisibleLength);
}
// Config Game
{
SongOffset = (float)MainConfig.FindItem(nameof(SongOffset), SongOffset);
SetupSongDuration = GameContent.instance.SetupSongDuration;
SetSongCurrentTime = GameContent.instance.SetSongCurrentTime;
}
}
// Setup Game Rules
{
foreach (var ab in ((string)MainConfig.FindItem(nameof(AssetBundle), "")).Split(';'))
{
if (string.IsNullOrEmpty(ab))
continue;
StartCoroutine(AssetBundlesLoadHelper.LoadAssetBundleAsync(ab.Trim(), null));
}
IsAutoPlay = GameContent.instance.IsAutoPlay;
WhichOpenScript = (string)MainConfig.FindItem(nameof(WhichOpenScript), WhichOpenScript);
// Open Project
WhichOpenProject = (string)MainConfig.FindItem(nameof(WhichOpenProject), WhichOpenProject);
if (string.IsNullOrEmpty(WhichOpenProject) == false)
{
string path = string.Format($"{WhichOpenProject}", $"\"{Editor.EditorController.instance.PersistentDataPath}\"");
try
{
System.Diagnostics.Process.Start(path);
}
catch (Exception ex)
{
Debug.LogError($"Cannt open {path}", this);
Debug.LogException(ex, this);
}
}
}
// Load Root Object
{
while (MainConfig.Contains("root") == false)
{
string defaultRootPath = "root.rscript";
if (content.IsCreateNewProject)
{
MainConfig["root"] = defaultRootPath;
}
else
{
Debug.LogError($"{nameof(defaultRootPath)} is cannt create or config's root property is not exist", this);
StartCoroutine(GameExit());
yield break;
}
}
var rootFileName = (string)MainConfig.FindItem("root");
var rootObject = new ToolFile(Path.Combine(content.RootSourceDir, rootFileName));
rootObject.MustExistsPath();
var rootGameObject = new GameObject(rootObject.GetName(true)).AddComponent<RootObject>();
rootGameObject.transform.SetParent(transform);
rootGameObject.ScriptName = rootObject.GetName(true);
rootGameObject.audioSystem = MainAudio;
rootGameObject.EnableScript(content.RootSourceDir, this);
try
{
yield return rootGameObject.ParseScript2Expr(rootObject.LoadAsText());
yield return rootGameObject.ApplyScript();
}
finally
{
MainObject = rootGameObject;
}
}
}
finally
{
MainConfig.SaveProperties();
}
}
@@ -357,11 +357,16 @@ namespace Demo.Game
{
try
{
Stop();
yield return MainObject.UnloadScript();
if (MainObject)
{
Stop();
yield return MainObject.UnloadScript();
}
}
finally
{
// 预防一些情况
MainConfig.SaveProperties();
if (MainObject)
Destroy(MainObject.gameObject);
if (Editor.EditorController.instance.MainGameController == this)

View File

@@ -2,15 +2,11 @@ using Convention;
using Convention.RScript;
using Convention.WindowsUI.Variant;
using Demo.Game;
using Flee.PublicTypes;
using Sirenix.OdinInspector;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using Unity.Profiling;
using UnityEngine;
@@ -458,13 +454,20 @@ namespace Demo
/// <para>使用<see cref="Convention.RScript.Variable.Attr.MethodAttribute"/>标记可编辑脚本所能够调用的函数</para>
/// <para>使用<see cref="Convention.RScript.Variable.Attr.DefaultAttribute"/>标记派生类,并附加默认模板</para>
/// </summary>
public partial class ScriptableObject : SerializedMonoBehaviour, IHierarchyItemClickEventListener
public partial class ScriptableObject :
#if ENABLE_SerializedMonoBehaviour_CLASS
SerializedMonoBehaviour,
#else
MonoBehaviour,
#endif
IHierarchyItemClickEventListener
{
protected virtual IEnumerator DoSomethingDuringApplyScript()
{
yield break;
}
[Convention.RScript.Variable.Attr.Method]
public IEnumerator ApplyScript()
{
if (EnsureEnableScript() == false)
@@ -530,7 +533,7 @@ namespace Demo
}
}
#endregion
#endregion
public interface IAssetBundleLoader : IScriptableObject
{