private void Awake()
 {
     if (instance == null)                   // check to see if the instance has a reference
     {
         instance = this;                    // if not, give it a reference to this class
         DontDestroyOnLoad(this.gameObject); // and make this object persistant as new scenes are laoded
     }
     else // if there is already a reference then remove the extra manager from the scene
     {
         Destroy(this.gameObject);
     }
 }
Example #2
0
 private void Awake()
 {
     if (Instance == null)
     {
         Instance = this;
         DontDestroyOnLoad(gameObject);
     }
     else
     {
         Destroy(gameObject);
     }
 }
Example #3
0
    public void OnMessageReceived(RTPacket _packet)
    {
        Debug.Log("Message Received...\n" + _packet.Data.GetString(1));

        foreach (RTSessionInfo.RTPlayer player in GameSparksManager.Instance().GetSessionInfo().GetPlayerList())
        {
            if (player.peerId == _packet.Sender)
            {
                UpdateChatLog(player.displayName, _packet.Data.GetString(1), _packet.Data.GetString(2));
            }
        }
    }
Example #4
0
 private void Awake()
 {
     m_switchScene                           = GetComponent <SwitchScene>();
     m_gameSparksManager                     = GameObject.Find("GameSparks").GetComponent <GameSparksManager>();
     MatchFoundMessage.Listener             += OnMatchFound;
     MatchNotFoundMessage.Listener          += OnMatchNotFound;
     m_gameSparksManager.OnPlayerReady      += OnMatchReady;
     m_gameSparksManager.OnPacketReceived   += PacketReceived;
     m_gameSparksManager.OnPlayerConnect    += PlayerConnected;
     m_gameSparksManager.OnPlayerDisconnect += PlayerDisconnect;
     FindMatch();
 }
 void Awake()
 {
     if (instance == null)                   // check to see if the instance has a refrence
     {
         instance = this;                    // if not, give it a reference to this class...
         DontDestroyOnLoad(this.gameObject); // and make this object persistant as we load new scenes
     }
     else // if we already have a refrence then remove the extra manager from the scene
     {
         Destroy(this.gameObject);
     }
 }
Example #6
0
    //public CardLoader cardLoader;

    void Awake()
    {
        if (instance == null)
        {
            instance = this;
            DontDestroyOnLoad(this.gameObject);
        }
        else
        {
            Destroy(this.gameObject);
        }
    }
 void Awake()
 {
     if (instance == null) // check to see if the instance has a reference
     {
         instance = this; // if not, give it a reference to this class...
         DontDestroyOnLoad(this.gameObject); // and make this object persistent as we load new scenes
     }
     else // if we already have a reference then remove the extra manager from the scene
     {
         Destroy(this.gameObject);
     }
 }
Example #8
0
 private void Update()
 {
     if (GameSparksManager.getInstance().getPlayerID() == NextPlayer)
     {
         gameStatus.text         = "Your turn";
         playButton.interactable = true;
     }
     else
     {
         gameStatus.text         = "Waiting for other player to take turn";
         playButton.interactable = false;
     }
 }
    private bool LoggedIn()
    {
        bool loggedIn = false;
        GameSparksManager gameSparksManager = GameObject.Find("GameSparksManager").GetComponent <GameSparksManager>();
        //loggedIn = gameSparksManager.connected;
        GameSparksUserID gameSparksUserID = GameObject.Find("GameSparksUserID").GetComponent <GameSparksUserID>();

        if (gameSparksUserID.myUserID != "" && gameSparksManager.connected && !adminLogin)
        {
            loggedIn = true;
        }
        return(loggedIn);
    }
    void Start()
    {
        if (!GameSparksManager.IsTokenAvailable())
        {
            GameSparksManager.Instance.AnonymousLogin();
        }

        GameManager.SafeAddListener <FacebookProfilePictureMessage> (FacebookProfilePictureHandler);

        ChallengeManager.Instance.SetOnChallengeDetected(this);

        StartGame();
    }
 private void SetupListeners()
 {
     if (GameSession.GameMode == GameModeEnum.MULTIPLAYER)
     {
         eventManager.ListenToLostConnection(ActivateDisconnectPanel);
         eventManager.ListenToDisconnectReconnectionYes(ReconnectYes);
         eventManager.ListenToDisconnectReconnectionNo(ReconnectNo);
         eventManager.ListenToDisconnectAIEasy(AiSelectEasy);
         eventManager.ListenToDisconnectAIHard(AiSelectHard);
         GameSparksManager gsm = GameObject.Find("GameSparksManager").GetComponent <GameSparksManager>();
         gsm.connectedValueChanged.AddListener(AttemptReconnect);
         FindSceneGameObjects();
     }
 }
