123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- using System.Collections.Generic;
- using System;
-
- using UnityEditorInternal;
- using UnityEngine;
-
- using UnityEditor.AdaptivePerformance.Editor.Metadata;
-
- namespace UnityEditor.AdaptivePerformance.Editor
- {
- internal interface IAdaptivePerformanceLoaderOrderManager
- {
- List<AdaptivePerformanceLoaderInfo> AssignedLoaders { get; }
- List<AdaptivePerformanceLoaderInfo> UnassignedLoaders { get; }
-
- void AssignLoader(AdaptivePerformanceLoaderInfo assignedInfo);
- void UnassignLoader(AdaptivePerformanceLoaderInfo unassignedInfo);
- void Update();
- }
-
- internal class AdaptivePerformanceLoaderOrderUI
- {
- struct LoaderInformation
- {
- public string packageName;
- public string packageId;
- public string loaderName;
- public string loaderType;
- public string licenseURL;
- public bool toggled;
- public bool stateChanged;
- }
-
- struct Content
- {
- public static readonly string k_AtNoLoaderInstance = L10n.Tr("There are no Adaptive Performance providers available for this platform.");
- public static readonly string k_LicenseText = L10n.Tr("By clicking the checkbox to install a provider, you acknowledge that you have read and agreed to the terms and conditions found under \"View licenses.\"");
- public static readonly GUIContent k_LicenseViewText = new GUIContent(L10n.Tr("View licenses"));
- public static readonly GUIContent k_LoaderUITitle = EditorGUIUtility.TrTextContent(L10n.Tr("Providers"));
- public static readonly GUIContent k_HelpContent = new GUIContent("", EditorGUIUtility.IconContent("_Help@2x").image, L10n.Tr("Selecting a provider installs that providers package. Packages can be managed through the Package Manager."));
- }
-
- private List<LoaderInformation> m_LoaderMetadata = null;
-
- ReorderableList m_OrderedList = null;
-
- public BuildTargetGroup CurrentBuildTargetGroup { get; set; }
-
- internal AdaptivePerformanceLoaderOrderUI()
- {
- }
-
- void DrawElementCallback(Rect rect, int index, bool isActive, bool isFocused)
- {
- var li = m_LoaderMetadata[index];
-
- li.toggled = AdaptivePerformancePackageMetadataStore.IsLoaderAssigned(li.loaderType, CurrentBuildTargetGroup);
- bool preToggledState = li.toggled;
- rect.width *= 0.51f;
- EditorGUIUtility.labelWidth = 180;
- li.toggled = EditorGUI.Toggle(rect, li.loaderName, preToggledState);
- if (li.toggled != preToggledState)
- {
- li.stateChanged = true;
- m_LoaderMetadata[index] = li;
- }
-
- if (li.licenseURL != null)
- DisplayLink(Content.k_LicenseViewText, new Uri(li.licenseURL), 2, 80, rect);
- }
-
- private void DisplayLink(GUIContent text, Uri link, float leftMargin, float width, Rect rect)
- {
- var labelStyle = EditorStyles.linkLabel;
- var uriRect = rect;
-
- uriRect.x += uriRect.width * 2;
- uriRect.y -= 1;
- uriRect.x -= width + leftMargin;
- uriRect.width = width;
-
- if (GUI.Button(uriRect, text, labelStyle))
- {
- System.Diagnostics.Process.Start(link.AbsoluteUri);
- }
- EditorGUIUtility.AddCursorRect(uriRect, MouseCursor.Link);
- EditorGUI.DrawRect(new Rect(uriRect.x + 2, uriRect.y + uriRect.height - 3, uriRect.width - 3, 1), labelStyle.normal.textColor);
- }
-
- float GetElementHeight(int index)
- {
- return m_OrderedList.elementHeight;
- }
-
- internal bool OnGUI(BuildTargetGroup buildTargetGroup)
- {
- var settings = AdaptivePerformanceGeneralSettingsPerBuildTarget.AdaptivePerformanceGeneralSettingsForBuildTarget(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 AdaptivePerformancePackageMetadataStore.GetLoadersForBuildTarget(buildTargetGroup))
- {
- m_LoaderMetadata.Add(new LoaderInformation() {
- packageName = pmd.packageName,
- packageId = pmd.packageId,
- loaderName = pmd.loaderName,
- loaderType = pmd.loaderType,
- licenseURL = pmd.licenseURL,
- toggled = AdaptivePerformancePackageMetadataStore.IsLoaderAssigned(pmd.loaderType, buildTargetGroup)
- });
- }
-
- if (settings != null)
- {
- LoaderInformation li;
- for (int i = 0; i < m_LoaderMetadata.Count; i++)
- {
- li = m_LoaderMetadata[i];
- if (AdaptivePerformancePackageMetadataStore.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) =>
- {
- 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);
- EditorGUI.LabelField(imageRect, Content.k_HelpContent);
- };
-
- m_OrderedList.drawElementCallback = (rect, index, isActive, isFocused) => DrawElementCallback(rect, index, isActive, isFocused);
- m_OrderedList.elementHeightCallback = (index) => GetElementHeight(index);
- m_OrderedList.drawFooterCallback = (rect) =>
- {
- var status = AdaptivePerformancePackageMetadataStore.GetCurrentStatusDisplayText();
- GUI.Label(rect, status, EditorStyles.label);
- };
- }
-
- if (m_LoaderMetadata == null || m_LoaderMetadata.Count == 0)
- {
- EditorGUILayout.HelpBox(Content.k_AtNoLoaderInstance, MessageType.Info);
- }
- else
- {
- EditorGUILayout.HelpBox(Content.k_LicenseText, MessageType.Info);
- EditorGUILayout.Space();
-
- 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)
- {
- AdaptivePerformancePackageMetadataStore.InstallPackageAndAssignLoaderForBuildTarget(li.packageId, li.loaderType, buildTargetGroup);
- }
- else
- {
- AdaptivePerformancePackageMetadataStore.RemoveLoader(settings.AssignedSettings, li.loaderType, buildTargetGroup);
- }
- li.stateChanged = false;
- m_LoaderMetadata[i] = li;
- }
- }
- }
- }
-
- return false;
- }
- }
- }
|