Unity NetworkManager整理160616
2016-06-16 22:16
519 查看
最近都在学习unity Network的知识,思绪凌乱,整理了些常用的方法和构造函数
2、NetworkManager.StartServer():成为服务器
3、NetworkManager.StartHost():成为主机(既是服务器也是客户端)
4、ClientScene.RegisterPrefab():在客户端中注册预设体
5、NetworkManager.OnServerAddPlayer:添加玩家到服务器中,此方法也可以重载
例如:
6、NetworkManager.StartMatchmaker():开始Matchmaker
2、在客户端可以调用的
3、在Matchmaker可以调用的
这些在官方文档里都有
Unity新手,仅作记录作用
一、添加NetworkManager组件
1、NetworkManager.StartClien():成为客户端2、NetworkManager.StartServer():成为服务器
3、NetworkManager.StartHost():成为主机(既是服务器也是客户端)
4、ClientScene.RegisterPrefab():在客户端中注册预设体
5、NetworkManager.OnServerAddPlayer:添加玩家到服务器中,此方法也可以重载
例如:
public virtual void OnServerAddPlayer(NetworkConnection conn, short playerControllerId) { var player = (GameObject)GameObject.Instantiate(playerPrefab, playerSpawnPos, Quaternion.identity); NetworkServer.AddPlayerForConnection(conn, player, playerControllerId); }
6、NetworkManager.StartMatchmaker():开始Matchmaker
二、定制自己的函数
1、在服务器/主机可以调用的// called when a client connects public virtual void OnServerConnect(NetworkConnection conn); // called when a client disconnects public virtual void OnServerDisconnect(NetworkConnection conn) { NetworkServer.DestroyPlayersForConnection(conn); } // called when a client is ready public virtual void OnServerReady(NetworkConnection conn) { NetworkServer.SetClientReady(conn); } // called when a new player is added for a client public virtual void OnServerAddPlayer(NetworkConnection conn, short playerControllerId) { var player = (GameObject)GameObject.Instantiate(playerPrefab, playerSpawnPos, Quaternion.identity); NetworkServer.AddPlayerForConnection(conn, player, playerControllerId); } // called when a player is removed for a client public virtual void OnServerRemovePlayer(NetworkConnection conn, short playerControllerId) { PlayerController player; if (conn.GetPlayer(playerControllerId, out player)) { if (player.NetworkIdentity != null && player.NetworkIdentity.gameObject != null) NetworkServer.Destroy(player.NetworkIdentity.gameObject); } } // called when a network error occurs public virtual void OnServerError(NetworkConnection conn, int errorCode);
2、在客户端可以调用的
// called when connected to a server public virtual void OnClientConnect(NetworkConnection conn) { ClientScene.Ready(conn); ClientScene.AddPlayer(0); } // called when disconnected from a server public virtual void OnClientDisconnect(NetworkConnection conn) { StopClient(); } // called when a network error occurs public virtual void OnClientError(NetworkConnection conn, int errorCode); // called when told to be not-ready by a server public virtual void OnClientNotReady(NetworkConnection conn);
3、在Matchmaker可以调用的
// called when a match is created public virtual void OnMatchCreate(CreateMatchResponse matchInfo) // called when a list of matches is received public virtual void OnMatchList(ListMatchResponse matchList) // called when a match is joined public void OnMatchJoined(JoinMatchResponse matchInfo)
这些在官方文档里都有
Unity新手,仅作记录作用
相关文章推荐
- JavaScript Archive Network 集合
- unity实现多点触控代码
- 在Unity中实现动画的正反播放代码
- Unity UGUI教程之实现滑页效果
- unity实现摄像头跟随
- IEEE/ACM ASONAM 2014 Industry Track Call for Paper
- linux系统调优-Network
- Android library listening network events.
- LINUN 网络连接小记
- docker跨主机网络通信实践
- docker的网络
- Unity3D上路_01-2D太空射击游戏
- Unity3D上路_02-第一视角射击游戏
- Unity3D上路_03-塔防游戏
- Unity3D上路_04-基础资源介绍
- Unity3D上路_05-网络相关
- Unity3D-5.3.5发布VR项目到Android
- unity 新UI草稿
- 开源监控工具Hyperic 的 Network Device配置过程