Example #12
0
    void Start()
    {
        UpdateUserStatus();
        GS.GameSparksAvailable += (isAvailable) =>
        {
            UpdateUserStatus();
        };

        // we add a custom listener to the on-click delegate of the login button so we don't need to create extra methods
        loginBttn.onClick.AddListener(() =>
        {
            GameSparksManager.Instance().AuthenticateUser(userNameInput.text, passwordInput.text, OnRegistration, OnAuthentication);
        });
    }
    private void Awake()
    {
        // For Flurry Android only:
        FlurryAndroid.SetLogEnabled(false);

        // For Flurry iOS only:
        FlurryIOS.SetDebugLogEnabled(false);

        IAnalytics service = Flurry.Flurry.Instance;

        service.StartSession(_iosApiKey, _androidApiKey);

        service.LogUserID(GameSparksManager.UserID());
    }
    // Login/Registration
    public void Login(string username, string password)
    {
        BlockLoginInput();
        GameSparksManager gsm = GameObject.Find("GameSparksManager").GetComponent <GameSparksManager>();

        gsm.CheckInternetConnection();

        GameSparksUserID.currentUsername = username;
        GameSparksUserID.currentPassword = password;
        AuthenticationRequest request = new AuthenticationRequest();

        request.SetUserName(username);
        request.SetPassword(password);
        request.Send(OnLoginSuccess, OnLoginError);
    }
Example #15
0
    void Start()
    {
        userId.text           = "No User Logged In...";
        connectionStatus.text = "No Connection...";

        GS.GameSparksAvailable += (isAvailable) => {
            if (isAvailable)
            {
                connectionStatus.text = "GameSparks Connected...";
            }
            else
            {
                connectionStatus.text = "GameSparks Disconnected...";
            }
        };

        playerListPanel.SetActive(false);
        matchmakingBttn.gameObject.SetActive(false);
        startGameBttn.gameObject.SetActive(false);
        cancelMatchmakingBttn.gameObject.SetActive(false);

        loginBttn.onClick.AddListener(() => {
            GameSparksManager.Instance().AuthenticateUser(userNameInput.text, passwordInput.text, OnRegistration, OnAuthentication);
        });

        matchmakingBttn.onClick.AddListener(() => {
            GameSparksManager.Instance().FindPlayers();
            playerList.text = "Searching For Players...";
            ToggleMatchmakingBttn();
        });

        cancelMatchmakingBttn.onClick.AddListener(() => {
            GameSparksManager.Instance().CancelFindPlayers();
            playerList.text = "Canceled search";
            ToggleMatchmakingBttn();
        });

        GameSparks.Api.Messages.MatchNotFoundMessage.Listener = (message) => {
            playerList.text = "No Match Found...";
        };

        GameSparks.Api.Messages.MatchFoundMessage.Listener += OnMatchFound;

        startGameBttn.onClick.AddListener(() => {
            GameSparksManager.Instance().StartNewRTSession(tempRTSessionInfo);
        });
    }
Example #16
0
    private void SendMessage()
    {
        UpdateChatLog("Me", messageInput.text, DateTime.Now.ToString());
        if (messageInput.text != string.Empty)
        {
            using (RTData data = RTData.Get()) {
                data.SetString(1, messageInput.text);
                data.SetString(2, DateTime.Now.ToString());
                messageInput.text = string.Empty;

                GameSparksManager.Instance().GetRTSession().SendData(1, GameSparks.RT.GameSparksRT.DeliveryIntent.RELIABLE, data);
            }
        }
        else
        {
            Debug.Log("No Chat Message To Send...");
        }
    }
Example #17
0
    // Use this for initialization
    void Start()
    {
        GameObject gameSparksObject = GameObject.Find(GameSparksManagerObjectName);

        if (!gameSparksObject)
        {
            Debug.LogError("GameSparks not in scene!");
            return;
        }

        m_gameSparksManager = gameSparksObject.GetComponent <GameSparksManager>();
        m_gameSparksManager.OnPacketReceived   += PacketReceived;
        m_gameSparksManager.OnPlayerDisconnect += OnPlayerDisconnected;

        m_spawnPoints = SpawnPointParent.GetComponentsInChildren <Transform>();

        InstantiatePlayers(m_gameSparksManager.CurrentMultiplayerSession);
    }
