feat: migrate setting centralize to haptic system.
This commit is contained in:
@@ -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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user