public override void OnCreatedRoom() { if (OnRoomCreated != null) { OnRoomCreated.Invoke(); } }
private void MessageHandler(object sender, MessageEventArgs e) { var bb = new ByteBuffer(e.RawData); ServerMessage msg = ServerMessage.GetRootAsServerMessage(bb); switch (msg.Type) { case msgType.RoomStateUpdate: //handle message if (msg.Data <StateUpdate>() == null) { print("empty state update. this should not happen"); return; } StateUpdate?stateUpdate = msg.Data <StateUpdate>(); if (stateUpdate != null) { StateUpdate sup = stateUpdate.Value; UpdateLocalState(sup); } break; case msgType.SocketReady: print("connected to server"); StringData?stringData = msg.Data <StringData>(); if (stringData != null) { OnConnectedArgs connectedEventArgs = new OnConnectedArgs { sid = stringData.Value.Data, }; NeuraCore.Instance.sid = connectedEventArgs.sid; } if (OnConnected != null) { OnConnected.Invoke(this, new EventArgs()); } break; case msgType.SocketRoomJoined: { print("Joined room "); inRoom = true; UsersInRoom.Add(localUserName); NeuraCore.Instance.connectionState = ConnectionState.Connected; if (msg.DataType != Transport.FlatBuffers.msg.StateUpdate) { return; } if (msg.Data <StateUpdate>().HasValue) { var initStateSUP = msg.Data <StateUpdate>().Value; UpdateLocalState(initStateSUP); } if (OnRoomJoined != null) { OnRoomJoined.Invoke(this, RoomName); } } break; case msgType.RoomCreated: StringData?createMsg = msg.Data <StringData>(); if (createMsg != null) { //var rmName = createMsg.Value.Data; //RoomName = rmName; print("room " + RoomName + " has been created"); if (OnRoomCreated != null) { OnRoomCreated.Invoke(this, RoomName); } if (string.IsNullOrEmpty((globalState ?? (globalState = new RoomStateGen())).siteDrive)) { //Handle things like critical room state here to make sure that the initial state sent has the required information //For onsight the site drive is of critical importance so we are setting it below //globalState.siteDrive = string.IsNullOrEmpty(requestedSiteDrive) // ? MultiUserConnectionManager.Instance.CurrentSiteDriveJSON // : requestedSiteDrive; } Debug.Assert(!string.IsNullOrEmpty(globalState.siteDrive)); NeuraCore.Instance.SendInitialState(ServerMessageFactory.BuildMessage(globalState)); } break; case msgType.RoomUserOnjoined: StringData?joinedMsg = msg.Data <StringData>(); if (joinedMsg != null) { var user = joinedMsg.Value.Data; print(user + " has joined the room"); UsersInRoom.Add(user); if (OnUserJoined != null) { OnUserJoined.Invoke(this, new UserJoinedEventArgs { username = user }); } } break; case msgType.RoomUserOnLeft: StringData?leftMsg = msg.Data <StringData>(); if (leftMsg != null) { var user = leftMsg.Value.Data; print(user + " has left the room"); if (UsersInRoom.Contains(user)) { UsersInRoom.Remove(user); } if (OnUserLeft != null) { OnUserLeft.Invoke(this, new UserLeftEventArgs { username = user }); } } break; } }
private void FireRoomCreated(string roomId) { OnRoomCreated?.Invoke(roomId); }
private void CreateNewRoom() { GameObject nextRoom = null; Vector3 nextRoomPos = Vector3.zero; Vector3 nextRoomSize = Vector3.zero; // create right or left if (Mathf.Abs(_distanceFromCenter.x) > Mathf.Abs(_distanceFromCenter.y)) { if (_distanceFromCenter.x > 0) { int rand = Random.Range(0, LevelGenerator.Instance.leftRooms.Length); nextRoom = Instantiate(LevelGenerator.Instance.leftRooms[rand], transform.position, Quaternion.identity); RoomType nextRoomScript = nextRoom.GetComponent <RoomType>(); int rand2 = Random.Range(0, nextRoomScript.leftExit.Length); Vector3 nextRoomEntrancePosition = nextRoomScript.leftExit[rand2].position - nextRoom.transform.position; nextRoomSize = nextRoom.GetComponent <BoxCollider>().size; nextRoomPos = transform.parent.position + new Vector3(_roomSize.x / 2 + nextRoomSize.x / 2, _distanceFromCenter.y - nextRoomEntrancePosition.y, 0); } // room with rigth open else { int rand = Random.Range(0, LevelGenerator.Instance.rightRooms.Length); nextRoom = Instantiate(LevelGenerator.Instance.rightRooms[rand], transform.position, Quaternion.identity); RoomType nextRoomScript = nextRoom.GetComponent <RoomType>(); int rand2 = Random.Range(0, nextRoomScript.rightExit.Length); Vector3 nextRoomEntrancePosition = nextRoomScript.rightExit[rand2].position - nextRoom.transform.position; nextRoomSize = nextRoom.GetComponent <BoxCollider>().size; nextRoomPos = transform.parent.position - new Vector3(_roomSize.x / 2 + nextRoomSize.x / 2, -_distanceFromCenter.y + nextRoomEntrancePosition.y, 0); } // create up or down } else { if (_distanceFromCenter.y > 0) { int rand = Random.Range(0, LevelGenerator.Instance.bottomRooms.Length); nextRoom = Instantiate(LevelGenerator.Instance.bottomRooms[rand], transform.position, Quaternion.identity); RoomType nextRoomScript = nextRoom.GetComponent <RoomType>(); int rand2 = Random.Range(0, nextRoomScript.bottomExit.Length); Vector3 nextRoomEntrancePosition = nextRoomScript.bottomExit[rand2].position - nextRoom.transform.position; nextRoomSize = nextRoom.GetComponent <BoxCollider>().size; nextRoomPos = transform.parent.position + new Vector3(_distanceFromCenter.x - nextRoomEntrancePosition.x, _roomSize.y / 2 + nextRoomSize.y / 2, 0); } else { int rand = Random.Range(0, LevelGenerator.Instance.topRooms.Length); nextRoom = Instantiate(LevelGenerator.Instance.topRooms[rand], transform.position, Quaternion.identity); RoomType nextRoomScript = nextRoom.GetComponent <RoomType>(); int rand2 = Random.Range(0, nextRoomScript.topExit.Length); Vector3 nextRoomEntrancePosition = nextRoomScript.topExit[rand2].position - nextRoom.transform.position; nextRoomSize = nextRoom.GetComponent <BoxCollider>().size; nextRoomPos = transform.parent.position - new Vector3(-_distanceFromCenter.x - nextRoomEntrancePosition.x, _roomSize.y / 2 + nextRoomSize.y / 2, 0); } } nextRoom.transform.position = nextRoomPos; nextRoom.transform.SetParent(transform.parent); OnRoomCreated?.Invoke(nextRoom); Destroy(gameObject); }