Example #18
0
 void takeTurn()
 {
     new LogChallengeEventRequest()
     .SetChallengeInstanceId(GameSparksManager.getInstance().getChallengeID())
     .SetEventKey("TT")
     .SetEventAttribute("GD", "set from c#: " + GameSparksManager.getInstance().getPlayerName())
     .Send((response) =>
     {
         if (response.HasErrors)
         {
             Debug.Log("Failed");
         }
         else
         {
             Debug.Log("Successful");
         }
     });
 }
Example #19
0
        private void Update()
        {
            if (!IsNetworkMatch || !GameSparksManager.Instance() || !IsMine)
            {
                return;
            }

            if (_previouslyPosition != transform.position)
            {
                _velocity           = transform.position - _previouslyPosition;
                _velocity          /= Time.deltaTime;
                _previouslyPosition = transform.position;

                SendNetworkPackage(new NetworkPackage()
                                   .SetVector3(transform.position)
                                   .SetVector3(_velocity)
                                   .SetInt(NetworkManager.Latency));
            }
        }
Example #20
0
    private void SetupAllPlayers(PlayerSpawnPoint[] spawnPoints)
    {
        int playerCount = 1;

        if (GameSparksManager.Instance())
        {
            playerCount = (int)GameSparksManager.Instance().GetSessionInfo().GetPlayerList().Count;
        }

        m_playerAvatarList = new Player[playerCount];

        Debug.Log("GC| Found " + m_playerAvatarList.Length + " Players...");

        // Loop through each player, and all spawn points, to assign each player to a spawn point based on the player's peerID
        for (int playerIndex = 0; playerIndex < playerCount; playerIndex++)
        {
            Debug.Log("GameController| playerIndex:" + playerIndex);
            for (int spawnerIndex = 0; spawnerIndex < spawnPoints.Length; spawnerIndex++)
            {
                Debug.Log("    GameController| Peer ID: " + GameSparksManager.Instance().GetSessionInfo().GetPlayerList()[playerIndex].peerID + " || SpawnID: " + spawnPoints[spawnerIndex].SpawnID);
                if (spawnPoints[spawnerIndex].SpawnID == GameSparksManager.Instance().GetSessionInfo().GetPlayerList()[playerIndex].peerID)
                {
                    GameObject newAvatar = Instantiate(PlayerAvatarPrefab, spawnPoints[spawnerIndex].gameObject.transform.position, spawnPoints[spawnerIndex].gameObject.transform.rotation) as GameObject;
                    newAvatar.name = GameSparksManager.Instance().GetSessionInfo().GetPlayerList()[playerIndex].peerID.ToString();

                    m_playerAvatarList[playerIndex] = newAvatar.GetComponent <Player>(); // add the new tank object to the corresponding reference in the list

                    if (GameSparksManager.Instance().GetSessionInfo().GetPlayerList()[playerIndex].peerID == GameSparksManager.Instance().GetRTSession().PeerId)
                    {
                        m_playerAvatarList[playerIndex].SetupPlayerAvatar(spawnPoints[spawnerIndex].gameObject.transform, true, Team.Blue); // @TODO - Setup HUD, setup player team to be read
                        ThirdPersonCamera.SetMainTarget(newAvatar.transform);
                    }
                    else
                    {
                        m_playerAvatarList[playerIndex].SetupPlayerAvatar(spawnPoints[spawnerIndex].gameObject.transform, false, Team.Red); // @TODO - Setup HUD, setup player team to be read
                    }

                    break;
                }
            }
        }
    }
Example #21
0
 void takeTurn()
 {
     new LogChallengeEventRequest()
     .SetChallengeInstanceId(game.getGame().getName())
     .SetEventKey("TT")
     .SetEventAttribute("GD", lastUploadId)
     .Send((response) =>
     {
         if (response.HasErrors)
         {
             Debug.Log("Failed");
         }
         else
         {
             Debug.Log("Successful");
             GameSparksManager.getInstance().setGameDataURL(lastUploadId);
             SceneManager.LoadScene(0);
         }
     });
 }
