Example #1
0
 private void Awake()
 {
     if (_instance != null && _instance != this)
     {
         Debug.Log("StateFluxClient blocking double instantiate");
         Destroy(this.gameObject);
     }
     else
     {
         _instance = this;
         DontDestroyOnLoad(this.gameObject);
     }
 }
Example #2
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));
        }
    }
Example #3
0
    public IEnumerator Initialize()
    {
        yield return(new WaitForEndOfFrame());

        _players = new List <Player>();
        _games   = new List <GameInstance>();
        _said    = new List <ChatSaidMessage>();
        _lastUsernameSaveFile = Application.persistentDataPath + (Application.isEditor ? "/lastUsername-editor.txt" : "/lastUsername.txt");
        FindGameObjects();
        SceneManager.activeSceneChanged += ChangedActiveScene;

        StateFluxClient client = StateFluxClient.Instance;

        client.AddListener(this);
        StateFluxClient.Instance.Initialize();

        StartCoroutine(StateFluxClient.Instance.hasSavedSession ? ActivateLobbyPanel() : ActivateLoginPanel());
        Initialized = true;
    }
Example #4
0
        //private Queue<Change2d> changeQueue;

        public GameObjectTracker()
        {
            stateFluxClient = StateFluxClient.Instance;
            trackingMap     = new Dictionary <string, ChangeTracker>();
            //changeQueue = new Queue<Change2d>();
        }