Esempio n. 1
0
    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
        });
    }
Esempio n. 2
0
    // Use this for initialization
    void Start()
    {
        // Enable EzyLogger
        EzyLoggerFactory.setLoggerSupply(type => new UnityLogger(type));
        logger = EzyLoggerFactory.getLogger <SocketInitializer>();

        // Set up socket client
        var socketProxy = SocketProxy.getInstance();

        client = socketProxy.setup(host, port);
    }