<commit_before>﻿// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using Microsoft.MixedReality.Toolkit.Utilities.Editor;
using UnityEditor;
using UnityEngine;

namespace Microsoft.MixedReality.Toolkit.Editor
{
    [CustomEditor(typeof(MixedRealityToolkit))]
    public class MixedRealityToolkitInspector : UnityEditor.Editor
    {
        private SerializedProperty activeProfile;
        private UnityEditor.Editor activeProfileEditor;
        private Object cachedProfile;

        private void OnEnable()
        {
            activeProfile = serializedObject.FindProperty("activeProfile");
            cachedProfile = activeProfile.objectReferenceValue;
        }

        public override void OnInspectorGUI()
        {
            MixedRealityToolkit instance = (MixedRealityToolkit)target;

            if (MixedRealityToolkit.Instance == null && instance.isActiveAndEnabled)
            {   // See if an active instance exists at all. If it doesn't register this instance preemptively.
                MixedRealityToolkit.SetActiveInstance(instance);
            }

            if (!instance.IsActiveInstance)
            {
                EditorGUILayout.HelpBox("This instance of the toolkit is inactive. There can only be one active instance loaded at any time.", MessageType.Warning);
                using (new EditorGUILayout.HorizontalScope())
                {
                    if (GUILayout.Button("Select Active Instance"))
                    {
                        Selection.activeGameObject = MixedRealityToolkit.Instance.gameObject;
                    }

                    if (GUILayout.Button("Make this the Active Instance"))
                    {
                        MixedRealityToolkit.SetActiveInstance(instance);
                    }
                }
                return;
            }

            serializedObject.Update();

            // If no profile is assigned, then warn user
            if (activeProfile.objectReferenceValue == null)
            {
                EditorGUILayout.HelpBox("MixedRealityToolkit cannot initialize unless an Active Profile is assigned!", MessageType.Error);
            }

            bool changed = MixedRealityInspectorUtility.DrawProfileDropDownList(activeProfile, null, activeProfile.objectReferenceValue, typeof(MixedRealityToolkitConfigurationProfile), false, false) ||
                cachedProfile != activeProfile.objectReferenceValue;

            serializedObject.ApplyModifiedProperties();

            if (changed)
            {
                MixedRealityToolkit.Instance.ResetConfiguration((MixedRealityToolkitConfigurationProfile)activeProfile.objectReferenceValue);
                activeProfileEditor = null;
                cachedProfile = activeProfile.objectReferenceValue;
            }

            if (activeProfile.objectReferenceValue != null && activeProfileEditor == null)
            {
                // For the configuration profile, show the default inspector GUI
                activeProfileEditor = CreateEditor(activeProfile.objectReferenceValue);
            }

            if (activeProfileEditor != null)
            {
                activeProfileEditor.OnInspectorGUI();
            }
        }

        [MenuItem("Mixed Reality/Toolkit/Add to Scene and Configure...")]
        public static void CreateMixedRealityToolkitGameObject()
        {
            MixedRealityInspectorUtility.AddMixedRealityToolkitToScene();
            Selection.activeObject = MixedRealityToolkit.Instance;
            EditorGUIUtility.PingObject(MixedRealityToolkit.Instance);
        }
    }
}<commit_msg>Update OnInspectorGUI for Toolkit Inspector (#10936)<commit_after>﻿// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using Microsoft.MixedReality.Toolkit.Utilities.Editor;
using UnityEditor;
using UnityEngine;

namespace Microsoft.MixedReality.Toolkit.Editor
{
    [CustomEditor(typeof(MixedRealityToolkit))]
    public class MixedRealityToolkitInspector : UnityEditor.Editor
    {
        private SerializedProperty activeProfile;
        private UnityEditor.Editor activeProfileEditor;
        private Object cachedProfile;

        private void OnEnable()
        {
            activeProfile = serializedObject.FindProperty("activeProfile");
            cachedProfile = activeProfile.objectReferenceValue;
        }

        public override void OnInspectorGUI()
        {
            MixedRealityToolkit instance = (MixedRealityToolkit)target;

            if (MixedRealityToolkit.Instance == null && instance.isActiveAndEnabled)
            {   // See if an active instance exists at all. If it doesn't register this instance preemptively.
                MixedRealityToolkit.SetActiveInstance(instance);
            }

            if (!instance.IsActiveInstance)
            {
                EditorGUILayout.HelpBox("This instance of the toolkit is inactive. There can only be one active instance loaded at any time.", MessageType.Warning);
                using (new EditorGUILayout.HorizontalScope())
                {
                    if (GUILayout.Button("Select Active Instance"))
                    {
                        Selection.activeGameObject = MixedRealityToolkit.Instance.gameObject;
                    }

                    if (GUILayout.Button("Make this the Active Instance"))
                    {
                        MixedRealityToolkit.SetActiveInstance(instance);
                    }
                }
                return;
            }

            serializedObject.Update();

            // If no profile is assigned, then warn user
            if (activeProfile.objectReferenceValue == null)
            {
                EditorGUILayout.HelpBox("MixedRealityToolkit cannot initialize unless an Active Profile is assigned!", MessageType.Error);
            }

            bool changed = MixedRealityInspectorUtility.DrawProfileDropDownList(activeProfile, null, activeProfile.objectReferenceValue, typeof(MixedRealityToolkitConfigurationProfile), false, false) ||
                cachedProfile != activeProfile.objectReferenceValue;

            serializedObject.ApplyModifiedProperties();

            if (changed)
            {
                TryResetConfiguration();
            }

            if (activeProfile.objectReferenceValue != null && activeProfileEditor == null)
            {
                // For the configuration profile, show the default inspector GUI
                activeProfileEditor = CreateEditor(activeProfile.objectReferenceValue);
            }

            if (activeProfileEditor != null)
            {
                activeProfileEditor.OnInspectorGUI();
            }
        }

        private void TryResetConfiguration()
        {
            var newProfile = (MixedRealityToolkitConfigurationProfile)activeProfile.objectReferenceValue;
            try
            {
                if (!Application.isPlaying)
                {
                    MixedRealityToolkit.Instance.ResetConfiguration(newProfile);
                }
                else
                {
                    MixedRealityToolkit.Instance.ActiveProfile = newProfile;
                }

                activeProfileEditor = null;
                cachedProfile = activeProfile.objectReferenceValue;
            }
            catch (System.Exception e)
            {
                Debug.LogError($"Failed to switch MRTK profile to {newProfile?.name}:\n{e}");
            }
        }

        [MenuItem("Mixed Reality/Toolkit/Add to Scene and Configure...")]
        public static void CreateMixedRealityToolkitGameObject()
        {
            MixedRealityInspectorUtility.AddMixedRealityToolkitToScene();
            Selection.activeObject = MixedRealityToolkit.Instance;
            EditorGUIUtility.PingObject(MixedRealityToolkit.Instance);
        }
    }
}
{'fraction_non_alphanumeric': 0.06895677525668653, 'fraction_numerical': 0.0006337938902268982, 'mean_word_length': 2.0045696877380044, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '414766', 'n_tokens_mistral': 1847, 'n_tokens_neox': 1747, 'n_words': 386}