first commit

This commit is contained in:
2022-07-01 09:54:51 +08:00
commit 445012dd48
1394 changed files with 198277 additions and 0 deletions

View File

@@ -0,0 +1,80 @@
using UnityEngine;
using Unity.Netcode;
using TMPro;
[RequireComponent(typeof(NetworkObject))]
public class FoxMovement : NetworkBehaviour
{
private CharacterController controller;
public float Speed = 10f;
public float RotateSpeed = 1f;
public float Gravity = -9.8f;
private Vector3 Velocity = Vector3.zero;
public Transform GroundCheck;
public float checkRadius = 0.2f;
public bool IsGround;
public LayerMask layerMask;
public NetworkVariable<Vector3> Position = new NetworkVariable<Vector3>();
public NetworkVariable<Vector3> MoveVector = new NetworkVariable<Vector3>();
public NetworkVariable<float> Angle = new NetworkVariable<float>();
public TextMeshPro IsOwnerText;
private CharacterController characterController;
private void Awake()
{
characterController = GetComponent<CharacterController>();
}
// Start is called before the first frame update
void Start()
{
controller = transform.GetComponent<CharacterController>();
}
// Update is called once per frame
void Update()
{
IsOwnerText.text = IsOwner ? "Owner" : "";
IsOwnerText.text += IsClient ? " Client" : "";
if (IsOwner && IsClient)
{
ClientInput();
}
ClientMoveAndRotate();
}
void ClientInput()
{
var horizontal = Input.GetAxis("Horizontal");
var vertical = Input.GetAxis("Vertical");
var move = transform.forward * Speed * vertical * Time.deltaTime;
IsGround = Physics.CheckSphere(GroundCheck.position, checkRadius, layerMask);
if (IsGround && Velocity.y < 0)
{
Velocity.y = 0;
}
else
{
Velocity.y += Gravity * Time.deltaTime;
}
updateClientPositionAndRotationServerRpc(move + Velocity * Time.deltaTime, horizontal * RotateSpeed);
}
void ClientMoveAndRotate()
{
characterController.Move(MoveVector.Value);
transform.Rotate(Vector3.up, Angle.Value);
}
[ServerRpc]
void updateClientPositionAndRotationServerRpc(Vector3 moveVector, float angle)
{
MoveVector.Value = moveVector;
Angle.Value = angle;
}
}

View File

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

119
Assets/Scripts/UIManager.cs Normal file
View File

@@ -0,0 +1,119 @@
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.UI;
public class UIManager : MonoBehaviour
{
[SerializeField]
private Button startServerButton;
[SerializeField]
private Button startHostButton;
[SerializeField]
private Button startClientButton;
[SerializeField]
private Button leaveButton;
[SerializeField]
private GameObject connectedPanel;
[SerializeField]
private GameObject unconnectedPanel;
// [SerializeField]
// private TextMeshProUGUI playersInGameText;
// [SerializeField]
// private TMP_InputField joinCodeInput;
// [SerializeField]
// private Button executePhysicsButton;
private bool hasServerStarted;
private void Awake()
{
Cursor.visible = true;
}
void Update()
{
// playersInGameText.text = $"Players in game: {PlayersManager.Instance.PlayersInGame}";
}
void Start()
{
UnconnectedPanel();
// START SERVER
startServerButton?.onClick.AddListener(() =>
{
if (NetworkManager.Singleton.StartServer())
ConnectedPanel();
});
// START HOST
startHostButton?.onClick.AddListener(() =>
{
// this allows the UnityMultiplayer and UnityMultiplayerRelay scene to work with and without
// relay features - if the Unity transport is found and is relay protocol then we redirect all the
// traffic through the relay, else it just uses a LAN type (UNET) communication.
// if (RelayManager.Instance.IsRelayEnabled)
// await RelayManager.Instance.SetupRelay();
if (NetworkManager.Singleton.StartHost())
ConnectedPanel();
});
// START CLIENT
startClientButton?.onClick.AddListener(() =>
{
// if (RelayManager.Instance.IsRelayEnabled && !string.IsNullOrEmpty(joinCodeInput.text))
// await RelayManager.Instance.JoinRelay(joinCodeInput.text);
if (NetworkManager.Singleton.StartClient())
ConnectedPanel();
// else
// Logger.Instance.LogInfo("Unable to start client...");
});
leaveButton?.onClick.AddListener(() =>
{
NetworkManager.Singleton.Shutdown();
UnconnectedPanel();
});
// STATUS TYPE CALLBACKS
// NetworkManager.Singleton.OnClientConnectedCallback += (id) =>
// {
// Logger.Instance.LogInfo($"{id} just connected...");
// };
// NetworkManager.Singleton.OnServerStarted += () =>
// {
// hasServerStarted = true;
// };
// executePhysicsButton.onClick.AddListener(() =>
// {
// if (!hasServerStarted)
// {
// Logger.Instance.LogWarning("Server has not started...");
// return;
// }
// SpawnerControl.Instance.SpawnObjects();
// });
}
void ConnectedPanel()
{
unconnectedPanel.SetActive(false);
connectedPanel.SetActive(true);
}
void UnconnectedPanel()
{
unconnectedPanel.SetActive(true);
connectedPanel.SetActive(false);
}
}

View File

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