Added MainMenu, Bootstrap and Factory scenes
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using Unity.Netcode;
|
||||
using UnityEngine;
|
||||
|
||||
public interface IPlayerSystem { void Initialize(PlayerFacade facade); }
|
||||
|
||||
[RequireComponent(typeof(NetworkObject))]
|
||||
public sealed class PlayerFacade : NetworkBehaviour
|
||||
{
|
||||
[SerializeField] private MonoBehaviour[] initializationOrder;
|
||||
|
||||
public event Action<PlayerFacade> Initialized;
|
||||
|
||||
public override void OnNetworkSpawn()
|
||||
{
|
||||
MonoBehaviour[] systems = initializationOrder.Length > 0
|
||||
? initializationOrder
|
||||
: GetComponents<MonoBehaviour>();
|
||||
foreach (MonoBehaviour system in systems)
|
||||
if (system is IPlayerSystem playerSystem) playerSystem.Initialize(this);
|
||||
Initialized?.Invoke(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3b718b186a728344ab8c35780b227699
|
||||
@@ -0,0 +1,29 @@
|
||||
using Unity.Netcode;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public sealed class PlayerMovementController : NetworkBehaviour, IPlayerSystem
|
||||
{
|
||||
[SerializeField, Min(0.1f)] private float movementSpeed = 4.5f;
|
||||
private bool isInitialized;
|
||||
|
||||
public void Initialize(PlayerFacade facade) => isInitialized = true;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!isInitialized || !IsOwner || Keyboard.current == null) return;
|
||||
Vector2 input = new(
|
||||
(Keyboard.current.dKey.isPressed ? 1 : 0) - (Keyboard.current.aKey.isPressed ? 1 : 0),
|
||||
(Keyboard.current.wKey.isPressed ? 1 : 0) - (Keyboard.current.sKey.isPressed ? 1 : 0));
|
||||
if (IsServer) Move(input); else MoveServerRpc(input);
|
||||
}
|
||||
|
||||
[ServerRpc] private void MoveServerRpc(Vector2 input) => Move(input);
|
||||
private void Move(Vector2 input)
|
||||
{
|
||||
if (input.sqrMagnitude > 1) input.Normalize();
|
||||
Vector3 direction = new(input.x, 0, input.y);
|
||||
transform.position += direction * (movementSpeed * Time.deltaTime);
|
||||
if (direction.sqrMagnitude > 0.001f) transform.forward = direction;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f8af29dd6e4daa6479ef978bdd3b2e6d
|
||||
Reference in New Issue
Block a user