1) Refactor Project Architecture 2) Add Assets 3) Change Prefabs 4) Change Input Method (now using PlayerInput Component) 5) Add Weapon Prefab & Simple Script with Shooting() 6) Add Menu Scene & two btn functions: QuitGame() & PlayGame()
54 lines
1.4 KiB
C#
54 lines
1.4 KiB
C#
using System.Collections.Generic;
|
|
using Unity.Netcode;
|
|
using UnityEngine;
|
|
|
|
public class NetworkCommandLine : MonoBehaviour
|
|
{
|
|
private NetworkManager netManager;
|
|
|
|
void Start()
|
|
{
|
|
netManager = GetComponentInParent<NetworkManager>();
|
|
|
|
if (Application.isEditor) return;
|
|
|
|
var args = GetCommandlineArgs();
|
|
|
|
if (args.TryGetValue("-mode", out string mode))
|
|
{
|
|
switch (mode)
|
|
{
|
|
case "server":
|
|
netManager.StartServer();
|
|
break;
|
|
case "host":
|
|
netManager.StartHost();
|
|
break;
|
|
case "client":
|
|
netManager.StartClient();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
private Dictionary<string, string> GetCommandlineArgs()
|
|
{
|
|
Dictionary<string, string> argDictionary = new Dictionary<string, string>();
|
|
|
|
var args = System.Environment.GetCommandLineArgs();
|
|
|
|
for (int i = 0; i < args.Length; ++i)
|
|
{
|
|
var arg = args[i].ToLower();
|
|
if (arg.StartsWith("-"))
|
|
{
|
|
var value = i < args.Length - 1 ? args[i + 1].ToLower() : null;
|
|
value = (value?.StartsWith("-") ?? false) ? null : value;
|
|
|
|
argDictionary.Add(arg, value);
|
|
}
|
|
}
|
|
return argDictionary;
|
|
}
|
|
}
|