From cbe042fec169cb619810c7e6b466557e36d8b532 Mon Sep 17 00:00:00 2001 From: Ding Yuntian <1491671119@qq.com> Date: Mon, 24 Mar 2025 20:47:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=AD=98=E5=82=A8=E7=B3=BB=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FMOD/Resources/FMODStudioSettings.asset | 686 +++++++++--------- Assets/Scripts/Framework/Core/Core.cs | 89 ++- Assets/Scripts/Game Loop/StorageSystem.cs | 110 ++- 3 files changed, 513 insertions(+), 372 deletions(-) diff --git a/Assets/Plugins/FMOD/Resources/FMODStudioSettings.asset b/Assets/Plugins/FMOD/Resources/FMODStudioSettings.asset index 231cfd48f..d2fb5278a 100644 --- a/Assets/Plugins/FMOD/Resources/FMODStudioSettings.asset +++ b/Assets/Plugins/FMOD/Resources/FMODStudioSettings.asset @@ -1,6 +1,6 @@ %YAML 1.1 %TAG !u! tag:unity3d.com,2011: ---- !u!114 &-6421979802148699356 +--- !u!114 &-7599089935785178640 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -9,10 +9,10 @@ MonoBehaviour: m_GameObject: {fileID: 0} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 73549a74f689f0849a8271d9e908c514, type: 3} + m_Script: {fileID: 11500000, guid: 97ba6cc2660c0ca498540d254701057a, type: 3} m_Name: FMODStudioSettingsPlatform m_EditorClassIdentifier: - identifier: b7716510a1f36934c87976f3a81dbf3d + identifier: 2fea114e74ecf3c4f920e1d5cc1c4c40 parentIdentifier: default active: 0 Properties: @@ -73,7 +73,7 @@ MonoBehaviour: codecChannels: Value: [] HasValue: 0 ---- !u!114 &-2493609972237370556 +--- !u!114 &-5493265246809852409 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -146,7 +146,7 @@ MonoBehaviour: codecChannels: Value: [] HasValue: 0 ---- !u!114 &-1580684736993228498 +--- !u!114 &-4289928003684796904 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -155,10 +155,10 @@ MonoBehaviour: m_GameObject: {fileID: 0} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: b87314b32fbe18943af496e4b47136c6, type: 3} + m_Script: {fileID: 11500000, guid: 93a382382f106584e8f8f62412fee177, type: 3} m_Name: FMODStudioSettingsPlatform m_EditorClassIdentifier: - identifier: 46fbfdf3fc43db0458918377fd40293e + identifier: fd7c55dab0fce234b8c25f6ffca523c1 parentIdentifier: default active: 0 Properties: @@ -219,7 +219,163 @@ MonoBehaviour: codecChannels: Value: [] HasValue: 0 ---- !u!114 &-785679389004310805 +--- !u!114 &-2619252103634704479 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9587379c972e4a54da1949613f11e1c6, type: 3} + m_Name: FMODStudioSettingsPlatform + m_EditorClassIdentifier: + identifier: default + parentIdentifier: + active: 1 + Properties: + LiveUpdate: + Value: 0 + HasValue: 0 + LiveUpdatePort: + Value: 9264 + HasValue: 1 + Overlay: + Value: 0 + HasValue: 0 + OverlayPosition: + Value: 0 + HasValue: 0 + OverlayFontSize: + Value: 0 + HasValue: 0 + Logging: + Value: 0 + HasValue: 0 + SampleRate: + Value: 0 + HasValue: 0 + BuildDirectory: + Value: + HasValue: 0 + SpeakerMode: + Value: 0 + HasValue: 0 + VirtualChannelCount: + Value: 0 + HasValue: 0 + RealChannelCount: + Value: 0 + HasValue: 0 + DSPBufferLength: + Value: 0 + HasValue: 0 + DSPBufferCount: + Value: 0 + HasValue: 0 + Plugins: + Value: [] + HasValue: 1 + StaticPlugins: + Value: [] + HasValue: 1 + CallbackHandler: + Value: {fileID: 0} + HasValue: 0 + OutputTypeName: + threadAffinities: + Value: [] + HasValue: 0 + displaySortOrder: 0 + childIdentifiers: + - 0f8eb3f400726694eb47beb1a9f94ce8 + - 46fbfdf3fc43db0458918377fd40293e + - 2fea114e74ecf3c4f920e1d5cc1c4c40 + - e7a046c753c3c3d4aacc91f6597f310d + - 52eb9df5db46521439908db3a29a1bbb + - 2c5177b11d81d824dbb064f9ac8527da + - b7716510a1f36934c87976f3a81dbf3d + - c88d16e5272a4e241b0ef0ac2e53b73d + - de700ef3f37a49b58a57ae3addf01ad9 + - fd7c55dab0fce234b8c25f6ffca523c1 + codecChannels: + Value: [] + HasValue: 0 +--- !u!114 &-2507512691418502381 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3abeb1429547a134480f4f2f1efc7e21, type: 3} + m_Name: FMODStudioSettingsPlatform + m_EditorClassIdentifier: + identifier: c88d16e5272a4e241b0ef0ac2e53b73d + parentIdentifier: default + active: 0 + Properties: + LiveUpdate: + Value: 0 + HasValue: 0 + LiveUpdatePort: + Value: 0 + HasValue: 0 + Overlay: + Value: 0 + HasValue: 0 + OverlayPosition: + Value: 0 + HasValue: 0 + OverlayFontSize: + Value: 0 + HasValue: 0 + Logging: + Value: 0 + HasValue: 0 + SampleRate: + Value: 0 + HasValue: 0 + BuildDirectory: + Value: + HasValue: 0 + SpeakerMode: + Value: 0 + HasValue: 0 + VirtualChannelCount: + Value: 0 + HasValue: 0 + RealChannelCount: + Value: 0 + HasValue: 0 + DSPBufferLength: + Value: 0 + HasValue: 0 + DSPBufferCount: + Value: 0 + HasValue: 0 + Plugins: + Value: [] + HasValue: 0 + StaticPlugins: + Value: [] + HasValue: 0 + CallbackHandler: + Value: {fileID: 0} + HasValue: 0 + OutputTypeName: + threadAffinities: + Value: [] + HasValue: 0 + displaySortOrder: 0 + childIdentifiers: [] + codecChannels: + Value: [] + HasValue: 0 +--- !u!114 &-1855877162769961118 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -292,7 +448,7 @@ MonoBehaviour: codecChannels: Value: [] HasValue: 0 ---- !u!114 &-712030531834803398 +--- !u!114 &-1279143063320469121 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -301,10 +457,83 @@ MonoBehaviour: m_GameObject: {fileID: 0} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 93a382382f106584e8f8f62412fee177, type: 3} + m_Script: {fileID: 11500000, guid: 17eea195bdfbf014e91ba7620ee491f8, type: 3} m_Name: FMODStudioSettingsPlatform m_EditorClassIdentifier: - identifier: fd7c55dab0fce234b8c25f6ffca523c1 + identifier: e7a046c753c3c3d4aacc91f6597f310d + parentIdentifier: default + active: 0 + Properties: + LiveUpdate: + Value: 0 + HasValue: 0 + LiveUpdatePort: + Value: 0 + HasValue: 0 + Overlay: + Value: 0 + HasValue: 0 + OverlayPosition: + Value: 0 + HasValue: 0 + OverlayFontSize: + Value: 0 + HasValue: 0 + Logging: + Value: 0 + HasValue: 0 + SampleRate: + Value: 0 + HasValue: 0 + BuildDirectory: + Value: + HasValue: 0 + SpeakerMode: + Value: 0 + HasValue: 0 + VirtualChannelCount: + Value: 0 + HasValue: 0 + RealChannelCount: + Value: 0 + HasValue: 0 + DSPBufferLength: + Value: 0 + HasValue: 0 + DSPBufferCount: + Value: 0 + HasValue: 0 + Plugins: + Value: [] + HasValue: 0 + StaticPlugins: + Value: [] + HasValue: 0 + CallbackHandler: + Value: {fileID: 0} + HasValue: 0 + OutputTypeName: + threadAffinities: + Value: [] + HasValue: 0 + displaySortOrder: 0 + childIdentifiers: [] + codecChannels: + Value: [] + HasValue: 0 +--- !u!114 &-634705678149131141 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9660e62d6232af242877f0cc2b90c63d, type: 3} + m_Name: FMODStudioSettingsPlatform + m_EditorClassIdentifier: + identifier: 2c5177b11d81d824dbb064f9ac8527da parentIdentifier: default active: 0 Properties: @@ -379,13 +608,13 @@ MonoBehaviour: m_EditorClassIdentifier: switchSettingsMigration: 1 HasSourceProject: 0 - HasPlatforms: 0 + HasPlatforms: 1 sourceProjectPath: - sourceBankPath: Assets/FMOD Banks/Desktop + sourceBankPath: Assets/FMOD Banks sourceBankPathUnformatted: BankRefreshCooldown: 5 ShowBankRefreshWindow: 1 - AutomaticEventLoading: 0 + AutomaticEventLoading: 1 BankLoadType: 0 AutomaticSampleLoading: 0 EncryptionKey: @@ -403,14 +632,14 @@ MonoBehaviour: RealChannelSettings: [] Plugins: [] MasterBanks: - - Master + - Desktop/Master Banks: - - Ambience - - Environment - - Interactions - - Music - - UI - - VO + - Desktop/Ambience + - Desktop/Environment + - Desktop/Interactions + - Desktop/Music + - Desktop/UI + - Desktop/VO BanksToLoad: [] LiveUpdatePort: 9264 EnableMemoryTracking: 0 @@ -426,20 +655,20 @@ MonoBehaviour: HideSetupWizard: 1 LastEventReferenceScanVersion: 131621 Platforms: - - {fileID: -6421979802148699356} - - {fileID: -2493609972237370556} - - {fileID: -1580684736993228498} - - {fileID: -785679389004310805} - - {fileID: -712030531834803398} - - {fileID: 1100827045814593625} - - {fileID: 1132312529069990576} - - {fileID: 3979222738758991920} - - {fileID: 5613685733850034091} - - {fileID: 6330521338056678831} - - {fileID: 6477534247104662684} - - {fileID: 9010303474896345012} - MigratedPlatforms: 0500000000000000060000000a0000000800000009000000120000000c000000150000000b0000000200000001000000 ---- !u!114 &1100827045814593625 + - {fileID: 4397086664669695925} + - {fileID: -2619252103634704479} + - {fileID: 7223939234266169234} + - {fileID: 4669352974370910123} + - {fileID: -7599089935785178640} + - {fileID: -1279143063320469121} + - {fileID: -1855877162769961118} + - {fileID: -634705678149131141} + - {fileID: 9199457959637037873} + - {fileID: -2507512691418502381} + - {fileID: -5493265246809852409} + - {fileID: -4289928003684796904} + MigratedPlatforms: 150000000a0000000800000005000000060000000c0000000b0000001200000000000000090000000200000001000000 +--- !u!114 &4397086664669695925 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -448,10 +677,83 @@ MonoBehaviour: m_GameObject: {fileID: 0} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 97ba6cc2660c0ca498540d254701057a, type: 3} + m_Script: {fileID: 11500000, guid: 335f0a4b26fb46942858ea029e030d2a, type: 3} m_Name: FMODStudioSettingsPlatform m_EditorClassIdentifier: - identifier: 2fea114e74ecf3c4f920e1d5cc1c4c40 + identifier: playInEditor + parentIdentifier: + active: 1 + Properties: + LiveUpdate: + Value: 0 + HasValue: 1 + LiveUpdatePort: + Value: 0 + HasValue: 0 + Overlay: + Value: 1 + HasValue: 1 + OverlayPosition: + Value: 0 + HasValue: 0 + OverlayFontSize: + Value: 0 + HasValue: 0 + Logging: + Value: 0 + HasValue: 0 + SampleRate: + Value: 48000 + HasValue: 1 + BuildDirectory: + Value: + HasValue: 0 + SpeakerMode: + Value: 0 + HasValue: 0 + VirtualChannelCount: + Value: 1024 + HasValue: 1 + RealChannelCount: + Value: 256 + HasValue: 1 + DSPBufferLength: + Value: 0 + HasValue: 0 + DSPBufferCount: + Value: 0 + HasValue: 0 + Plugins: + Value: [] + HasValue: 0 + StaticPlugins: + Value: [] + HasValue: 0 + CallbackHandler: + Value: {fileID: 0} + HasValue: 0 + OutputTypeName: + threadAffinities: + Value: [] + HasValue: 0 + displaySortOrder: 0 + childIdentifiers: [] + codecChannels: + Value: [] + HasValue: 0 +--- !u!114 &4669352974370910123 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: b87314b32fbe18943af496e4b47136c6, type: 3} + m_Name: FMODStudioSettingsPlatform + m_EditorClassIdentifier: + identifier: 46fbfdf3fc43db0458918377fd40293e parentIdentifier: default active: 0 Properties: @@ -512,80 +814,7 @@ MonoBehaviour: codecChannels: Value: [] HasValue: 0 ---- !u!114 &1132312529069990576 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 0} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 9660e62d6232af242877f0cc2b90c63d, type: 3} - m_Name: FMODStudioSettingsPlatform - m_EditorClassIdentifier: - identifier: 2c5177b11d81d824dbb064f9ac8527da - parentIdentifier: default - active: 0 - Properties: - LiveUpdate: - Value: 0 - HasValue: 0 - LiveUpdatePort: - Value: 0 - HasValue: 0 - Overlay: - Value: 0 - HasValue: 0 - OverlayPosition: - Value: 0 - HasValue: 0 - OverlayFontSize: - Value: 0 - HasValue: 0 - Logging: - Value: 0 - HasValue: 0 - SampleRate: - Value: 0 - HasValue: 0 - BuildDirectory: - Value: - HasValue: 0 - SpeakerMode: - Value: 0 - HasValue: 0 - VirtualChannelCount: - Value: 0 - HasValue: 0 - RealChannelCount: - Value: 0 - HasValue: 0 - DSPBufferLength: - Value: 0 - HasValue: 0 - DSPBufferCount: - Value: 0 - HasValue: 0 - Plugins: - Value: [] - HasValue: 0 - StaticPlugins: - Value: [] - HasValue: 0 - CallbackHandler: - Value: {fileID: 0} - HasValue: 0 - OutputTypeName: - threadAffinities: - Value: [] - HasValue: 0 - displaySortOrder: 0 - childIdentifiers: [] - codecChannels: - Value: [] - HasValue: 0 ---- !u!114 &3979222738758991920 +--- !u!114 &7223939234266169234 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -658,7 +887,7 @@ MonoBehaviour: codecChannels: Value: [] HasValue: 0 ---- !u!114 &5613685733850034091 +--- !u!114 &9199457959637037873 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -667,10 +896,10 @@ MonoBehaviour: m_GameObject: {fileID: 0} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 3abeb1429547a134480f4f2f1efc7e21, type: 3} + m_Script: {fileID: 11500000, guid: 73549a74f689f0849a8271d9e908c514, type: 3} m_Name: FMODStudioSettingsPlatform m_EditorClassIdentifier: - identifier: c88d16e5272a4e241b0ef0ac2e53b73d + identifier: b7716510a1f36934c87976f3a81dbf3d parentIdentifier: default active: 0 Properties: @@ -731,232 +960,3 @@ MonoBehaviour: codecChannels: Value: [] HasValue: 0 ---- !u!114 &6330521338056678831 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 0} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 9587379c972e4a54da1949613f11e1c6, type: 3} - m_Name: FMODStudioSettingsPlatform - m_EditorClassIdentifier: - identifier: default - parentIdentifier: - active: 1 - Properties: - LiveUpdate: - Value: 0 - HasValue: 0 - LiveUpdatePort: - Value: 9264 - HasValue: 1 - Overlay: - Value: 0 - HasValue: 0 - OverlayPosition: - Value: 0 - HasValue: 0 - OverlayFontSize: - Value: 0 - HasValue: 0 - Logging: - Value: 0 - HasValue: 0 - SampleRate: - Value: 0 - HasValue: 0 - BuildDirectory: - Value: - HasValue: 0 - SpeakerMode: - Value: 0 - HasValue: 0 - VirtualChannelCount: - Value: 0 - HasValue: 0 - RealChannelCount: - Value: 0 - HasValue: 0 - DSPBufferLength: - Value: 0 - HasValue: 0 - DSPBufferCount: - Value: 0 - HasValue: 0 - Plugins: - Value: [] - HasValue: 1 - StaticPlugins: - Value: [] - HasValue: 1 - CallbackHandler: - Value: {fileID: 0} - HasValue: 0 - OutputTypeName: - threadAffinities: - Value: [] - HasValue: 0 - displaySortOrder: 0 - childIdentifiers: - - b7716510a1f36934c87976f3a81dbf3d - - de700ef3f37a49b58a57ae3addf01ad9 - - 46fbfdf3fc43db0458918377fd40293e - - 52eb9df5db46521439908db3a29a1bbb - - fd7c55dab0fce234b8c25f6ffca523c1 - - 2fea114e74ecf3c4f920e1d5cc1c4c40 - - 2c5177b11d81d824dbb064f9ac8527da - - 0f8eb3f400726694eb47beb1a9f94ce8 - - c88d16e5272a4e241b0ef0ac2e53b73d - - e7a046c753c3c3d4aacc91f6597f310d - codecChannels: - Value: [] - HasValue: 0 ---- !u!114 &6477534247104662684 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 0} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 17eea195bdfbf014e91ba7620ee491f8, type: 3} - m_Name: FMODStudioSettingsPlatform - m_EditorClassIdentifier: - identifier: e7a046c753c3c3d4aacc91f6597f310d - parentIdentifier: default - active: 0 - Properties: - LiveUpdate: - Value: 0 - HasValue: 0 - LiveUpdatePort: - Value: 0 - HasValue: 0 - Overlay: - Value: 0 - HasValue: 0 - OverlayPosition: - Value: 0 - HasValue: 0 - OverlayFontSize: - Value: 0 - HasValue: 0 - Logging: - Value: 0 - HasValue: 0 - SampleRate: - Value: 0 - HasValue: 0 - BuildDirectory: - Value: - HasValue: 0 - SpeakerMode: - Value: 0 - HasValue: 0 - VirtualChannelCount: - Value: 0 - HasValue: 0 - RealChannelCount: - Value: 0 - HasValue: 0 - DSPBufferLength: - Value: 0 - HasValue: 0 - DSPBufferCount: - Value: 0 - HasValue: 0 - Plugins: - Value: [] - HasValue: 0 - StaticPlugins: - Value: [] - HasValue: 0 - CallbackHandler: - Value: {fileID: 0} - HasValue: 0 - OutputTypeName: - threadAffinities: - Value: [] - HasValue: 0 - displaySortOrder: 0 - childIdentifiers: [] - codecChannels: - Value: [] - HasValue: 0 ---- !u!114 &9010303474896345012 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 0} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 335f0a4b26fb46942858ea029e030d2a, type: 3} - m_Name: FMODStudioSettingsPlatform - m_EditorClassIdentifier: - identifier: playInEditor - parentIdentifier: - active: 1 - Properties: - LiveUpdate: - Value: 1 - HasValue: 1 - LiveUpdatePort: - Value: 0 - HasValue: 0 - Overlay: - Value: 1 - HasValue: 1 - OverlayPosition: - Value: 0 - HasValue: 0 - OverlayFontSize: - Value: 0 - HasValue: 0 - Logging: - Value: 0 - HasValue: 0 - SampleRate: - Value: 48000 - HasValue: 1 - BuildDirectory: - Value: - HasValue: 0 - SpeakerMode: - Value: 0 - HasValue: 0 - VirtualChannelCount: - Value: 1024 - HasValue: 1 - RealChannelCount: - Value: 256 - HasValue: 1 - DSPBufferLength: - Value: 0 - HasValue: 0 - DSPBufferCount: - Value: 0 - HasValue: 0 - Plugins: - Value: [] - HasValue: 0 - StaticPlugins: - Value: [] - HasValue: 0 - CallbackHandler: - Value: {fileID: 0} - HasValue: 0 - OutputTypeName: - threadAffinities: - Value: [] - HasValue: 0 - displaySortOrder: 0 - childIdentifiers: [] - codecChannels: - Value: [] - HasValue: 0 diff --git a/Assets/Scripts/Framework/Core/Core.cs b/Assets/Scripts/Framework/Core/Core.cs index 250567fbd..28ce0f076 100644 --- a/Assets/Scripts/Framework/Core/Core.cs +++ b/Assets/Scripts/Framework/Core/Core.cs @@ -152,10 +152,93 @@ namespace AibisDream.Framework data.Load(); } } + + public bool TryGetFieldValue(string variableName, out T fieldValue) + { + fieldValue = default; + var parts = variableName.Split('.'); + if (parts.Length <= 3) + { + Debug.LogError($"{variableName}输入格式错误,应为 '$data.类名.字段名'"); + return false; + } + + var className = parts[1]; + var fieldName = parts[2]; + + var key = _instances.Keys.FirstOrDefault(key => key.Contains(className)); + if (string.IsNullOrEmpty(key)) + { + Debug.LogError($"未找到类名为 {className} 的实例"); + return false; + } + + var instance = _instances[key]; + var fieldInfo = instance.GetType().GetField(fieldName); + if (fieldInfo == null) + { + Debug.LogError($"未找到字段名为 {fieldName} 的字段"); + return false; + } + + var value = fieldInfo.GetValue(instance); + if (typeof(T) == typeof(string)) + { + // 单独处理字符串类型 + fieldValue = (T)(object)(value?.ToString() ?? string.Empty); + return true; + } + else if (typeof(T) == typeof(float)) + { + // 处理数字类型转换为 float + if (value is IConvertible) + { + try + { + fieldValue = (T)(object)Convert.ToSingle(value); + return true; + } + catch (Exception ex) + { + Debug.LogError($"无法将字段值转换为 float: {ex.Message}"); + return false; + } + } + else + { + Debug.LogError("字段值不是可转换为 float 的类型"); + return false; + } + } + else if (typeof(T) == typeof(bool)) + { + // 处理布尔类型转换为 bool + if (value is IConvertible) + { + fieldValue = (T)(object)Convert.ToBoolean(value); + return true; + } + else + { + Debug.LogError("字段值不是可转换为 bool 的类型"); + return false; + } + } + else if (value is T typedValue) + { + // 处理其他类型 + fieldValue = typedValue; + return true; + } + else + { + Debug.LogError($"未找到类型为 {typeof(T).Name} 的转换方法"); + return false; + } + } } #endregion - #region 事件相关 public interface IEasyEvent @@ -177,7 +260,7 @@ namespace AibisDream.Framework public void UnRegister(Action onEvent) => OnEvent -= onEvent; public void Trigger() => OnEvent?.Invoke(); - + public void UnRegisterAll() { OnEvent = null; @@ -229,7 +312,7 @@ namespace AibisDream.Framework return Register(Action); void Action(T _, TK __) => onEvent(); } - + public void UnRegisterAll() { OnEvent = null; diff --git a/Assets/Scripts/Game Loop/StorageSystem.cs b/Assets/Scripts/Game Loop/StorageSystem.cs index 9d833a0c6..436109b58 100644 --- a/Assets/Scripts/Game Loop/StorageSystem.cs +++ b/Assets/Scripts/Game Loop/StorageSystem.cs @@ -1,6 +1,10 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.Globalization; using System.Linq; using AibisDream.Framework; +using AibisDream.Utility; +using Newtonsoft.Json.Linq; using UnityEngine; using Yarn.Unity; @@ -11,6 +15,8 @@ namespace AibisDream private const string VariablePrefix = "$"; private const string GlobalPrefix = "$global."; private const string DataPrefix = "$data."; + + private static readonly string SaveFilePath = Application.streamingAssetsPath + "/SaveFiles"; #region 存储部分 @@ -77,7 +83,7 @@ namespace AibisDream }; EnumEventSystem.Global.Send(StorageEvent.VariableSet, variableItem); } - + public override void Clear() { _variableDict.Clear(); @@ -100,9 +106,15 @@ namespace AibisDream public override bool Contains(string variableName) { - return _variableDict.ContainsKey(variableName); + var variableType = ValidateVariableName(variableName); + if (variableType == VariableType.Illegal) + { + return false; + } + return variableType == VariableType.DataField ? + _dataContainer.TryGetFieldValue(variableName, out _) : _variableDict.ContainsKey(variableName); } - + public override bool TryGetValue(string variableName, out T result) { var variableType = ValidateVariableName(variableName); @@ -115,9 +127,7 @@ namespace AibisDream // 在系统数据中查找 if (variableType == VariableType.DataField) { - Debug.LogWarning("查找Data数据功能待实现"); - result = default; - return true; + return _dataContainer.TryGetFieldValue(variableName, out result); } // 直接查找数据 if (_variableDict.TryGetValue(variableName, out var value)) @@ -128,13 +138,13 @@ namespace AibisDream return true; } } - + result = default; return false; } - #endregion - + #endregion + #region 序列化 public override void SetAllVariables(Dictionary floats, Dictionary strings, @@ -165,29 +175,29 @@ namespace AibisDream var floatDict = new Dictionary(); var stringDict = new Dictionary(); var boolDict = new Dictionary(); - + foreach (var variablePair in _variableDict) { switch (variablePair.Value) { case float: - { - var value = System.Convert.ToSingle(variablePair.Value); - floatDict.Add(variablePair.Key, value); - break; - } + { + var value = System.Convert.ToSingle(variablePair.Value); + floatDict.Add(variablePair.Key, value); + break; + } case string: - { - var value = System.Convert.ToString(variablePair.Value); - stringDict.Add(variablePair.Key, value); - break; - } + { + var value = System.Convert.ToString(variablePair.Value); + stringDict.Add(variablePair.Key, value); + break; + } case bool: - { - var value = System.Convert.ToBoolean(variablePair.Value); - boolDict.Add(variablePair.Key, value); - break; - } + { + var value = System.Convert.ToBoolean(variablePair.Value); + boolDict.Add(variablePair.Key, value); + break; + } default: Debug.Log($"{variablePair.Key} is not a valid type"); break; @@ -197,6 +207,54 @@ namespace AibisDream return (floatDict, stringDict, boolDict); } + #endregion + + #region 保存/加载 + + public void Save() + { + // 先序列化Yarn变量 + var saveFile = new JObject(); + + // 保存系统数据 + saveFile["systemData"] = _dataContainer.SaveAsJson(); + + // 保存对话变量 + var (floatDict, stringDict, boolDict) = GetAllVariables(); + saveFile["floatDict"] = JObject.FromObject(floatDict); + saveFile["stringDict"] = JObject.FromObject(stringDict); + saveFile["boolDict"] = JObject.FromObject(boolDict); + + // 存为Json + JsonUtil.SaveJObject(saveFile, GetSavePath()); +#if !UNITY_EDITOR + DeleteOldSave(); +#endif + } + + public void Load() + { + // 先将存档文件转为JObject + } + + private string GetSavePath() + { + string gameStageStr; + try + { + TryGetValue("$gameStage", out float gameStage); + gameStageStr = gameStage.ToString(CultureInfo.InvariantCulture); + } + catch (Exception) + { + TryGetValue("$gameStage", out string gameStage); + gameStageStr = gameStage; + } + + return $"{SaveFilePath}/{DateTime.Now:yyyyMMdd_HHmmss}_SOName_{gameStageStr}"; + } + + #endregion private static VariableType ValidateVariableName(string variableName)