Settings.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using System.Collections.Generic;
  2. using UnityEditor;
  3. using UnityEngine;
  4. //-----------------------------------------------------------------------------
  5. // Copyright 2012-2022 RenderHeads Ltd. All rights reserved.
  6. //-----------------------------------------------------------------------------
  7. namespace RenderHeads.Media.AVProMovieCapture.Editor
  8. {
  9. internal class Settings : ScriptableObject
  10. {
  11. const string SettingsPath = "Assets/Plugins/RenderHeads/AVProMovieCapture/Editor/Settings.asset";
  12. #pragma warning disable 0414 // "field is assigned but its value is never used"
  13. [SerializeField] string _photoLibraryUsageDescription = string.Empty;
  14. [SerializeField] string _photoLibraryAddUsageDescription = string.Empty;
  15. #pragma warning restore 0414
  16. internal static Settings GetOrCreateSettings()
  17. {
  18. Settings settings = AssetDatabase.LoadAssetAtPath<Settings>(SettingsPath);
  19. if (settings == null)
  20. {
  21. settings = ScriptableObject.CreateInstance<Settings>();
  22. AssetDatabase.CreateAsset(settings, SettingsPath);
  23. AssetDatabase.SaveAssets();
  24. }
  25. return settings;
  26. }
  27. internal static SerializedObject GetSerializedSettings()
  28. {
  29. return new SerializedObject(GetOrCreateSettings());
  30. }
  31. }
  32. internal static class SettingsIMGUIRegister
  33. {
  34. #if UNITY_2018_3_OR_NEWER
  35. private class MySettingsProvider : SettingsProvider
  36. {
  37. public MySettingsProvider(string path, SettingsScope scope)
  38. : base(path, scope)
  39. {
  40. this.keywords = new HashSet<string>(new[] { "Photo" });
  41. }
  42. public override void OnGUI(string searchContext)
  43. {
  44. SettingsGUI();
  45. }
  46. }
  47. [SettingsProvider]
  48. static SettingsProvider CreateSettingsProvider()
  49. {
  50. return new MySettingsProvider("Project/AVPro Movie Capture", SettingsScope.Project);
  51. }
  52. #elif UNITY_5_6_OR_NEWER
  53. [PreferenceItem("AVPro Movie Capture")]
  54. #endif
  55. private static void SettingsGUI()
  56. {
  57. SerializedObject settings = Settings.GetSerializedSettings();
  58. SerializedProperty propPhotoLibraryUsageDescription = settings.FindProperty("_photoLibraryUsageDescription");
  59. SerializedProperty propPhotoLibraryAddUsageDescription = settings.FindProperty("_photoLibraryAddUsageDescription");
  60. EditorGUILayout.Space();
  61. EditorGUILayout.LabelField("macOS / iOS", EditorStyles.boldLabel);
  62. // Photo library usage description
  63. EditorGUILayout.BeginHorizontal();
  64. EditorGUILayout.LabelField(
  65. new GUIContent(
  66. "Photo Library Usage Description",
  67. "Adds the NSPhotoLibraryUsageDescription key with the text provided to the generated apps Info.plist file."
  68. ),
  69. GUILayout.MaxWidth(250.0f)
  70. );
  71. propPhotoLibraryUsageDescription.stringValue = EditorGUILayout.TextField(propPhotoLibraryUsageDescription.stringValue);
  72. EditorGUILayout.EndHorizontal();
  73. // Photo library add usage description
  74. EditorGUILayout.BeginHorizontal();
  75. EditorGUILayout.LabelField(
  76. new GUIContent(
  77. "Photo Library Add Usage Description",
  78. "Adds the NSPhotoLibraryAddUsageDescription key with the text provided to the generated apps Info.plist file."
  79. ),
  80. GUILayout.MaxWidth(250.0f)
  81. );
  82. propPhotoLibraryAddUsageDescription.stringValue = EditorGUILayout.TextField(propPhotoLibraryAddUsageDescription.stringValue);
  83. EditorGUILayout.EndHorizontal();
  84. settings.ApplyModifiedPropertiesWithoutUndo();
  85. }
  86. }
  87. }