improve: 整体健壮性
This commit is contained in:
Binary file not shown.
@@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 21ad6923737cb4c9bbb7577a5f361772
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -31,15 +31,12 @@ namespace OCES.Haptic
|
||||
{
|
||||
if (bytes == null)
|
||||
return false;
|
||||
using (MemoryStream memoryStream = new(bytes))
|
||||
{
|
||||
using (var br = new BinaryReader(memoryStream))
|
||||
using MemoryStream memoryStream = new(bytes);
|
||||
using (BinaryReader br = new(memoryStream))
|
||||
{
|
||||
data.DeSerialize(br);
|
||||
br.Close();
|
||||
}
|
||||
memoryStream.Close();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<HapticObjectConfig>(k_hapticConfigPath + "HapticObject");
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
if (Instance == this) Instance = null;
|
||||
}
|
||||
|
||||
static HapticClip GetHapticClip(HapticObject hapticObject)
|
||||
{
|
||||
return Resources.Load<HapticClip>(k_hapticResourcesPath + hapticObject.Payload);
|
||||
//TODO: cache HapticClips into a Dictionary<string, HapticClip> or using AsyncLoad
|
||||
}
|
||||
|
||||
static class HapticConfigLoader
|
||||
@@ -125,7 +137,11 @@ namespace OCES.Haptic
|
||||
{
|
||||
TextAsset bytes = Resources.Load<TextAsset>(tableName);
|
||||
if (!bytes)
|
||||
{
|
||||
Debug.LogError($"未找到表 {tableName}");
|
||||
return default;
|
||||
}
|
||||
|
||||
IBinarySerializable data = new T();
|
||||
bool readOk = FileManager.ReadBinaryDataFromBytes(bytes.bytes, ref data);
|
||||
if (readOk)
|
||||
|
||||
Reference in New Issue
Block a user