feat: migrate setting centralize to haptic system.
This commit is contained in:
@@ -1176,6 +1176,7 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: b1939bb20b5db46c1a5f7354ca0fba87, type: 3}
|
m_Script: {fileID: 11500000, guid: b1939bb20b5db46c1a5f7354ca0fba87, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
|
hapticSettings: {fileID: 11400000, guid: b0dd00ff5fbbb41859f0a6b6aa75f232, type: 2}
|
||||||
--- !u!4 &1013617500
|
--- !u!4 &1013617500
|
||||||
Transform:
|
Transform:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
@@ -13,10 +13,10 @@ namespace OCES.Audio.Editor
|
|||||||
return new SettingsProvider("Project/Audio Extend", SettingsScope.Project)
|
return new SettingsProvider("Project/Audio Extend", SettingsScope.Project)
|
||||||
{
|
{
|
||||||
label = "Audio Extend",
|
label = "Audio Extend",
|
||||||
guiHandler = searchContext =>
|
guiHandler = _ =>
|
||||||
{
|
{
|
||||||
var settings = AssetDatabase.LoadAssetAtPath<AudioExtendSettings>(k_assetPath);
|
AudioExtendSettings settings = AssetDatabase.LoadAssetAtPath<AudioExtendSettings>(k_assetPath);
|
||||||
if (settings == null)
|
if (!settings)
|
||||||
{
|
{
|
||||||
EditorGUILayout.HelpBox(
|
EditorGUILayout.HelpBox(
|
||||||
$"未找到 AudioExtendSettings.asset\n期望路径: {k_assetPath}",
|
$"未找到 AudioExtendSettings.asset\n期望路径: {k_assetPath}",
|
||||||
@@ -26,21 +26,24 @@ namespace OCES.Audio.Editor
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SerializedObject so = new SerializedObject(settings);
|
SerializedObject serializedObject = new(settings);
|
||||||
SerializedProperty prop = so.GetIterator();
|
SerializedProperty serializedProperty = serializedObject.GetIterator();
|
||||||
prop.NextVisible(true); // 跳过 Script 字段
|
serializedProperty.NextVisible(true); // 跳过 Script 字段
|
||||||
|
|
||||||
EditorGUI.BeginChangeCheck();
|
EditorGUI.BeginChangeCheck();
|
||||||
while (prop.NextVisible(false))
|
while (serializedProperty.NextVisible(false))
|
||||||
EditorGUILayout.PropertyField(prop, true);
|
{
|
||||||
|
EditorGUILayout.PropertyField(serializedProperty, true);
|
||||||
|
}
|
||||||
|
|
||||||
if (EditorGUI.EndChangeCheck())
|
if (EditorGUI.EndChangeCheck())
|
||||||
{
|
{
|
||||||
so.ApplyModifiedProperties();
|
serializedObject.ApplyModifiedProperties();
|
||||||
EditorUtility.SetDirty(settings);
|
EditorUtility.SetDirty(settings);
|
||||||
AssetDatabase.SaveAssets();
|
AssetDatabase.SaveAssets();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
keywords = new[] { "Audio", "SFX", "Music", "Mixer", "Path", "Import" }
|
keywords = new[] { "Audio", "SFX", "Music", "Mixer", "Path", "Import" },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
public bool IsHapticSupported;
|
||||||
[NonSerialized]
|
[NonSerialized]
|
||||||
public bool IsMeetsAdvanceRequirements;
|
public bool IsMeetsAdvanceRequirements;
|
||||||
|
[SerializeField]
|
||||||
|
HapticSettings hapticSettings;
|
||||||
|
|
||||||
|
|
||||||
internal ResourceLoader ResourceLoader;
|
internal ResourceLoader ResourceLoader;
|
||||||
|
|
||||||
HapticObjectConfig m_hapticObjects;
|
HapticObjectConfig m_hapticObjects;
|
||||||
const string k_hapticConfigPath = "HapticData/";
|
|
||||||
const string k_hapticResourcesPath = "Haptics/";
|
|
||||||
|
|
||||||
public void Play(uint hapticId, bool isDirectCall = true)
|
public void Play(uint hapticId, bool isDirectCall = true)
|
||||||
{
|
{
|
||||||
HapticObject hapticObject = this.m_hapticObjects.QueryById(hapticId);
|
HapticObject hapticObject = this.m_hapticObjects.QueryById(hapticId);
|
||||||
@@ -105,6 +106,8 @@ namespace OCES.Haptic
|
|||||||
|
|
||||||
void Awake()
|
void Awake()
|
||||||
{
|
{
|
||||||
|
HapticSettings.Instance = this.hapticSettings;
|
||||||
|
|
||||||
if (Instance && Instance != this)
|
if (Instance && Instance != this)
|
||||||
{
|
{
|
||||||
Destroy(gameObject);
|
Destroy(gameObject);
|
||||||
@@ -115,14 +118,14 @@ namespace OCES.Haptic
|
|||||||
|
|
||||||
this.ResourceLoader = gameObject.AddComponent<ResourceLoader>();
|
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.IsHapticSupported = DeviceCapabilities.isVersionSupported;
|
||||||
this.IsMeetsAdvanceRequirements = DeviceCapabilities.meetsAdvancedRequirements;
|
this.IsMeetsAdvanceRequirements = DeviceCapabilities.meetsAdvancedRequirements;
|
||||||
}
|
}
|
||||||
|
|
||||||
static HapticClip GetHapticClip(HapticObject hapticObject)
|
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
|
static class HapticConfigLoader
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!114 &11400000
|
||||||
|
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: cf447f41468045bf9789408bd135ebeb, type: 3}
|
||||||
|
m_Name: HapticSettings
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
hapticConfigPath: HapticData/
|
||||||
|
hapticResourcePath: Haptics/
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b0dd00ff5fbbb41859f0a6b6aa75f232
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 11400000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Reference in New Issue
Block a user