// Start is called before the first frame update public void Start() { io = FindObjectOfType <SocketIOController>(); io.Connect(); Initialize(); SetupEvents(); }
public void Start() { socket = gameObject.GetComponent <SocketIOController>(); Debug.Log(socket); mapHandler = GameObject.Find("Map").GetComponent <MapHandler>(); playerMovement = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerMovement>(); //Default socket messages socket.On("connect", SocketOpen); socket.On("open", SocketOpen); socket.On("ping", SocketPing); socket.On("error", SocketError); socket.On("close", SocketClose); //Custom socket messages socket.On("mapres", MapDataFromServer); socket.On("newmove", PositionDataFromServer); //socket.On("newtweet", TweetDataFromServer); socket.On("tweets", TweetDataFromServer); socket.On("win", WinDataFromServer); socket.Connect(); }
// Start is called before the first frame update void Start() { io = GameObject.Find("SocketIOController").GetComponent <SocketIOController>(); spawnLocalPlayer(); requestPlayersPosition(); // TODO : request start => check if there are 4 players in the room }
void Start() { Instance = this; io = FindObjectOfType <SocketIOController>(); io.On("connect", e => { //We just connected to the socket server Debug.Log("Connected"); io.Emit("vieweronline"); }); io.On("reset", e => { SceneManager.LoadScene(0); }); io.On("enroll", e => { ScreenDetector.gameObject.SetActive(true); ScreenDetector.EnrollNewScreen(e); }); io.Connect(); }
void Start() { if (isBotClient && isBotOrc) { botsetup(PlayerFaction.Orc); } else if (isBotClient && !isBotOrc) { botsetup(PlayerFaction.Warrior); } // socket = GetComponent<SocketIOControllerWeb>(); socket = GetComponent <SocketIOController>(); socket.Connect(); socket.On("open", OnConnected); socket.On("register", OnRegister); socket.On("zone_data", OnInitialZoneData); socket.On("name", OnName); socket.On("spawn", OnSpawn); socket.On("move", OnMove); socket.On("jump", OnJump); socket.On("disconnected", OnDisconnected); socket.On("damage", OnDamage); socket.On("died", OnDeath); socket.On("respawn1", OnRespawnRequest); socket.On("respawn2", OnRespawn); socket.On("attack_animation", OnAttackAnimation); socket.On("reset_animation", OnResetAnimation); socket.On("score", OnScore); socket.On("chat", OnChat); socket.On("zone_update", OnZoneUpdate); socket.On("ai_animation", OnAIPlayAnimation); socket.On("disconnect", delegate { Application.Quit(); }); }
public void Join() { Debug.Log("Join a room is clicked:" + EventSystem.current.currentSelectedGameObject.name); string roomName = GameObject.Find(EventSystem.current.currentSelectedGameObject.name).GetComponentInChildren <TextMeshProUGUI>().text; roomName = roomName.Split('\n')[0]; SocketIOController io = GameObject.Find("SocketIOController").GetComponent <SocketIOController>(); RoomName JSONobj = new RoomName(); JSONobj.roomName = roomName; // socket io emit {join, room name} io.Emit("joinRoom", JsonUtility.ToJson(JSONobj), (string data) => { Debug.Log(data); bool roomAvailable = JsonUtility.FromJson <RoomAvailability>(data).roomAvailable; Debug.Log(roomAvailable); if (roomAvailable == true) { SceneManager.LoadScene("Arena-1", LoadSceneMode.Single); } else { GameObject notAvailableTextMeshInstance = Instantiate(notAvailableTextMesh, new Vector3(411, 470, 0), Quaternion.identity) as GameObject; // wait 1 second and delete message //Start the coroutine we define below named ExampleCoroutine. StartCoroutine(ExampleCoroutine(notAvailableTextMeshInstance)); } }); }
public void SendName() { roomName = roomNameTextMesh.text; if (roomName != "") { SocketIOController io = GameObject.Find("SocketIOController").GetComponent <SocketIOController>(); Debug.Log("room name received: " + roomName); RoomName JSONobj = new RoomName(); JSONobj.roomName = roomName; Debug.Log("test:" + JSONobj.roomName + ":"); // then send the name to the server io.Emit("createRoom", JsonUtility.ToJson(JSONobj), (string data) => { Debug.Log(data); bool roomAvailable = JsonUtility.FromJson <RoomAvailability>(data).roomAvailable; Debug.Log(roomAvailable); if (roomAvailable == true) { SceneManager.LoadScene("Arena-1", LoadSceneMode.Single); } else { notAvailableTextMesh.gameObject.SetActive(true); } }); } }
void Start() { rb = GetComponent <Rigidbody2D>(); rb.constraints = RigidbodyConstraints2D.FreezeRotation; anim = GetComponent <Animator>(); eulerAngles = transform.eulerAngles; io = GameObject.Find("NetworkManager").GetComponent <ConnectToServer>().io; deathFloor = GameObject.Find("DeathFloor").GetComponent <BoxCollider2D>(); }
private IEnumerator ConnectionSequence() { // initialize the socket object socket = InitializeSocket(); // wait some time so that the Javascript part can run in the webgl build. Not sure if there's any way to detect when it's ready yield return(new WaitForSeconds(1)); // connect to the server socket.Connect(); InitializeMessageHandlers(); }
void Start() { socket = GetComponent <SocketIOController>(); socket.On("mothership", OnMothershipEmit); socket.On("session", OnSessionStarted); socket.On("open", OnConnected); socket.On("spawn", OnSpawned); socket.On("unspawn", OnUnspawned); socket.On("move", OnPlayerMovement); socket.On("enemy", OnEnemyMovement); socket.Connect(); }
public void TestWorldControllerHasWorldControlsAndSocketIO() { Assert.IsNotNull(worldController); WorldControls worldControls = worldController.GetComponent <WorldControls>(); Assert.IsNotNull(worldControls); GameObject socketIOController = GameObject.Find("SocketIOController"); Assert.IsNotNull(socketIOController); SocketIOController socketIOScript = socketIOController.GetComponent <SocketIOController>(); Assert.IsNotNull(socketIOScript); Assert.AreEqual(socketIOScript, worldControls.io); }
public void RefreshRoomsList() { Debug.Log("refresh room list"); SocketIOController io = GameObject.Find("SocketIOController").GetComponent <SocketIOController>(); io.Emit("refreshRoomsList", JsonUtility.ToJson(""), (string data) => { Debug.Log(data); RoomsList roomsList = new RoomsList(); roomsList = JsonUtility.FromJson <RoomsList>(data); foreach (Room room in roomsList.Rooms) { Debug.Log(room.roomName); GameObject buttonPrefabInstance = Instantiate(buttonPrefab, content.transform, false) as GameObject; buttonPrefabInstance.name = "Button" + room.roomName; //buttonPrefabInstance.transform.parent = content.transform; buttonPrefabInstance.GetComponentInChildren <TextMeshProUGUI>().text = room.roomName + "\nnumber of players: " + room.numPlayers.ToString() + "/4"; } }); }
//Network Initialization private void Start() { socket = GetComponent <SocketIOController>(); socket.Connect(); //Begin socket listening socket.On("register", OnRegister); socket.On("spawn", OnSpawned); socket.On("moved", OnMoved); socket.On("disconnected", OnDisconnected); socket.On("requestPosition", OnRequestPosition); socket.On("updatingPosition", OnUpdatingPosition); socket.On("attack", OnAttack); socket.On("face", OnFace); //Instantiate player list otherPlayers = new Dictionary <string, GameObject>(); //TODO: Delete this, it's for testing only socket.On("test-event", (SocketIOEvent e) => { var purp = block.GetComponent <SpriteRenderer>(); purp.color = Color.blue; }); }
void Start() { Application.targetFrameRate = 60; socket = GetComponent<SocketIOController>(); gameMenu = GetComponent<GameMenu>(); //to switch quickly between local and online you can override the settings here if (GLITCH) { socket.settings.url = "yourglitchdomain.glitch.me"; socket.settings.port = 0 ; socket.settings.sslEnabled = true; } else if (HEROKU) { socket.settings.url = "yourherokudomain.herokuapp.com"; socket.settings.port = 5000; socket.settings.sslEnabled = true; } //connect to the server socket.Connect(); Net.connected = false; //Listeners connecting socket events from the server and the functions below socket.On("socketConnect", OnSocketConnect); socket.On("nameError", OnNameError); //any player connected including me socket.On("playerJoin", OnPlayerJoin); //just connected, server sends me all the player info socket.On("addPlayerData", OnAddPlayerData); //another player disconnected socket.On("playerDisconnect", OnPlayerDisconnect); //a net object is instantiated socket.On("instantiate", OnNetInstantiate); //or destroyed socket.On("destroy", OnNetDestroy); //a net object position has changed socket.On("updateTransform", OnUpdateTransform); //a net object changed ownership socket.On("changeOwner", OnChangeOwner); //a net object changed type TEMPORARY, PRIVATE, SHARED... socket.On("changeType", OnChangeType); //net variables changed socket.On("setVariables", OnSetVariables); //a net function has been called socket.On("netFunction", OnNetFunction); //the server changes the authority socket.On("setAuthority", OnSetAuthority); //a chat message arrives socket.On("message", OnMessage); //Net.cs is just a global class //every variable in there is visible from anywhere //initialize players Net.players = new Dictionary<string, Player>(); //initialize net objects Net.objects = new Dictionary<string, NetObject>(); //make a global reference to this script Net.manager = this; ServerMessage("Connecting to server..."); Invoke("Timeout", 10); }//end start
public void SetSocketRefrence(SocketIOController Socket) { socket = Socket; }
void Start() { DontDestroyOnLoad(this.gameObject); socket = gameObject.GetComponent <SocketIOController>(); }
void Start() { scriptPlayerController = GameObject.FindGameObjectWithTag("Knight").GetComponent <PlayerController>(); io = GameObject.Find("NetworkManager").GetComponent <ConnectToServer>().io; }
void Start() { io = GameObject.Find("SocketIOController").GetComponent <SocketIOController>(); io.On("connect", (SocketIOEvent e) => { Debug.Log("SocketIO connected"); io.Emit("test-event1"); TestObject t = new TestObject(); t.test = 123; t.test2 = "test1"; io.Emit("test-event2", JsonUtility.ToJson(t)); TestObject t2 = new TestObject(); t2.test = 1234; t2.test2 = "test2"; io.Emit("test-event3", JsonUtility.ToJson(t2), (string data) => { Debug.Log(data); }); }); io.On("allPlayersPositions", (SocketIOEvent ev) => { Debug.Log("allPlayersPositions received"); Debug.Log(ev.data.ToString()); PlayersList playersList = new PlayersList(); playersList = JsonUtility.FromJson <PlayersList>(ev.data); foreach (Players player in playersList.Players) { Debug.Log(player.playerId); Debug.Log(player.pos); string playerName = "Player" + player.playerId; GameObject playerInstance = Instantiate(playerPrefab, player.pos, Quaternion.identity); playerInstance.name = playerName; playerInstance.tag = "Player"; /*LocalPlayer localPlayer = playerInstance.GetComponent<LocalPlayer>(); * localPlayer.playerId = player.playerId; */ } }); // delete an instance of the disconnected player io.On("playerDisconnected", (SocketIOEvent ev) => { string playerId = JsonUtility.FromJson <PlayerIdJSON>(ev.data).playerId; string playerName = "Player" + playerId; Destroy(GameObject.Find(playerName)); }); io.On("spawnPlayer", (SocketIOEvent ev) => { playerSpawn.GetComponent <SpawnPlayer>().spawnLocalPlayer(); }); io.On("moveInput", (SocketIOEvent ev) => { Debug.Log("moveInput received : " + ev.data.ToString()); Movement movement = JsonUtility.FromJson <Movement>(ev.data); string playerName = "Player" + movement.playerId; GameObject.Find(playerName).GetComponent <PlayerState>().moveInput = movement.moveInput; }); io.On("playerMoved", (SocketIOEvent ev) => { Debug.Log("playerMoved received : " + ev.data.ToString()); PlayerPos playerPos = JsonUtility.FromJson <PlayerPos>(ev.data); string playerId = playerPos.playerId; string playerName = "Player" + playerId; Debug.Log(playerName); GameObject playerToMove = GameObject.Find(playerName); if (playerToMove == null) { playerToMove = Instantiate(playerPrefab, playerPos.pos, Quaternion.identity); playerToMove.name = playerName; playerToMove.tag = "Player"; playerToMove.GetComponent <LocalPlayer>().setPlayerId(playerId); } // TODO: playerToMove.Move(player.pos); playerToMove.transform.position = playerPos.pos; Debug.Log("playerPos.pos"); Debug.Log(playerPos.pos); /*if(playerToMove != null){ * playerToMove.transform.position = playerPos.pos; * } * else{ * Debug.Log("cannot find the playerToMove!"); * }*/ }); io.On("playerRotated", (SocketIOEvent ev) => { Debug.Log("playerRotated received : " + ev.data.ToString()); PlayerPos playerPos = JsonUtility.FromJson <PlayerPos>(ev.data); string playerId = playerPos.playerId; string playerName = "Player" + playerId; Debug.Log(playerName); GameObject playerToMove = GameObject.Find(playerName); playerToMove.transform.eulerAngles = playerPos.pos; Debug.Log("playerPos.pos"); Debug.Log(playerPos.pos); }); io.On("velocityChanged", (SocketIOEvent ev) => { Debug.Log("velocityChanged received : " + ev.data.ToString()); PlayerVelocity playerVelocity = JsonUtility.FromJson <PlayerVelocity>(ev.data); string playerId = playerVelocity.playerId; string playerName = "Player" + playerId; Debug.Log(playerName); GameObject playerToMove = GameObject.Find(playerName); playerToMove.GetComponent <PlayerController>().ComputeVelocity(playerVelocity.velocity); /*if (playerVelocity.velocity.x == 0) * { * playerToMove.GetComponent<Animator>.SetBool("IsRunning", false); * } * else * { * playerToMove.GetComponent<Animator>.SetBool("IsRunning", true); * }*/ Debug.Log("playerVelocity.velocity"); Debug.Log(playerVelocity.velocity); }); io.On("playerAttack", (SocketIOEvent ev) => { Debug.Log("playerAttack received"); string playerId = JsonUtility.FromJson <PlayerIdJSON>(ev.data).playerId; string playerName = "Player" + playerId; GameObject playerInstance = GameObject.Find(playerName); playerInstance.GetComponent <PlayerState>().isAttacking = true; playerInstance.GetComponent <Animator>().SetTrigger("Attack"); }); io.On("playerEndAttack", (SocketIOEvent ev) => { Debug.Log("playerAttack received"); string playerId = JsonUtility.FromJson <PlayerIdJSON>(ev.data).playerId; string playerName = "Player" + playerId; GameObject.Find(playerName).GetComponent <PlayerState>().isAttacking = false; }); io.On("jump", (SocketIOEvent ev) => { Debug.Log("jump received"); string playerId = JsonUtility.FromJson <PlayerIdJSON>(ev.data).playerId; string playerName = "Player" + playerId; GameObject.Find(playerName).GetComponent <PlayerState>().jump = true; }); io.On("playerKilled", (SocketIOEvent ev) => { Debug.Log("another player killed by a player"); string playerId = JsonUtility.FromJson <PlayerIdJSON>(ev.data).playerId; string playerName = "Player" + playerId; Destroy(GameObject.Find(playerName)); }); io.On("playerDeathByDeathFloor", (SocketIOEvent ev) => { Debug.Log("another player killed by death floor"); string playerId = JsonUtility.FromJson <PlayerIdJSON>(ev.data).playerId; string playerName = "Player" + playerId; Destroy(GameObject.Find(playerName)); }); /*io.On("anotherPlayerConnected", (SocketIOEvent e) => { * Debug.Log(e.data); * Instantiate(myPrefab, new Vector3(0, 0, 0), Quaternion.identity); * });*/ io.Connect(); io.On("test-event", (SocketIOEvent e) => { Debug.Log(e.data); }); }