返回介绍

Network.OnDisconnectedFromServer(NetworkDisconnection) 当从服务器断开

发布于 2019-12-18 15:38:07 字数 1811 浏览 1257 评论 0 收藏 0

Description 描述

Called on client during disconnection from server, but also on the server when the connection has disconnected.

在服务器上当连接已经断开,在客户端调用这个函数,但当连接已经被禁用,也在服务器上调用。

When called on the client the connection was lost or you disconnected from the server. The NetworkDisconnection enum will indicate if the connection was cleanly disconnected or if the connection was lost. When called on the server the connection has successfully disconnected (after a call to Network.Disconnect).

当这个连接已经丢失或从服务器断开,在客户端调用这个函数。NetworkDisconnection枚举将表示,如果连接已经干净断开或如果连接已经丢失。当在服务器上调用,该连接已经成功地断开(调用Network.Disconnect之后)。

JavaScript:

function OnDisconnectedFromServer(info : NetworkDisconnection) {
		if (Network.isServer) {
			Debug.Log("Local server connection disconnected");
		}
		else {
			if (info == NetworkDisconnection.LostConnection)
				Debug.Log("Lost connection to the server");
			else
				Debug.Log("Successfully diconnected from the server");
		}
	}

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    void OnDisconnectedFromServer(NetworkDisconnection info) {
        if (Network.isServer)
            Debug.Log("Local server connection disconnected");
        else
            if (info == NetworkDisconnection.LostConnection)
                Debug.Log("Lost connection to the server");
            else
                Debug.Log("Successfully diconnected from the server");
    }
}

network

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文