Example #22
0
    void Start()
    {
        readyButton.onClick.AddListener(() =>
        {
            OnReadyButton();
            SetPlayerReady(GameSparksManager.PeerId());
        });

        // Player list
        var players = GameSparksManager.Instance().GetSessionInfo().GetPlayerList();

        playerPanels = new List <Transform>();
        foreach (var player in players)
        {
            Transform playerPanel = Instantiate(PlayerPanelPrefab, playerList, false).transform;
            playerPanel.Find("DisplayName").GetComponent <Text>().text = player.displayName;

            playerPanels.Add(playerPanel);
        }
    }
 private void ReconnectYes()
 {
     // handle reconnection UI logic
     // SWITCH TO AI GAME
     //SearchForDisconnectPanel();
     FindSceneGameObjects();
     if (inGameBoard)
     {
         ActivateDisconnectionAiSelectPanel();
     }
     else if (inLobby)
     {
         attemptingReconnect = true;
         GameSparksManager gsm = GameObject.Find("GameSparksManager").GetComponent <GameSparksManager>();
         gsm.CheckInternetConnection();
     }
     inLobby        = false;
     inGameBoard    = false;
     disconnectLock = false;
 }
Example #24
0
    void Start()
    {
        GS.GameSparksAvailable = (isAvailable) =>
        {
            UpdateUserStatus();
        };

        findPanel.SetActive(true);
        searchingPanel.SetActive(false);
        foundPanel.SetActive(false);

        soloMatchmakingButton.onClick.AddListener(() =>
        {
            FindMatch("solo");
        });

        duoMatchmakingButton.onClick.AddListener(() =>
        {
            FindMatch("duo");
        });

        cancelButton.onClick.AddListener(() =>
        {
            findPanel.SetActive(true);
            searchingPanel.SetActive(false);

            GameSparksManager.Instance().CancelMatchmaking(currentMatchCode);
        });

        // this listener will update the text in the player-list field if no match was found
        GameSparks.Api.Messages.MatchNotFoundMessage.Listener = (message) =>
        {
            searchingPanel.SetActive(false);
            foundPanel.SetActive(true);
            matchDetails.text = "No Match Found...";
        };

        GameSparks.Api.Messages.MatchFoundMessage.Listener = OnMatchFound;

        UpdateUserStatus();
    }
Example #25
0
    public void StartMatch()
    {
        matchStartCountdown.gameObject.SetActive(false);
        inGameUi.SetActive(true);

        if (!IsHost)
        {
            return;
        }

        spawnPoints = GameObject.FindGameObjectsWithTag("SpawnPoint");

        for (int i = 0; i < playerList.Length; i++)
        {
            int        peerId   = GameSparksManager.Instance().GetSessionInfo().GetPlayerList()[i].peerId;
            Vector3    spawnPos = spawnPoints[i].transform.position;
            Quaternion spawnRot = spawnPoints[i].transform.rotation;

            playerList[i] = NetworkManager.NetworkInstantiate(playerPrefab, peerId, spawnPos, spawnRot).GetComponent <Player>();
        }
    }
Example #26
0
    // Use this for initialization
    void Start()
    {
        Debug.Log("names length: " + names.Count);
        inviteNameLabel.text = challenger + " VS " + challenged;

        if (GameSparksManager.getInstance().getPlayerID() == NextPlayer)
        {
            gameStatus.text         = "Your turn";
            playButton.interactable = true;
        }
        else
        {
            gameStatus.text         = "Waiting for other player to take turn";
            playButton.interactable = false;
        }

        new GetChallengeRequest()
        .SetChallengeInstanceId(challengeId)
        .Send((response) => {
            NextPlayer = response.Challenge.NextPlayer;
        });
    }
Example #27
0
        public IEnumerator SendUnitNewPos()
        {
            Debug.Log("Want to move" + _wantToMove);
            Debug.Log("gamesparksmanager>" + GameSparksManager.Instance().GameSparksRtUnity);

            if (_wantToMove)
            {
                using (RTData data = RTData.Get())
                {
                    data.SetVector2(1, actualUnit.Position);
                    // data.SetString(1, actualUnit.gameObject.name);

                    GameSparksManager.Instance().GameSparksRtUnity.SendData(1, GameSparksRT.DeliveryIntent.UNRELIABLE_SEQUENCED, data);
                    Debug.Log(actualUnit.name + "has moved");
                }
            }

            _wantToMove = false;
            yield return(new WaitForSeconds(0.1f));

            StartCoroutine(SendUnitNewPos());
        }
