Esempio n. 1
0
    public void Initialize()
    {
        GameObject go = GameObject.Find("SocketIO");
        socket = go.GetComponent<SocketIOComponent>();

        socket.Connect();

        // Register callbacks
        socket.On("message", OnMessage);

        // Send first contact to server
        socket.Emit("connection");

        // Log in
        Dictionary<string,string> login = new Dictionary<string,string>();
        login["username"] = "******";
        socket.Emit("login", new JSONObject(login));

        /*
        client = new Client(url);

        client.Opened += OnSocketOpened;
        client.Message += SocketMessage;
        client.SocketConnectionClosed += SocketConnectionClosed;
        client.Error +=SocketError;

        client.Connect();
        */
    }
Esempio n. 2
0
    /* Send packets
     */

    public void SendImage(Texture2D texture)
    {
        Dictionary <string, string> data = new Dictionary <string, string>();

        data["encodedTexture"] = Convert.ToBase64String(texture.EncodeToJPG());
        data["textureWidth"]   = "" + texture.width;
        data["textureHeight"]  = "" + texture.width;

        socket.Emit("mapUpdate", new JSONObject(data));
    }
Esempio n. 3
0
    private void OnConnection(SocketIO.SocketIOEvent e)
    {
        if (!joined)
        {
            Dictionary <string, string> data = new Dictionary <string, string>();
            data["connectionType"] = connectionType;

            socket.Emit("join", new JSONObject(data));
        }
    }
Esempio n. 4
0
 public void socketConnected(SocketIOEvent e)
 {
     if (first)
     {
         first = false;
         JSONObject msg = new JSONObject(JSONObject.Type.STRING);
         msg.str = "A";
         socket.Emit("connect drone", msg);
     }
 }
Esempio n. 5
0
    /* Send data to the server. */

    private void PlayerJoinServer(SocketIO.SocketIOEvent e)
    {
        if (!joined)
        {
            Dictionary <string, string> data = new Dictionary <string, string>();
            data["playerTypeId"] = "" + selectedTypeId;
            data["x"]            = "" + this.transform.position.x;
            data["y"]            = "" + this.transform.position.y;
            data["rotZ"]         = "" + this.transform.rotation.z;
            data["rotY"]         = "" + this.transform.rotation.y;

            socket.Emit("join", new JSONObject(data));
        }
    }
Esempio n. 6
0
 // Use this for initialization
 void Start()
 {
     GameObject go = GameObject.Find("SocketIO");
     socket = go.GetComponent<SocketIOComponent>();
     transform.position = startPosition;
     socket.Emit("LoadMap");
 }
Esempio n. 7
0
	void Start () 
	{
		GameObject go = GameObject.Find("SocketIO");
		socket = go.GetComponent<SocketIOComponent>();
		myscript = go.GetComponent<ectScript>();
		socket.Emit("LoadMap");
		socket.On("swapAllPlayer",swapAllPlayer);

	}
Esempio n. 8
0
    public void sendTransform(Vector3 pos, Quaternion rot)
    {
        if (io.IsConnected)
        {
            JSONObject data     = new JSONObject();
            JSONObject position = new JSONObject();
            position.AddField("x", pos.x);
            position.AddField("y", pos.y);
            position.AddField("z", pos.z);

            JSONObject rotation = new JSONObject();
            rotation.AddField("x", rot.x);
            rotation.AddField("y", rot.y);
            rotation.AddField("z", rot.z);
            rotation.AddField("w", rot.w);

            data.AddField("position", position);
            data.AddField("rotation", rotation);

            io.Emit("player-position", data);
        }
    }
Esempio n. 9
0
 protected void Send()
 {
     socket.Emit(packetName, new JSONObject(data));
 }
    void Update()
    {
        if (BodySourceManager == null)
        {
            return;
        }
        if (socket == null)
        {
            print("Null socket");
            socket = BodySourceManager.AddComponent<SocketIOComponent>();
            //socket.Awake();
            socket.Start();
            socket.Emit("kinect",  JSONObject.StringObject("60"));
        }
        _BodyManager = BodySourceManager.GetComponent<BodySourceManager>();
        if (_BodyManager == null)
        {
            return;
        }

        Kinect.Body[] data = _BodyManager.GetData();
        if (data == null)
        {
            return;
        }

        List<ulong> trackedIds = new List<ulong>();
        foreach(var body in data)
        {
            if (body == null)
            {
                continue;
              }

            if (body.IsTracked)
            {
                trackedIds.Add (body.TrackingId);
            }
        }

        List<ulong> knownIds = new List<ulong>(_Bodies.Keys);

        // First delete untracked bodies
        //foreach(ulong trackingId in knownIds)
        //{
        //    if(!trackedIds.Contains(trackingId))
        //    {
        //        Destroy(_Bodies[trackingId]);
        //        _Bodies.Remove(trackingId);
        //    }
        //}

        foreach(var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if(body.IsTracked)
            {
                if(!_Bodies.ContainsKey(body.TrackingId))
                {
                    _Bodies[body.TrackingId] = CreateBodyObject(body.TrackingId);
                }

                RefreshBodyObject(body, _Bodies[body.TrackingId]);
            }
        }
    }