using System.Collections; using System.Collections.Generic; using UnityEngine; using DG.Tweening; using Mirror; using TMPro; public class invitePlayer : NetworkBehaviour { [Header("UI References")] [SerializeField] private GameObject inviteUI, beingInviteUI; [SerializeField] private GameObject inPartyUI; [SerializeField] private TMP_Text inPartyOwnerNameTxt; [SerializeField] private TMP_Text inPartyPlayersTxt; [SerializeField] private TMP_Text inviteOwnerNameTxt; [SerializeField] private CanvasGroup uiCanvasGroup, bUiCanvasGroup; [SerializeField] private RectTransform uiRectTransform, panelRect; [Header("Animation Settings")] [SerializeField] private float appearDuration = 0.3f; [SerializeField] private float disappearDuration = 0.2f; [SerializeField] private Ease appearEase = Ease.OutBack; [SerializeField] private Ease disappearEase = Ease.InBack; [SerializeField] private Vector2 offScreenPosition = new Vector2(1200, -140); [SerializeField] private Vector2 onScreenPosition = new Vector2(1300, -140); private void Start() { uiRectTransform.localScale = Vector3.zero; uiCanvasGroup.alpha = 0; inviteUI.SetActive(false); beingInviteUI.SetActive(false); onScreenPosition = panelRect.anchoredPosition; offScreenPosition = new Vector2( +Screen.width, // Use screen width for consistent off-screen positioning onScreenPosition.y ); panelRect.anchoredPosition = offScreenPosition; } void Update() { if (Input.GetKeyDown(KeyCode.L)) { ShowInvite("keyBoard"); } } private void OnMouseDown() //clicking on collider //ToDo exclude owner { Debug.Log("OnMouseDown on invitePlayer " + GetComponent().playerName); ShowInviteUI(); } public void ShowInviteUI() { inviteUI.SetActive(true); uiCanvasGroup.alpha = 0; uiRectTransform.localScale = Vector3.zero; Sequence showSequence = DOTween.Sequence(); showSequence.Append(uiRectTransform.DOScale(1, appearDuration).SetEase(appearEase)) .Join(uiCanvasGroup.DOFade(1, appearDuration)) .SetUpdate(true); Camera.main.DOShakePosition(0.2f, 0.1f, 1, 90f, false); } public void CloseInviteUI() { Sequence hideSequence = DOTween.Sequence(); hideSequence.Append(uiRectTransform.DOScale(0, disappearDuration).SetEase(disappearEase)) .Join(uiCanvasGroup.DOFade(0, disappearDuration)) .OnComplete(() => inviteUI.SetActive(false)); } public void InvitePlayer() { string thisPlayerName = GetComponent().playerName; playerNetwork.localPlayer.CmdInvitePlayer(thisPlayerName); CloseInviteUI(); } public string InviteOwner = ""; public void ShowInvite(string ownerName) { InviteOwner = ownerName; inviteOwnerNameTxt.text = "You are being invited to a Party by " + ownerName; Debug.Log("ShowPanel called"); beingInviteUI.SetActive(true); panelRect.DOAnchorPos(onScreenPosition, 0.5f) .SetEase(Ease.OutBack); } public void AcceptInvite() { playerNetwork.localPlayer.CmdAcceptInvite(InviteOwner); HidePanel(); } public void DeclineInvite() { HidePanel(); } public void HidePanel() { panelRect.DOAnchorPos(offScreenPosition, 0.5f) .SetEase(Ease.OutBack) .OnComplete(() => beingInviteUI.SetActive(false)); } public void InParty(string ownerName) { if (ownerName.Length == 0) { inPartyUI.SetActive(false); } else { inPartyUI.SetActive(true); inPartyOwnerNameTxt.text = $"{ownerName}'s Party"; playerNetwork[] players = FindObjectsOfType(); List playerNames = new List(); foreach (playerNetwork player in players) { if (player.myPartyOwner == ownerName) { playerNames.Add(player.playerName); } } inPartyPlayersTxt.text = string.Join(", ", playerNames); } } public void LeaveParty(){ //playerNetwork.localPlayer.CmdLeaveParty(); inPartyUI.SetActive(false); } }