Exemple #1
0
        void OnGUI()
        {
            GUILayout.Space(5);
            GUIStyle titleStyle = new GUIStyle(GUI.skin.label);

            titleStyle.wordWrap = true;
            EditorGUILayout.LabelField("Select an existing ARCoreSettings object or create a new one.", titleStyle);

            EditorGUI.BeginChangeCheck();
            ARCoreSettings.currentSettings =
                EditorGUILayout.ObjectField("ARCoreSettings", ARCoreSettings.currentSettings, typeof(ARCoreSettings), false) as ARCoreSettings;
            if (EditorGUI.EndChangeCheck())
            {
                ARCoreSettings.TrySelect();
            }

            GUILayout.Space(5);

            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Create New"))
            {
                Create();
            }

            if (GUILayout.Button("Close"))
            {
                Close();
            }

            EditorGUILayout.EndHorizontal();
        }
Exemple #2
0
        static void ShowSelectionWindow()
        {
            ARCoreSettings.TrySelect();
            Rect rect   = new Rect(500, 300, 400, 150);
            var  window = GetWindowWithRect <SettingsSelectionWindow>(rect);

            window.titleContent = new GUIContent("ARCore");
            window.Show();
        }
        static void EnsureMinSdkVersion()
        {
            var arcoreSettings = ARCoreSettings.GetOrCreateSettings();
            var minSdkVersion  = arcoreSettings.requirement == ARCoreSettings.Requirement.Optional ? 14 : 24;

            if ((int)PlayerSettings.Android.minSdkVersion < minSdkVersion)
            {
                throw new BuildFailedException($"ARCore {arcoreSettings.requirement} apps require a minimum SDK version of {minSdkVersion}. Currently set to {PlayerSettings.Android.minSdkVersion}");
            }
        }
        static void EnsureGradleVersionIsSupported()
        {
            var settings = ARCoreSettings.GetOrCreateSettings();

            if (settings.ignoreGradleVersion)
            {
                return;
            }

            if (Gradle.TryGetVersion(out var gradleVersion, out var diagnosticMessage))
            {
                if (gradleVersion < k_MinimumGradleVersion)
                {
                    var errorMessage = $"ARCore requires at least Gradle version {k_MinimumGradleVersion} ({gradleVersion} detected). Visit https://developers.google.com/ar/develop/unity/android-11-build for further details.";
                    var selection    = EditorUtility.DisplayDialogComplex(
                        "Gradle update required",
                        errorMessage,
                        "Cancel build", "Continue anyway", "Continue and don't warn me again");

                    switch (selection)
                    {
                    // Cancel the build
                    case 0: throw new BuildFailedException(errorMessage);

                    // Continue as normal
                    case 1: break;

                    // Continue, and never ask again
                    case 2:
                    {
                        if (ARCoreSettings.currentSettings == null)
                        {
                            var shouldCreateSettingsProvider = EditorUtility.DisplayDialog("Create ARCoreSettings Asset",
                                                                                           "In order to remember this setting, you must create an ARCoreSettings asset in Edit > Project Settings > XR > ARCore",
                                                                                           "Create", "Cancel");

                            if (shouldCreateSettingsProvider)
                            {
                                ARCoreSettingsProvider.Create();
                                settings = ARCoreSettings.GetOrCreateSettings();
                            }
                        }

                        settings.ignoreGradleVersion = true;

                        break;
                    }
                    }
                }
            }
            else
            {
                Debug.LogWarning($"ARCore requires Gradle {k_MinimumGradleVersion} or later. The Gradle version could not be determined because \"{diagnosticMessage}\"");
            }
        }
        // This ensures the Android Manifest corresponds to
        // https://developers.google.com/ar/develop/java/enable-arcore
        public void OnPostGenerateGradleAndroidProject(string path)
        {
            if (!ARCorePreprocessBuild.isARCoreLoaderEnabled)
            {
                return;
            }

            string manifestPath = path + k_AndroidManifestPath;
            var    manifestDoc  = new XmlDocument();

            manifestDoc.Load(manifestPath);

            var manifestNode = FindFirstChild(manifestDoc, "manifest");

            if (manifestNode == null)
            {
                return;
            }

            var applicationNode = FindFirstChild(manifestNode, "application");

            if (applicationNode == null)
            {
                return;
            }

            FindOrCreateTagWithAttribute(manifestDoc, manifestNode, "uses-permission", "name", k_AndroidPermissionCamera);
            FindOrCreateTagWithAttributes(manifestDoc, applicationNode, "meta-data", "name", "unityplayer.SkipPermissionsDialog", "value", "true");

            var settings = ARCoreSettings.GetOrCreateSettings();

            if (settings.requirement == ARCoreSettings.Requirement.Optional)
            {
                FindOrCreateTagWithAttributes(manifestDoc, applicationNode, "meta-data", "name", k_AndroidNameValue, "value", "optional");
            }
            else if (settings.requirement == ARCoreSettings.Requirement.Required)
            {
                FindOrCreateTagWithAttributes(manifestDoc, manifestNode, "uses-feature", "name", k_AndroidHardwareCameraAr, "required", "true");
                FindOrCreateTagWithAttributes(manifestDoc, applicationNode, "meta-data", "name", k_AndroidNameValue, "value", "required");
            }

            if (settings.depth == ARCoreSettings.Requirement.Required)
            {
                FindOrCreateTagWithAttributes(manifestDoc, manifestNode, "uses-feature", "name", k_AndroidDepth, "required", "true");
            }
            manifestDoc.Save(manifestPath);
        }
