예제 #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
        });
    }
예제 #2
0
        public static void Main(string[] args)
        {
            Thread.CurrentThread.Name = "main";

            new BindingExample().Run();
            new EntityExample().Run();
            new DateTimeExample().Run();

            EzyLoggerFactory.setLoggerLevel(EzyLoggerLevel.DEBUG);

            EzyClientConfig clientConfig = EzyClientConfig
                                           .builder()
                                           .clientName("freetanks")
                                           .zoneName("example")
                                           .build();
            EzyClients clients = EzyClients.getInstance();
            //EzyClient client = clients.newDefaultClient(clientConfig);
            EzyClient client = new EzyUTClient(clientConfig);

            clients.addClient(client);
            EzySetup setup = client.setup();

            setup.addEventHandler(EzyEventType.CONNECTION_SUCCESS, new EzyConnectionSuccessHandler());
            setup.addEventHandler(EzyEventType.CONNECTION_FAILURE, new EzyConnectionFailureHandler());
            setup.addEventHandler(EzyEventType.DISCONNECTION, new EzyDisconnectionHandler());
            setup.addDataHandler(EzyCommand.HANDSHAKE, new ExHandshakeEventHandler());
            setup.addDataHandler(EzyCommand.LOGIN, new ExLoginSuccessHandler());
            //setup.addDataHandler(EzyCommand.LOGIN_ERROR, new ExLoginErrorHandler());
            setup.addDataHandler(EzyCommand.APP_ACCESS, new ExAccessAppHandler());
            setup.addDataHandler(EzyCommand.UDP_HANDSHAKE, new UdpHandshakeHandler());

            EzyAppSetup appSetup = setup.setupApp("hello-world");

            //appSetup.addDataHandler(Commands.ERROR, new ErrorResponseHandler());
            appSetup.addDataHandler(Commands.ACCESS_LOBBY_ROOM, new AccessLobbyResponseHandler());
            appSetup.addDataHandler(Commands.ROOM_INFO, new RoomInfoResponseHandler());
            appSetup.addDataHandler(Commands.SYNC_POSITION, new SyncPositionHandler());

            client.connect("ws.tvd12.com", 3005);
            //client.connect("127.0.0.1", 3005);

            int time = 0;

            while (true)
            {
                Thread.Sleep(3);
                client.processEvents();
                time += 3;
                if (time > 5000)
                {
                    //client.disconnect(401);
                    time = 0;
                    //break;
                }
            }

            //mainEventsLoopTest();
        }
예제 #3
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);
    }
예제 #4
0
 public EzyTcpClient(EzyClientConfig config)
 {
     this.config             = config;
     this.name               = config.getClientName();
     this.status             = EzyConnectionStatus.NULL;
     this.status             = EzyConnectionStatus.NULL;
     this.pingManager        = new EzySimplePingManager(config.getPing());
     this.pingSchedule       = new EzyPingSchedule(this);
     this.handlerManager     = new EzySimpleHandlerManager(this);
     this.networkStatistics  = new EzySimpleStatistics();
     this.requestSerializer  = new EzySimpleRequestSerializer();
     this.settingUp          = new EzySimpleSetup(handlerManager);
     this.unloggableCommands = newUnloggableCommands();
     this.socketClient       = newSocketClient();
     this.logger             = EzyLoggerFactory.getLogger(GetType());
 }
예제 #5
0
 public EzyLoggable()
 {
     this.logger = EzyLoggerFactory.getLogger(GetType());
 }