Exemple #1
0
        void DrawElementCallback(Rect rect, int index, bool isActive, bool isFocused)
        {
            var li = m_LoaderMetadata[index];

            if (PackageNotificationUtils.registeredPackagesWithNotifications.TryGetValue(li.packageId, out var notificationInfo))
            {
                PackageNotificationUtils.DrawNotificationIconUI(notificationInfo, rect);
            }

            li.toggled = XRPackageMetadataStore.IsLoaderAssigned(li.loaderType, CurrentBuildTargetGroup);
            var preToggledState = li.toggled;

            EditorGUI.BeginDisabledGroup(li.disabled);

            if (li.customLoaderUI != null)
            {
                li.customLoaderUI.OnGUI(rect);
                li.toggled = li.customLoaderUI.IsLoaderEnabled;
            }
            else
            {
                li.toggled = EditorGUI.ToggleLeft(rect, li.loaderName, preToggledState);
            }

            li.stateChanged         = (li.toggled != preToggledState);
            m_LoaderMetadata[index] = li;
            EditorGUI.EndDisabledGroup();
        }
Exemple #2
0
        void DrawElementCallback(Rect rect, int index, bool isActive, bool isFocused)
        {
            var li = m_LoaderMetadata[index];

            li.toggled = XRPackageMetadataStore.IsLoaderAssigned(li.loaderType, CurrentBuildTargetGroup);
            bool preToggledState = li.toggled;

            li.toggled = EditorGUI.ToggleLeft(rect, li.loaderName, preToggledState);
            if (li.toggled != preToggledState)
            {
                li.stateChanged         = true;
                m_LoaderMetadata[index] = li;
            }
        }
        void DrawElementCallback(Rect rect, int index, bool isActive, bool isFocused)
        {
            var li = m_LoaderMetadata[index];

            if (PackageNotificationUtils.registeredPackagesWithNotifications.TryGetValue(li.packageId, out var notificationInfo))
            {
                PackageNotificationUtils.DrawNotificationIconUI(notificationInfo, rect);
            }

            li.toggled = XRPackageMetadataStore.IsLoaderAssigned(li.loaderType, CurrentBuildTargetGroup);
            var preToggledState = li.toggled;

            EditorGUI.BeginDisabledGroup(li.disabled);

            if (li.customLoaderUI != null)
            {
                li.customLoaderUI.OnGUI(rect);
                li.toggled = li.customLoaderUI.IsLoaderEnabled;
            }
            else
            {
                string name = li.loaderName;
                if (s_DeprecationInfo.ContainsKey(name))
                {
                    var depInfo = s_DeprecationInfo[name];

                    var labelRect = rect;
                    var size      = EditorStyles.label.CalcSize(depInfo.icon);
                    labelRect.width -= size.y + 1;

                    var imageRect = new Rect(rect);
                    imageRect.xMin  = labelRect.xMax + 1;
                    imageRect.width = size.y;

                    li.toggled = EditorGUI.ToggleLeft(labelRect, li.loaderName, preToggledState);
                    EditorGUI.LabelField(imageRect, depInfo.renderContent);
                }
                else
                {
                    li.toggled = EditorGUI.ToggleLeft(rect, li.loaderName, preToggledState);
                }
            }

            li.stateChanged         = (li.toggled != preToggledState);
            m_LoaderMetadata[index] = li;
            EditorGUI.EndDisabledGroup();
        }
