//UI magic to group the path pairs from profile variables List <ProfileGroupType> CreateGroupTypes(AddressableAssetProfileSettings.BuildProfile buildProfile) { Dictionary <string, ProfileGroupType> groups = new Dictionary <string, ProfileGroupType>(); foreach (var profileEntry in settings.profileSettings.profileEntryNames) { string[] parts = profileEntry.ProfileName.Split(k_PrefixSeparator); if (parts.Length > 1) { string prefix = String.Join(k_PrefixSeparator.ToString(), parts, 0, parts.Length - 1); string suffix = parts[parts.Length - 1]; string profileEntryValue = buildProfile.GetValueById(profileEntry.Id); ProfileGroupType group; groups.TryGetValue(prefix, out group); if (group == null) { group = new ProfileGroupType(prefix); } ProfileGroupType.GroupTypeVariable variable = new ProfileGroupType.GroupTypeVariable(suffix, profileEntryValue); group.AddVariable(variable); groups[prefix] = group; } } List <ProfileGroupType> groupList = new List <ProfileGroupType>(); groupList.AddRange(groups.Values.Where(group => group.IsValidGroupType())); return(groupList); }
public void RenameProfileFailsOnNullProfile() { Assert.IsNotNull(Settings.profileSettings, "Profile settings should not be null"); Settings.activeProfileId = null; var baseid = Settings.profileSettings.Reset(); var profile1Id = Settings.profileSettings.AddProfile("Profile1", baseid); AddressableAssetProfileSettings.BuildProfile nullProfile = null; //Act bool renameSuccessful = Settings.profileSettings.RenameProfile(nullProfile, "invalidId"); //Assert LogAssert.Expect(LogType.Error, "Profile rename failed because profile passed in is null"); Assert.AreEqual(false, renameSuccessful, "Rename succeeded when it should have failed because of null profile."); Assert.AreEqual("Profile1", Settings.profileSettings.GetProfileName(profile1Id), "Profile name was changed when rename should have failed."); }
protected override void RenameEnded(RenameEndedArgs args) { var item = FindItemInVisibleRows(args.itemID); AddressableAssetProfileSettings.BuildProfile profile = GetProfile(item.id); Undo.RecordObject(m_Window.settings, "Profile renamed"); bool renameSuccessful = m_Window.settings.profileSettings.RenameProfile(profile, args.newName); AddressableAssetUtility.OpenAssetIfUsingVCIntegration(m_Window.settings, true); if (renameSuccessful) { Reload(); } }
public void RenameProfileFailsOnExternallyCreatedProfile() { //Arrange Assert.IsNotNull(Settings.profileSettings, "Profile settings should not be null"); Settings.activeProfileId = null; var baseid = Settings.profileSettings.Reset(); var baseProfile = Settings.profileSettings.GetProfile(baseid); var externalProfile = new AddressableAssetProfileSettings.BuildProfile("Bad profile", baseProfile, Settings.profileSettings); //Act bool renameSuccessful = Settings.profileSettings.RenameProfile(externalProfile, "new name"); //Assert Assert.AreEqual(true, renameSuccessful, "Rename was unsuccessful when it should have succeeded."); Assert.AreEqual("new name", externalProfile.profileName, "Profile name was not changed despite rename succeeding. "); Assert.AreEqual(1, Settings.profileSettings.profiles.Count, "Number of profiles changed when should be left the same"); Assert.AreEqual(null, Settings.profileSettings.GetProfile(externalProfile.id), "Externally created profile was added to profile settings despite not being created properly."); }
//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); }
//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); }
public ProfileTreeViewItem(AddressableAssetProfileSettings.BuildProfile buildProfile) : base(buildProfile.GetHashCode(), 0, buildProfile.profileName) { m_buildProfile = buildProfile; }