Beispiel #1
0
    void HideResult(bool returnToMenu)
    {
        Sequence      seq = DOTween.Sequence();
        RectTransform rt;

        rt = objPepsiPlayer.GetComponent <RectTransform> ();
        seq.Append(rt.DOAnchorPosX(1000f, 0.2f).SetEase(Ease.InBack));

        rt = objColaPlayer.GetComponent <RectTransform> ();
        seq.Join(rt.DOAnchorPosX(-1000f, 0.2f).SetEase(Ease.InBack));

        rt = txtResult.GetComponent <RectTransform> ();
        seq.Join(rt.DOScale(Vector2.zero, 0.2f).SetEase(Ease.InBack));

        rt = btnPlayAgain.GetComponent <RectTransform> ();
        seq.Join(rt.DOAnchorPosY(-1150, 0.2f).SetEase(Ease.InBack));

        rt = btnHomeResult.GetComponent <RectTransform> ();
        seq.Join(rt.DOAnchorPosY(-1150, 0.2f).SetEase(Ease.InBack));

        seq.Append(pnlResult.GetComponent <Image>().DOFade(0f, 0.5f));

        seq.OnComplete(() => {
            pnlResult.SetActive(false);

            if (returnToMenu)
            {
                ManagersController.Message(Message.Create(this, MessageData.EVENT_SHOW_MENU));
            }
            else
            {
                ManagersController.Message(Message.Create(this, MessageData.EVENT_PLAY_AGAIN));
            }
        });
    }
    private void TeamScoreCallback(LogEventResponse response)
    {
        if (response.HasErrors)
        {
            Debug.Log("GameSparksManager: Error: " + response.Errors.JSON);
        }
        else
        {
            GSData dataCola  = response.ScriptData.GetGSData("ColaData");
            GSData dataPepsi = response.ScriptData.GetGSData("PepsiData");

            int counterCola = 0;
            if (dataCola.ContainsKey("count"))
            {
                counterCola = dataCola.GetInt("count").Value;
            }

            int counterPepsi = 0;
            if (dataPepsi.ContainsKey("count"))
            {
                counterPepsi = dataPepsi.GetInt("count").Value;
            }

            ManagersController.Message(Message.Create(this, MessageData.EVENT_GET_TEAMS_SCORE, counterCola, counterPepsi));
        }
    }
    void MatchFound(MatchFoundMessage message)
    {
        session_info = new RTSessionInfo(message);
        ManagersController.Message(Message.Create(this, MessageData.EVENT_SET_ONLINE_PLAYERS, session_info.players));

        #region Create Session

        session = this.gameObject.GetComponent <GameSparksRTUnity> ();

        GSRequestData mockedResponse = new GSRequestData()
                                       .AddNumber("port", session_info.PortID)
                                       .AddString("host", session_info.HostURL)
                                       .AddString("accessToken", session_info.AccessToken);
        FindMatchResponse response = new FindMatchResponse(mockedResponse);

        session.Configure(
            response,
            peerID => OnPlayerConnected(peerID),
            peerID => OnPlayerDisconnected(peerID),
            ready => OnRTReady(ready),
            packet => OnPacketRecieved(packet)
            );

        session.Connect();

        #endregion
    }
