IEnumerator SpawnWaves() { yield return(new WaitForSeconds(startWait)); while (true) { var socketClientProxy = SocketClientProxy.getInstance(); for (int i = 0; i < hazardCount && socketClientProxy.isConnected(); i++) { var gameObjectType = Random.Range(0, hazards.Length); GameObject hazard = hazards[gameObjectType]; Vector3 spawnPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z); Quaternion spawnRotation = Quaternion.identity; var gameObject = Instantiate(hazard, spawnPosition, spawnRotation); gameObject.name = "hazard"; GameManager.getInstance().addGameObject(gameObjectType, gameObject); yield return(new WaitForSeconds(spawnWait)); } yield return(new WaitForSeconds(waveWait)); if (gameOver) { restartText.text = "Press 'R' for Restart"; restart = true; break; } } }
public void OnClick() { SocketClientProxy socketClientProxy = SocketClientProxy.getInstance(); socketClientProxy.setCredential(usernameInput.text, "123456"); socketClientProxy.connectToServer(); }
protected override void handleLoginSuccess(EzyData responseData) { client.udpConnect(2611); if (SocketClientProxy.getInstance().firstLogin) { SocketClientProxy.getInstance().firstLogin = false; } }
public Done_GameController() { EzyLoggerFactory.setLoggerSupply(type => new UnityLogger(type)); var socketClientProxy = SocketClientProxy.getInstance(); socketClientProxy.onReconnected(data => { var gameId = data.get <int>("gameId"); var gameState = data.get <string>("gameState"); GameManager.getInstance().gameId = gameId; var gameObjectDatas = data.get <EzyArray>("gameObjects"); for (var i = 0; i < gameObjectDatas.size(); ++i) { var gameObjectData = gameObjectDatas.get <EzyObject>(i); var gameObjectType = gameObjectData.get <int>("type"); var position = gameObjectData.get <EzyObject>("position"); var x = position.get <float>("x"); var y = position.get <float>("y"); var z = position.get <float>("z"); var spawnPosition = new Vector3(x, y, z); var visible = gameObjectData.get <bool>("visible"); gameObject.SetActive(visible); var objectName = gameObjectData.get <string>("name"); if (objectName.Equals("hazard")) { GameObject hazard = hazards[gameObjectType]; var gameObject = Instantiate(hazard, spawnPosition, Quaternion.identity); GameManager.getInstance().addGameObject(gameObjectType, gameObject); } else if (objectName.Equals("ship")) { ship.transform.position = spawnPosition; } } score = data.get <int>("playerScore"); UpdateScore(); if (gameId > 0 && gameState.Equals("PLAYING")) { StartCoroutine(SpawnWaves()); } else { GameManager.getInstance().getGameId(); } usernameInput.gameObject.SetActive(false); loginButton.gameObject.SetActive(false); }); socketClientProxy.onGameIdReceived(data => { var gameId = data.get <int>("gameId"); GameManager.getInstance().gameId = gameId; SocketClientProxy.getInstance().startGame(gameId); }); socketClientProxy.onStartGame(data => { StartCoroutine(SpawnWaves()); }); socketClientProxy.onDisconnected(() => { // do something }); }
protected override EzyRequest getLoginRequest() { return(new EzyLoginRequest( SocketClientProxy.ZONE_NAME, SocketClientProxy.getInstance().username, SocketClientProxy.getInstance().password, EzyEntityFactory.newArrayBuilder() .append("gameName", SocketClientProxy.GAME_NAME) .build() )); }
public void deleteGameObject(GameObject gameObject) { if (gameObjectById.ContainsKey(gameObject.GetInstanceID())) { SocketClientProxy.getInstance().deleteGameObject( gameId, gameObject.GetInstanceID() ); } gameObjectById.Remove(gameObject.GetInstanceID()); gameObjectPositions.Remove(gameObject); gameObjectTypes.Remove(gameObject); }
public void syncGameObjectPositions() { var socketClientProxy = SocketClientProxy.getInstance(); foreach (var obj in gameObjectPositions.Keys) { var position = gameObjectPositions[obj]; if (obj == null || !obj.activeSelf) { gameObjectPositionsChanged[obj] = position; continue; } var objectPosition = obj.transform.position; if (!objectPosition.Equals(position)) { gameObjectPositionsChanged[obj] = objectPosition; } } foreach (var obj in gameObjectPositionsChanged.Keys) { if (obj == null || !obj.activeSelf) { gameObjectById.Remove(obj.GetInstanceID()); gameObjectPositions.Remove(obj); gameObjectTypes.Remove(obj); continue; } var position = gameObjectPositionsChanged[obj]; gameObjectPositions[obj] = position; socketClientProxy.syncPosition( gameId, obj.name, gameObjectTypes[obj], obj.GetInstanceID(), true, position.x, position.y, position.z ); } gameObjectPositionsChanged.Clear(); }
void Start() { ship.name = "ship"; gameOver = false; restart = false; restartText.text = ""; gameOverText.text = ""; usernameInput.gameObject.SetActive(false); loginButton.gameObject.SetActive(false); score = 0; UpdateScore(); GameManager.getInstance().clear(); GameManager.getInstance().addGameObject(0, ship); var socketClientProxy = SocketClientProxy.getInstance(); if (socketClientProxy.firstLogin) { usernameInput.gameObject.SetActive(true); loginButton.gameObject.SetActive(true); } }
void Update() { var socketClientProxy = SocketClientProxy.getInstance(); if (!socketClientProxy.isConnected()) { return; } if (restart) { if (Input.GetKeyDown(KeyCode.R)) { SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); SocketClientProxy.getInstance().getGameId(); } } if (!gameOver) { GameManager.getInstance().syncGameObjectPositions(); } }
private void Update() { SocketClientProxy.getInstance().processEvents(); }
public void syncScore(long score) { SocketClientProxy.getInstance().syncScore(gameId, score); }
public void finishGame() { SocketClientProxy.getInstance().finishGame(gameId); }
public void startGame() { SocketClientProxy.getInstance().startGame(gameId); }
public void getGameId() { SocketClientProxy.getInstance().getGameId(); }
protected override void process(EzyApp app, EzyObject data) { SocketClientProxy.getInstance().emitStartGame(data); }
protected override void postHandle(EzyDisconnectionEvent evt) { SocketClientProxy.getInstance().emitDisconnected(); }