Esempio n. 1
0
        private void OnGUI()
        {
            if (window == null)
            {
                Close();
            }

            EditorGUILayout.BeginVertical();
            MixedRealityInspectorUtility.RenderMixedRealityToolkitLogo();
            EditorGUILayout.LabelField("Mixed Reality Toolkit Unity Package Manager");

            if (packages == null)
            {
                EditorGUILayout.LabelField(isError ? "Failed to find packages!" : "Gathering Package data...");
                EditorGUILayout.EndVertical();
                return;
            }

            var prevLabelWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = 256;

            for (var i = 0; i < packages.Length; i++)
            {
                (MixedRealityPackageInfo package, bool packageEnabled, bool packageInstalled) = packages[i];

                bool CheckDependency(Tuple <MixedRealityPackageInfo, bool, bool> packageSetting)
                {
                    (MixedRealityPackageInfo packageInfo, bool isEnabled, bool isInstalled) = packageSetting;
                    return(packageEnabled && packageInstalled && isEnabled && isInstalled && packageInfo.Dependencies.Contains(package.Name));
                }

                var hasDependency = packages.Any(CheckDependency);
                GUI.enabled = !package.IsRequiredPackage && !hasDependency;
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(16);
                isPackageEnabled[i] = EditorGUILayout.Toggle(isPackageEnabled[i], GUILayout.Width(12));
                var packageName = package.DisplayName.Replace("XRTK.", package.IsRequiredPackage
                    ? " (Required) " : hasDependency
                        ? " (Dependency) " : "");
                EditorGUILayout.LabelField(new GUIContent(packageName));
                GUILayout.FlexibleSpace();
                EditorGUILayout.EndHorizontal();
                GUI.enabled = true;
            }

            EditorGUIUtility.labelWidth = prevLabelWidth;

            if (GUILayout.Button("Apply"))
            {
                for (var i = 0; i < packages.Length; i++)
                {
                    (MixedRealityPackageInfo package, bool _, bool _) = packages[i];

                    if (!isPackageEnabled[i] && isPackageInstalled[i])
                    {
                        EditorPreferences.Set($"{package.Name}_enabled", false);

                        if (MixedRealityPackageUtilities.DebugEnabled)
                        {
                            Debug.LogWarning($"{package.Name}_enabled == false");
                        }
                    }

                    if (isPackageEnabled[i] && !isPackageInstalled[i])
                    {
                        EditorPreferences.Set($"{package.Name}_enabled", true);

                        if (MixedRealityPackageUtilities.DebugEnabled)
                        {
                            Debug.LogWarning($"{package.Name}_enabled == true");
                        }
                    }
                }

                MixedRealityPackageUtilities.CheckPackageManifest();
                Close();
            }

            EditorGUILayout.EndVertical();
        }
Esempio n. 2
0
        private void OnGUI()
        {
            if (window == null)
            {
                Close();
            }

            EditorGUILayout.BeginVertical();
            MixedRealityInspectorUtility.RenderMixedRealityToolkitLogo();
            EditorGUILayout.LabelField("Mixed Reality Toolkit Unity Package Manager");

            if (packages == null)
            {
                EditorGUILayout.LabelField(isError ? "Failed to find packages!" : "Gathering Package data...");
                EditorGUILayout.EndVertical();
                return;
            }

            var prevLabelWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = 256;

            for (var i = 0; i < packages.Length; i++)
            {
                (MixedRealityPackageInfo package, bool _) = packages[i];

                GUI.enabled = !package.IsRequiredPackage;
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(16);
                isPackageEnabled[i] = EditorGUILayout.Toggle(isPackageEnabled[i], GUILayout.Width(12));
                var packageName = package.DisplayName.Replace("XRTK.", package.IsRequiredPackage ? " (Required) " : string.Empty);
                EditorGUILayout.LabelField(new GUIContent(packageName));
                GUILayout.FlexibleSpace();
                EditorGUILayout.EndHorizontal();
                GUI.enabled = true;
            }

            EditorGUIUtility.labelWidth = prevLabelWidth;

            if (GUILayout.Button("Apply"))
            {
                for (var i = 0; i < packages.Length; i++)
                {
                    (MixedRealityPackageInfo package, bool isInstalled) = packages[i];

                    if (!isPackageEnabled[i] && isInstalled)
                    {
                        package.IsEnabled = false;

                        if (MixedRealityPackageUtilities.DebugEnabled)
                        {
                            Debug.LogWarning($"{package.Name} isEnabled == false");
                        }
                    }

                    if (isPackageEnabled[i] && !isInstalled)
                    {
                        package.IsEnabled = true;

                        if (MixedRealityPackageUtilities.DebugEnabled)
                        {
                            Debug.LogWarning($"{package.Name} isEnabled == true");
                        }
                    }

                    packages[i] = new Tuple <MixedRealityPackageInfo, bool>(package, isInstalled);
                }

                var newPackages = packages.Select(tuple => tuple.Item1).ToArray();
                MixedRealityPackageUtilities.PackageSettings.MixedRealityPackages = newPackages;
                MixedRealityPackageUtilities.CheckPackageManifest();
                Close();
            }

            if (GUILayout.Button("Restore Default Packages"))
            {
                for (int i = 0; i < packages.Length; i++)
                {
                    (MixedRealityPackageInfo package, bool isInstalled) = packages[i];

                    if (package.IsDefaultPackage)
                    {
                        package.IsEnabled = true;
                    }

                    packages[i] = new Tuple <MixedRealityPackageInfo, bool>(package, isInstalled);
                }

                var newPackages = packages.Select(tuple => tuple.Item1).ToArray();
                MixedRealityPackageUtilities.PackageSettings.MixedRealityPackages = newPackages;
                MixedRealityPackageUtilities.CheckPackageManifest();
                Close();
            }

            EditorGUILayout.EndVertical();
        }