Exemple #6
0
        static SettingsProvider CreateSettingsProvider()
        {
            GUIContent s_WarningToCreateSettings = EditorGUIUtility.TrTextContent(
                "You 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/ARCore", SettingsScope.Project)
            {
                // By default the last token of the path is used as display name if no label is provided.
                label = "ARCore",

                // Create the SettingsProvider and initialize its drawing (IMGUI) function in place:
                guiHandler = (searchContext) =>
                {
                    if (ARCoreSettings.currentSettings == null)
                    {
                        EditorGUILayout.HelpBox(s_WarningToCreateSettings);
                        if (GUILayout.Button(EditorGUIUtility.TrTextContent("Create")))
                        {
                            Create();
                        }
                        else
                        {
                            return;
                        }
                    }

                    var serializedSettings = ARCoreSettings.GetSerializedSettings();

                    EditorGUILayout.PropertyField(serializedSettings.FindProperty("m_Requirement"), new GUIContent(
                                                      "Requirement",
                                                      "Toggles whether ARCore is required for this app. This will make the app only downloadable by devices with ARCore support if set to 'Required'."));

                    EditorGUILayout.PropertyField(serializedSettings.FindProperty("m_IgnoreGradleVersion"), new GUIContent(
                                                      "Ignore Gradle Version",
                                                      "Toggles whether the Gradle version is validated during Player build."));

                    serializedSettings.ApplyModifiedProperties();
                },

                // Populate the search keywords to enable smart search filtering and label highlighting:
                keywords = new HashSet <string>(new[] { "ARCore", "optional", "required" })
            };

            return(provider);
        }
        void EnsureMinSdkVersion()
        {
            var arcoreSettings = ARCoreSettings.GetOrCreateSettings();
            int minSdkVersion;

            if (arcoreSettings.requirement == ARCoreSettings.Requirement.Optional)
            {
                minSdkVersion = 14;
            }
            else
            {
                minSdkVersion = 24;
            }

            if ((int)PlayerSettings.Android.minSdkVersion < minSdkVersion)
            {
                throw new BuildFailedException(string.Format("ARCore {0} apps require a minimum SDK version of {1}. Currently set to {2}",
                                                             arcoreSettings.requirement, minSdkVersion, PlayerSettings.Android.minSdkVersion));
            }
        }