Exemple #4
0
        internal static bool ContainsLoaderForAnyBuildTarget(string loaderTypeName)
        {
            XRGeneralSettingsPerBuildTarget buildTargetSettings = null;

            EditorBuildSettings.TryGetConfigObject(XRGeneralSettings.k_SettingsKey, out buildTargetSettings);
            if (buildTargetSettings == null)
            {
                return(false);
            }

            foreach (var settings in buildTargetSettings.Settings.Values)
            {
                if (XRPackageMetadataStore.IsLoaderAssigned(settings.Manager, loaderTypeName))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #5
0
        internal bool OnGUI(BuildTargetGroup buildTargetGroup)
        {
            var settings = XRGeneralSettingsPerBuildTarget.XRGeneralSettingsForBuildTarget(buildTargetGroup);

            if (buildTargetGroup != CurrentBuildTargetGroup || m_LoaderMetadata == null)
            {
                CurrentBuildTargetGroup = buildTargetGroup;

                if (m_LoaderMetadata == null)
                {
                    m_LoaderMetadata = new List <LoaderInformation>();
                }
                else
                {
                    m_LoaderMetadata.Clear();
                }

                foreach (var pmd in XRPackageMetadataStore.GetLoadersForBuildTarget(buildTargetGroup))
                {
                    var newLi = new LoaderInformation()
                    {
                        packageName    = pmd.packageName,
                        packageId      = pmd.packageId,
                        loaderName     = pmd.loaderName,
                        loaderType     = pmd.loaderType,
                        toggled        = XRPackageMetadataStore.IsLoaderAssigned(pmd.loaderType, buildTargetGroup),
                        disabled       = false,
                        customLoaderUI = XRCustomLoaderUIManager.GetCustomLoaderUI(pmd.loaderType, buildTargetGroup)
                    };

                    if (newLi.customLoaderUI != null)
                    {
                        newLi.customLoaderUI.IsLoaderEnabled        = newLi.toggled;
                        newLi.customLoaderUI.ActiveBuildTargetGroup = CurrentBuildTargetGroup;
                    }
                    m_LoaderMetadata.Add(newLi);
                }

                if (settings != null)
                {
                    List <LoaderInformation> loadersWantingToDisableOtherLoaders = new List <LoaderInformation>();

                    LoaderInformation li;
                    for (int i = 0; i < m_LoaderMetadata.Count; i++)
                    {
                        li = m_LoaderMetadata[i];
                        if (XRPackageMetadataStore.IsLoaderAssigned(settings.AssignedSettings, li.loaderType))
                        {
                            li.toggled          = true;
                            m_LoaderMetadata[i] = li;

                            if (li.customLoaderUI != null)
                            {
                                loadersWantingToDisableOtherLoaders.Add(li);
                            }
                            break;
                        }
                    }

                    foreach (var loader in loadersWantingToDisableOtherLoaders)
                    {
                        SetDisablesStateOnLoadersFromLoader(loader);
                    }
                }

                m_OrderedList = new ReorderableList(m_LoaderMetadata, typeof(LoaderInformation), false, true, false, false);
                m_OrderedList.drawHeaderCallback = (rect) =>
                {
                    var labelSize = EditorStyles.label.CalcSize(Content.k_LoaderUITitle);
                    var labelRect = new Rect(rect);
                    labelRect.width = labelSize.x;

                    labelSize = EditorStyles.label.CalcSize(Content.k_HelpContent);
                    var imageRect = new Rect(rect);
                    imageRect.xMin  = labelRect.xMax + 1;
                    imageRect.width = labelSize.x;

                    EditorGUI.LabelField(labelRect, Content.k_LoaderUITitle, EditorStyles.label);
                    if (GUI.Button(imageRect, Content.k_HelpContent, EditorStyles.label))
                    {
                        System.Diagnostics.Process.Start(Content.k_HelpUri);
                    }
                };
                m_OrderedList.drawElementCallback           = (rect, index, isActive, isFocused) => DrawElementCallback(rect, index, isActive, isFocused);
                m_OrderedList.drawElementBackgroundCallback = (rect, index, isActive, isFocused) =>
                {
                    var tex = GUI.skin.label.normal.background;
                    if (tex == null && GUI.skin.label.normal.scaledBackgrounds.Length > 0)
                    {
                        tex = GUI.skin.label.normal.scaledBackgrounds[0];
                    }
                    if (tex == null)
                    {
                        return;
                    }

                    GUI.DrawTexture(rect, GUI.skin.label.normal.background);
                };
                m_OrderedList.drawFooterCallback = (rect) =>
                {
                    var status = XRPackageMetadataStore.GetCurrentStatusDisplayText();
                    GUI.Label(rect, EditorGUIUtility.TrTextContent(status), EditorStyles.label);
                };
                m_OrderedList.elementHeightCallback = (index) => GetElementHeight(index);
            }

            if (m_LoaderMetadata == null || m_LoaderMetadata.Count == 0)
            {
                EditorGUILayout.HelpBox(k_AtNoLoaderInstance, MessageType.Info);
            }
            else
            {
                m_OrderedList.DoLayoutList();
                if (settings != null)
                {
                    LoaderInformation li;
                    for (int i = 0; i < m_LoaderMetadata.Count; i++)
                    {
                        li = m_LoaderMetadata[i];
                        if (li.stateChanged && li.customLoaderUI != null)
                        {
                            SetDisablesStateOnLoadersFromLoader(li);
                        }
                    }

                    for (int i = 0; i < m_LoaderMetadata.Count; i++)
                    {
                        li = m_LoaderMetadata[i];
                        if (li.stateChanged)
                        {
                            if (li.toggled)
                            {
                                XRPackageMetadataStore.InstallPackageAndAssignLoaderForBuildTarget(li.packageId, li.loaderType, buildTargetGroup);
                            }
                            else
                            {
                                XRPackageMetadataStore.RemoveLoader(settings.AssignedSettings, li.loaderType, buildTargetGroup);
                            }
                            li.stateChanged     = false;
                            m_LoaderMetadata[i] = li;
                        }
                    }
                }
            }

            return(false);
        }
Exemple #6
0
        internal bool OnGUI(BuildTargetGroup buildTargetGroup)
        {
            var settings = XRGeneralSettingsPerBuildTarget.XRGeneralSettingsForBuildTarget(buildTargetGroup);

            if (buildTargetGroup != CurrentBuildTargetGroup || m_LoaderMetadata == null)
            {
                CurrentBuildTargetGroup = buildTargetGroup;

                if (m_LoaderMetadata == null)
                {
                    m_LoaderMetadata = new List <LoaderInformation>();
                }
                else
                {
                    m_LoaderMetadata.Clear();
                }

                foreach (var pmd in XRPackageMetadataStore.GetLoadersForBuildTarget(buildTargetGroup))
                {
                    m_LoaderMetadata.Add(new LoaderInformation()
                    {
                        packageName = pmd.packageName,
                        packageId   = pmd.packageId,
                        loaderName  = pmd.loaderName,
                        loaderType  = pmd.loaderType,
                        toggled     = XRPackageMetadataStore.IsLoaderAssigned(pmd.loaderType, buildTargetGroup)
                    });
                }

                if (settings != null)
                {
                    LoaderInformation li;
                    for (int i = 0; i < m_LoaderMetadata.Count; i++)
                    {
                        li = m_LoaderMetadata[i];
                        if (XRPackageMetadataStore.IsLoaderAssigned(settings.AssignedSettings, li.loaderType))
                        {
                            li.toggled          = true;
                            m_LoaderMetadata[i] = li;
                            break;
                        }
                    }
                }

                m_OrderedList = new ReorderableList(m_LoaderMetadata, typeof(LoaderInformation), false, true, false, false);
                m_OrderedList.drawHeaderCallback    = (rect) => GUI.Label(rect, EditorGUIUtility.TrTextContent("Plug-in Providers"), EditorStyles.label);
                m_OrderedList.drawElementCallback   = (rect, index, isActive, isFocused) => DrawElementCallback(rect, index, isActive, isFocused);
                m_OrderedList.elementHeightCallback = (index) => GetElementHeight(index);
            }

            if (m_LoaderMetadata == null || m_LoaderMetadata.Count == 0)
            {
                EditorGUILayout.HelpBox(k_AtNoLoaderInstance, MessageType.Info);
            }
            else
            {
                m_OrderedList.DoLayoutList();
                if (settings != null)
                {
                    LoaderInformation li;
                    for (int i = 0; i < m_LoaderMetadata.Count; i++)
                    {
                        li = m_LoaderMetadata[i];
                        if (li.stateChanged)
                        {
                            if (li.toggled)
                            {
                                if (XRPackageMetadataStore.IsPackageInstalled(li.packageId))
                                {
                                    XRPackageMetadataStore.AssignLoader(settings.AssignedSettings, li.loaderType, buildTargetGroup);
                                }
                                else
                                {
                                    XRPackageMetadataStore.InstallPackageAndAssignLoaderForBuildTarget(li.packageId, li.loaderType, buildTargetGroup);
                                }
                            }
                            else
                            {
                                XRPackageMetadataStore.RemoveLoader(settings.AssignedSettings, li.loaderType, buildTargetGroup);
                            }
                            li.stateChanged     = false;
                            m_LoaderMetadata[i] = li;
                        }
                    }
                }
            }

            return(false);
        }