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(); */ }
/* 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)); }
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)); } }
public void socketConnected(SocketIOEvent e) { if (first) { first = false; JSONObject msg = new JSONObject(JSONObject.Type.STRING); msg.str = "A"; socket.Emit("connect drone", msg); } }
/* 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)); } }
// Use this for initialization void Start() { GameObject go = GameObject.Find("SocketIO"); socket = go.GetComponent<SocketIOComponent>(); transform.position = startPosition; socket.Emit("LoadMap"); }
void Start () { GameObject go = GameObject.Find("SocketIO"); socket = go.GetComponent<SocketIOComponent>(); myscript = go.GetComponent<ectScript>(); socket.Emit("LoadMap"); socket.On("swapAllPlayer",swapAllPlayer); }
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); } }
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]); } } }