chunk 1: core gameplay scripts scenes runtime assets

This commit is contained in:
2026-04-06 11:02:34 +03:00
parent fa0388bc79
commit 0d11a097d8
703 changed files with 2292651 additions and 0 deletions

View 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);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 733c62aa19a5f384ea007d48fd472e50
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View 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;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e20fb9a3b0e7eae4e9e630fc6e8b1a3f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View 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;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 63b2534bfb74738418425a76f03357fe
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View 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;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 90ce320e2fa6597478b575fc077d0c27
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View 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);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3b9c7226a9b7db047a442efcb4f263ea
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: