99 lines
2.5 KiB
C#
99 lines
2.5 KiB
C#
using Photon.Pun;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
|
||
public class PlayerInput : MonoBehaviour
|
||
{
|
||
[Header("UI References")]
|
||
[SerializeField] private GameObject characterPanel;
|
||
[SerializeField] private GameObject inventoryPanel;
|
||
[SerializeField] private GameObject radialMenu;
|
||
|
||
private PhotonView photonView;
|
||
private bool isRadialMenuOpen;
|
||
|
||
private void Awake()
|
||
{
|
||
photonView = GetComponent<PhotonView>();
|
||
}
|
||
|
||
private void Update()
|
||
{
|
||
if (!photonView.IsMine) return;
|
||
|
||
// D-Pad controls
|
||
if (Input.GetButtonDown("DPadUp"))
|
||
{
|
||
TogglePanel(characterPanel);
|
||
}
|
||
if (Input.GetButtonDown("DPadDown"))
|
||
{
|
||
TogglePanel(inventoryPanel);
|
||
}
|
||
|
||
// Radial Menu
|
||
float leftTrigger = Input.GetAxisRaw("LeftTrigger");
|
||
if (leftTrigger > 0.5f && !isRadialMenuOpen)
|
||
{
|
||
OpenRadialMenu();
|
||
}
|
||
else if (leftTrigger < 0.5f && isRadialMenuOpen)
|
||
{
|
||
CloseRadialMenu();
|
||
}
|
||
|
||
if (isRadialMenuOpen)
|
||
{
|
||
// Handle radial menu selection with right stick
|
||
Vector2 rightStick = new Vector2(
|
||
Input.GetAxisRaw("RightStickHorizontal"),
|
||
Input.GetAxisRaw("RightStickVertical")
|
||
);
|
||
|
||
if (rightStick.magnitude > 0.5f)
|
||
{
|
||
UpdateRadialMenuSelection(rightStick);
|
||
}
|
||
}
|
||
}
|
||
|
||
private void TogglePanel(GameObject panel)
|
||
{
|
||
if (panel.activeSelf)
|
||
{
|
||
panel.SetActive(false);
|
||
}
|
||
else
|
||
{
|
||
// Close other panels first
|
||
characterPanel.SetActive(false);
|
||
inventoryPanel.SetActive(false);
|
||
// Open requested panel
|
||
panel.SetActive(true);
|
||
}
|
||
}
|
||
|
||
private void OpenRadialMenu()
|
||
{
|
||
isRadialMenuOpen = true;
|
||
radialMenu.SetActive(true);
|
||
Time.timeScale = 0.2f; // Slow down time while menu is open
|
||
}
|
||
|
||
private void CloseRadialMenu()
|
||
{
|
||
isRadialMenuOpen = false;
|
||
radialMenu.SetActive(false);
|
||
Time.timeScale = 1f;
|
||
}
|
||
|
||
private void UpdateRadialMenuSelection(Vector2 direction)
|
||
{
|
||
float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
|
||
if (angle < 0) angle += 360f;
|
||
|
||
// Update radial menu UI based on angle
|
||
// Each menu item covers 360<36> / number_of_items degrees
|
||
}
|
||
} |