public void SocketConnect () {

            // Show the user URL
            if (showUrl != null)
                showUrl.text = uri.Replace("/socket.io/display", "");

			// Build an options object and disable reconnect to keep the system from timing itself out
			// @todo: investigate this line for the Windows implementation
			SocketOptions options = new SocketOptions();
			options.Reconnection = false;

			// Create the SocketManager instance
			manager = new SocketManager(new Uri(uri), options);

			// Start the socket
			Debug.Log("Starting Socket on server " + uri);
			Socket = manager["/display"];
			RootSocket = manager.Socket;

			// Add error handler, so we can display it
			Socket.On(SocketIOEventTypes.Error, OnError);

			// Set up our event handlers.
			Socket.On(SocketIOEventTypes.Connect, OnConnected);

			Socket.On(SocketIOEventTypes.Disconnect, OnDisconnected);

			// Generic control changes
			Socket.On ("control", (socket, packet, args) => {
                // Debug.Log("control event on socket" + packet.ToString());

                ControlData cd = JsonUtility.FromJson<ControlData>(MessageData(packet.ToString()));
                
                // Send the control data to the Game Controller
                gc.UserControl(cd);
		    });

            Socket.On("controlsDisconnect", (socket, packet, args) => {
                Debug.Log("disconnect event on socket" + packet.ToString());
                gc.UserExit(MessageData(packet.ToString().Replace("\"", "")));
            });
		}
예제 #2
0
        // activate reticles at all the touchpoints
        private void TouchStart(ControlData controlData)
        {
            TouchData[] touches = controlData.touches;
            ScreenData  screen  = controlData.screen;

            // deactivate the reticles
            foreach (GameObject retic in reticles)
            {
                retic.SetActive(false);
            }

            // If there's an item indicated, move the indicated to selected status
            if (indicated != null)
            {
                selected = indicated;
                Debug.Log("selected indicated: " + indicated.gameObject.name);
                if (hinge)
                {
                    hinge.transform.position = hit.point;
                    hinge.connectedBody      = selected.gameObject.GetComponent <Rigidbody>();
                }
            }

            foreach (TouchData touch in touches)
            {
                int touchIndex = Int32.Parse(touch.identifier);
                if (touchIndex < reticles.Length)
                {
                    // Activate the reticle
                    reticles[touchIndex].SetActive(true);

                    // Move the reticle to the indicated relative touch location
                    reticles[touchIndex].transform.localPosition = TouchToScreen(touch, screen);
                }
            }
        }