void CheckColorArrowsState() { CustomizationProfile modifiableProfile = customizationProfiles[selectedProfile]; previousColorButton.interactable = modifiableProfile.colorIndex > 0; nextColorButton.interactable = modifiableProfile.colorIndex < selectableColorsLength - 1; }
void CheckGadgetArrowsState() { CustomizationProfile modifiableProfile = customizationProfiles[selectedProfile]; previousGadgetButton.interactable = modifiableProfile.gadgetIndex > 0; nextGadgetButton.interactable = modifiableProfile.gadgetIndex < selectableGadgetsLength - 1; }
void CheckHatArrowsState() { CustomizationProfile modifiableProfile = customizationProfiles[selectedProfile]; previousHatButton.interactable = modifiableProfile.hatIndex > 0; nextHatButton.interactable = modifiableProfile.hatIndex < selectableHatsLength - 1; }
void SelectProfile(int index) { selectedProfile = index; CustomizationProfile profile = customizationProfiles[index]; selectedProfileNameText.text = profile.name; SetHat(profile.hatIndex); SetColor(profile.colorIndex); SetGadget(profile.gadgetIndex); spawnedProfileTickets.ForEach(item => { if (!item.HasThisProfile(profile)) { item.UnloadProfile(); } else { item.selectedStateImage.enabled = true; } }); CheckHatArrowsState(); CheckColorArrowsState(); CheckGadgetArrowsState(); }
void CreateCustomizationProfile() { // if new profile name is empty if (string.IsNullOrEmpty(newProfileNameInputField.text)) { Debug.LogWarning(debugTag + "Profile name was empty, therefore profile was not created"); return; } // if new profile name is the same as profile that already exists foreach (CustomizationProfile profile in customizationProfiles) { if (profile.name == newProfileNameInputField.text) { Debug.LogWarning(debugTag + "Can't create new profile with the same name as an already existing profile"); return; } } CustomizationProfile createdProfile = new CustomizationProfile(newProfileNameInputField.text, customizationProfiles[selectedProfile]); customizationProfiles.Add(createdProfile); SelectProfile(customizationProfiles.Count - 1); SpawnProfileTicket(createdProfile); }
public void Init(PlayerBehaviour player) { this.player = player; CustomizationProfilesList profileList = FileManager.LoadFile <CustomizationProfilesList>(FILE_LIST_NAME + CustomizationProfilesList.FILE_TYPE); // not the first time we play if (profileList != null) { loadedProfiles = new CustomizationProfile[profileList.profilesNames.Length]; for (int i = 0; i < profileList.profilesNames.Length; i++) { loadedProfiles[i] = FileManager.LoadFile <CustomizationProfile>(profileList.profilesNames[i], PROFILE_FOLDER_NAME); } } else // first time we play { Debug.Log(debugTag + "No profile names found, generating default profile"); loadedProfiles = new CustomizationProfile[1]; loadedProfiles[0] = new CustomizationProfile("Default"); } preferences = FileManager.LoadFile <PlayerPreferences>(PLAYER_PREFERENCES_FILE_NAME + CustomizationProfilesList.FILE_TYPE); if (preferences == null) { preferences = new PlayerPreferences(); } InitInternal(); }
public CustomizationProfile(string name, CustomizationProfile original) { this.name = name; hatIndex = original.hatIndex; colorIndex = original.colorIndex; gadgetIndex = original.gadgetIndex; }
void SpawnProfileTicket(CustomizationProfile profile) { CustomizationProfileTicket profileTicket = Instantiate(profileTicketprefab, profilesList); profileTicket.Init( profile, profile => { int index = customizationProfiles.IndexOf(profile); if (index == -1) { Debug.LogError(debugTag + "Profile not found, this should not happen...like ever"); return; } SelectProfile(index); }, (profile, ticket) => { if (spawnedProfileTickets.Count > 1) { if (selectedProfile > 0) { SelectProfile(selectedProfile - 1); } spawnedProfileTickets.Remove(ticket); customizationProfiles.Remove(profile); return(true); } else { return(false); } }, selectedProfile == profileTicket.transform.GetSiblingIndex() ); spawnedProfileTickets.Add(profileTicket); }
public void Init(CustomizationProfile profile, Action <CustomizationProfile> LoadProfile, Func <CustomizationProfile, CustomizationProfileTicket, bool> DeleteProfile, bool isInitialSelected) { selectedStateImage.enabled = isInitialSelected; profileNameText.text = profile.name; this.profile = profile; loadProfileButton.onClick.AddListener(() => { LoadProfile(profile); selectedStateImage.enabled = true; }); deleteProfileButton.onClick.AddListener(() => { bool shouldDestroy = DeleteProfile(profile, this); if (shouldDestroy) { Destroy(gameObject); } }); InitInternal(); }
public bool HasThisProfile(CustomizationProfile profile) { return(this.profile == profile); }
public void Init(Action ClosePanel, Func <int, Hat> giveHatToPlayer, Func <int, Color> giveColorToPlayer, Func <int, Gadget> giveGadgetToPlayer, CustomizationProfile[] loadedProfiles, int lastSelectedProfile, int selectableHatsLength, int selectableColorsLength, int selectableGadgetsLength) { GiveHatToPlayer = giveHatToPlayer; GiveColorToPlayer = giveColorToPlayer; GiveGadgetToPlayer = giveGadgetToPlayer; this.selectableHatsLength = selectableHatsLength; this.selectableColorsLength = selectableColorsLength; this.selectableGadgetsLength = selectableGadgetsLength; customizationProfiles = new List <CustomizationProfile>(loadedProfiles); spawnedProfileTickets = new List <CustomizationProfileTicket>(); selectedProfile = lastSelectedProfile; customizationProfiles.ForEach(item => SpawnProfileTicket(item)); exitPanelButton.onClick.AddListener(() => ClosePanel()); newProfileCreateButton.onClick.AddListener(() => { CreateCustomizationProfile(); newProfileNameInputField.SetTextWithoutNotify(""); }); previousHatButton.onClick.AddListener(() => { CustomizationProfile profile = customizationProfiles[selectedProfile]; profile.hatIndex--; SetHat(profile.hatIndex); CheckHatArrowsState(); }); nextHatButton.onClick.AddListener(() => { CustomizationProfile profile = customizationProfiles[selectedProfile]; profile.hatIndex++; SetHat(profile.hatIndex); CheckHatArrowsState(); }); previousColorButton.onClick.AddListener(() => { CustomizationProfile profile = customizationProfiles[selectedProfile]; profile.colorIndex--; SetColor(profile.colorIndex); CheckColorArrowsState(); }); nextColorButton.onClick.AddListener(() => { CustomizationProfile profile = customizationProfiles[selectedProfile]; profile.colorIndex++; SetColor(profile.colorIndex); CheckColorArrowsState(); }); previousGadgetButton.onClick.AddListener(() => { CustomizationProfile profile = customizationProfiles[selectedProfile]; profile.gadgetIndex--; SetGadget(profile.gadgetIndex); CheckGadgetArrowsState(); }); nextGadgetButton.onClick.AddListener(() => { CustomizationProfile profile = customizationProfiles[selectedProfile]; profile.gadgetIndex++; SetGadget(profile.gadgetIndex); CheckGadgetArrowsState(); }); CheckHatArrowsState(); CheckColorArrowsState(); CheckGadgetArrowsState(); SelectProfile(lastSelectedProfile); InitInternal(); }