Beispiel #4
0
    void SetResult(bool isPlayerWon, Player player, Player enemy)
    {
        if (isPlayerWon)
        {
            txtResult.text = "ВЫ ВЫЙГРАЛИ!";
            ManagersController.Message(Message.Create(this, MessageData.EVENT_SUBMIT_WINNED_TEAM));
        }
        else
        {
            txtResult.text = "ВЫ ПРОИГРАЛИ!";
        }

        Player colaPlayer  = null;
        Player pepsiPlayer = null;

        if (player.team == Team.Cola)
        {
            colaPlayer  = player;
            pepsiPlayer = enemy;
        }
        else
        {
            colaPlayer  = enemy;
            pepsiPlayer = player;
        }

        objColaPlayer.transform.Find("imgCrown").gameObject.SetActive(isPlayerWon && player.team == Team.Cola);
        objPepsiPlayer.transform.Find("imgCrown").gameObject.SetActive(isPlayerWon && player.team == Team.Pepsi);

        objColaPlayer.transform.Find("txtScore").GetComponent <Text> ().text  = colaPlayer.currentScore.ToString();
        objPepsiPlayer.transform.Find("txtScore").GetComponent <Text> ().text = pepsiPlayer.currentScore.ToString();

        objColaPlayer.transform.Find("txtName").GetComponent <Text> ().text  = colaPlayer.displayName;
        objPepsiPlayer.transform.Find("txtName").GetComponent <Text> ().text = pepsiPlayer.displayName;
    }
 private void WeeklyLeaderboardCallback(LeaderboardDataResponse response)
 {
     if (response.HasErrors)
     {
         Debug.Log("GameSparksManager: Error: " + response.Errors.JSON);
     }
     else
     {
         List <GlobalScore> weekly_leaderboard = new List <GlobalScore> ();
         foreach (LeaderboardDataResponse._LeaderboardData data in response.Data)
         {
             string displayName = data.UserName;
             string score       = data.JSONData ["SCORE"].ToString();
             string team        = "Cola";
             if (data.JSONData.ContainsKey("TEAM"))
             {
                 team = data.JSONData ["TEAM"].ToString();
             }
             weekly_leaderboard.Add(new GlobalScore(displayName, score, team));
         }
         if (weekly_leaderboard.Count != 0)
         {
             ManagersController.Message(Message.Create(this, MessageData.EVENT_LEADERBOARD_DAY, weekly_leaderboard));
         }
     }
 }
Beispiel #6
0
 void OnEnable()
 {
     btnPause.onClick.AddListener(() => {
         Time.timeScale = 0f;
         ManagersController.Message(Message.Create(this, MessageData.EVENT_PAUSE_GAME));
     });
 }
Beispiel #7
0
 public void SetPepsiScore(int score)
 {
     txtScorePepsi.text = score.ToString();
     if (score >= 50 && GameManager.Instance.currentPlayer.currentID == 2)
     {
         bool isWon = PlayerManager.Instance.player.team == Team.Pepsi ? true : false;
         ManagersController.Message(Message.Create(this, MessageData.EVENT_FINISH_GAME, isWon));
     }
 }
    void PacketRecieved_Ring(RTPacket rt_packet)
    {
        OnlinePacket packet = new OnlinePacket(
            1,
            new Vector3(rt_packet.Data.GetVector3(1).Value.x, rt_packet.Data.GetVector3(1).Value.y, rt_packet.Data.GetVector3(1).Value.z),
            new Vector3(rt_packet.Data.GetVector3(2).Value.x, rt_packet.Data.GetVector3(2).Value.y, rt_packet.Data.GetVector3(2).Value.z),
            new Vector3(rt_packet.Data.GetVector3(3).Value.x, rt_packet.Data.GetVector3(3).Value.y, rt_packet.Data.GetVector3(3).Value.z)
            );

        ManagersController.Message(Message.Create(this, MessageData.EVENT_RECIEVE_PACKET, packet));
    }
    void PacketRecieved_Field(RTPacket rt_packet)
    {
        OnlinePacket packet = new OnlinePacket(
            2,
            new Score((int)rt_packet.Data.GetInt(1), (int)rt_packet.Data.GetInt(2)),
            (string)rt_packet.Data.GetString(3),
            (string)rt_packet.Data.GetString(4)
            );

        ManagersController.Message(Message.Create(this, MessageData.EVENT_RECIEVE_PACKET, packet));
    }
