浏览代码

Add NetworkingManager HUD

/main
Luke Stampfli 4 年前
当前提交
5430c156
共有 2 个文件被更改,包括 49 次插入0 次删除
  1. 38
      Assets/Scripts/NetworkingManagerHUD.cs
  2. 11
      Assets/Scripts/NetworkingManagerHUD.cs.meta

38
Assets/Scripts/NetworkingManagerHUD.cs


using UnityEngine;
using MLAPI;
[RequireComponent(typeof(NetworkingManager))]
public class NetworkingManagerHUD : MonoBehaviour
{
void OnGUI()
{
GUILayout.BeginArea(new Rect(10, 10, 300, 300));
if (!NetworkingManager.Singleton.IsClient && !NetworkingManager.Singleton.IsServer)
{
StartButtons();
}
else
{
StatusLabels();
}
GUILayout.EndArea();
}
void StartButtons()
{
if (GUILayout.Button("Host")) NetworkingManager.Singleton.StartHost();
if (GUILayout.Button("Client")) NetworkingManager.Singleton.StartClient();
if (GUILayout.Button("Server")) NetworkingManager.Singleton.StartServer();
}
void StatusLabels()
{
string mode = NetworkingManager.Singleton.IsHost ? "Host" : NetworkingManager.Singleton.IsServer ? "Server" : "Client";
GUILayout.Label("Transport: " + NetworkingManager.Singleton.NetworkConfig.NetworkTransport.GetType().Name);
GUILayout.Label("Mode: " + mode);
}
}

11
Assets/Scripts/NetworkingManagerHUD.cs.meta


fileFormatVersion: 2
guid: e26f82009f8f36d45a99adae79eab7b9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存