/// <summary> /// Return all JarArtifacts to be used in External Dependencies Resolvor while building /// Android app. /// It will generate an AndroidResolverDependencies.xml file under ProjectSettings folder /// and then be used in Gradle build process. /// </summary> /// <param name="settings">ARCore Extensions Project Settings.</param> /// <returns>An array defining all Android dependencies.</returns> public override JarArtifact[] GetAndroidDependencies( ARCoreExtensionsProjectSettings settings) { return(new JarArtifact[] { new JarArtifact("com.google.android.gms", "play-services-location", "16+") }); }
/// <summary> /// Checking whether it needs to be included into the application. If it returns true, /// all related content, including AndroidManifest, proguard rules and Android external /// dependencies would be injected during build time. The default values for new fields in /// ARCoreExtensionsProjectSettings should guarantee the associated module to return false. /// </summary> /// <param name="settings">ARCore Extensions Project Settings.</param> /// <param name="buildTarget">Target build platform.</param> /// <returns>The boolean shows whether the module is enabled.</returns> public override bool IsEnabled(ARCoreExtensionsProjectSettings settings, UnityEditor.BuildTarget buildTarget) { if (buildTarget == UnityEditor.BuildTarget.iOS) { bool isEnabled = settings.IOSAuthenticationStrategySetting != IOSAuthenticationStrategy.DoNotUse; if (settings.IsIOSSupportEnabled && !isEnabled) { Debug.LogWarning( "Cloud Anchor APIs require one of the iOS authentication strategies. " + "If it’s not in use, you can uncheck iOS Support Enabled in " + "Edit > Project Settings > XR > ARCore Extensions " + "so ARCore Extensions won’t import Cloud Anchor iOS cocoapod into " + "your project."); } return(isEnabled); } else { return(settings.AndroidAuthenticationStrategySetting != AndroidAuthenticationStrategy.DoNotUse); } }
/// <summary> /// Loads previous settings. /// </summary> public void Load() { // Default settings. IsIOSSupportEnabled = false; AndroidAuthenticationStrategySetting = AndroidAuthenticationStrategy.DoNotUse; IOSAuthenticationStrategySetting = IOSAuthenticationStrategy.DoNotUse; AndroidCloudServicesApiKey = string.Empty; IOSCloudServicesApiKey = string.Empty; if (File.Exists(_projectSettingsPath)) { ARCoreExtensionsProjectSettings settings = JsonUtility.FromJson <ARCoreExtensionsProjectSettings>( File.ReadAllText(_projectSettingsPath)); foreach (FieldInfo fieldInfo in this.GetType().GetFields()) { fieldInfo.SetValue(this, fieldInfo.GetValue(settings)); } } if (!string.IsNullOrEmpty(AndroidCloudServicesApiKey)) { AndroidAuthenticationStrategySetting = AndroidAuthenticationStrategy.ApiKey; } if (!string.IsNullOrEmpty(IOSCloudServicesApiKey)) { IOSAuthenticationStrategySetting = IOSAuthenticationStrategy.ApiKey; } // Update the settings version as needed. Version = VersionInfo.Version; }
/// <summary> /// Return the XML snippet needs to be included if location module is enabled. /// The string output would be added as a child node of in the ‘manifest’ node /// of the customized AndroidManifest.xml. The android namespace would be provided /// and feature developers could use it directly. /// </summary> /// <param name="settings">ARCore Extensions Project Settings.</param> /// <returns>The XML string snippet to add as a child of node 'manifest'.</returns> public override string GetAndroidManifestSnippet(ARCoreExtensionsProjectSettings settings) { return(@" <uses-permission android:name=""android.permission.ACCESS_FINE_LOCATION""/> <uses-permission android:name=""android.permission.ACCESS_COARSE_LOCATION"" android:minSdkVersion=""31""/> <uses-feature android:name=""android.hardware.location.gps"" android:required=""true""/> <uses-feature android:name=""android.hardware.location"" android:required=""true""/>"); }
/// <summary> /// Checking whether it needs to be included into the application. If it returns true, /// all related content, including AndroidManifest, proguard rules and Android external /// dependencies would be injected during build time. The default values for new fields in /// ARCoreExtensionsProjectSettings should guarantee the associated module to return false. /// </summary> /// <param name="settings">ARCore Extensions Project Settings.</param> /// <param name="buildTarget">Target build platform.</param> /// <returns>The boolean shows whether the module is enabled.</returns> public override bool IsEnabled(ARCoreExtensionsProjectSettings settings, UnityEditor.BuildTarget buildTarget) { if (settings.GeospatialEnabled && (buildTarget == UnityEditor.BuildTarget.Android || (settings.IsIOSSupportEnabled && buildTarget == UnityEditor.BuildTarget.iOS))) { return(true); } return(false); }
/// <summary> /// Return the Proguard to include if this module is enabled. The string output will be /// added into "proguard-user.txt" directly. /// </summary> /// <param name="settings">ARCore Extensions Project Settings.</param> /// <returns>The proguard rule string snippet.</returns> public override string GetProguardSnippet(ARCoreExtensionsProjectSettings settings) { if (settings.AndroidAuthenticationStrategySetting == AndroidAuthenticationStrategy.Keyless) { return(@"-keep class com.google.android.gms.common.** { *; } -keep class com.google.android.gms.auth.** { *; } -keep class com.google.android.gms.tasks.** { *; }"); } return(string.Empty); }
/// <summary> /// In CompatibilityCheckPreprocessBuild, if no session configs require this /// module but this module is still enabled, it would call this function to get /// a warning message. /// </summary> /// <param name="settings">ARCore Extensions Project Settings.</param> /// <param name="buildTarget">Target build platform.</param> /// <returns> /// The warning message if this module is enabled but not required by any sessionConfigs. /// </returns> public override string GetEnabledNotRequiredWarning( ARCoreExtensionsProjectSettings settings, UnityEditor.BuildTarget buildTarget) { string platformName = buildTarget == UnityEditor.BuildTarget.iOS ? "iOS" : "Android"; return(string.Format( "{0} Authentication is enabled in ARCore Extensions Project Settings " + "but the feature is not used by any Scenes in Build.\n" + "To turn off authentication, select Do Not Use in Edit > " + "Project Settings > XR > ARCore Extensions > {0} Authentication Strategy.", platformName)); }
/// <summary> /// Checking whether this module is compatible with given ARCoreExtensionsConfig and /// ARCoreExtensionsProjectSettings. If it returns false, the /// CompatibilityCheckPreprocessBuild will throw a general Build Failure Error. /// A feature developer should use this function to log detailed error messages that /// also include a recommendation of how to resolve the issue. Note: This method is /// called once per session config. Do not log any warning or info messages here to /// avoid duplicated and/or conflicted information. /// </summary> /// <param name="settings">ARCore Extensions Project Settings.</param> /// <param name="sessionConfig">ARCore Extensions Config.</param> /// <param name="buildTarget">Target build platform.</param> /// <returns>The boolean shows whether the ARCoreExtensionsProjectSettings is compatible /// with the ARCoreExtensionsConfig.</returns> public virtual bool IsCompatible( ARCoreExtensionsProjectSettings settings, ARCoreExtensionsConfig sessionConfig, UnityEditor.BuildTarget buildTarget) { if (GetModuleNecessity(sessionConfig) == ModuleNecessity.Required && !IsEnabled(settings, buildTarget)) { Debug.LogErrorFormat("{0} is required but not enabled.", this.GetType().Name); return(false); } return(true); }
/// <summary> /// Checking whether it needs to be included into the application. If it returns true, /// all related content, including AndroidManifest, proguard rules and Android external /// dependencies would be injected during build time. The default values for new fields in /// ARCoreExtensionsProjectSettings should guarantee the associated module to return false. /// </summary> /// <param name="settings">ARCore Extensions Project Settings.</param> /// <param name="buildTarget">Target build platform.</param> /// <returns>The boolean shows whether the module is enabled.</returns> public override bool IsEnabled(ARCoreExtensionsProjectSettings settings, UnityEditor.BuildTarget buildTarget) { if (buildTarget == UnityEditor.BuildTarget.iOS) { return(settings.IOSAuthenticationStrategySetting != IOSAuthenticationStrategy.DoNotUse); } else { return(settings.AndroidAuthenticationStrategySetting != AndroidAuthenticationStrategy.DoNotUse); } }
/// <summary> /// Return the XML snippet needs to be included if location module is enabled. /// The string output would be added as a child node of in the ‘manifest’ node /// of the customized AndroidManifest.xml. The android namespace would be provided /// and feature developers could use it directly. /// </summary> /// <param name="settings">ARCore Extensions Project Settings.</param> /// <returns>The XML string snippet to add as a child of node 'manifest'.</returns> public override string GetAndroidManifestSnippet(ARCoreExtensionsProjectSettings settings) { if (!string.IsNullOrEmpty(settings.AndroidCloudServicesApiKey)) { return(string.Format( @"<application> <meta-data android:name=""com.google.android.ar.API_KEY"" android:value=""{0}""/> </application>", settings.AndroidCloudServicesApiKey)); } return(string.Empty); }
/// <summary> /// Return all JarArtifacts to be used in External Dependencies Resolvor while building /// Android app. /// It will generate an AndroidResolverDependencies.xml file under ProjectSettings folder /// and then be used in Gradle build process. /// </summary> /// <param name="settings">ARCore Extensions Project Settings.</param> /// <returns>An array defining all Android dependencies.</returns> public override JarArtifact[] GetAndroidDependencies( ARCoreExtensionsProjectSettings settings) { if (settings.AndroidAuthenticationStrategySetting == AndroidAuthenticationStrategy.Keyless) { return(new JarArtifact[] { new JarArtifact("com.google.android.gms", "play-services-auth-base", "16+") }); } else { return(null); } }
/// <summary> /// Return the snippet to be used in Play Services Resolver while building Android app. /// The string output will be added into a new created file whose name would combine the /// module name and "Dependencies.xml". /// </summary> /// <param name="settings">ARCore Extensions Project Settings.</param> /// <returns>The dependencies to be resolved in Play Services Resolver.</returns> public override string GetAndroidDependenciesSnippet( ARCoreExtensionsProjectSettings settings) { if (settings.AndroidAuthenticationStrategySetting == AndroidAuthenticationStrategy.Keyless) { return(@"<!-- Required by Keyless authentication, allows dynamite-loaded part of ARCore to access Google Play Services APIs via reflection in order to access authentication APIs. --> <androidPackage spec=""com.google.android.gms:play-services-auth-base:16+"" />"); } return(string.Empty); }
/// <summary> /// In CompatibilityCheckPreprocessBuild, if no session configs require this /// module but this module is still enabled, it would call this function to get /// a warning message. /// </summary> /// <param name="settings">ARCore Extensions Project Settings.</param> /// <param name="buildTarget">Target build platform.</param> /// <returns> /// The warning message if this module is enabled but not required by any sessionConfigs. /// </returns> public override string GetEnabledNotRequiredWarning( ARCoreExtensionsProjectSettings settings, UnityEditor.BuildTarget buildTarget) { string featureName = "null"; if (settings.GeospatialEnabled) { featureName = "Geospatial"; } return(string.Format( "{0} feature is checked in ARCore Extensions Project Settings, but " + "it is not used by any Scenes in Build.\nTo turn off {0}, uncheck it in " + "Edit > Project Settings > XR > ARCore Extensions > Optional Features > {0}.", featureName)); }
/// <summary> /// Loads previous settings. /// </summary> public void Load() { // Default settings. IsIOSSupportEnabled = false; AndroidAuthenticationStrategySetting = AndroidAuthenticationStrategy.DoNotUse; IOSAuthenticationStrategySetting = IOSAuthenticationStrategy.DoNotUse; AndroidCloudServicesApiKey = string.Empty; IOSCloudServicesApiKey = string.Empty; if (File.Exists(_projectSettingsPath)) { ARCoreExtensionsProjectSettings settings = JsonUtility.FromJson <ARCoreExtensionsProjectSettings>( File.ReadAllText(_projectSettingsPath)); foreach (FieldInfo fieldInfo in this.GetType().GetFields()) { fieldInfo.SetValue(this, fieldInfo.GetValue(settings)); } // Set the initial value in previous settings to keep Cloud Anchors enabled. int[] versions = string.IsNullOrEmpty(Version) ? new int[0] : Array.ConvertAll( Version.Split('.'), s => { int.TryParse(s, out int num); return(num); }); if (versions.Length == 3 && versions[0] == 1 && versions[1] <= 30) { CloudAnchorEnabled = true; } } if (!string.IsNullOrEmpty(AndroidCloudServicesApiKey)) { AndroidAuthenticationStrategySetting = AndroidAuthenticationStrategy.ApiKey; } if (!string.IsNullOrEmpty(IOSCloudServicesApiKey)) { IOSAuthenticationStrategySetting = IOSAuthenticationStrategy.ApiKey; } // Update the settings version as needed. Version = VersionInfo.Version; }
/// <summary> /// Checking whether this module is compatible with given ARCoreExtensionsConfig and /// ARCoreExtensionsProjectSettings. If it returns false, the /// CompatibilityCheckPreprocessBuild will throw a general Build Failure Error. /// A feature developer should use this function to log detailed error messages that /// also include a recommendation of how to resolve the issue. Note: This method is /// called once per session config. Do not log any warning or info messages here to /// avoid duplicated and/or conflicted information. /// </summary> /// <param name="settings">ARCore Extensions Project Settings.</param> /// <param name="sessionConfig">ARCore Extensions Config.</param> /// <param name="buildTarget">Target build platform.</param> /// <returns>The boolean shows whether the ARCoreExtensionsProjectSettings is compatible /// with the ARCoreExtensionsConfig.</returns> public override bool IsCompatible( ARCoreExtensionsProjectSettings settings, ARCoreExtensionsConfig sessionConfig, UnityEditor.BuildTarget buildTarget) { string optionFeaturesSettings = "Edit > Project Settings > XR > ARCore Extensions > Optional Features"; if (sessionConfig.GeospatialMode != GeospatialMode.Disabled && !settings.GeospatialEnabled) { Debug.LogErrorFormat( "LocationModule is required by GeospatialMode {0}. " + "Navigate to {1} and select Geospatial.", sessionConfig.GeospatialMode, optionFeaturesSettings); return(false); } return(true); }
/// <summary> /// Checking whether this module is compatible with given ARCoreExtensionsConfig and /// ARCoreExtensionsProjectSettings. If it returns false, the /// CompatibilityCheckPreprocessBuild will throw a general Build Failure Error. /// A feature developer should use this function to log detailed error messages that /// also include a recommendation of how to resolve the issue. Note: This method is /// called once per session config. Do not log any warning or info messages here to /// avoid duplicated and/or conflicted information. /// </summary> /// <param name="settings">ARCore Extensions Project Settings.</param> /// <param name="sessionConfig">ARCore Extensions Config.</param> /// <param name="buildTarget">Target build platform.</param> /// <returns>The boolean shows whether the ARCoreExtensionsProjectSettings is compatible /// with the ARCoreExtensionsConfig.</returns> public override bool IsCompatible( ARCoreExtensionsProjectSettings settings, ARCoreExtensionsConfig sessionConfig, UnityEditor.BuildTarget buildTarget) { if (buildTarget == UnityEditor.BuildTarget.iOS) { if (sessionConfig.CloudAnchorMode == CloudAnchorMode.Enabled && settings.IOSAuthenticationStrategySetting == IOSAuthenticationStrategy.DoNotUse) { Debug.LogErrorFormat( "Cloud Anchor authentication is required by CloudAnchorMode {0}. " + "An iOS Authentication Strategy must be set in " + "Edit > Project Settings > XR > ARCore Extensions > " + "iOS Authentication Strategy when CloudAnchorMode is {0}", sessionConfig.CloudAnchorMode); return(false); } return(true); } else { if (sessionConfig.CloudAnchorMode == CloudAnchorMode.Enabled && settings.AndroidAuthenticationStrategySetting == AndroidAuthenticationStrategy.DoNotUse) { Debug.LogErrorFormat( "Cloud Anchor authentication is required by CloudAnchorMode {0}. " + "An Android Authentication Strategy must be set in " + "Edit > Project Settings > XR > ARCore Extensions > " + "Android Authentication Strategy when CloudAnchorMode is {0}.", sessionConfig.CloudAnchorMode); return(false); } return(true); } }
/// <summary> /// In CompatibilityCheckPreprocessBuild, if no session configs require this /// module but this module is still enabled, it would call this function to get /// a warning message. /// </summary> /// <param name="settings">ARCore Extensions Project Settings.</param> /// <param name="buildTarget">Target build platform.</param> /// <returns> /// The warning message if this module is enabled but not required by any sessionConfigs. /// </returns> public override string GetEnabledNotRequiredWarning( ARCoreExtensionsProjectSettings settings, UnityEditor.BuildTarget buildTarget) { string featureName = "Cloud Anchor"; string platformName; if (buildTarget == UnityEditor.BuildTarget.iOS) { platformName = "iOS"; } else { platformName = "Android"; } return(string.Format("{0} Authentication is enabled in ARCore Extensions Project " + "Settings but {0} is not used in any Scenes in Build.\n" + "To turn off authentication, select Do Not Use in Edit > " + "Project Settings > XR > ARCore Extensions > {1} Authentication Strategy.", featureName, platformName)); }
/// <summary> /// Return the snippet to be used in External Dependencies Resolvor while building /// Android app. The string output will be added into a new created file whose name /// would combine the module name and "Dependencies.xml". /// </summary> /// <param name="settings">ARCore Extensions Project Settings.</param> /// <returns>The string snippet to be used in Play Services Resolver.</returns> public virtual string GetAndroidDependenciesSnippet( ARCoreExtensionsProjectSettings settings) { return(string.Empty); }
/// <summary> /// Return the Proguard snippet to include if this module is enabled. The string output /// will be added into "proguard-user.txt" directly. /// </summary> /// <param name="settings">ARCore Extensions Project Settings.</param> /// <returns>The proguard rule string snippet.</returns> public virtual string GetProguardSnippet(ARCoreExtensionsProjectSettings settings) { return(string.Empty); }
/// <summary> /// Return the XML snippet to include if this module is enabled. The string output will be /// added as a child node of the ‘manifest’ node of the customized AndroidManifest.xml. /// The android namespace will be available. /// </summary> /// <param name="settings">ARCore Extensions Project Settings.</param> /// <returns>The XML string snippet to add as a child of node 'manifest'.</returns> public virtual string GetAndroidManifestSnippet(ARCoreExtensionsProjectSettings settings) { return(string.Empty); }
/// <summary> /// In CompatibilityCheckPreprocessBuild, if no session configs require this /// module but this module is still enabled, it would call this function to get /// a warning message. /// </summary> /// <param name="settings">ARCore Extensions Project Settings.</param> /// <param name="buildTarget">Target build platform.</param> /// <returns> /// The warning message if this module is enabled but not required by any sessionConfigs. /// </returns> public virtual string GetEnabledNotRequiredWarning( ARCoreExtensionsProjectSettings settings, UnityEditor.BuildTarget buildTarget) { return(string.Format("{0} is enabled but not required. Should it be disabled?", this.GetType().Name)); }
/// <summary> /// Return the Proguard to include if this module is enabled. The string output will be /// added into "proguard-user.txt" directly. /// </summary> /// <param name="settings">ARCore Extensions Project Settings.</param> /// <returns>The proguard rule string snippet.</returns> public override string GetProguardSnippet(ARCoreExtensionsProjectSettings settings) { return(@"-keep class com.google.android.gms.common.** { *; } -keep class com.google.android.gms.location.** { *; } -keep class com.google.android.gms.tasks.** { *; }"); }
/// <summary> /// Checking whether it needs to be included into the application. If it returns true, /// all related content, including AndroidManifest, proguard rules and Android external /// dependencies would be injected during build time. The default values for new fields in /// ARCoreExtensionsProjectSettings should guarantee the associated module to return false. /// </summary> /// <param name="settings">ARCore Extensions Project Settings.</param> /// <param name="buildTarget">Target build platform.</param> /// <returns>The boolean shows whether the module is enabled.</returns> public virtual bool IsEnabled(ARCoreExtensionsProjectSettings settings, UnityEditor.BuildTarget buildTarget) { return(false); }
/// <summary> /// Checking whether this module is compatible with given ARCoreExtensionsConfig and /// ARCoreExtensionsProjectSettings. If it returns false, the /// CompatibilityCheckPreprocessBuild will throw a general Build Failure Error. /// A feature developer should use this function to log detailed error messages that /// also include a recommendation of how to resolve the issue. Note: This method is /// called once per session config. Do not log any warning or info messages here to /// avoid duplicated and/or conflicted information. /// </summary> /// <param name="settings">ARCore Extensions Project Settings.</param> /// <param name="sessionConfig">ARCore Extensions Config.</param> /// <param name="buildTarget">Target build platform.</param> /// <returns>The boolean shows whether the ARCoreExtensionsProjectSettings is compatible /// with the ARCoreExtensionsConfig.</returns> public override bool IsCompatible( ARCoreExtensionsProjectSettings settings, ARCoreExtensionsConfig sessionConfig, UnityEditor.BuildTarget buildTarget) { string optionFeaturesSettings = "Edit > Project Settings > XR > ARCore Extensions > Optional Features"; if (sessionConfig.CloudAnchorMode != CloudAnchorMode.Disabled && !settings.CloudAnchorEnabled) { Debug.LogErrorFormat( "Cloud Anchors feature is required by CloudAnchorMode {0}. " + "It must be set in {1} > Cloud Anchors.", sessionConfig.CloudAnchorMode, optionFeaturesSettings); return(false); } else if (sessionConfig.GeospatialMode != GeospatialMode.Disabled && !settings.GeospatialEnabled) { Debug.LogErrorFormat( "Geospatial feature is required by GeospatialMode {0}. " + "It must be set in {1} > Geospatial.", sessionConfig.GeospatialMode, optionFeaturesSettings); return(false); } if (buildTarget == UnityEditor.BuildTarget.iOS) { string requirement = string.Empty; string iosAuthSettings = "Edit > Project Settings > XR > ARCore Extensions > " + "iOS Authentication Strategy"; if (sessionConfig.CloudAnchorMode == CloudAnchorMode.Enabled && settings.IOSAuthenticationStrategySetting == IOSAuthenticationStrategy.DoNotUse) { requirement = string.Format( "A valid authentication strategy is required by CloudAnchorMode {0}.", sessionConfig.CloudAnchorMode); } else if ( sessionConfig.GeospatialMode == GeospatialMode.Enabled && settings.IOSAuthenticationStrategySetting == IOSAuthenticationStrategy.DoNotUse) { requirement = string.Format( "A valid authentication strategy is required by GeospatialMode {0}.", sessionConfig.GeospatialMode); } if (string.IsNullOrEmpty(requirement)) { return(true); } else { Debug.LogErrorFormat("{0} It must be set in {1}.", requirement, iosAuthSettings); return(false); } } else { string requirement = string.Empty; string androidAuthSettings = "Edit > Project Settings > XR > ARCore Extensions > " + "Android Authentication Strategy"; if (sessionConfig.CloudAnchorMode == CloudAnchorMode.Enabled && settings.AndroidAuthenticationStrategySetting == AndroidAuthenticationStrategy.DoNotUse) { requirement = string.Format( "A valid authentication strategy is required by CloudAnchorMode {0}.", sessionConfig.CloudAnchorMode); } else if ( sessionConfig.GeospatialMode == GeospatialMode.Enabled && settings.AndroidAuthenticationStrategySetting == AndroidAuthenticationStrategy.DoNotUse) { requirement = string.Format( "A valid authentication strategy is required by GeospatialMode {0}.", sessionConfig.GeospatialMode); } if (string.IsNullOrEmpty(requirement)) { return(true); } else { Debug.LogErrorFormat("{0} It must be set in {1}.", requirement, androidAuthSettings); return(false); } } }
/// <summary> /// Return all JarArtifacts to be used in External Dependencies Resolvor while building /// Android app. /// It will generate an AndroidResolverDependencies.xml file under ProjectSettings folder /// and then be used in Gradle build process. /// </summary> /// <param name="settings">ARCore Extensions Project Settings.</param> /// <returns>An array defining all Android dependencies.</returns> public virtual JarArtifact[] GetAndroidDependencies( ARCoreExtensionsProjectSettings settings) { return(null); }