Exemplo n.º 1
0
    void Start()
    {
        gameObjectTracker = new GameObjectTracker();
        lastGuestInput    = new GuestInput();
        miceTracker       = new MiceTracker();

        Cursor.visible = false;

        stateFluxClient = GameObject.Find("StateFlux").GetComponent <StateFluxClient>();
        if (stateFluxClient == null)
        {
            DebugLog("Failed to connect with StateFluxClient");
            return;
        }
        stateFluxClient.AddListener(this);

        // lobby makes sure we are logged in before starting a game
        playerId = stateFluxClient.clientId;

        // when the game instance starts, LobbyManager receives a game instance start notification and saves these
        // we copy them here for convenience
        hostPlayer = LobbyManager.Instance.hostPlayer;
        players    = LobbyManager.Instance.players;
        thisPlayer = players[playerId];
        thatPlayer = players.Values.Where(p => p.Id != playerId).FirstOrDefault();

        CreateMousePointerGameObjects();

        if (stateFluxClient.isHosting)
        {
            var g = GameObject.Find("State_IsGuest");
            g.SetActive(false);
            var textMesh = g.GetComponentInChildren <TextMesh>();
            if (textMesh != null)
            {
                textMesh.color = StateFluxTypeConvert.Convert(thisPlayer.Color);
            }
            StartCoroutine(gameObjectTracker.SendStateAsHost());
        }
        else
        {
            var g = GameObject.Find("State_IsHost");
            g.SetActive(false);
            var textMesh = g.GetComponentInChildren <TextMesh>();
            if (textMesh != null)
            {
                textMesh.color = StateFluxTypeConvert.Convert(thisPlayer.Color);
            }
            StartCoroutine(nameof(SendInputAsGuest));
        }
    }