100 lines
3.1 KiB
C#
100 lines
3.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using DG.Tweening;
|
|
|
|
public class InviteUIManager : MonoBehaviour
|
|
{
|
|
[Header("UI References")]
|
|
[SerializeField] private GameObject inviteUI , beingInviteUI;
|
|
[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()
|
|
{
|
|
// Initialize hidden state
|
|
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
|
|
);
|
|
|
|
// Start with panel hidden
|
|
panelRect.anchoredPosition = offScreenPosition;
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.L))
|
|
{
|
|
ShowPanel();
|
|
}
|
|
}
|
|
private void OnMouseDown()
|
|
{
|
|
ShowInviteUI();
|
|
|
|
}
|
|
|
|
public void ShowInviteUI()
|
|
{
|
|
inviteUI.SetActive(true);
|
|
|
|
// Reset values before animation
|
|
uiCanvasGroup.alpha = 0;
|
|
uiRectTransform.localScale = Vector3.zero;
|
|
|
|
// Parallel animations
|
|
Sequence showSequence = DOTween.Sequence();
|
|
showSequence.Append(uiRectTransform.DOScale(1, appearDuration).SetEase(appearEase))
|
|
.Join(uiCanvasGroup.DOFade(1, appearDuration))
|
|
.SetUpdate(true); // Ensures animation runs smoothly even if time scale is modified
|
|
// Add to ShowInviteUI()
|
|
Camera.main.DOShakePosition(0.2f, 0.1f, 1, 90f, false );
|
|
// Ensures animation runs smoothly even if time scale is modified
|
|
}
|
|
|
|
public void CloseInviteUI()
|
|
{
|
|
// Animate before disabling
|
|
Sequence hideSequence = DOTween.Sequence();
|
|
hideSequence.Append(uiRectTransform.DOScale(0, disappearDuration).SetEase(disappearEase))
|
|
.Join(uiCanvasGroup.DOFade(0, disappearDuration))
|
|
.OnComplete(() => inviteUI.SetActive(false));
|
|
}
|
|
|
|
|
|
public void ShowPanel()
|
|
{
|
|
Debug.Log("ShowPanel called");
|
|
// Enable panel before animation
|
|
beingInviteUI.SetActive(true);
|
|
|
|
panelRect.DOAnchorPos(onScreenPosition, 0.5f)
|
|
.SetEase(Ease.OutBack);
|
|
}
|
|
|
|
public void HidePanel()
|
|
{
|
|
panelRect.DOAnchorPos(offScreenPosition, 0.5f)
|
|
.SetEase(Ease.OutBack)
|
|
.OnComplete(() => beingInviteUI.SetActive(false));
|
|
}
|
|
}
|