Beispiel #10
0
 public void SwitchRating()
 {
     if (!pnlRatings.activeSelf)
     {
         ManagersController.Message(Message.Create(this, MessageData.EVENT_LEADERBOARD_UPDATE));
         ShowRatings();
     }
     else
     {
         HideRatings();
     }
 }
    IEnumerator LoadProfileTexture()
    {
        // Start a download of the given URL
        WWW www = new WWW(_userInfo.PictureURL);

        // Wait for download to complete
        yield return(www);

        UserInfo.Picture = www.texture;

        ManagersController.Message(Message.Create(this, MessageData.EVENT_CONNECT_SERVER, GetAccessToken()));
        OnFacebookProfileLoadResult(true);
    }
Beispiel #12
0
 void SaveResult(Player player)
 {
     if (FacebookManager.Instance.IsLoggedIn())
     {
         ManagersController.Message(Message.Create(this, MessageData.EVENT_SUBMIT_SCORE, player.currentScore));
         PlayerPrefs.SetInt("Score", PlayerPrefs.GetInt("Score", 0) + player.currentScore);
     }
     else
     {
         registration_required_player = player;
         AnimatePopupOpen(pnlSaveResult, 2.5f);
     }
 }
Beispiel #13
0
 public void SendRingShootInfo(Vector3 velocity)
 {
     if (GameManager.Instance.currentMode == GameMode.MultiplayerOnline)
     {
         OnlinePacket packet = new OnlinePacket(
             1,
             transform.position,
             transform.rotation.eulerAngles,
             velocity
             );
         ManagersController.Message(Message.Create(this, MessageData.EVENT_SEND_PACKET, packet));
     }
 }
Beispiel #14
0
    //CALLBACKS

    public void OnLoginResult(bool isSucceeded)
    {
        SwitchLoading();
        SwitchRegistration();

        if (isSucceeded)
        {
            ManagersController.Message(Message.Create(this, MessageData.EVENT_SHOW_PROFILE));
        }
        else
        {
            string notification = "РЕГИСТРАЦИЯ НЕ УДАЛАСЬ";
            SwitchNotification(notification);
        }
    }
Beispiel #15
0
    public void StartGame(String team)
    {
        Team _team = Team.Cola;

        if (team == "Cola")
        {
            _team = Team.Cola;
        }
        if (team == "Pepsi")
        {
            _team = Team.Pepsi;
        }

        mode_data.teamPlayer = _team;
        mode_data.teamEnemy  = _team == Team.Cola ? Team.Pepsi : Team.Cola;

        switch (mode_data.mode)
        {
        case GameMode.Practice:
            ManagersController.Message(Message.Create(this, MessageData.EVENT_START_GAME, mode_data));
            if (imgBG.color.a > 0f)
            {
                HideMenu();
            }
            break;

        case GameMode.MultiplayerOnline:
            ManagersController.Message(Message.Create(this, MessageData.EVENT_FIND_MATCH, _team));
            break;

        case GameMode.MultiPlayer:
            ManagersController.Message(Message.Create(this, MessageData.EVENT_START_GAME, mode_data));
            if (imgBG.color.a > 0f)
            {
                HideMenu();
            }
            break;

        case GameMode.SinglePlayer:
            ManagersController.Message(Message.Create(this, MessageData.EVENT_START_GAME, mode_data));
            if (imgBG.color.a > 0f)
            {
                HideMenu();
            }
            break;
        }
    }
Beispiel #16
0
    public void OnMatchResult(bool isMathced)
    {
        SwitchLoading();

        if (isMathced)
        {
            ManagersController.Message(Message.Create(this, MessageData.EVENT_START_GAME, mode_data));
            if (imgBG.color.a > 0f)
            {
                HideMenu();
            }
        }
        else
        {
            string notification = "ПРОТИВНИК НЕ НАЙДЕН\nПОПЫТАЙТЕСЬ ПОЗЖЕ";
            SwitchNotification(notification);
        }
    }
