void Start() { Setup(); btAddTween = BtAdd.transform.DORotate(new Vector3(0, 0, -45), 0.3f).SetAutoKill(false).Pause() .SetEase(Ease.OutBack) .OnRewind(() => { if (ProfileManager.AvailablePlayerProfiles == null || ProfileManager.AvailablePlayerProfiles.Count == 0) { BtAdd.Pulse(); } }); btPlayTween = DOTween.Sequence().SetAutoKill(false).Pause() .Append(BtPlay.RectT.DOAnchorPosY(-210, 0.2f).From(true)) .OnPlay(() => BtPlay.gameObject.SetActive(true)) .OnRewind(() => BtPlay.gameObject.SetActive(false)) .OnComplete(() => BtPlay.Pulse()); BtPlay.gameObject.SetActive(false); // Listeners BtAdd.Bt.onClick.AddListener(() => OnClick(BtAdd)); BtPlay.Bt.onClick.AddListener(() => { AudioManager.I.PlaySfx(Sfx.UIButtonClick); HomeManager.I.Play(); }); foreach (ProfileSelectorAvatarButton bt in avatarButtons) { ProfileSelectorAvatarButton b = bt; b.Bt.onClick.AddListener(() => OnClick(b)); } }
public void OnClick(ProfileSelectorAvatarButton _bt) { if (showTween.IsPlaying()) { return; } ProfileSelectorUI.I.AddProfile(Array.IndexOf(avatarButtons, _bt) + 1); }
// Layout with current profiles void Setup() { ActivateProfileButtons(true); int totProfiles = ProfileManager.AvailablePlayerProfiles == null ? 0 : ProfileManager.AvailablePlayerProfiles.Count; int len = avatarButtons.Length; for (int i = 0; i < len; ++i) { ProfileSelectorAvatarButton bt = GetAvatarButtonByPlayerId(i + 1); // right to left if (i >= totProfiles) { bt.gameObject.SetActive(false); } else { bt.gameObject.SetActive(true); bt.SetAvatar(ProfileManager.AvailablePlayerProfiles[i].AvatarId); if (i == ProfileManager.CurrentPlayer.Id - 1) { bt.Toggle(true, true); } else { bt.Toggle(false); } } } if (totProfiles == 0) { BtAdd.Pulse(); BtPlay.StopPulsing(); btPlayTween.PlayBackwards(); } else { // Set play button position this.StartCoroutine(CO_SetupPlayButton()); } if (totProfiles >= maxProfiles) { btAddTween.Rewind(); BtAdd.gameObject.SetActive(false); } }
void Awake() { avatarButtons = this.GetComponentsInChildren <ProfileSelectorAvatarButton>(true); for (int i = 0; i < avatarButtons.Length; ++i) { avatarButtons[i].SetAvatar(i + 1); } showTween = this.GetComponent <RectTransform>().DOAnchorPosY(-200, 0.24f).From(true) .SetAutoKill(false).Pause() .OnPlay(() => this.gameObject.SetActive(true)) .OnRewind(() => this.gameObject.SetActive(false)); this.gameObject.SetActive(false); // Listeners foreach (ProfileSelectorAvatarButton bt in avatarButtons) { ProfileSelectorAvatarButton b = bt; b.Bt.onClick.AddListener(() => OnClick(b)); } }
internal void Show() { if (IsShown) { return; } IsShown = true; AudioManager.I.PlaySfx(ProfileSelectorUI.I.SfxOpenCreateProfile); // Set available avatars bool hasProfiles = ProfileSelectorUI.I.ProfileManager.AvailablePlayerProfiles != null && ProfileSelectorUI.I.ProfileManager.AvailablePlayerProfiles.Count > 0; for (int i = 0; i < avatarButtons.Length; ++i) { ProfileSelectorAvatarButton bt = avatarButtons[i]; int id = i + 1; bool isAvailable = true; if (hasProfiles) { foreach (PlayerProfile pp in ProfileSelectorUI.I.ProfileManager.AvailablePlayerProfiles) { if (pp.AvatarId == id) { isAvailable = false; break; } } } bt.SetInteractivity(isAvailable); } this.gameObject.SetActive(true); showTween.PlayForward(); }
int GetPlayerIdByAvatarButton(ProfileSelectorAvatarButton _bt) { return(avatarButtons.Length - Array.IndexOf(avatarButtons, _bt)); }