private void CycleThroughOptions(CustomisationType customisationType, Direction direction) { if (direction == Direction.Left) { // This wraps around if the user reaches the end of the customisation options for that group if (customisationType.index > 0) { customisationType.index--; } else { customisationType.index = colors.Length - 1; } } else if (direction == Direction.Right) { if (customisationType.index < colors.Length - 1) { customisationType.index++; } else { customisationType.index = 0; } } customisationType.color = colors[customisationType.index]; customisationType.image.color = customisationType.color; LogCustomisationState(); }
/// <summary> /// Sets up the sprite for a specific customisation /// </summary> private void SetupCustomisationSprite(CustomisationType customisationType, string customisationKey, string customisationName, Color?color = null) { if (customisationName != "None") { SpriteDataSO spriteDataSO = PlayerCustomisationDataSOs.Instance.Get(customisationType, ThisCharacter.Gender, customisationName).SpriteEquipped; SetupSprite(spriteDataSO, customisationKey, color); } }
/// <summary> /// Returns all PlayerCustomisationDatas of a certain type. /// </summary> public IEnumerable <PlayerCustomisationData> GetAll(CustomisationType type, Gender gender) { if (!IsTypePopulated(type)) { return(null); } return(playerCustomisationDictionary[type].Where(pcd => pcd.Type == type && (pcd.gender == gender || pcd.gender == Gender.Neuter))); }
/// <summary> /// Returns the first customisation type it can find /// </summary> private PlayerCustomisationData GetFirst(CustomisationType type, Gender gender) { if (!IsTypePopulated(type)) { return(null); } return(playerCustomisationDictionary[type].FirstOrDefault(pcd => pcd.Type == type && (pcd.gender == gender || pcd.gender == Gender.Neuter))); }
/// <summary> /// Returns a PlayerCustomisationData using the type and name. /// Returns null if not found. /// </summary> public PlayerCustomisationData Get(CustomisationType type, Gender gender, string customisationName) { if (!IsTypePopulated(type)) { return(null); } return(playerCustomisationDictionary[type].FirstOrDefault(pcd => pcd.Type == type && (pcd.gender == gender || pcd.gender == Gender.Neuter) && pcd.Name == customisationName)); }
/// <summary> /// Sets up the sprite for a specific customisation /// </summary> private void SetupCustomisationSprite(CustomisationType customisationType, string customisationKey, string customisationName, string htmlColor) { if (ColorUtility.TryParseHtmlString(htmlColor, out var newColor)) { SetupCustomisationSprite(customisationType, customisationKey, customisationName, newColor); } else { SetupCustomisationSprite(customisationType, customisationKey, customisationName); } }
private bool IsTypePopulated(CustomisationType type) { if (playerCustomisationDictionary.ContainsKey(type) && playerCustomisationDictionary[type].Any()) { return(true); } Logger.LogErrorFormat( "No entries for {0} CustomisationType. Have they been populated correctly in the inspector?", Category.Character, type); return(false); }
private void PopulateDropdown(CustomisationType type, Dropdown itemDropdown) { // Clear out old options itemDropdown.ClearOptions(); // Make a list of all available options which can then be passed to the dropdown box var itemOptions = PlayerCustomisationDataSOs.Instance.GetAll(type, currentCharacter.Gender) .Select(pcd => pcd.Name).ToList(); itemOptions.Sort(); // Ensure "None" is at the top of the option lists itemOptions.Insert(0, "None"); itemDropdown.AddOptions(itemOptions); }
/// <summary> /// Checks if a customisation type with settingName exists. /// If it can't find one then defaultSettingName contains a default one. /// </summary> /// <param name="type">Customisation type of settingName</param> /// <param name="gender">The gender of the customisation option</param> /// <param name="settingName">The name of the setting</param> /// <param name="defaultSettingName">The default setting to assign on failure</param> /// <returns></returns> private bool IsSettingValid(CustomisationType type, Gender gender, string settingName, out string defaultSettingName) { var foundSetting = Get(type, gender, settingName); if (settingName == "None" || foundSetting != null) { defaultSettingName = string.Empty; return(true); } defaultSettingName = GetFirst(type, gender)?.Name ?? "None"; Logger.LogWarningFormat("Invalid {0} setting: cannot find {1}. Resetting to {2}.", Category.Character, type, settingName, defaultSettingName); return(false); }
public void Setup(CustomisationGroup Customisations, CharacterCustomization incharacterCustomization, SpriteOrder _SpriteOrder) { thisCustomisations = Customisations; characterCustomization = incharacterCustomization; HeadName.text = Customisations.ThisType.ToString(); spriteOrder = _SpriteOrder; spriteHandlerNorder.SetSpriteOrder(spriteOrder); ThisType = Customisations.ThisType; // Make a list of all available options which can then be passed to the dropdown box var itemOptions = Customisations.PlayerCustomisations.Select(pcd => pcd.Name).ToList(); itemOptions.Sort(); // Ensure "None" is at the top of the option lists itemOptions.Insert(0, "None"); Dropdown.AddOptions(itemOptions); RelatedSpriteRenderer.gameObject.transform.SetParent(incharacterCustomization.SpriteContainer.transform); RelatedSpriteRenderer.gameObject.transform.localPosition = Vector3.zero; Dropdown.onValueChanged.AddListener(ItemChange); }
private void PopulateDropdown(CustomisationType type, Dropdown itemDropdown) { var itemCollection = PlayerCustomisationDataSOs.Instance.GetAll(type); // Clear out old options itemDropdown.ClearOptions(); // Make a list of all available options which can then be passed to the dropdown box List <string> itemOptions = new List <string>(); foreach (var item in itemCollection) { // Only add options that match current gender or are Neuter if (item.gender == currentCharacter.Gender || item.gender == Gender.Neuter) { itemOptions.Add(item.Name); } } itemOptions.Sort(); // Ensure "None" is at the top of the option lists itemOptions.Insert(0, "None"); itemDropdown.AddOptions(itemOptions); }
/// <summary> /// Returns all PlayerCustomisationDatas of a certain type. /// </summary> public IEnumerable <PlayerCustomisationData> GetAll(CustomisationType type) { return(DataPCD.Where(data => data.Type == type)); }
/// <summary> /// Returns a PlayerCustomisationData using the type and name. /// Returns null if not found. /// </summary> public PlayerCustomisationData Get(CustomisationType type, string customisationName) { return(DataPCD.FirstOrDefault(data => data.Type == type && data.Name == customisationName)); }