Beispiel #17
0
    void SendFieldStateInfo(Score score_info)
    {
        string cola_state = "";

        foreach (bool b in cola_bottles_state)
        {
            if (b)
            {
                cola_state += "1";
            }
            else
            {
                cola_state += "0";
            }
            cola_state += ",";
        }

        string pepsi_state = "";

        foreach (bool b in pepsi_bottles_state)
        {
            if (b)
            {
                pepsi_state += "1";
            }
            else
            {
                pepsi_state += "0";
            }
            pepsi_state += ",";
        }

        if (GameManager.Instance.currentMode == GameMode.MultiplayerOnline)
        {
            OnlinePacket packet = new OnlinePacket(
                2,
                score_info,
                cola_state,
                pepsi_state
                );
            ManagersController.Message(Message.Create(this, MessageData.EVENT_SEND_PACKET, packet));
        }
    }
Beispiel #18
0
    void OnEnable()
    {
        //Single Mode
        btnSinglePlayer.onClick.AddListener(() => OnClick(btnSinglePlayer.GetInstanceID()));
        btnSingleEasy.onClick.AddListener(() => OnClick(btnSingleEasy.GetInstanceID()));
        btnSingleMedium.onClick.AddListener(() => OnClick(btnSingleMedium.GetInstanceID()));
        btnSingleHard.onClick.AddListener(() => OnClick(btnSingleHard.GetInstanceID()));
        btnBack.onClick.AddListener(() => OnClick(btnBack.GetInstanceID()));

        //Practice
        btnPractice.onClick.AddListener(() => OnClick(btnPractice.GetInstanceID()));

        //MultiOff Mode
        btnMultiPlayerOff.onClick.AddListener(() => OnClick(btnMultiPlayerOff.GetInstanceID()));

        //MultiOn Mode
        btnMultiPlayerOn.onClick.AddListener(() => OnClick(btnMultiPlayerOn.GetInstanceID()));

        //Exit Game Popup
        btnExitGame.onClick.AddListener(() => OnClick(btnExitGame.GetInstanceID()));
        btnResume.onClick.AddListener(() => OnClick(btnResume.GetInstanceID()));

        //Team
        btnColaTeam.onClick.AddListener(() => SetPlayerTeam("Cola"));
        btnPepsiTeam.onClick.AddListener(() => SetPlayerTeam("Pepsi"));
        btnCloseChooseTeam.onClick.AddListener(() => SwitchTeam());

        //Profile and Registration
        btnProfile.onClick.AddListener(() => ManagersController.Message(Message.Create(this, MessageData.EVENT_SHOW_PROFILE)));
        btnCloseProfile.onClick.AddListener(() => SwitchProfile());
        btnCloseRegistration.onClick.AddListener(() => SwitchRegistration());

        //Social
        btnLogin.onClick.AddListener(() => OnClick(btnLogin.GetInstanceID()));
        btnLogout.onClick.AddListener(() => OnClick(btnLogout.GetInstanceID()));

        //Notification
        btnCloseNotification.onClick.AddListener(() => SwitchNotification(""));

        //Leaderboards
        btnRatings.onClick.AddListener(() => OnClick(btnRatings.GetInstanceID()));
    }
Beispiel #19
0
    public void TimeIsOut()
    {
        if (currentMode == GameMode.Practice)
        {
            NextPlayer();
            return;
        }

        if (currentPlayer.team == Team.Cola)
        {
            numPassedShootsCola++;

            if (numPassedShootsCola == 2)
            {
                bool isWon = PlayerManager.Instance.player.team == Team.Cola ? false : true;
                ManagersController.Message(Message.Create(this, MessageData.EVENT_FINISH_GAME, isWon));
            }
            else
            {
                NextPlayer();
            }
        }
        else
        {
            numPassedShootsPepsi++;

            if (numPassedShootsPepsi == 2)
            {
                bool isWon = PlayerManager.Instance.player.team == Team.Pepsi ? false : true;
                ManagersController.Message(Message.Create(this, MessageData.EVENT_FINISH_GAME, isWon));
            }
            else
            {
                NextPlayer();
            }
        }
    }
