From 66c63896b02d5a25aa539bed68b71ad5a25352e3 Mon Sep 17 00:00:00 2001 From: Oliver Wong Date: Thu, 9 Apr 2026 17:37:03 +0800 Subject: [PATCH] =?UTF-8?q?improve:=20=E6=95=B4=E4=BD=93=E5=81=A5=E5=A3=AE?= =?UTF-8?q?=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Resources/HapticData/HapticObject.bytes | Bin 356 -> 0 bytes .../HapticData/HapticObject.bytes.meta | 7 ------ .../Handwritten/HandwrittenDefinitions.cs | 11 ++++----- .../OCES/Haptic/Handwritten/HapticSystem.cs | 22 +++++++++++++++--- 4 files changed, 23 insertions(+), 17 deletions(-) delete mode 100644 Assets/Resources/HapticData/HapticObject.bytes delete mode 100644 Assets/Resources/HapticData/HapticObject.bytes.meta diff --git a/Assets/Resources/HapticData/HapticObject.bytes b/Assets/Resources/HapticData/HapticObject.bytes deleted file mode 100644 index 6c8776c4f9705ea028a1cb9c666241c67b28c177..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 356 zcmWe+U|?VbVidq=z`%qe0OT+lGB9I^88NV6h#51mVu+bAuwjUqGO%NanK5u+h?z5R zVu)EVZ~?`D?ryM$V2}!Kgb)Kz7zB8L800%7RlGnh&~tE&Kq)?i5QF`!nKSJe82BMV qaE%TO3<5wQln`L^3v?53-d@#EGkJ#O)M#9Gy(v{9}`Ug diff --git a/Assets/Resources/HapticData/HapticObject.bytes.meta b/Assets/Resources/HapticData/HapticObject.bytes.meta deleted file mode 100644 index 27cbfed..0000000 --- a/Assets/Resources/HapticData/HapticObject.bytes.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 21ad6923737cb4c9bbb7577a5f361772 -TextScriptImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/OCES/Haptic/Handwritten/HandwrittenDefinitions.cs b/Assets/Scripts/OCES/Haptic/Handwritten/HandwrittenDefinitions.cs index fa11f17..72949c8 100644 --- a/Assets/Scripts/OCES/Haptic/Handwritten/HandwrittenDefinitions.cs +++ b/Assets/Scripts/OCES/Haptic/Handwritten/HandwrittenDefinitions.cs @@ -31,15 +31,12 @@ namespace OCES.Haptic { if (bytes == null) return false; - using (MemoryStream memoryStream = new(bytes)) + using MemoryStream memoryStream = new(bytes); + using (BinaryReader br = new(memoryStream)) { - using (var br = new BinaryReader(memoryStream)) - { - data.DeSerialize(br); - br.Close(); - } - memoryStream.Close(); + data.DeSerialize(br); } + memoryStream.Close(); return true; } } diff --git a/Assets/Scripts/OCES/Haptic/Handwritten/HapticSystem.cs b/Assets/Scripts/OCES/Haptic/Handwritten/HapticSystem.cs index 2ce7b4a..2475270 100644 --- a/Assets/Scripts/OCES/Haptic/Handwritten/HapticSystem.cs +++ b/Assets/Scripts/OCES/Haptic/Handwritten/HapticSystem.cs @@ -20,6 +20,12 @@ namespace OCES.Haptic public void Play(uint hapticId, bool isDirectCall = true) { + if (this.m_hapticObjects is null) + { + Debug.LogError($"[Haptic System] Config not loaded!"); + return; + } + HapticObject hapticObject = this.m_hapticObjects.QueryById(hapticId); if (hapticObject != null) { @@ -52,7 +58,7 @@ namespace OCES.Haptic } break; case HapticType.Emphasis: - if (hapticObject.Amplitude < 0f || hapticObject.Frequency < 0f) + if (hapticObject.Amplitude <= 0f || hapticObject.Frequency <= 0f) { Debug.LogWarning($"[Haptic System] Haptic {hapticObject.Id} have no amplitude or frequency." + "Please check the datatable."); @@ -61,7 +67,7 @@ namespace OCES.Haptic HapticPatterns.PlayEmphasis(hapticObject.Amplitude, hapticObject.Frequency); break; case HapticType.Constant: - if (hapticObject.Amplitude < 0f || hapticObject.Frequency < 0f || hapticObject.Duration < 0f) + if (hapticObject.Amplitude <= 0f || hapticObject.Frequency <= 0f || hapticObject.Duration <= 0f) { Debug.LogWarning($"[Haptic System] Haptic {hapticObject.Id} have no amplitude, frequency or duration." + "Please check the datatable."); @@ -73,10 +79,10 @@ namespace OCES.Haptic case HapticType.Advance: if (Enum.TryParse(hapticObject.FallbackPreset, out HapticPatterns.PresetType fallbackPreset)) { - HapticController.fallbackPreset = fallbackPreset; HapticClip hapticClip = GetHapticClip(hapticObject); if (hapticClip) { + HapticController.fallbackPreset = fallbackPreset; HapticController.Stop(); HapticController.Play(hapticClip); } @@ -114,9 +120,15 @@ namespace OCES.Haptic this.m_hapticObjects = HapticConfigLoader.Load(k_hapticConfigPath + "HapticObject"); } + void OnDestroy() + { + if (Instance == this) Instance = null; + } + static HapticClip GetHapticClip(HapticObject hapticObject) { return Resources.Load(k_hapticResourcesPath + hapticObject.Payload); + //TODO: cache HapticClips into a Dictionary or using AsyncLoad } static class HapticConfigLoader @@ -125,7 +137,11 @@ namespace OCES.Haptic { TextAsset bytes = Resources.Load(tableName); if (!bytes) + { Debug.LogError($"未找到表 {tableName}"); + return default; + } + IBinarySerializable data = new T(); bool readOk = FileManager.ReadBinaryDataFromBytes(bytes.bytes, ref data); if (readOk)