ARKitSettingsProvider.cs
2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEngine;
namespace UnityEditor.XR.ARKit
{
public static class ARKitSettingsProvider
{
[SettingsProvider]
static SettingsProvider CreateSettingsProvider()
{
GUIContent s_WarningToCreateSettings = EditorGUIUtility.TrTextContent(
"This controls the Build Settings for ARKit.\n\nYou must create a serialized instance of the settings data in order to modify the settings in this UI. Until then only default settings set by the provider will be available.");
// First parameter is the path in the Settings window.
// Second parameter is the scope of this setting: it only appears in the Project Settings window.
var provider = new SettingsProvider("Project/XR/ARKit", SettingsScope.Project)
{
// By default the last token of the path is used as display name if no label is provided.
label = "ARKit Build Settings",
// Create the SettingsProvider and initialize its drawing (IMGUI) function in place:
guiHandler = (searchContext) =>
{
if (ARKitSettings.currentSettings == null)
{
EditorGUILayout.HelpBox(s_WarningToCreateSettings);
if (GUILayout.Button(EditorGUIUtility.TrTextContent("Create")))
{
Create();
}
else
{
return;
}
}
var serializedSettings = ARKitSettings.GetSerializedSettings();
EditorGUILayout.PropertyField(serializedSettings.FindProperty("m_Requirement"), new GUIContent(
"Requirement",
"Toggles whether ARKit is required for this app. This will make the app only downloadable by devices with ARKit support if set to 'Required'."));
serializedSettings.ApplyModifiedProperties();
},
// Populate the search keywords to enable smart search filtering and label highlighting:
keywords = new HashSet<string>(new[] { "ARKit", "optional", "required" })
};
return provider;
}
static void Create()
{
var path = EditorUtility.SaveFilePanelInProject("Save ARKit Settings", "ARKitSettings", "asset", "Please enter a filename to save the ARKit settings.");
if (string.IsNullOrEmpty(path))
return;
var settings = ScriptableObject.CreateInstance<ARKitSettings>();
AssetDatabase.CreateAsset(settings, path);
ARKitSettings.currentSettings = settings;
}
}
}