Beispiel #20
0
    void OnClick(int instanceID)
    {
        if (instanceID == btnPractice.GetInstanceID())
        {
            mode_data.mode     = GameMode.Practice;
            mode_data.sub_mode = GameSubMode.None;
            StartGame(PlayerPrefs.GetString("Team", "Cola"));
        }
        else if (instanceID == btnSinglePlayer.GetInstanceID())
        {
            mode_data.mode = GameMode.SinglePlayer;
            Invoke("HideMainMenu", 0.35f);
            Invoke("ShowSingleModeMenu", 0.75f);
        }
        else if (instanceID == btnMultiPlayerOff.GetInstanceID())
        {
            mode_data.mode     = GameMode.MultiPlayer;
            mode_data.sub_mode = GameSubMode.None;
            StartGame(PlayerPrefs.GetString("Team", "Cola"));
        }
        else if (instanceID == btnMultiPlayerOn.GetInstanceID())
        {
            if (IsInternetAccessible())
            {
                mode_data.mode     = GameMode.MultiplayerOnline;
                mode_data.sub_mode = GameSubMode.None;
                StartGame(PlayerPrefs.GetString("Team", "Cola"));
            }
        }
        else if (instanceID == btnSingleEasy.GetInstanceID())
        {
            mode_data.sub_mode = GameSubMode.Easy;
            StartGame(PlayerPrefs.GetString("Team", "Cola"));
        }
        else if (instanceID == btnSingleMedium.GetInstanceID())
        {
            mode_data.sub_mode = GameSubMode.Medium;
            StartGame(PlayerPrefs.GetString("Team", "Cola"));
        }
        else if (instanceID == btnSingleHard.GetInstanceID())
        {
            mode_data.sub_mode = GameSubMode.Hard;
            StartGame(PlayerPrefs.GetString("Team", "Cola"));
        }
        else if (instanceID == btnBack.GetInstanceID())
        {
            Invoke("HideSingleModeMenu", 0.35f);
            Invoke("ShowMainMenu", 0.75f);
        }
        else if (instanceID == btnExitGame.GetInstanceID())
        {
            if (GameManager.Instance.currentMode == GameMode.MultiplayerOnline)
            {
                ManagersController.Message(Message.Create(this, MessageData.EVENT_TERMINATE_ONLINE_GAME));
            }

            GameManager.Instance.FinishGame();

            Time.timeScale = 1f;
            AnimatePopupClose(pnlExitGame);
            ShowMenu();
        }
        else if (instanceID == btnResume.GetInstanceID())
        {
            Time.timeScale = 1f;
            AnimatePopupClose(pnlExitGame);
        }
        else if (instanceID == btnLogin.GetInstanceID())
        {
            if (IsInternetAccessible())
            {
                SwitchLoading("ИДЕТ ЗАГРУЗКА ДАННЫХ...");
                ManagersController.Message(Message.Create(this, MessageData.EVENT_LOGIN));
            }
        }
        else if (instanceID == btnLogout.GetInstanceID())
        {
            if (IsInternetAccessible())
            {
                SwitchProfile();
                ManagersController.Message(Message.Create(this, MessageData.EVENT_LOGOUT));
            }
        }
        else if (instanceID == btnRatings.GetInstanceID())
        {
            if (IsInternetAccessible())
            {
                ManagersController.Message(Message.Create(this, MessageData.EVENT_SWITCH_LEADERBOARD));
            }
        }
    }
 void TerminateSession()
 {
     EndSession();
     ManagersController.Message(Message.Create(this, MessageData.EVENT_ONLINE_GAME_TERMINATED));
 }
Beispiel #22
0
 void Start()
 {
     ManagersController.Message(Message.Create(this, MessageData.EVENT_LEADERBOARD_UPDATE));
 }
Beispiel #23
0
 void RegistratePlayer()
 {
     ManagersController.Message(Message.Create(this, MessageData.EVENT_LOGIN2));
     AnimatePopupClose(pnlSaveResult);
 }