Esempio n. 1
0
 /// <summary>
 /// Configures current Unity project to contain the default Spatial Awareness layer set in the Layers settings
 /// </summary>
 public static void SetSpatialAwarenessLayer()
 {
     if (!HasSpatialAwarenessLayer())
     {
         if (!EditorLayerExtensions.SetupLayer(SpatialAwarenessDefaultLayer, "Spatial Awareness"))
         {
             Debug.LogWarning(string.Format($"Can't modify project layers. It's possible the format of the layers and tags data has changed in this version of Unity. Set layer {SpatialAwarenessDefaultLayer} to \"Spatial Awareness\" manually via Project Settings > Tags and Layers window."));
         }
     }
 }
        /// <summary>
        /// On load, show dialog to confirm MRTK can apply useful settings
        /// </summary>
        private static void ShowSettingsDialog()
        {
            bool refresh = false;
            bool restart = false;

            if (!MixedRealityPreferences.IgnoreSettingsPrompt)
            {
                StringBuilder builder = new StringBuilder();
                builder.Append("The Mixed Reality Toolkit needs to apply the following settings to your project:\n\n");

                var forceTextSerialization = EditorSettings.serializationMode == SerializationMode.ForceText;

                if (!forceTextSerialization)
                {
                    builder.AppendLine("- Force Text Serialization");
                }

                var visibleMetaFiles = EditorSettings.externalVersionControl.Equals("Visible Meta Files");

                if (!visibleMetaFiles)
                {
                    builder.AppendLine("- Visible meta files");
                }

                if (!PlayerSettings.virtualRealitySupported)
                {
                    builder.AppendLine("- Enable XR Settings for your current platform");
                }

                var usingSinglePassInstancing = PlayerSettings.stereoRenderingPath == StereoRenderingPath.Instancing;
                if (!usingSinglePassInstancing)
                {
                    builder.AppendLine("- Set Single Pass Instanced rendering path");
                }

                // Only make change if not already set. Regardless of whether it is already SpatialAwareness or something user set
                var isSpatialLayerAvailable = string.IsNullOrEmpty(LayerMask.LayerToName(SpatialAwarenessDefaultLayer));
                if (isSpatialLayerAvailable)
                {
                    builder.AppendLine("- Set Default Spatial Awareness Layer");
                }

                builder.Append("\nWould you like to make these changes?");

                if (!forceTextSerialization || !visibleMetaFiles || !PlayerSettings.virtualRealitySupported || !usingSinglePassInstancing || isSpatialLayerAvailable)
                {
                    var choice = EditorUtility.DisplayDialogComplex("Apply Mixed Reality Toolkit Default Settings?", builder.ToString(), "Apply", "Ignore", "Later");

                    switch (choice)
                    {
                    case 0:
                        EditorSettings.serializationMode      = SerializationMode.ForceText;
                        EditorSettings.externalVersionControl = "Visible Meta Files";
                        ApplyXRSettings();
                        PlayerSettings.stereoRenderingPath = StereoRenderingPath.Instancing;
                        if (isSpatialLayerAvailable)
                        {
                            if (EditorLayerExtensions.SetupLayer(SpatialAwarenessDefaultLayer, "Spatial Awareness"))
                            {
                                Debug.LogWarning(string.Format($"Can't modify project layers. It's possible the format of the layers and tags data has changed in this version of Unity. Set layer {SpatialAwarenessDefaultLayer} to \"Spatial Awareness\" manually via Project Settings > Tags and Layers window."));
                            }
                        }
                        refresh = true;
                        break;

                    case 1:
                        MixedRealityPreferences.IgnoreSettingsPrompt = true;
                        break;

                    case 2:
                        break;
                    }
                }
            }

#if !UNITY_2019_3_OR_NEWER
            if (PlayerSettings.scriptingRuntimeVersion != ScriptingRuntimeVersion.Latest)
            {
                PlayerSettings.scriptingRuntimeVersion = ScriptingRuntimeVersion.Latest;
                restart = true;
            }
#endif

            if (refresh || restart)
            {
                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
            }

            if (restart)
            {
                EditorApplication.OpenProject(Directory.GetParent(Application.dataPath).ToString());
            }
        }