资源简介
完全正常使用 分别挂在客户端和服务端 赚点零花钱 不容易。 这么多人收藏 就降价分享给大家了
完全正常使用 分别挂在客户端和服务端 赚点零花钱 不容易。 这么多人收藏 就降价分享给大家了
代码片段和文件信息
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using System;
using UnityEngine.UI;
public class UserMsg : Messagebase
{
public string message;
}
public class NetClient : MonoBehaviour
{
public Text _Text;
///
/// 服务器ip地址
///
public string ip = “192.168.1.101“;
///
/// 服务器端口
///
public string port = “9050“;
///
/// 要发送的信息
///
public string send=“sendstr“;
///
/// 显示信息
///
public string info;
///
/// 网络客户端
///
private NetworkClient myClient;
///
/// 用户信息分类
///
private const short userMsg = 64;
public Gameobject Capsule;
public Gameobject CapsuleRed;
public Gameobject CubeRed;
// Use this for initialization
void Start ()
{
info = “Start...“;
_Text.text = info;
Capsule.SetActive(false);
myClient = new NetworkClient();
SetupClient();
}
// Update is called once per frame
void Update () {
}
///
/// 显示信息
///
/// Message.
private void ShowMsg(string Msg)
{
info = Msg + “\n\r“ + info;
Debug.Log(info);
}
///
/// 建立客户端
///
public void SetupClient()
{
if (!myClient.isConnected)
{
ShowMsg(“setup client“);
ClientRegisterHandler();
myClient.Connect(ip int.Parse(port));
}
}
///
/// 停止客户端
///
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 ();
}
}
///
/// 客户端连接到服务器事件
///
/// Net message.
private void OnClientConnected(NetworkMessage netMsg)
{
ShowMsg(“Client connected to server“);
ClientSend ();
}
///
///客户端从服务器断开事件
///
/// Net message.
private void OnClientDisconnected(NetworkMessage netMsg)
{
ShowMsg(“Client disconnected from server“);
}
///
/// 客户端错误事件
///
/// Net message.
private void OnClientError(NetworkMessage netMsg)
{
ClientUnregisterHandler();
ShowMsg(“Client error“);
}
///
/// 客户端注册事件
///
private void ClientRegisterHandler()
{
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 5041 2017-02-21 14:15 NetServer.cs
文件 5029 2017-02-16 17:09 NetClient.cs
----------- --------- ---------- ----- ----
10070 2
- 上一篇:MapGIS6.7破解电子狗
- 下一篇:unity人脸识别插件
评论
共有 条评论