feat: migrate setting centralize to haptic system.
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e681c729026b4fdf83b38f1824f4ab02
|
||||
timeCreated: 1778761511
|
||||
@@ -0,0 +1,62 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace OCES.Haptic.Editor
|
||||
{
|
||||
static class HapticSettingsProvider
|
||||
{
|
||||
const string k_settingPath = "Assets/Settings/HapticSettings.asset";
|
||||
|
||||
[SettingsProvider]
|
||||
static SettingsProvider Creat()
|
||||
{
|
||||
return new SettingsProvider("Project/Haptic Settings", SettingsScope.Project)
|
||||
{
|
||||
label = "Haptic Settings",
|
||||
guiHandler = _ =>
|
||||
{
|
||||
HapticSettings settings = AssetDatabase.LoadAssetAtPath<HapticSettings>(k_settingPath);
|
||||
if (!settings)
|
||||
{
|
||||
EditorGUILayout.HelpBox(
|
||||
$"未找到 AudioExtendSettings.asset\n期望路径: {k_settingPath}",
|
||||
MessageType.Warning);
|
||||
if (GUILayout.Button("创建默认配置"))
|
||||
CreateDefaultAsset();
|
||||
return;
|
||||
}
|
||||
|
||||
SerializedObject serializedObject = new(settings);
|
||||
SerializedProperty serializedProperty = serializedObject.GetIterator();
|
||||
serializedProperty.NextVisible(true);
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
while (serializedProperty.NextVisible(false))
|
||||
{
|
||||
EditorGUILayout.PropertyField(serializedProperty, true);
|
||||
}
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
EditorUtility.SetDirty(settings);
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
},
|
||||
keywords = new[] { "Haptic", "Audio", "Vibration", "Vibrator", "Path" },
|
||||
};
|
||||
}
|
||||
|
||||
[MenuItem("Tools/Haptic/Create Haptic Settings Asset")]
|
||||
static void CreateDefaultAsset()
|
||||
{
|
||||
if (!AssetDatabase.IsValidFolder("Assets/Settings"))
|
||||
AssetDatabase.CreateFolder("Assets", "Settings");
|
||||
|
||||
HapticSettings asset = ScriptableObject.CreateInstance<HapticSettings>();
|
||||
AssetDatabase.CreateAsset(asset, k_settingPath);
|
||||
AssetDatabase.SaveAssets();
|
||||
Debug.Log($"[HapticSettings] 已创建默认配置:{k_settingPath}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fd277ab8102549be90d99031ceb8193a
|
||||
timeCreated: 1778761525
|
||||
@@ -0,0 +1,20 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace OCES.Haptic
|
||||
{
|
||||
/// <summary>
|
||||
/// 触感反馈系统扩展配置,集中管理所有路径和可调参数。
|
||||
/// 资产位置:Assets/Resources/AudioExtendSettings.asset
|
||||
/// 编辑入口:Project Settings > Audio Extend
|
||||
/// </summary>
|
||||
public class HapticSettings : ScriptableObject
|
||||
{
|
||||
[Tooltip("Resources 子目录:触感配置文件")]
|
||||
public string hapticConfigPath = "HapticData/";
|
||||
|
||||
[Tooltip("Resources 子目录:触感资源文件(.haptic)")]
|
||||
public string hapticResourcePath = "Haptics/";
|
||||
|
||||
public static HapticSettings Instance { get; internal set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cf447f41468045bf9789408bd135ebeb
|
||||
timeCreated: 1778750228
|
||||
@@ -13,13 +13,14 @@ namespace OCES.Haptic
|
||||
public bool IsHapticSupported;
|
||||
[NonSerialized]
|
||||
public bool IsMeetsAdvanceRequirements;
|
||||
[SerializeField]
|
||||
HapticSettings hapticSettings;
|
||||
|
||||
|
||||
internal ResourceLoader ResourceLoader;
|
||||
|
||||
HapticObjectConfig m_hapticObjects;
|
||||
const string k_hapticConfigPath = "HapticData/";
|
||||
const string k_hapticResourcesPath = "Haptics/";
|
||||
|
||||
|
||||
public void Play(uint hapticId, bool isDirectCall = true)
|
||||
{
|
||||
HapticObject hapticObject = this.m_hapticObjects.QueryById(hapticId);
|
||||
@@ -105,6 +106,8 @@ namespace OCES.Haptic
|
||||
|
||||
void Awake()
|
||||
{
|
||||
HapticSettings.Instance = this.hapticSettings;
|
||||
|
||||
if (Instance && Instance != this)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
@@ -115,14 +118,14 @@ namespace OCES.Haptic
|
||||
|
||||
this.ResourceLoader = gameObject.AddComponent<ResourceLoader>();
|
||||
|
||||
this.m_hapticObjects = HapticConfigLoader.Load<HapticObjectConfig>(k_hapticConfigPath + "HapticObject");
|
||||
this.m_hapticObjects = HapticConfigLoader.Load<HapticObjectConfig>(HapticSettings.Instance.hapticConfigPath + "HapticObject");
|
||||
this.IsHapticSupported = DeviceCapabilities.isVersionSupported;
|
||||
this.IsMeetsAdvanceRequirements = DeviceCapabilities.meetsAdvancedRequirements;
|
||||
}
|
||||
|
||||
static HapticClip GetHapticClip(HapticObject hapticObject)
|
||||
{
|
||||
return Instance.ResourceLoader.LoadSync<HapticClip>(k_hapticResourcesPath + hapticObject.Payload);
|
||||
return Instance.ResourceLoader.LoadSync<HapticClip>(HapticSettings.Instance.hapticResourcePath + hapticObject.Payload);
|
||||
}
|
||||
|
||||
static class HapticConfigLoader
|
||||
|
||||
Reference in New Issue
Block a user