Boss Room 是一款使用 Unity MLAPI 制作的全功能合作多人 RPG。 它旨在作为学习样本,展示类似游戏中经常出现的某些典型游戏模式。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

57 行
1.4 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BossRoom.Viz
{
/// <summary>
/// Provides backing logic for all of the UI that runs in the MainMenu stage.
/// </summary>
public class MainMenuUI : MonoBehaviour
{
public GameObject GameHubGO;
public GameObject InputTextGO;
private BossRoom.GameNetHub m_netHub;
// Start is called before the first frame update
void Start()
{
m_netHub = GameHubGO.GetComponent<BossRoom.GameNetHub>();
}
// Update is called once per frame
void Update()
{
}
/// <summary>
/// Gets the IP Address the user set in the UI, or returns 127.0.0.1 if IP is not present.
/// </summary>
/// <returns>IP address entered by user, in string form. </returns>
private string GetIPAddress()
{
string iptext = InputTextGO.GetComponent<UnityEngine.UI.Text>().text;
if( iptext == "" )
{
return "127.0.0.1";
}
return iptext;
}
public void OnHostClicked()
{
GetIPAddress();
m_netHub.StartHost(GetIPAddress(), 9998);
}
public void OnConnectClicked()
{
m_netHub.StartClient(GetIPAddress(), 9998);
}
}
}