chunk 1: core gameplay scripts scenes runtime assets
This commit is contained in:
8
Assets/Scripts/Behaviours/Player.meta
Normal file
8
Assets/Scripts/Behaviours/Player.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f8fc13f43eb65864db04c81601dcf0cc
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
39
Assets/Scripts/Behaviours/Player/PlayerAnimationBehaviour.cs
Normal file
39
Assets/Scripts/Behaviours/Player/PlayerAnimationBehaviour.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerAnimationBehaviour : MonoBehaviour
|
||||
{
|
||||
[Header("Component References")]
|
||||
public Animator playerAnimator;
|
||||
|
||||
//Animation String IDs
|
||||
private int playerMovementAnimationID;
|
||||
private int playerAttackAnimationID;
|
||||
|
||||
public void SetupBehaviour()
|
||||
{
|
||||
SetupAnimationIDs();
|
||||
}
|
||||
|
||||
void SetupAnimationIDs()
|
||||
{
|
||||
playerMovementAnimationID = Animator.StringToHash("Movement");
|
||||
playerAttackAnimationID = Animator.StringToHash("Attack");
|
||||
}
|
||||
|
||||
public void UpdateMovementAnimation(float movementBlendValue)
|
||||
{
|
||||
playerAnimator.SetFloat(playerMovementAnimationID, movementBlendValue);
|
||||
}
|
||||
|
||||
public void PlayAttackAnimation()
|
||||
{
|
||||
// If the unified input-to-animation system is present, avoid double-triggering
|
||||
if (GetComponent<InputToAnimation>() != null)
|
||||
return;
|
||||
playerAnimator.SetTrigger(playerAttackAnimationID);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 733c62aa19a5f384ea007d48fd472e50
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
209
Assets/Scripts/Behaviours/Player/PlayerController.cs
Normal file
209
Assets/Scripts/Behaviours/Player/PlayerController.cs
Normal file
@@ -0,0 +1,209 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class PlayerController : MonoBehaviour
|
||||
{
|
||||
|
||||
//Player ID
|
||||
private int playerID;
|
||||
|
||||
[Header("Sub Behaviours")]
|
||||
public PlayerMovementBehaviour playerMovementBehaviour;
|
||||
public PlayerAnimationBehaviour playerAnimationBehaviour;
|
||||
public PlayerVisualsBehaviour playerVisualsBehaviour;
|
||||
|
||||
|
||||
[Header("Input Settings")]
|
||||
public PlayerInput playerInput;
|
||||
public float movementSmoothingSpeed = 1f;
|
||||
private Vector3 rawInputMovement;
|
||||
private Vector3 smoothInputMovement;
|
||||
|
||||
//Action Maps
|
||||
private string actionMapPlayerControls = "Player Controls";
|
||||
private string actionMapMenuControls = "Menu Controls";
|
||||
|
||||
//Current Control Scheme
|
||||
private string currentControlScheme;
|
||||
|
||||
|
||||
//This is called from the GameManager; when the game is being setup.
|
||||
public void SetupPlayer(int newPlayerID)
|
||||
{
|
||||
playerID = newPlayerID;
|
||||
|
||||
currentControlScheme = playerInput.currentControlScheme;
|
||||
|
||||
playerMovementBehaviour.SetupBehaviour();
|
||||
playerAnimationBehaviour.SetupBehaviour();
|
||||
playerVisualsBehaviour.SetupBehaviour(playerID, playerInput);
|
||||
}
|
||||
|
||||
|
||||
//INPUT SYSTEM ACTION METHODS --------------
|
||||
|
||||
//This is called from PlayerInput; when a joystick or arrow keys has been pushed.
|
||||
//It stores the input Vector as a Vector3 to then be used by the smoothing function.
|
||||
|
||||
|
||||
public void OnMovement(InputAction.CallbackContext value)
|
||||
{
|
||||
Vector2 inputMovement = value.ReadValue<Vector2>();
|
||||
rawInputMovement = new Vector3(inputMovement.x, 0, inputMovement.y);
|
||||
}
|
||||
|
||||
//This is called from PlayerInput, when a button has been pushed, that corresponds with the 'Attack' action
|
||||
public void OnAttack(InputAction.CallbackContext value)
|
||||
{
|
||||
// If the unified InputToAnimation exists on this GameObject, let it handle attacks exclusively
|
||||
if (GetComponent<InputToAnimation>() != null)
|
||||
return;
|
||||
|
||||
if(value.started)
|
||||
{
|
||||
playerAnimationBehaviour.PlayAttackAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
//This is called from Player Input, when a button has been pushed, that correspons with the 'TogglePause' action
|
||||
public void OnTogglePause(InputAction.CallbackContext value)
|
||||
{
|
||||
if(value.started)
|
||||
{
|
||||
//GameObject.Find("GameManager").GetComponent<GameManager>().TogglePauseState(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//INPUT SYSTEM AUTOMATIC CALLBACKS --------------
|
||||
|
||||
//This is automatically called from PlayerInput, when the input device has changed
|
||||
//(IE: Keyboard -> Xbox Controller)
|
||||
public void OnControlsChanged()
|
||||
{
|
||||
|
||||
if(playerInput.currentControlScheme != currentControlScheme)
|
||||
{
|
||||
currentControlScheme = playerInput.currentControlScheme;
|
||||
|
||||
playerVisualsBehaviour.UpdatePlayerVisuals();
|
||||
RemoveAllBindingOverrides();
|
||||
}
|
||||
}
|
||||
|
||||
//This is automatically called from PlayerInput, when the input device has been disconnected and can not be identified
|
||||
//IE: Device unplugged or has run out of batteries
|
||||
|
||||
|
||||
|
||||
public void OnDeviceLost()
|
||||
{
|
||||
playerVisualsBehaviour.SetDisconnectedDeviceVisuals();
|
||||
}
|
||||
|
||||
|
||||
public void OnDeviceRegained()
|
||||
{
|
||||
StartCoroutine(WaitForDeviceToBeRegained());
|
||||
}
|
||||
|
||||
IEnumerator WaitForDeviceToBeRegained()
|
||||
{
|
||||
yield return new WaitForSeconds(0.1f);
|
||||
playerVisualsBehaviour.UpdatePlayerVisuals();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//Update Loop - Used for calculating frame-based data
|
||||
void Update()
|
||||
{
|
||||
CalculateMovementInputSmoothing();
|
||||
UpdatePlayerMovement();
|
||||
UpdatePlayerAnimationMovement();
|
||||
}
|
||||
|
||||
//Input's Axes values are raw
|
||||
|
||||
|
||||
void CalculateMovementInputSmoothing()
|
||||
{
|
||||
|
||||
smoothInputMovement = Vector3.Lerp(smoothInputMovement, rawInputMovement, Time.deltaTime * movementSmoothingSpeed);
|
||||
|
||||
}
|
||||
|
||||
void UpdatePlayerMovement()
|
||||
{
|
||||
playerMovementBehaviour.UpdateMovementData(smoothInputMovement);
|
||||
}
|
||||
|
||||
void UpdatePlayerAnimationMovement()
|
||||
{
|
||||
playerAnimationBehaviour.UpdateMovementAnimation(smoothInputMovement.magnitude);
|
||||
}
|
||||
|
||||
|
||||
public void SetInputActiveState(bool gameIsPaused)
|
||||
{
|
||||
switch (gameIsPaused)
|
||||
{
|
||||
case true:
|
||||
playerInput.DeactivateInput();
|
||||
break;
|
||||
|
||||
case false:
|
||||
playerInput.ActivateInput();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void RemoveAllBindingOverrides()
|
||||
{
|
||||
InputActionRebindingExtensions.RemoveAllBindingOverrides(playerInput.currentActionMap);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Switching Action Maps ----
|
||||
|
||||
|
||||
|
||||
public void EnableGameplayControls()
|
||||
{
|
||||
playerInput.SwitchCurrentActionMap(actionMapPlayerControls);
|
||||
}
|
||||
|
||||
public void EnablePauseMenuControls()
|
||||
{
|
||||
playerInput.SwitchCurrentActionMap(actionMapMenuControls);
|
||||
}
|
||||
|
||||
|
||||
//Get Data ----
|
||||
public int GetPlayerID()
|
||||
{
|
||||
return playerID;
|
||||
}
|
||||
|
||||
public InputActionAsset GetActionAsset()
|
||||
{
|
||||
return playerInput.actions;
|
||||
}
|
||||
|
||||
public PlayerInput GetPlayerInput()
|
||||
{
|
||||
return playerInput;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
11
Assets/Scripts/Behaviours/Player/PlayerController.cs.meta
Normal file
11
Assets/Scripts/Behaviours/Player/PlayerController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e20fb9a3b0e7eae4e9e630fc6e8b1a3f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
75
Assets/Scripts/Behaviours/Player/PlayerMovementBehaviour.cs
Normal file
75
Assets/Scripts/Behaviours/Player/PlayerMovementBehaviour.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerMovementBehaviour : MonoBehaviour
|
||||
{
|
||||
|
||||
[Header("Component References")]
|
||||
public Rigidbody playerRigidbody;
|
||||
|
||||
[Header("Movement Settings")]
|
||||
public float movementSpeed = 3f;
|
||||
public float turnSpeed = 0.1f;
|
||||
|
||||
|
||||
//Stored Values
|
||||
private Camera mainCamera;
|
||||
private Vector3 movementDirection;
|
||||
|
||||
|
||||
public void SetupBehaviour()
|
||||
{
|
||||
SetGameplayCamera();
|
||||
}
|
||||
|
||||
void SetGameplayCamera()
|
||||
{
|
||||
mainCamera = CameraManager.Instance.GetGameplayCamera();
|
||||
}
|
||||
|
||||
public void UpdateMovementData(Vector3 newMovementDirection)
|
||||
{
|
||||
movementDirection = newMovementDirection;
|
||||
}
|
||||
|
||||
void FixedUpdate()
|
||||
{
|
||||
MoveThePlayer();
|
||||
TurnThePlayer();
|
||||
}
|
||||
|
||||
void MoveThePlayer()
|
||||
{
|
||||
Vector3 movement = CameraDirection(movementDirection) * movementSpeed * Time.deltaTime;
|
||||
playerRigidbody.MovePosition(transform.position + movement);
|
||||
}
|
||||
|
||||
void TurnThePlayer()
|
||||
{
|
||||
if(movementDirection.sqrMagnitude > 0.01f)
|
||||
{
|
||||
|
||||
Quaternion rotation = Quaternion.Slerp(playerRigidbody.rotation,
|
||||
Quaternion.LookRotation (CameraDirection(movementDirection)),
|
||||
turnSpeed);
|
||||
|
||||
playerRigidbody.MoveRotation(rotation);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vector3 CameraDirection(Vector3 movementDirection)
|
||||
{
|
||||
var cameraForward = mainCamera.transform.forward;
|
||||
var cameraRight = mainCamera.transform.right;
|
||||
|
||||
cameraForward.y = 0f;
|
||||
cameraRight.y = 0f;
|
||||
|
||||
return cameraForward * movementDirection.z + cameraRight * movementDirection.x;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 63b2534bfb74738418425a76f03357fe
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
29
Assets/Scripts/Behaviours/Player/PlayerUIDisplayBehaviour.cs
Normal file
29
Assets/Scripts/Behaviours/Player/PlayerUIDisplayBehaviour.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
|
||||
public class PlayerUIDisplayBehaviour : MonoBehaviour
|
||||
{
|
||||
|
||||
public TextMeshProUGUI IDDisplayText;
|
||||
public TextMeshProUGUI deviceNameDisplayText;
|
||||
public Image deviceDisplayIcon;
|
||||
|
||||
public void UpdatePlayerIDDisplayText(int newPlayerID)
|
||||
{
|
||||
IDDisplayText.SetText((newPlayerID + 1).ToString());
|
||||
}
|
||||
|
||||
public void UpdatePlayerDeviceNameDisplayText(string newDeviceName)
|
||||
{
|
||||
deviceNameDisplayText.SetText(newDeviceName);
|
||||
}
|
||||
|
||||
public void UpdatePlayerIconDisplayColor(Color newColor)
|
||||
{
|
||||
deviceDisplayIcon.color = newColor;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 90ce320e2fa6597478b575fc077d0c27
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
72
Assets/Scripts/Behaviours/Player/PlayerVisualsBehaviour.cs
Normal file
72
Assets/Scripts/Behaviours/Player/PlayerVisualsBehaviour.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class PlayerVisualsBehaviour : MonoBehaviour
|
||||
{
|
||||
|
||||
//Player ID
|
||||
private int playerID;
|
||||
private PlayerInput playerInput;
|
||||
|
||||
[Header("Device Display Settings")]
|
||||
public DeviceDisplayConfigurator deviceDisplaySettings;
|
||||
|
||||
[Header("Sub Behaviours")]
|
||||
public PlayerUIDisplayBehaviour playerUIDisplayBehaviour;
|
||||
|
||||
[Header("Player Material")]
|
||||
public SkinnedMeshRenderer playerSkinnedMeshRenderer;
|
||||
|
||||
private int clothingTintShaderID;
|
||||
|
||||
public void SetupBehaviour(int newPlayerID, PlayerInput newPlayerInput)
|
||||
{
|
||||
playerID = newPlayerID;
|
||||
playerInput = newPlayerInput;
|
||||
|
||||
SetupShaderIDs();
|
||||
|
||||
UpdatePlayerVisuals();
|
||||
}
|
||||
|
||||
void SetupShaderIDs()
|
||||
{
|
||||
clothingTintShaderID = Shader.PropertyToID("_Clothing_Tint");
|
||||
}
|
||||
|
||||
public void UpdatePlayerVisuals()
|
||||
{
|
||||
UpdateUIDisplay();
|
||||
UpdateCharacterShader();
|
||||
}
|
||||
|
||||
void UpdateUIDisplay()
|
||||
{
|
||||
playerUIDisplayBehaviour.UpdatePlayerIDDisplayText(playerID);
|
||||
|
||||
string deviceName = deviceDisplaySettings.GetDeviceName(playerInput);
|
||||
playerUIDisplayBehaviour.UpdatePlayerDeviceNameDisplayText(deviceName);
|
||||
|
||||
Color deviceColor = deviceDisplaySettings.GetDeviceColor(playerInput);
|
||||
playerUIDisplayBehaviour.UpdatePlayerIconDisplayColor(deviceColor);
|
||||
}
|
||||
|
||||
void UpdateCharacterShader()
|
||||
{
|
||||
Color deviceColor = deviceDisplaySettings.GetDeviceColor(playerInput);
|
||||
playerSkinnedMeshRenderer.material.SetColor(clothingTintShaderID, deviceColor);
|
||||
}
|
||||
|
||||
public void SetDisconnectedDeviceVisuals()
|
||||
{
|
||||
string disconnectedName = deviceDisplaySettings.GetDisconnectedName();
|
||||
playerUIDisplayBehaviour.UpdatePlayerDeviceNameDisplayText(disconnectedName);
|
||||
|
||||
Color disconnectedColor = deviceDisplaySettings.GetDisconnectedColor();
|
||||
playerUIDisplayBehaviour.UpdatePlayerIconDisplayColor(disconnectedColor);
|
||||
playerSkinnedMeshRenderer.material.SetColor(clothingTintShaderID, disconnectedColor);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3b9c7226a9b7db047a442efcb4f263ea
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/Behaviours/UI.meta
Normal file
8
Assets/Scripts/Behaviours/UI.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 045edeee3a7092d418dde20ef8ae339b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
29
Assets/Scripts/Behaviours/UI/UIBillboardBehaviour.cs
Normal file
29
Assets/Scripts/Behaviours/UI/UIBillboardBehaviour.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
[ExecuteAlways]
|
||||
public class UIBillboardBehaviour : MonoBehaviour
|
||||
{
|
||||
private Transform gameplayCameraTransform;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
gameplayCameraTransform = CameraManager.Instance.GetGameplayCameraTransform();
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
gameplayCameraTransform = null;
|
||||
}
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
|
||||
if(gameplayCameraTransform)
|
||||
{
|
||||
transform.LookAt(transform.position + gameplayCameraTransform.rotation * Vector3.forward, gameplayCameraTransform.rotation * Vector3.up);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Behaviours/UI/UIBillboardBehaviour.cs.meta
Normal file
11
Assets/Scripts/Behaviours/UI/UIBillboardBehaviour.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0d237ecbece995f4b99ac5ebab0f1baf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
29
Assets/Scripts/Behaviours/UI/UIContextPanelsBehaviour.cs
Normal file
29
Assets/Scripts/Behaviours/UI/UIContextPanelsBehaviour.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class UIContextPanelsBehaviour : MonoBehaviour
|
||||
{
|
||||
public GameObject[] contextPanels;
|
||||
private int currentContextPanelID;
|
||||
|
||||
public void SetupContextPanels()
|
||||
{
|
||||
currentContextPanelID = 0;
|
||||
|
||||
for(int i = 0; i < contextPanels.Length; i++)
|
||||
{
|
||||
contextPanels[i].SetActive(false);
|
||||
}
|
||||
|
||||
contextPanels[currentContextPanelID].SetActive(true);
|
||||
}
|
||||
|
||||
public void UpdateContextPanels(int newContextPanelID)
|
||||
{
|
||||
contextPanels[currentContextPanelID].SetActive(false);
|
||||
currentContextPanelID = newContextPanelID;
|
||||
contextPanels[currentContextPanelID].SetActive(true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a55701e00d9d61e4d857a2040c6c872d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
100
Assets/Scripts/Behaviours/UI/UIMenuBehaviour.cs
Normal file
100
Assets/Scripts/Behaviours/UI/UIMenuBehaviour.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
|
||||
public class UIMenuBehaviour : MonoBehaviour
|
||||
{
|
||||
|
||||
[Header("Sub-Behaviours")]
|
||||
public UIContextPanelsBehaviour uiContextPanelsBehaviour;
|
||||
public UIPanelRebindBehaviour uiPanelRebindBehaviour;
|
||||
|
||||
[Header("Core Object References")]
|
||||
public GameObject uiMenuCameraObject;
|
||||
public GameObject uiMenuCanvasObject;
|
||||
|
||||
[Header("Default Selected")]
|
||||
public GameObject defaultSelectedGameObject;
|
||||
|
||||
|
||||
[Header("Player Display")]
|
||||
public DeviceDisplayConfigurator deviceDisplayconfigurator;
|
||||
public Image deviceDisplayIcon;
|
||||
public TextMeshProUGUI IDDisplayText;
|
||||
|
||||
|
||||
public void SetupBehaviour()
|
||||
{
|
||||
UpdateUIMenuState(false);
|
||||
}
|
||||
|
||||
public void UpdateUIMenuState(bool newState)
|
||||
{
|
||||
switch (newState)
|
||||
{
|
||||
case true:
|
||||
ResetContextPanels();
|
||||
UpdateEventSystemDefaultSelected();
|
||||
UpdateEventSystemUIInputModule();
|
||||
UpdateUIPlayerDisplay();
|
||||
UpdateUIRebindActions();
|
||||
break;
|
||||
|
||||
case false:
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
UpdateCoreUIObjectsState(newState);
|
||||
}
|
||||
|
||||
void ResetContextPanels()
|
||||
{
|
||||
uiContextPanelsBehaviour.SetupContextPanels();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void UpdateCoreUIObjectsState(bool newState)
|
||||
{
|
||||
uiMenuCameraObject.SetActive(newState);
|
||||
uiMenuCanvasObject.SetActive(newState);
|
||||
}
|
||||
|
||||
|
||||
void UpdateUIPlayerDisplay()
|
||||
{
|
||||
/*PlayerController focusedPlayerController = GameObject.Find("GameManager").GetComponent<GameManager>().GetFocusedPlayerController();
|
||||
|
||||
//ID
|
||||
int focusedPlayerID = focusedPlayerController.GetPlayerID();
|
||||
IDDisplayText.SetText((focusedPlayerID + 1).ToString());
|
||||
|
||||
//Color
|
||||
Color focusedPlayerDeviceColor = deviceDisplayconfigurator.GetDeviceColor(focusedPlayerController.GetPlayerInput());
|
||||
deviceDisplayIcon.color = focusedPlayerDeviceColor;*/
|
||||
}
|
||||
|
||||
void UpdateEventSystemDefaultSelected()
|
||||
{
|
||||
EventSystemManager.Instance.SetCurrentSelectedGameObject(defaultSelectedGameObject);
|
||||
}
|
||||
|
||||
void UpdateEventSystemUIInputModule()
|
||||
{
|
||||
EventSystemManager.Instance.UpdateActionAssetToFocusedPlayer();
|
||||
}
|
||||
|
||||
void UpdateUIRebindActions()
|
||||
{
|
||||
uiPanelRebindBehaviour.UpdateRebindActions();
|
||||
}
|
||||
|
||||
public void SwitchUIContextPanels(int selectedPanelID)
|
||||
{
|
||||
uiContextPanelsBehaviour.UpdateContextPanels(selectedPanelID);
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Scripts/Behaviours/UI/UIMenuBehaviour.cs.meta
Normal file
11
Assets/Scripts/Behaviours/UI/UIMenuBehaviour.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d4cf0d34234797b4f8e05fdf8db216f7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
13
Assets/Scripts/Behaviours/UI/UIMenuOptionBehaviour.cs
Normal file
13
Assets/Scripts/Behaviours/UI/UIMenuOptionBehaviour.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class UIMenuOptionBehaviour : MonoBehaviour
|
||||
{
|
||||
public int contextPanelID;
|
||||
|
||||
public void ButtonOptionSelected()
|
||||
{
|
||||
UIManager.Instance.MenuButtonOptionSelected(contextPanelID);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Behaviours/UI/UIMenuOptionBehaviour.cs.meta
Normal file
11
Assets/Scripts/Behaviours/UI/UIMenuOptionBehaviour.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab404cb73cfd59041ae6fa39d672efef
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,32 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class UIMenuPlayerDeviceDisplayBehaviour : MonoBehaviour
|
||||
{
|
||||
|
||||
[Header("Device Display")]
|
||||
public DeviceDisplayConfigurator deviceDisplayConfigurator;
|
||||
|
||||
[Header("Display References")]
|
||||
public TextMeshProUGUI playerIDDisplay;
|
||||
public TextMeshProUGUI playerDeviceDisplay;
|
||||
public Image playerDeviceDisplayIcon;
|
||||
|
||||
public void SetPlayerDeviceDisplay(int playerID, string playerDevicePath)
|
||||
{
|
||||
playerIDDisplay.SetText((playerID + 1).ToString());
|
||||
UpdatePlayerDeviceDisplay(playerDevicePath);
|
||||
}
|
||||
|
||||
public void UpdatePlayerDeviceDisplay(string playerDevicePath)
|
||||
{
|
||||
/*
|
||||
playerDeviceDisplay.SetText(deviceDisplayConfigurator.GetDeviceDisplayName(playerDevicePath));
|
||||
playerDeviceDisplayIcon.color = deviceDisplayConfigurator.GetDeviceDisplayColor(playerDevicePath);
|
||||
*/
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fb9fa96d7e2cd5d429bb276c06a46c72
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
20
Assets/Scripts/Behaviours/UI/UIPanelQuitBehaviour.cs
Normal file
20
Assets/Scripts/Behaviours/UI/UIPanelQuitBehaviour.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class UIPanelQuitBehaviour : MonoBehaviour
|
||||
{
|
||||
public void ButtonPressedQuitGame()
|
||||
{
|
||||
QuitGame();
|
||||
}
|
||||
|
||||
void QuitGame()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.EditorApplication.isPlaying = false;
|
||||
#else
|
||||
Application.Quit();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Behaviours/UI/UIPanelQuitBehaviour.cs.meta
Normal file
11
Assets/Scripts/Behaviours/UI/UIPanelQuitBehaviour.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dda3a4598827131489bee68ae015c43e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
16
Assets/Scripts/Behaviours/UI/UIPanelRebindBehaviour.cs
Normal file
16
Assets/Scripts/Behaviours/UI/UIPanelRebindBehaviour.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class UIPanelRebindBehaviour : MonoBehaviour
|
||||
{
|
||||
public UIRebindActionBehaviour[] uiRebindActionBehaviours;
|
||||
|
||||
public void UpdateRebindActions()
|
||||
{
|
||||
for(int i = 0; i < uiRebindActionBehaviours.Length; i++)
|
||||
{
|
||||
uiRebindActionBehaviours[i].UpdateBehaviour();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Behaviours/UI/UIPanelRebindBehaviour.cs.meta
Normal file
11
Assets/Scripts/Behaviours/UI/UIPanelRebindBehaviour.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1d0ee8987180cc640b92a50bdf409025
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
144
Assets/Scripts/Behaviours/UI/UIRebindActionBehaviour.cs
Normal file
144
Assets/Scripts/Behaviours/UI/UIRebindActionBehaviour.cs
Normal file
@@ -0,0 +1,144 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
|
||||
public class UIRebindActionBehaviour : MonoBehaviour
|
||||
{
|
||||
//Input System Stored Data
|
||||
private InputActionAsset focusedInputActionAsset;
|
||||
private PlayerInput focusedPlayerInput;
|
||||
private InputAction focusedInputAction;
|
||||
private InputActionRebindingExtensions.RebindingOperation rebindOperation;
|
||||
|
||||
[Header("Rebind Settings")]
|
||||
public string actionName;
|
||||
|
||||
[Header("Device Display Settings")]
|
||||
public DeviceDisplayConfigurator deviceDisplaySettings;
|
||||
|
||||
[Header("UI Display - Action Text")]
|
||||
public TextMeshProUGUI actionNameDisplayText;
|
||||
|
||||
[Header("UI Display - Binding Text or Icon")]
|
||||
public TextMeshProUGUI bindingNameDisplayText;
|
||||
public Image bindingIconDisplayImage;
|
||||
|
||||
[Header("UI Display - Buttons")]
|
||||
public GameObject rebindButtonObject;
|
||||
public GameObject resetButtonObject;
|
||||
|
||||
[Header("UI Display - Listening Text")]
|
||||
public GameObject listeningForInputObject;
|
||||
|
||||
|
||||
public void UpdateBehaviour()
|
||||
{
|
||||
GetFocusedPlayerInput();
|
||||
SetupFocusedInputAction();
|
||||
UpdateActionDisplayUI();
|
||||
UpdateBindingDisplayUI();
|
||||
}
|
||||
|
||||
void GetFocusedPlayerInput()
|
||||
{
|
||||
/*PlayerController focusedPlayerController = GameObject.Find("GameManager").GetComponent<GameManager>().GetFocusedPlayerController();
|
||||
focusedPlayerInput = focusedPlayerController.GetPlayerInput();*/
|
||||
}
|
||||
|
||||
void SetupFocusedInputAction()
|
||||
{
|
||||
focusedInputAction = focusedPlayerInput.actions.FindAction(actionName);
|
||||
}
|
||||
|
||||
public void ButtonPressedStartRebind()
|
||||
{
|
||||
StartRebindProcess();
|
||||
}
|
||||
|
||||
void StartRebindProcess()
|
||||
{
|
||||
|
||||
ToggleGameObjectState(rebindButtonObject, false);
|
||||
ToggleGameObjectState(resetButtonObject, false);
|
||||
ToggleGameObjectState(listeningForInputObject, true);
|
||||
|
||||
|
||||
rebindOperation = focusedInputAction.PerformInteractiveRebinding()
|
||||
.WithControlsExcluding("<Mouse>/position")
|
||||
.WithControlsExcluding("<Mouse>/delta")
|
||||
.WithControlsExcluding("<Gamepad>/Start")
|
||||
.WithControlsExcluding("<Keyboard>/p")
|
||||
.WithControlsExcluding("<Keyboard>/escape")
|
||||
.OnMatchWaitForAnother(0.1f)
|
||||
.OnComplete(operation => RebindCompleted());
|
||||
|
||||
rebindOperation.Start();
|
||||
}
|
||||
|
||||
|
||||
void RebindCompleted()
|
||||
{
|
||||
rebindOperation.Dispose();
|
||||
rebindOperation = null;
|
||||
|
||||
ToggleGameObjectState(rebindButtonObject, true);
|
||||
ToggleGameObjectState(resetButtonObject, true);
|
||||
ToggleGameObjectState(listeningForInputObject, false);
|
||||
|
||||
UpdateActionDisplayUI();
|
||||
UpdateBindingDisplayUI();
|
||||
}
|
||||
|
||||
public void ButtonPressedResetBinding()
|
||||
{
|
||||
ResetBinding();
|
||||
}
|
||||
|
||||
public void ResetBinding()
|
||||
{
|
||||
InputActionRebindingExtensions.RemoveAllBindingOverrides(focusedInputAction);
|
||||
UpdateBindingDisplayUI();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void UpdateActionDisplayUI()
|
||||
{
|
||||
actionNameDisplayText.SetText(actionName);
|
||||
}
|
||||
|
||||
void UpdateBindingDisplayUI()
|
||||
{
|
||||
|
||||
int controlBindingIndex = focusedInputAction.GetBindingIndexForControl(focusedInputAction.controls[0]);
|
||||
string currentBindingInput = InputControlPath.ToHumanReadableString(focusedInputAction.bindings[controlBindingIndex].effectivePath, InputControlPath.HumanReadableStringOptions.OmitDevice);
|
||||
|
||||
Sprite currentDisplayIcon = deviceDisplaySettings.GetDeviceBindingIcon(focusedPlayerInput, currentBindingInput);
|
||||
|
||||
if(currentDisplayIcon)
|
||||
{
|
||||
ToggleGameObjectState(bindingNameDisplayText.gameObject, false);
|
||||
ToggleGameObjectState(bindingIconDisplayImage.gameObject, true);
|
||||
bindingIconDisplayImage.sprite = currentDisplayIcon;
|
||||
} else if(currentDisplayIcon == null)
|
||||
{
|
||||
ToggleGameObjectState(bindingNameDisplayText.gameObject, true);
|
||||
ToggleGameObjectState(bindingIconDisplayImage.gameObject, false);
|
||||
bindingNameDisplayText.SetText(currentBindingInput);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ToggleGameObjectState(GameObject targetGameObject, bool newState)
|
||||
{
|
||||
targetGameObject.SetActive(newState);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
11
Assets/Scripts/Behaviours/UI/UIRebindActionBehaviour.cs.meta
Normal file
11
Assets/Scripts/Behaviours/UI/UIRebindActionBehaviour.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d6005e3b6c6ebbd4a98d34a9488cf066
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user