1 Star 0 Fork 3

wayfarer/rongYaoDaLuCode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
TNAutoJoin.cs 2.45 KB
一键复制 编辑 原始数据 按行查看 历史
liyonghelpme 提交于 2015-05-19 23:14 +08:00 . rong Yao Da Lu Some Code For Game
using System;
using TNet;
using UnityEngine;
[RequireComponent(typeof(TNManager))]
public class TNAutoJoin : MonoBehaviour
{
public bool allowUDP = true;
public int channelID = 1;
public bool connectOnStart = true;
public string disconnectLevel;
public string failureFunctionName;
public string firstLevel = "Example 1";
public static TNAutoJoin instance;
public string serverAddress = "127.0.0.1";
public int serverPort = 0x1407;
public string successFunctionName;
private void Awake()
{
if (instance == null)
{
instance = this;
}
}
public void Connect()
{
Screen.sleepTimeout = -1;
TNManager.Connect(this.serverAddress, this.serverPort);
}
private void OnNetworkConnect(bool result, string message)
{
if (result)
{
if (this.allowUDP)
{
TNManager.StartUDP(UnityEngine.Random.Range(0x2710, 0xc350));
}
TNManager.JoinChannel(this.channelID, this.firstLevel);
}
else if (!string.IsNullOrEmpty(this.failureFunctionName))
{
object[] parameters = new object[] { message };
UnityTools.Broadcast(this.failureFunctionName, parameters);
}
else
{
Debug.LogError(message);
}
}
private void OnNetworkDisconnect()
{
if (!string.IsNullOrEmpty(this.disconnectLevel) && (Application.loadedLevelName != this.disconnectLevel))
{
Application.LoadLevel(this.disconnectLevel);
}
}
private void OnNetworkJoinChannel(bool result, string message)
{
if (result)
{
if (!string.IsNullOrEmpty(this.successFunctionName))
{
UnityTools.Broadcast(this.successFunctionName, new object[0]);
}
}
else
{
if (!string.IsNullOrEmpty(this.failureFunctionName))
{
object[] parameters = new object[] { message };
UnityTools.Broadcast(this.failureFunctionName, parameters);
}
else
{
Debug.LogError(message);
}
TNManager.Disconnect();
}
}
private void Start()
{
if (this.connectOnStart)
{
this.Connect();
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wayfarer/rongYaoDaLuCode.git
git@gitee.com:wayfarer/rongYaoDaLuCode.git
wayfarer
rongYaoDaLuCode
rongYaoDaLuCode
master

搜索帮助