public void CannotRenameEntryToDuplicateName() { //Arrange Assert.IsNotNull(m_Settings.profileSettings); m_Settings.activeProfileId = null; m_Settings.profileSettings.Reset(); string entryName = "SomeName"; string newName = "NewerName"; string originalPath = "/Assets/Important"; m_Settings.profileSettings.CreateValue(entryName, originalPath); m_Settings.profileSettings.CreateValue(newName, originalPath); AddressableAssetProfileSettings.ProfileIdData currEntry = null; foreach (var entry in m_Settings.profileSettings.profileEntryNames) { if (entry.ProfileName == entryName) { currEntry = entry; break; } } //Act Assert.NotNull(currEntry); currEntry.SetName(newName, m_Settings.profileSettings); //Assert Assert.AreNotEqual(currEntry.ProfileName, newName); }
public static string ValueGUILayout(AddressableAssetSettings settings, string label, string currentId) { string result = currentId; if (settings == null) { return(result); } var displayNames = settings.profileSettings.GetVariableNames(); AddressableAssetProfileSettings.ProfileIdData data = settings.profileSettings.GetProfileDataById(currentId); bool custom = data == null; int currentIndex = displayNames.Count; string toolTip = string.Empty; if (!custom) { currentIndex = displayNames.IndexOf(data.ProfileName); toolTip = data.Evaluate(settings.profileSettings, settings.activeProfileId); } displayNames.Add(AddressableAssetProfileSettings.customEntryString); var content = new GUIContent(label, toolTip); EditorGUILayout.BeginHorizontal(); var newIndex = EditorGUILayout.Popup(content, currentIndex, displayNames.ToArray()); if (newIndex != currentIndex) { if (displayNames[newIndex] == AddressableAssetProfileSettings.customEntryString) { custom = true; result = AddressableAssetProfileSettings.undefinedEntryValue; } else { data = settings.profileSettings.GetProfileDataByName(displayNames[newIndex]); if (data != null) { result = data.Id; } } } EditorGUILayout.EndHorizontal(); EditorGUI.indentLevel += 1; if (custom) { result = EditorGUILayout.TextField(result); } else if (!string.IsNullOrEmpty(toolTip)) { EditorGUILayout.HelpBox(toolTip, MessageType.None); } EditorGUI.indentLevel -= 1; return(result); }
public ProfileRenameVariablePopup(float labelWidth, AddressableAssetProfileSettings.ProfileIdData profileVariable, AddressableAssetSettings settings) { m_LabelWidth = labelWidth; m_ProfileVariable = profileVariable; m_Settings = settings; m_NewName = m_ProfileVariable.ProfileName; UnityEngine.GUI.enabled = true; }
public ProfileRenameVariablePopup(Rect fieldRect, AddressableAssetProfileSettings.ProfileIdData profileVariable, AddressableAssetSettings settings) { m_WindowRect = fieldRect; m_ProfileVariable = profileVariable; m_Settings = settings; m_NewName = m_ProfileVariable.ProfileName; UnityEngine.GUI.enabled = true; }
public static string ValueGUI(Rect rect, AddressableAssetSettings settings, string label, string currentId) { string result = currentId; if (settings == null) { return(result); } var displayNames = settings.profileSettings.GetVariableNames(); AddressableAssetProfileSettings.ProfileIdData data = settings.profileSettings.GetProfileDataById(currentId); bool custom = data == null; int currentIndex = displayNames.Count; string toolTip = string.Empty; if (!custom) { currentIndex = displayNames.IndexOf(data.ProfileName); toolTip = data.Evaluate(settings.profileSettings, settings.activeProfileId); } displayNames.Add(AddressableAssetProfileSettings.customEntryString); var labelContent = new GUIContent(label); var size = EditorStyles.popup.CalcSize(labelContent); var topRect = new Rect(rect.x, rect.y, rect.width, size.y); var newIndex = EditorGUI.Popup(topRect, label, currentIndex, displayNames.ToArray()); if (newIndex != currentIndex) { if (displayNames[newIndex] == AddressableAssetProfileSettings.customEntryString) { custom = true; result = AddressableAssetProfileSettings.undefinedEntryValue; } else { data = settings.profileSettings.GetProfileDataByName(displayNames[newIndex]); if (data != null) { result = data.Id; } } } var bottomRect = new Rect(rect.x + 10, rect.y + size.y + EditorGUIUtility.standardVerticalSpacing, rect.width - 20, rect.height - (size.y + EditorGUIUtility.standardVerticalSpacing)); if (custom) { result = EditorGUI.TextField(bottomRect, result); } else if (!string.IsNullOrEmpty(toolTip)) { EditorGUI.HelpBox(bottomRect, toolTip, MessageType.None); } return(result); }
//Opens ProfileRenameVariablePopup void RenameVariable(AddressableAssetProfileSettings.ProfileIdData profileVariable, Rect displayRect) { try { PopupWindow.Show(displayRect, new ProfileRenameVariablePopup(displayRect, profileVariable, settings)); } catch (ExitGUIException) { // Exception not being caught through OnGUI call } }
static string Evaluate(AddressableAssetSettings settings, AddressableAssetProfileSettings.ProfileIdData data) { if (data.InlineUsage) { return(settings.profileSettings.EvaluateString(settings.activeProfileId, data.Id)); } string baseValue = settings.profileSettings.GetValueById(settings.activeProfileId, data.Id); return(settings.profileSettings.EvaluateString(settings.activeProfileId, baseValue)); }
void DeleteVariable(int columnIndex) { AddressableAssetProfileSettings.ProfileIdData variable = m_Window.settings.profileSettings.profileEntryNames.Find((s) => s.ProfileName.Equals(state.columns[columnIndex].headerContent.text)); if (variable != null) { m_Window.settings.profileSettings.RemoveValue(variable.Id); } }
//Opens ProfileRenameVariablePopup void RenameVariable(AddressableAssetProfileSettings.ProfileIdData profileVariable, Rect parentWindow, Rect displayRect) { try { //Determines the current variable rect location Rect variableRect = new Rect(position.x + parentWindow.x + displayRect.x, position.y + parentWindow.y + displayRect.y, position.width, k_ToolbarHeight); PopupWindow.Show(variableRect, new ProfileRenameVariablePopup(displayRect, profileVariable, settings)); } catch (ExitGUIException) { // Exception not being caught through OnGUI call } }
//Creates the context menu for the selected variable void CreateVariableContextMenu(Rect parentWindow, Rect menuRect, AddressableAssetProfileSettings.ProfileIdData variable, Event evt) { if (menuRect.Contains(evt.mousePosition)) { GenericMenu menu = new GenericMenu(); //Displays name of selected variable so user can be confident they're deleting/renaming the right one menu.AddDisabledItem(new GUIContent(variable.ProfileName)); menu.AddSeparator(""); menu.AddItem(new GUIContent("Rename Variable (All Profiles)"), false, () => { RenameVariable(variable, parentWindow, menuRect); }); menu.AddItem(new GUIContent("Delete Variable (All Profiles)"), false, () => { DeleteVariable(variable); }); menu.ShowAsContext(); evt.Use(); } }
public static float CalcGUIHeight(AddressableAssetSettings settings, string label, string currentId) { var labelContent = new GUIContent(label); var size = EditorStyles.popup.CalcSize(labelContent); var height = size.y + EditorGUIUtility.standardVerticalSpacing; AddressableAssetProfileSettings.ProfileIdData data = settings.profileSettings.GetProfileDataById(currentId); if (data != null) { var val = data.Evaluate(settings.profileSettings, settings.activeProfileId); var h = EditorStyles.helpBox.CalcHeight(new GUIContent(val), EditorGUIUtility.currentViewWidth - EditorGUIUtility.labelWidth - 16); return(height + h); } return(height + EditorStyles.textField.CalcHeight(new GUIContent(currentId), EditorGUIUtility.currentViewWidth - EditorGUIUtility.labelWidth - 16)); }
public static string ValueGUI(Rect rect, AddressableAssetSettings settings, string label, string currentId, ref bool wasChanged) { string result = currentId; if (settings == null) { return(result); } var displayNames = settings.profileSettings.GetVariableNames(); AddressableAssetProfileSettings.ProfileIdData data = settings.profileSettings.GetProfileDataById(currentId); bool custom = data == null && currentId != "—"; int currentIndex = displayNames.Count; string toolTip = string.Empty; if (currentId == "—") { currentIndex = -1; toolTip = "—"; result = "—"; } else { if (!custom) { currentIndex = displayNames.IndexOf(data.ProfileName); toolTip = data.Evaluate(settings.profileSettings, settings.activeProfileId); } } displayNames.Add(AddressableAssetProfileSettings.customEntryString); var labelContent = new GUIContent(label); var size = EditorStyles.popup.CalcSize(labelContent); var topRect = new Rect(rect.x, rect.y, rect.width, size.y); EditorGUI.BeginChangeCheck(); var newIndex = EditorGUI.Popup(topRect, label, currentIndex, displayNames.ToArray()); wasChanged = EditorGUI.EndChangeCheck(); if (newIndex != -1 && newIndex != currentIndex) { if (displayNames[newIndex] == AddressableAssetProfileSettings.customEntryString) { custom = true; result = AddressableAssetProfileSettings.undefinedEntryValue; } else { data = settings.profileSettings.GetProfileDataByName(displayNames[newIndex]); if (data != null) { result = data.Id; } } } var bottomRect = new Rect(rect.x, rect.y + size.y + EditorGUIUtility.standardVerticalSpacing, rect.width, rect.height - (size.y + EditorGUIUtility.standardVerticalSpacing)); if (custom) { result = EditorGUI.TextField(bottomRect, " ", result); } else if (!string.IsNullOrEmpty(toolTip)) { GUIStyle pathBox = new GUIStyle(EditorStyles.miniLabel); pathBox.wordWrap = true; EditorGUI.LabelField(bottomRect, " ", toolTip, pathBox); } return(result); }
//Displays all variables for the currently selected profile and initializes each variable's context menu void VariablesPane(Rect variablesPaneRect) { DrawOutline(variablesPaneRect, 1); Event evt = Event.current; AddressableAssetProfileSettings.BuildProfile selectedProfile = GetSelectedProfile(); if (selectedProfile == null) { return; } if (evt.isMouse || evt.isKey) { m_ProfileTreeView.lastClickedProfile = ProfileIndex; } //ensures amount of visible text is not affected by label width float fieldWidth = variablesPaneRect.width - (2 * k_ItemRectPadding) + m_LabelWidth + m_FieldBufferWidth; float fieldX = variablesPaneRect.x + k_ItemRectPadding; float fieldHeight = k_ToolbarHeight; //Amount of text visible not affected by amount of text either, large enough for arbitrary # of variables float viewRectHeight = (fieldHeight + k_VariableItemPadding) * settings.profileSettings.profileEntryNames.Count + fieldHeight; float viewRectWidth = fieldWidth + (2 * k_ItemRectPadding); Rect viewRect = new Rect(variablesPaneRect.x, variablesPaneRect.y, viewRectWidth, viewRectHeight); if (!EditorGUIUtility.labelWidth.Equals(m_LabelWidth)) { EditorGUIUtility.labelWidth = m_LabelWidth; } int maxLabelLen = 0; int maxFieldLen = 0; m_VariablesPaneScrollPosition = UnityEngine.GUI.BeginScrollView(variablesPaneRect, m_VariablesPaneScrollPosition, viewRect); for (int i = 0; i < settings.profileSettings.profileEntryNames.Count; i++) { //Keep track of the maximum length label, field so we can ensure that variable names, values are always completely visible maxLabelLen = Math.Max(maxLabelLen, settings.profileSettings.profileEntryNames[i].ProfileName.Length); maxFieldLen = Math.Max(maxFieldLen, selectedProfile.values[i].value.Length); float fieldY = (variablesPaneRect.y + k_VariableItemPadding) * i + k_ItemRectPadding + k_ToolbarHeight; AddressableAssetProfileSettings.ProfileIdData curVariable = settings.profileSettings.profileEntryNames[i]; Rect fieldRect = new Rect(fieldX, fieldY, fieldWidth, fieldHeight); Rect labelRect = new Rect(fieldX, fieldY, m_LabelWidth, fieldHeight); string newName = EditorGUI.TextField(fieldRect, curVariable.ProfileName, selectedProfile.values[i].value); //Ensure changes get serialized if (selectedProfile.values[i].value != newName && ProfileIndex == m_ProfileTreeView.lastClickedProfile) { Undo.RecordObject(settings, "Variable value changed"); settings.profileSettings.SetValue(selectedProfile.id, settings.profileSettings.profileEntryNames[i].ProfileName, newName); AddressableAssetUtility.OpenAssetIfUsingVCIntegration(settings); } if (evt.type == EventType.ContextClick) { CreateVariableContextMenu(labelRect, curVariable, i, evt); } } UnityEngine.GUI.EndScrollView(); //Update the label width to the maximum of the minimum acceptable label width and the amount of //space required to contain the longest variable name m_LabelWidth = Mathf.Max(maxLabelLen * k_ApproxCharWidth, k_MinLabelWidth); m_FieldBufferWidth = Mathf.Clamp((maxFieldLen * k_ApproxCharWidth) - fieldWidth, 0f, float.MaxValue); }
void DeleteVariable(AddressableAssetProfileSettings.ProfileIdData toBeDeleted) { Undo.RecordObject(settings, "Profile Variable Deleted"); settings.profileSettings.RemoveValue(toBeDeleted.Id); AddressableAssetUtility.OpenAssetIfUsingVCIntegration(settings); }
//Displays all variables for the currently selected profile and initializes each variable's context menu void VariablesPane(Rect variablesPaneRect) { DrawOutline(variablesPaneRect, 1); Event evt = Event.current; AddressableAssetProfileSettings.BuildProfile selectedProfile = GetSelectedProfile(); if (selectedProfile == null) { return; } if (evt.isMouse || evt.isKey) { m_ProfileTreeView.lastClickedProfile = ProfileIndex; } //ensures amount of visible text is not affected by label width float fieldWidth = variablesPaneRect.width - (2 * k_ItemRectPadding) + m_LabelWidth + m_FieldBufferWidth; if (!EditorGUIUtility.labelWidth.Equals(m_LabelWidth)) { EditorGUIUtility.labelWidth = m_LabelWidth; } int maxLabelLen = 0; int maxFieldLen = 0; GUILayout.BeginArea(variablesPaneRect); EditorGUI.indentLevel++; List <ProfileGroupType> groupTypes = CreateGroupTypes(selectedProfile); HashSet <string> drawnGroupTypes = new HashSet <string>(); //Displaying Path Groups foreach (ProfileGroupType groupType in groupTypes) { bool?foldout; m_foldouts.TryGetValue(groupType.GroupTypePrefix, out foldout); GUILayout.Space(5); m_foldouts[groupType.GroupTypePrefix] = EditorGUILayout.Foldout(foldout != null ? foldout.Value : true, groupType.GroupTypePrefix, true); //Specific Grouped variables List <ProfileGroupType.GroupTypeVariable> pathVariables = new List <ProfileGroupType.GroupTypeVariable>(); pathVariables.Add(groupType.GetVariableBySuffix("BuildPath")); drawnGroupTypes.Add(groupType.GetName(groupType.GetVariableBySuffix("BuildPath"))); pathVariables.Add(groupType.GetVariableBySuffix("LoadPath")); drawnGroupTypes.Add(groupType.GetName(groupType.GetVariableBySuffix("LoadPath"))); if (m_foldouts[groupType.GroupTypePrefix].Value) { EditorGUI.indentLevel++; //Displaying Path Groups foreach (var variable in pathVariables) { Rect newPathRect = EditorGUILayout.BeginVertical(); string newPath = EditorGUILayout.TextField(groupType.GetName(variable), variable.Value); EditorGUILayout.EndVertical(); if (evt.type == EventType.ContextClick) { CreateVariableContextMenu(variablesPaneRect, newPathRect, settings.profileSettings.GetProfileDataByName(groupType.GetName(variable)), evt); } if (newPath != variable.Value && ProfileIndex == m_ProfileTreeView.lastClickedProfile) { Undo.RecordObject(settings, "Variable value changed"); settings.profileSettings.SetValue(selectedProfile.id, groupType.GetName(variable), newPath); AddressableAssetUtility.OpenAssetIfUsingVCIntegration(settings); } } EditorGUI.indentLevel--; } } //Display all other variables for (var i = 0; i < settings.profileSettings.profileEntryNames.Count; i++) { AddressableAssetProfileSettings.ProfileIdData curVariable = settings.profileSettings.profileEntryNames[i]; if (!drawnGroupTypes.Contains(curVariable.ProfileName)) { GUILayout.Space(5); Rect newValueRect = EditorGUILayout.BeginVertical(); string newValue = EditorGUILayout.TextField(curVariable.ProfileName, selectedProfile.values[i].value); EditorGUILayout.EndVertical(); if (newValue != selectedProfile.values[i].value && ProfileIndex == m_ProfileTreeView.lastClickedProfile) { Undo.RecordObject(settings, "Variable value changed"); settings.profileSettings.SetValue(selectedProfile.id, settings.profileSettings.profileEntryNames[i].ProfileName, newValue); AddressableAssetUtility.OpenAssetIfUsingVCIntegration(settings); } if (evt.type == EventType.ContextClick) { CreateVariableContextMenu(variablesPaneRect, newValueRect, curVariable, evt); } } maxLabelLen = Math.Max(maxLabelLen, curVariable.ProfileName.Length); } EditorGUI.indentLevel--; GUILayout.EndArea(); //Update the label width to the maximum of the minimum acceptable label width and the amount of //space required to contain the longest variable name m_LabelWidth = Mathf.Max(maxLabelLen * k_ApproxCharWidth, k_MinLabelWidth); m_FieldBufferWidth = Mathf.Clamp((maxFieldLen * k_ApproxCharWidth) - fieldWidth, 0f, float.MaxValue); }