//UI magic to group the path pairs from profile variables internal static List<ProfileGroupType> CreateGroupTypes(AddressableAssetProfileSettings.BuildProfile buildProfile) { AddressableAssetSettings settings = AddressableAssetSettingsDefaultObject.Settings; 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); } GroupTypeVariable variable = new 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; }
/// <summary> /// Adds a variable in the group /// </summary> /// <param name="variable"></param> /// <returns>True if the variable was added, false if the variable already exists</returns> internal bool AddVariable(GroupTypeVariable variable) { GroupTypeVariable exists = m_Variables.Where(ps => ps.Suffix == variable.Suffix).FirstOrDefault(); if (exists != null) { Addressables.LogErrorFormat("{0} already exists.", GetName(variable)); return false; } m_Variables.Add(variable); return true; }
/// <summary> /// Removes a variable from the group /// </summary> /// <param name="variable"></param> internal void RemoveVariable(GroupTypeVariable variable) { GroupTypeVariable exists = m_Variables.Where(ps => ps.Suffix == variable.Suffix).FirstOrDefault(); if (exists == null) { Addressables.LogErrorFormat("{0} does not exist.", GetName(variable)); return; } else { m_Variables.Remove(variable); } }
// Adds a variable to the group, or updates the value if already exists internal void AddOrUpdateVariable(GroupTypeVariable variable) { foreach (GroupTypeVariable typeVariable in m_Variables) { if (typeVariable.Suffix == variable.Suffix) { typeVariable.Value = variable.Value; return; } } m_Variables.Add(variable); }
/// <summary> /// Returns the full variable name /// </summary> /// <param name="variable"></param> /// <returns>the full name of a variable</returns> internal string GetName(GroupTypeVariable variable) { return m_GroupTypePrefix + k_PrefixSeparator + variable.Suffix; }
/// <summary> /// Returns true if a group type has a certain variable /// </summary> /// <param name="groupTypeVariable">group type variable</param> /// <returns>true if the group type contains the variable, false otherwise</returns> internal bool ContainsVariable(GroupTypeVariable groupTypeVariable) { return m_Variables.Any(var => var.Suffix == groupTypeVariable.Suffix && var.Value == groupTypeVariable.Value); }