资源简介
这是一个可以发布到HoloLens的socket通信示例,基于Unity5.3.4f1编写的,发布到HoloLens绝对没问题的,你可以根据自己需求自行修改。
代码片段和文件信息
/**
* 版本:0.01
* 作者:吴雁涛
* 日期:2016年4月29日
* 内容:服务器端客户端通信学习
*
**/
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
using System;
public class MyNetworkManager : MonoBehaviour
{
///
/// 服务器ip地址
///
public InputField ip;
///
/// 服务器端口
///
public InputField port;
///
/// 要发送的信息
///
public InputField send;
///
/// 显示信息
///
public Text info;
///
/// 网络客户端
///
private NetworkClient myClient;
///
/// 用户信息分类
///
private const short userMsg = 64;
void Start ()
{
info.text = “Start...“;
myClient = new NetworkClient ();
}
///
/// 建立服务器
///
public void SetupServer ()
{
if (!NetworkServer.active) {
ShowMsg (“setup server“);
ServerRegisterHandler ();
NetworkServer.Listen (int.Parse (port.text));
if (NetworkServer.active) {
ShowMsg (“Server setup ok.“);
}
}
}
///
/// 建立客户端
///
public void SetupClient ()
{
if (!myClient.isConnected) {
ShowMsg (“setup client“);
ClientRegisterHandler ();
myClient.Connect (ip.text int.Parse (port.text));
}
}
///
/// 停止客户端
///
public void ShutdownClient ()
{
if (myClient.isConnected) {
ClientUnregisterHandler ();
myClient.Disconnect ();
//NetworkClient.Shutdown()使用后,无法再次连接。
//This should be done when a client is no longer going to be used.
//myClient.Shutdown ();
}
}
///
/// 停止服务器端
///
public void ShutdownServer ()
{
if (NetworkServer.active) {
ServerUnregisterHandler ();
NetworkServer.DisconnectAll ();
NetworkServer.Shutdown ();
if (!NetworkServer.active) {
ShowMsg (“shut down server“);
}
}
}
///
/// 客户端连接到服务器事件
///
/// Net message.
private void OnClientConnected (NetworkMessage netMsg)
{
ShowMsg (“Client connected to server“);
}
///
///客户端从服务器断开事件
///
/// Net message.
private void OnClientDisconnected (NetworkMessage netMsg)
{
ShowMsg (“Client disconnected from server“);
}
///
/// 客户端错误事件
///
/// Net message.
private void OnClientError (NetworkMessage netMsg)
{
ClientUnregisterHandler ();
ShowMsg (“Client error“);
}
///
/// 服务器端有客户端连入事件
///
/// Net message.
private void OnServerConnected (NetworkMessage netMsg)
{
ShowMsg (“One client connected to server“);
}
///
/// 服务器端有客户端断开事件
///
/// Net message.
private void OnServerDisconnected (NetworkMessage netMsg)
{
ShowMsg (“One client connected from server“);
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 14435 2016-04-27 10:25 HololensSocketDemo\Assembly-CSharp-Editor.csproj
文件 4304 2016-04-28 09:22 HololensSocketDemo\Assembly-CSharp-firstpass.csproj
文件 4188 2016-04-29 14:11 HololensSocketDemo\Assembly-CSharp.csproj
文件 6246 2016-04-29 15:05 HololensSocketDemo\Assets\MyNetworkManager.cs
..A..H. 263 2016-04-28 17:51 HololensSocketDemo\Assets\MyNetworkManager.cs.me
文件 721 2016-04-28 17:56 HololensSocketDemo\Assets\NWLearn.cs
..A..H. 263 2016-04-28 17:40 HololensSocketDemo\Assets\NWLearn.cs.me
I.A.... 4908 2016-04-28 17:39 HololensSocketDemo\Assets\play.prefab
..A..H. 180 2016-04-28 17:39 HololensSocketDemo\Assets\play.prefab.me
I.A.... 38872 2016-04-28 17:57 HololensSocketDemo\Assets\server.unity
..A..H. 175 2016-04-28 17:38 HololensSocketDemo\Assets\server.unity.me
I.A.... 4120 2016-04-19 15:10 HololensSocketDemo\Library\AnnotationManager
I.A.... 1546436 2016-04-29 15:05 HololensSocketDemo\Library\assetDataba
I.A.... 17 2016-04-29 14:11 HololensSocketDemo\Library\AssetImportState
I.A.... 4756 2016-04-29 15:05 HololensSocketDemo\Library\AssetServerCacheV3
I.A.... 14336 2016-04-20 10:02 HololensSocketDemo\Library\AssetVersioning.db
I.A.... 267700 2016-04-25 10:54 HololensSocketDemo\Library\AtlasCache\11\111396342696616dd8dd8b995bde38c9
I.A.... 8596 2016-04-25 10:54 HololensSocketDemo\Library\AtlasCache\58\58dc768eb225cb597fc603bc9cc9ceca
I.A.... 5860 2016-04-25 10:54 HololensSocketDemo\Library\AtlasCache\79\79d17962e46a00b8a8886503a748da94
I.A.... 11195052 2016-04-25 10:54 HololensSocketDemo\Library\AtlasCache\a2\a2f82126fda7305f2a23618ab2749eba
I.A.... 0 2016-04-19 15:10 HololensSocketDemo\Library\BuildPla
I.A.... 4128 2016-04-19 15:10 HololensSocketDemo\Library\BuildSettings.asset
I.A.... 40260 2016-04-29 15:05 HololensSocketDemo\Library\CurrentLayout.dwlt
I.A.... 4341 2016-04-29 14:11 HololensSocketDemo\Library\EditorUserBuildSettings.asset
I.A.... 4148 2016-04-19 15:10 HololensSocketDemo\Library\EditorUserSettings.asset
I.A.... 4464 2016-04-29 15:05 HololensSocketDemo\Library\expandedItems
I.A.... 4544 2016-04-28 15:41 HololensSocketDemo\Library\InspectorExpandedItems.asset
文件 78 2016-04-29 15:05 HololensSocketDemo\Library\LastSceneManagerSetup.txt
文件 65 2016-04-19 15:10 HololensSocketDemo\Library\LibraryFormatVersion.txt
I.A.... 4285 2016-04-19 15:10 HololensSocketDemo\Library\me
............此处省略2125个文件信息
相关资源
- UnityChan2D素材包.unitypackage
- socket传输16进制客户端
- Unity无限滑动列表插件EnhancedScroller
- I2 Localization unity 国际化插件
- 基于Win socket简单实现一个FTP协议的客
- 基于socket的简易多人聊天室
- unity3D网络五子棋
- Unity3D海面效果不错的学习资料
- Highlighting System 高亮插件.unitypackage
- webRTC+socketio+SpringBoot视频及文字聊天
- unityWebgl文件选择.unitypackage
- okSocket库的使用
- Unity3D Glow Effect 自发光 颜色溢出效果
- Unity studio
- Unity AI Behavior Designe_1.6 官网最新版本
- Unity3d雨水特效资源包
- Unity3D画笔 涂鸦 签字
- Book Page Curl Pro.unitypackage
- unity 魔法效果闪电粒子包
- Cinemachine.rar
- Unity环境镜面效果
- Behavior Designer 1.6.4.zip
- CIS_Docker_Community_Edition_Benchmark_v1.1.0.
- unity语音识别Word Detection
- Unity3D掷筛子游戏源码
- Unity3d_动态改变按键设置
- Unity3d_项目_足球Game
- Unity 最新T4M地形插件,适用于5.6以上
- unity绳子插件
- Asset Studio v0.12.44
评论
共有 条评论