Example #28
0
    //This will be our message listener, this will be triggered when we successfully upload a file
    public void GetUploadMessage(GSMessage message)
    {
        new LogEventRequest_DeleteUploaded()
        .Set_Upload(GameSparksManager.getInstance().getGameDataURL())
        .Send((response) => {
            if (response.HasErrors)
            {
                Debug.Log(response.Errors.JSON);
            }
            else
            {
                Debug.Log("Deleted " + GameSparksManager.getInstance().getGameDataURL());
            }
        });
        new DismissMessageRequest()
        .SetMessageId(message.MessageId)
        .Send((response) => {
            if (response.HasErrors)
            {
                Debug.Log(response.Errors.JSON);
            }
            else
            {
                Debug.Log("Deleted message" + message.MessageId);
            }
        });

        //Every time we get a message
        Debug.Log(message.BaseData.GetString("uploadId"));
        //Save the last uploadId
        lastUploadId = message.BaseData.GetString("uploadId");

        new FileInfo(Application.persistentDataPath + "/Online/" + game.getGame().getName() + ".zip").Delete();
        new DirectoryInfo(Application.persistentDataPath + "/Online/" + game.getGame().getName()).Delete(true);

        takeTurn();
    }
    // Use this for initialization
    public void onClick()
    {
        Debug.Log("Button Clicked");

        new AuthenticationRequest()
        .SetPassword("foobar")
        .SetUserName("keer25")
        .Send((response) => {
            if (!response.HasErrors)
            {
                Debug.Log("Player Authenticated...");
                //script.uname = Uname.text;
                //script.playerId = response.UserId;
                GameSparksManager script = GameObject.Find("GameSparksManager").GetComponent <GameSparksManager>();
                script.uname             = "keer25";
                script.playerId          = "57729707808eb904a09d14c3";
                SceneManager.LoadScene("MatchFind");
            }
            else
            {
                Debug.Log("Error Authenticating Player...");
                error.text = "Please Enter valid details";
            }
        });

        /*
         * new FindMatchRequest()
         * .SetAction(null)
         * .SetMatchGroup(null)
         * .SetMatchShortCode("main")
         * .SetSkill(0)
         * .Send((response) => {
         *      //GSData scriptData = response.ScriptData;
         *      //Debug.Log(response);
         * });
         */
    }
Example #30
0
    public static GameObject NetworkInstantiate(GameObject original, int owner = 1, Vector3 position = new Vector3(), Quaternion rotation = new Quaternion())
    {
        // Copy
        GameObject copy = UnityEngine.Object.Instantiate(original);

        string objectId = NetworkObject.GenerateId();

        copy.name += " (" + objectId + ")";

        copy.transform.position = position;
        copy.transform.rotation = rotation;

        // Get all the NetworkObjects
        NetworkObject[] nos = copy.GetComponentsInChildren <NetworkObject>();

        // Set all the network ids
        for (uint i = 0; i < nos.Length; i++)
        {
            nos[i].SetOwner(owner);
            nos[i].SetId(objectId + "-" + i);
        }

        using (RTData data = RTData.Get())
        {
            // Set the prefab index
            data.SetInt(1, NetworkPrefabs.instance.prefabs.IndexOf(original));
            data.SetInt(2, owner);
            data.SetString(3, objectId);
            data.SetVector3(4, position);
            data.SetVector3(5, rotation.eulerAngles);

            // Send
            GameSparksManager.Instance().SendRTData(OpCodes.NetworkInstantiate, GameSparksRT.DeliveryIntent.RELIABLE, data);
        }

        return(copy);
    }
Example #31
0
    private void Start()
    {
        if (!GameSparksManager.IsTokenAvailable())
        {
            GameSparksManager.Instance.AnonymousLogin();
        }

        GameManager.SafeAddListener <FacebookProfilePictureMessage> (FacebookProfilePictureHandler);

        if (!_showInfo)
        {
            StartCoroutine(CoRoutines.DelayedCallback(0.35f, GetMonthlyScores));

            MontlyButton.GetComponent <ButtonHover>().selected  = true;
            TotalButton.GetComponent <ButtonHover>().selected   = false;
            RewardsButton.GetComponent <ButtonHover>().selected = false;
        }

        if (!Debug.isDebugBuild)
        {
            Flurry.Flurry.Instance.LogEvent("Leaderboard");
            Fabric.Answers.Answers.LogContentView("Leaderboard", "Dialog");
        }
    }