• 大小: 11.08MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-07-20
  • 语言: 其他
  • 标签: Socket  For  U  

资源简介

https://blog.csdn.net/nicepainkiller/article/details/80757719 https://blog.csdn.net/nicepainkiller/article/details/80757719 使用说明,Unity3D 中使用 Socket.IO

资源截图

代码片段和文件信息

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using SocketIO;
using System;
 
using LitJson;

public class SocketController : MonoBehaviour {
 

    SocketIOComponent socketIO;
    private bool    login;
    private string chatMessage = ““;
    private string chatContent = ““;
    private string nickName = ““;
    private Guid guid = Guid.NewGuid();


    // Use this for initialization
    void Start ()
    {

        Gameobject go = Gameobject.Find(“SocketIO“);
        if (go == null)
        {
            go       = new Gameobject(“SocketIO“);
            socketIO = go.AddComponent();
        }
        else
        {
            socketIO = go.GetComponent();
            if (socketIO == null)
            {
                socketIO = go.AddComponent();
            }
        }

        socketIO.url = “ws://192.168.0.170:4567/socket.io/?EIO=3&transport=websocket“;

        socketIO.Connect();


        OnAddEvemt();
    }



    private void OnGUI()
    {

        if (!login)
        {
            Rect rect = new Rect(Screen.width / 3 Screen.height / 3 Screen.width / 3 Screen.height / 2);
            GUI.Box(rect ““ );


            GUI.Label(new Rect(rect.x + Screen.width / 60 rect.y + Screen.height / 9 rect.width - Screen.width / 15 Screen.height / 15)“请输入昵称:“);
  
            nickName =  GUI.TextField(new Rect(rect.x + Screen.width / 10 rect.y+ Screen.height / 10 rect.width- Screen.width / 5 Screen.height / 15) nickName);

            if( GUI.Button(new Rect(rect.x + Screen.width / 30 rect.y + Screen.height/4 rect.width - Screen.width / 15 Screen.height / 15)“登录“ ))
            {
                
                if (nickName.Length > 0)
                {
                    Dictionary data = new Dictionary();
                    data[“guid“]                    = guid.ToString();
                    data[“nickName“]                = nickName;

                    socketIO.Emit(SocketIOProtocol.ProtocolLogin new JSONobject(data));
                }
            }  

           return;
        }

        GUI.Label(new Rect(0 0 Screen.width Screen.height - 200) chatContent);

        chatMessage = GUI.TextField(new Rect(0 Screen.height - 200 Screen.width - 200 200) chatMessage);
        if (GUI.Button(new Rect(Screen.width - 200 Screen.height - 200 200 200) “Send“))
        {


            Dictionary data = new Dictionary();
            data[“chatMessage“] = chatMessage;
            socketIO.Emit(SocketIOProtocol.ProtocolChat new JSONobject(data));

            chatMessage = string.Empty;
        }
    }




    void OnAddEvemt()
    {
        socketIO.On(SocketIOProtocol.ProtocolLogin (date) =>
        {
            JsonData jsonData = JsonMapper.Toobject(date.data.ToStr

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-06-25 16:00  工程\
     目录           0  2018-06-25 16:00  工程\Client\
     目录           0  2018-06-25 16:00  工程\Client\Unity3D_SocketIO\
     目录           0  2018-06-25 16:00  工程\Client\Unity3D_SocketIO\.vs\
     目录           0  2018-06-25 16:00  工程\Client\Unity3D_SocketIO\.vs\Unity3D_SocketIO\
     目录           0  2018-06-25 16:00  工程\Client\Unity3D_SocketIO\.vs\Unity3D_SocketIO\v15\
     文件      288768  2018-06-25 15:47  工程\Client\Unity3D_SocketIO\.vs\Unity3D_SocketIO\v15\.suo
     目录           0  2018-06-25 16:00  工程\Client\Unity3D_SocketIO\.vs\Unity3D_SocketIO\v15\Server\
     目录           0  2018-06-25 16:00  工程\Client\Unity3D_SocketIO\.vs\Unity3D_SocketIO\v15\Server\sqlite3\
     文件     2310144  2018-06-25 15:00  工程\Client\Unity3D_SocketIO\.vs\Unity3D_SocketIO\v15\Server\sqlite3\storage.ide
     文件       32768  2018-06-25 10:41  工程\Client\Unity3D_SocketIO\.vs\Unity3D_SocketIO\v15\Server\sqlite3\storage.ide-shm
     文件     4152992  2018-06-25 15:00  工程\Client\Unity3D_SocketIO\.vs\Unity3D_SocketIO\v15\Server\sqlite3\storage.ide-wal
     目录           0  2018-06-25 16:00  工程\Client\Unity3D_SocketIO\Assets\
     文件        7898  2018-06-22 11:35  工程\Client\Unity3D_SocketIO\Assets\CharRoom.unity
     文件         196  2018-06-22 10:30  工程\Client\Unity3D_SocketIO\Assets\CharRoom.unity.meta
     目录           0  2018-06-25 16:00  工程\Client\Unity3D_SocketIO\Assets\Plugins\
     文件       51712  2018-04-21 13:05  工程\Client\Unity3D_SocketIO\Assets\Plugins\LitJson.dll
     文件         610  2018-06-25 10:46  工程\Client\Unity3D_SocketIO\Assets\Plugins\LitJson.dll.meta
     文件         213  2018-06-25 10:46  工程\Client\Unity3D_SocketIO\Assets\Plugins.meta
     目录           0  2018-06-25 16:00  工程\Client\Unity3D_SocketIO\Assets\Socket.IO\
     目录           0  2018-06-25 16:00  工程\Client\Unity3D_SocketIO\Assets\Socket.IO\JSONobject\
     目录           0  2018-06-25 16:00  工程\Client\Unity3D_SocketIO\Assets\Socket.IO\JSONobject\Editor\
     文件        1339  2016-05-17 20:55  工程\Client\Unity3D_SocketIO\Assets\Socket.IO\JSONobject\Editor\JSONChecker.cs
     文件         178  2016-05-17 20:55  工程\Client\Unity3D_SocketIO\Assets\Socket.IO\JSONobject\Editor\JSONChecker.cs.meta
     文件         107  2016-05-17 20:55  工程\Client\Unity3D_SocketIO\Assets\Socket.IO\JSONobject\Editor.meta
     文件       27894  2016-05-17 20:55  工程\Client\Unity3D_SocketIO\Assets\Socket.IO\JSONobject\JSONobject.cs
     文件         178  2016-05-17 20:55  工程\Client\Unity3D_SocketIO\Assets\Socket.IO\JSONobject\JSONobject.cs.meta
     文件        2854  2016-05-17 20:55  工程\Client\Unity3D_SocketIO\Assets\Socket.IO\JSONobject\JSONTemplates.cs
     文件         178  2016-05-17 20:55  工程\Client\Unity3D_SocketIO\Assets\Socket.IO\JSONobject\JSONTemplates.cs.meta
     文件        7702  2016-05-17 20:55  工程\Client\Unity3D_SocketIO\Assets\Socket.IO\JSONobject\VectorTemplates.cs
     文件         178  2016-05-17 20:55  工程\Client\Unity3D_SocketIO\Assets\Socket.IO\JSONobject\VectorTemplates.cs.meta
............此处省略3428个文件信息

评论

共有 条评论