예제 #1
0
    private void FixedUpdate()
    {
        roomId = PlayerPrefs.GetInt("roomId");
        if (state == StateType.PENDING)
        {
            warningSign?.SetActive(true);
            /*Task.Run(()=> messageClient.Connect());*/
            Task.Run(() => ketFrameClient.Connect());
        }
        else
        {
            warningSign?.SetActive(false);
        }

        if (state == StateType.NON_INITIALIZED)
        {
            warningSign?.SetActive(true);
            TestModel generationCommand = ConfigureBasicModel();
            generationCommand.CommandType = 0;
            generationCommand.RoomId      = roomId; // temporary TODO: fixd it later
            messageClient.AskForUpdate(generationCommand);
        }

        if (state == StateType.INITIALIZED)
        {
            playerSpawnManager.Player.SyncModel();
            TestModel m = playerSpawnManager.Player.model;
            m.CommandType = 1;
            m.Name        = newName;
            m.Password    = password;
            m.Id          = id;
            messageClient.AskForUpdate(m);
        }

        if (state == StateType.DAMAGED)
        {
            state = StateType.INITIALIZED;
        }

        if (state == StateType.KILLED)
        {
            GameObject playerEntity = playerSpawnManager.Player.gameObj;
            playerEntity.GetComponent <PlayerHealth>().Death();
            TestModel damageDealer = playerEntity.GetComponent <Player>().GetLast();
            obManager.RegisterInfo(playerSpawnManager.Player.model);
            playerSpawnManager.Die();
            state = StateType.OB;
            ketFrameClient.AskForKeyFrame(new TestModel {
                CommandType = 6, Name = newName, Password = password, Id = id, EventTrigger = damageDealer.Id
            });
            Debug.Log("player was killed by: " + damageDealer.Id);
        }

        if (state == StateType.OB)
        {
            TestModel m = playerSpawnManager.Player.model;
            m.CommandType = 10;
            m.Name        = newName;
            m.Password    = password;
            m.Id          = id;
            messageClient.AskForUpdate(m); // get the other people's position

            if (!obManager.Spawned())
            {
                obManager.Spawn();
            }
        }

        if (state == StateType.EXIT)
        {
            TestModel m = new TestModel {
                CommandType = 11, Name = newName, Password = password, Id = id
            };
            ketFrameClient.AskForKeyFrame(m);
            state            = StateType.IDLE;
            Cursor.visible   = true;
            Cursor.lockState = CursorLockMode.None;
            SceneManager.LoadScene("LoginScene");
        }

        if (networkTimeout <= 0)
        {
            bool isSucceed = CheckNetWork();
            if (isSucceed)
            {
                networkTimeout = 6000;
            }
        }
        networkTimeout -= 1;
    }