1.33 sources
This commit is contained in:
9 files changed
+1943
No files matched your search
+521
@@ -0,0 +1,521 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Text.RegularExpressions;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class Account : MonoBehaviour
|
||||
{
|
||||
public GameObject registerPanel;
|
||||
|
||||
public Button registerPanelLoginBtn;
|
||||
|
||||
public GameObject loginPanel;
|
||||
|
||||
public Button loginPanelRegisterBtn;
|
||||
|
||||
public GameObject accountPanel;
|
||||
|
||||
public Button backButton;
|
||||
|
||||
public Button accountPanelSyncButton;
|
||||
|
||||
public Button accountPanelLogoutButton;
|
||||
|
||||
public TMP_InputField registerPanelUsernameForm;
|
||||
|
||||
public TMP_InputField registerPanelEmailForm;
|
||||
|
||||
public TMP_InputField registerPanelEmailConfirmForm;
|
||||
|
||||
public TMP_InputField registerPanelPasswordForm;
|
||||
|
||||
public TMP_InputField registerPanelPasswordConfirmForm;
|
||||
|
||||
public TMP_InputField loginPanelUsernameForm;
|
||||
|
||||
public TMP_InputField loginPanelPasswordForm;
|
||||
|
||||
public TMP_Text registerPanelStatusText;
|
||||
|
||||
public TMP_Text loginPanelStatusText;
|
||||
|
||||
public TMP_Text accountPanelStatusText;
|
||||
|
||||
public GameObject changeUsernamePanel;
|
||||
|
||||
public TMP_Text changeUsernamePanelStatusText;
|
||||
|
||||
public Button submitButton;
|
||||
|
||||
public Button changeUsernameButton;
|
||||
|
||||
public Button changePasswordButton;
|
||||
|
||||
public GameObject changePasswordPanel;
|
||||
|
||||
public TMP_Text changePasswordStatusText;
|
||||
|
||||
public TMP_Text changeUsernameStatusText;
|
||||
|
||||
public TMP_InputField changeUsernameCurrentForm;
|
||||
|
||||
public TMP_InputField changeUsernameNewForm;
|
||||
|
||||
public TMP_InputField changeUsernamePasswordForm;
|
||||
|
||||
public TMP_InputField changePasswordCurrentUsernameForm;
|
||||
|
||||
public TMP_InputField changePasswordCurrentForm;
|
||||
|
||||
public TMP_InputField changePasswordNewForm;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (PlayerPrefs.HasKey("gameSession") && PlayerPrefs.HasKey("userID"))
|
||||
{
|
||||
SwitchScene(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
SwitchScene(1);
|
||||
}
|
||||
backButton.onClick.AddListener(BackToMenu);
|
||||
registerPanelLoginBtn.onClick.AddListener(delegate
|
||||
{
|
||||
SwitchScene(2);
|
||||
});
|
||||
submitButton.onClick.AddListener(ButtonSubmit);
|
||||
loginPanelRegisterBtn.onClick.AddListener(delegate
|
||||
{
|
||||
SwitchScene(1);
|
||||
});
|
||||
accountPanelSyncButton.onClick.AddListener(StartSyncAccount);
|
||||
accountPanelLogoutButton.onClick.AddListener(LogoutAccount);
|
||||
changeUsernameButton.onClick.AddListener(delegate
|
||||
{
|
||||
SwitchScene(3);
|
||||
});
|
||||
changePasswordButton.onClick.AddListener(delegate
|
||||
{
|
||||
SwitchScene(4);
|
||||
});
|
||||
}
|
||||
|
||||
private void BackToMenu()
|
||||
{
|
||||
if (GetCurrentScene() == 3 || GetCurrentScene() == 4)
|
||||
{
|
||||
SwitchScene(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
SceneManager.LoadScene("Menu");
|
||||
}
|
||||
}
|
||||
|
||||
private int GetCurrentScene()
|
||||
{
|
||||
if (accountPanel.activeSelf)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (registerPanel.activeSelf)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (loginPanel.activeSelf)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
if (changeUsernamePanel.activeSelf)
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
if (changePasswordPanel.activeSelf)
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private void ButtonSubmit()
|
||||
{
|
||||
if (GetCurrentScene() == 1)
|
||||
{
|
||||
StartCoroutine(SubmitRegister());
|
||||
}
|
||||
else if (GetCurrentScene() == 2)
|
||||
{
|
||||
StartCoroutine(SubmitLogin());
|
||||
}
|
||||
else if (GetCurrentScene() == 3)
|
||||
{
|
||||
StartCoroutine(ChangeUsername());
|
||||
}
|
||||
else if (GetCurrentScene() == 4)
|
||||
{
|
||||
StartCoroutine(ChangePassword());
|
||||
}
|
||||
}
|
||||
|
||||
private void SwitchScene(int scene)
|
||||
{
|
||||
ClearForms();
|
||||
backButton.transform.localPosition = new Vector3(0f, -165f, 0f);
|
||||
backButton.GetComponent<RectTransform>().sizeDelta = new Vector2(90f, 30f);
|
||||
submitButton.transform.localPosition = new Vector3(110f, -165f, 0f);
|
||||
submitButton.gameObject.SetActive(value: true);
|
||||
accountPanel.SetActive(value: false);
|
||||
registerPanel.SetActive(value: false);
|
||||
loginPanel.SetActive(value: false);
|
||||
changeUsernamePanel.SetActive(value: false);
|
||||
changePasswordPanel.SetActive(value: false);
|
||||
registerPanelStatusText.text = "";
|
||||
loginPanelStatusText.text = "";
|
||||
accountPanelStatusText.text = "";
|
||||
changeUsernamePanelStatusText.text = "";
|
||||
changePasswordStatusText.text = "";
|
||||
changeUsernameStatusText.text = "";
|
||||
registerPanelStatusText.color = Color.white;
|
||||
loginPanelStatusText.color = Color.white;
|
||||
accountPanelStatusText.color = Color.white;
|
||||
changeUsernamePanelStatusText.color = Color.white;
|
||||
changePasswordStatusText.color = Color.white;
|
||||
changeUsernameStatusText.color = Color.white;
|
||||
accountPanelSyncButton.interactable = true;
|
||||
switch (scene)
|
||||
{
|
||||
case 0:
|
||||
accountPanel.SetActive(value: true);
|
||||
submitButton.gameObject.SetActive(value: false);
|
||||
backButton.transform.localPosition = new Vector3(-60f, -165f, 0f);
|
||||
backButton.GetComponent<RectTransform>().sizeDelta = new Vector2(110f, 30f);
|
||||
break;
|
||||
case 1:
|
||||
registerPanel.SetActive(value: true);
|
||||
break;
|
||||
case 2:
|
||||
loginPanel.SetActive(value: true);
|
||||
break;
|
||||
case 3:
|
||||
changeUsernamePanel.SetActive(value: true);
|
||||
backButton.transform.localPosition = new Vector3(-60f, -165f, 0f);
|
||||
backButton.GetComponent<RectTransform>().sizeDelta = new Vector2(110f, 30f);
|
||||
submitButton.transform.localPosition = new Vector3(60f, -165f, 0f);
|
||||
break;
|
||||
case 4:
|
||||
changePasswordPanel.SetActive(value: true);
|
||||
backButton.transform.localPosition = new Vector3(-60f, -165f, 0f);
|
||||
backButton.GetComponent<RectTransform>().sizeDelta = new Vector2(110f, 30f);
|
||||
submitButton.transform.localPosition = new Vector3(60f, -165f, 0f);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator SubmitRegister()
|
||||
{
|
||||
if (!registerPanelEmailForm.text.Trim().Equals(registerPanelEmailConfirmForm.text.Trim(), StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
UpdateStatusText(registerPanelStatusText, "Email doesn't match", Color.red);
|
||||
yield break;
|
||||
}
|
||||
if (!registerPanelPasswordForm.text.Trim().Equals(registerPanelPasswordConfirmForm.text.Trim(), StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
UpdateStatusText(registerPanelStatusText, "Password doesn't match", Color.red);
|
||||
yield break;
|
||||
}
|
||||
if (!Regex.IsMatch(registerPanelUsernameForm.text, "^[a-zA-Z0-9]{3,16}$"))
|
||||
{
|
||||
UpdateStatusText(registerPanelStatusText, "Username must be 3-16 characters, letters and numbers only", Color.red);
|
||||
yield break;
|
||||
}
|
||||
WWWForm wWWForm = new WWWForm();
|
||||
wWWForm.AddField("username", registerPanelUsernameForm.text);
|
||||
wWWForm.AddField("email", registerPanelEmailForm.text);
|
||||
wWWForm.AddField("password", registerPanelPasswordForm.text);
|
||||
using UnityWebRequest request = UnityWebRequest.Post("https://berrydash.lncvrt.xyz/database/registerAccount.php", wWWForm);
|
||||
request.SetRequestHeader("User-Agent", "BerryDashClient");
|
||||
request.SetRequestHeader("ClientVersion", "1.33");
|
||||
yield return request.SendWebRequest();
|
||||
if (request.result != UnityWebRequest.Result.Success)
|
||||
{
|
||||
Debug.LogError("HTTP Error: " + request.error);
|
||||
UpdateStatusText(registerPanelStatusText, "Failed to make HTTP request", Color.red);
|
||||
yield break;
|
||||
}
|
||||
string text = request.downloadHandler.text;
|
||||
Debug.Log(text);
|
||||
switch (text)
|
||||
{
|
||||
case "1":
|
||||
SwitchScene(2);
|
||||
break;
|
||||
case "-1":
|
||||
UpdateStatusText(registerPanelStatusText, "Internal login server error", Color.red);
|
||||
break;
|
||||
case "-2":
|
||||
UpdateStatusText(registerPanelStatusText, "Incomplete form data", Color.red);
|
||||
break;
|
||||
case "-3":
|
||||
UpdateStatusText(registerPanelStatusText, "Username not valid", Color.red);
|
||||
break;
|
||||
case "-4":
|
||||
UpdateStatusText(registerPanelStatusText, "Email not valid", Color.red);
|
||||
break;
|
||||
case "-5":
|
||||
UpdateStatusText(registerPanelStatusText, "Password must have 8 characters, one number and one letter", Color.red);
|
||||
break;
|
||||
case "-6":
|
||||
UpdateStatusText(registerPanelStatusText, "Username too long or short", Color.red);
|
||||
break;
|
||||
case "-7":
|
||||
UpdateStatusText(registerPanelStatusText, "Username must be 3-16 characters, letters and numbers only", Color.red);
|
||||
break;
|
||||
case "-8":
|
||||
UpdateStatusText(registerPanelStatusText, "Username or email already exists", Color.red);
|
||||
break;
|
||||
default:
|
||||
UpdateStatusText(registerPanelStatusText, "Unknown server response \"" + text + "\"", Color.red);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator SubmitLogin()
|
||||
{
|
||||
WWWForm wWWForm = new WWWForm();
|
||||
wWWForm.AddField("username", loginPanelUsernameForm.text);
|
||||
wWWForm.AddField("password", loginPanelPasswordForm.text);
|
||||
wWWForm.AddField("currentHighScore", PlayerPrefs.GetInt("HighScore", 0).ToString());
|
||||
using UnityWebRequest request = UnityWebRequest.Post("https://berrydash.lncvrt.xyz/database/loginAccount.php", wWWForm);
|
||||
request.SetRequestHeader("User-Agent", "BerryDashClient");
|
||||
request.SetRequestHeader("ClientVersion", "1.33");
|
||||
yield return request.SendWebRequest();
|
||||
if (request.result != UnityWebRequest.Result.Success)
|
||||
{
|
||||
Debug.LogError("HTTP Error: " + request.error);
|
||||
UpdateStatusText(loginPanelStatusText, "Failed to make HTTP request", Color.red);
|
||||
yield break;
|
||||
}
|
||||
string text = request.downloadHandler.text;
|
||||
Debug.Log(text);
|
||||
if (!(text == "-1"))
|
||||
{
|
||||
if (text == "-2")
|
||||
{
|
||||
UpdateStatusText(loginPanelStatusText, "Incorrect username or password", Color.red);
|
||||
}
|
||||
else if (Regex.IsMatch(text, "^[a-zA-Z0-9]{512}:\\d+:\\d+:\\d+:\\d+$"))
|
||||
{
|
||||
string[] array = text.Split(':');
|
||||
string value = array[0];
|
||||
int value2 = int.Parse(array[1]);
|
||||
int value3 = int.Parse(array[2]);
|
||||
int value4 = int.Parse(array[3]);
|
||||
int value5 = int.Parse(array[4]);
|
||||
PlayerPrefs.SetString("gameSession", value);
|
||||
PlayerPrefs.SetInt("userID", value2);
|
||||
PlayerPrefs.SetInt("HighScore", value3);
|
||||
PlayerPrefs.SetInt("icon", value4);
|
||||
PlayerPrefs.SetInt("overlay", value5);
|
||||
SwitchScene(0);
|
||||
UpdateStatusText(loginPanelStatusText, "", Color.red);
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateStatusText(loginPanelStatusText, "Unknown server response \"" + text + "\"", Color.red);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateStatusText(loginPanelStatusText, "Internal login server error", Color.red);
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator ChangeUsername()
|
||||
{
|
||||
WWWForm wWWForm = new WWWForm();
|
||||
wWWForm.AddField("username", changeUsernameCurrentForm.text);
|
||||
wWWForm.AddField("currentPassword", changeUsernamePasswordForm.text);
|
||||
wWWForm.AddField("newUsername", changeUsernameNewForm.text);
|
||||
using UnityWebRequest request = UnityWebRequest.Post("https://berrydash.lncvrt.xyz/database/changeAccountUsername.php", wWWForm);
|
||||
request.SetRequestHeader("User-Agent", "BerryDashClient");
|
||||
request.SetRequestHeader("ClientVersion", "1.33");
|
||||
yield return request.SendWebRequest();
|
||||
if (request.result != UnityWebRequest.Result.Success)
|
||||
{
|
||||
Debug.LogError("HTTP Error: " + request.error);
|
||||
UpdateStatusText(changeUsernameStatusText, "Failed to make HTTP request", Color.red);
|
||||
yield break;
|
||||
}
|
||||
string text = request.downloadHandler.text;
|
||||
Debug.Log(text);
|
||||
switch (text)
|
||||
{
|
||||
case "1":
|
||||
SwitchScene(0);
|
||||
UpdateStatusText(accountPanelStatusText, "Username changed successfully", Color.green);
|
||||
break;
|
||||
case "-1":
|
||||
UpdateStatusText(changeUsernameStatusText, "Internal login server error", Color.red);
|
||||
break;
|
||||
case "-2":
|
||||
UpdateStatusText(changeUsernameStatusText, "New Username, Password, or old username is empty", Color.red);
|
||||
break;
|
||||
case "-3":
|
||||
UpdateStatusText(changeUsernameStatusText, "New Username contains invalid characters", Color.red);
|
||||
break;
|
||||
case "-4":
|
||||
UpdateStatusText(changeUsernameStatusText, "New Username is too short or too long", Color.red);
|
||||
break;
|
||||
case "-5":
|
||||
UpdateStatusText(changeUsernameStatusText, "New Username does not match the required format", Color.red);
|
||||
break;
|
||||
case "-6":
|
||||
UpdateStatusText(changeUsernameStatusText, "Incorrect current password", Color.red);
|
||||
break;
|
||||
case "-7":
|
||||
UpdateStatusText(changeUsernameStatusText, "Current username is incorrect", Color.red);
|
||||
break;
|
||||
case "-8":
|
||||
UpdateStatusText(changeUsernameStatusText, "New username already exists", Color.red);
|
||||
break;
|
||||
default:
|
||||
UpdateStatusText(changeUsernameStatusText, "Unknown server response \"" + text + "\"", Color.red);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator ChangePassword()
|
||||
{
|
||||
WWWForm wWWForm = new WWWForm();
|
||||
wWWForm.AddField("username", changePasswordCurrentUsernameForm.text);
|
||||
wWWForm.AddField("currentPassword", changePasswordCurrentForm.text);
|
||||
wWWForm.AddField("newPassword", changePasswordNewForm.text);
|
||||
using UnityWebRequest request = UnityWebRequest.Post("https://berrydash.lncvrt.xyz/database/changeAccountPassword.php", wWWForm);
|
||||
request.SetRequestHeader("User-Agent", "BerryDashClient");
|
||||
request.SetRequestHeader("ClientVersion", "1.33");
|
||||
yield return request.SendWebRequest();
|
||||
if (request.result != UnityWebRequest.Result.Success)
|
||||
{
|
||||
Debug.LogError("HTTP Error: " + request.error);
|
||||
UpdateStatusText(changePasswordStatusText, "Failed to make HTTP request", Color.red);
|
||||
yield break;
|
||||
}
|
||||
string text = request.downloadHandler.text;
|
||||
Debug.Log(text);
|
||||
switch (text)
|
||||
{
|
||||
case "-1":
|
||||
UpdateStatusText(changePasswordStatusText, "Internal login server error", Color.red);
|
||||
yield break;
|
||||
case "-2":
|
||||
UpdateStatusText(changePasswordStatusText, "New Password, Password, or username is empty", Color.red);
|
||||
yield break;
|
||||
case "-3":
|
||||
UpdateStatusText(changePasswordStatusText, "New Password is too short or too long", Color.red);
|
||||
yield break;
|
||||
case "-4":
|
||||
UpdateStatusText(changePasswordStatusText, "Username must be 3-16 characters, letters and numbers only", Color.red);
|
||||
yield break;
|
||||
case "-5":
|
||||
UpdateStatusText(changePasswordStatusText, "Incorrect current password", Color.red);
|
||||
yield break;
|
||||
case "-6":
|
||||
UpdateStatusText(changePasswordStatusText, "Current username is incorrect", Color.red);
|
||||
yield break;
|
||||
case "-7":
|
||||
UpdateStatusText(changePasswordStatusText, "New password cannot be the same as your old password", Color.red);
|
||||
yield break;
|
||||
}
|
||||
if (Regex.IsMatch(text, "^[a-zA-Z0-9]{512}$"))
|
||||
{
|
||||
PlayerPrefs.SetString("gameSession", text);
|
||||
SwitchScene(0);
|
||||
UpdateStatusText(accountPanelStatusText, "Password changed successfully", Color.green);
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateStatusText(accountPanelStatusText, "Unknown server response \"" + text + "\"", Color.red);
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearForms()
|
||||
{
|
||||
registerPanelUsernameForm.text = "";
|
||||
registerPanelEmailForm.text = "";
|
||||
registerPanelEmailConfirmForm.text = "";
|
||||
registerPanelPasswordForm.text = "";
|
||||
registerPanelPasswordConfirmForm.text = "";
|
||||
loginPanelUsernameForm.text = "";
|
||||
loginPanelPasswordForm.text = "";
|
||||
changeUsernameNewForm.text = "";
|
||||
changeUsernamePasswordForm.text = "";
|
||||
changePasswordCurrentForm.text = "";
|
||||
changePasswordNewForm.text = "";
|
||||
changePasswordCurrentUsernameForm.text = "";
|
||||
changeUsernameCurrentForm.text = "";
|
||||
}
|
||||
|
||||
private IEnumerator SyncAccount()
|
||||
{
|
||||
WWWForm wWWForm = new WWWForm();
|
||||
wWWForm.AddField("userID", PlayerPrefs.GetInt("userID", 0).ToString());
|
||||
wWWForm.AddField("gameSession", PlayerPrefs.GetString("gameSession", ""));
|
||||
wWWForm.AddField("highScore", PlayerPrefs.GetInt("HighScore", 0).ToString());
|
||||
wWWForm.AddField("icon", PlayerPrefs.GetInt("icon", 1).ToString());
|
||||
wWWForm.AddField("overlay", PlayerPrefs.GetInt("overlay", 0).ToString());
|
||||
using UnityWebRequest request = UnityWebRequest.Post("https://berrydash.lncvrt.xyz/database/syncAccount.php", wWWForm);
|
||||
request.SetRequestHeader("User-Agent", "BerryDashClient");
|
||||
request.SetRequestHeader("ClientVersion", "1.33");
|
||||
yield return request.SendWebRequest();
|
||||
if (request.result != UnityWebRequest.Result.Success)
|
||||
{
|
||||
Debug.LogError("HTTP Error: " + request.error);
|
||||
UpdateStatusText(accountPanelStatusText, "Failed to make HTTP request", Color.red);
|
||||
yield break;
|
||||
}
|
||||
string text = request.downloadHandler.text;
|
||||
Debug.Log(text);
|
||||
switch (text)
|
||||
{
|
||||
case "1":
|
||||
accountPanelSyncButton.interactable = false;
|
||||
UpdateStatusText(accountPanelStatusText, "Synced account", Color.green);
|
||||
break;
|
||||
case "-1":
|
||||
UpdateStatusText(accountPanelStatusText, "Internal login server error", Color.red);
|
||||
break;
|
||||
case "-2":
|
||||
LogoutAccount();
|
||||
break;
|
||||
default:
|
||||
UpdateStatusText(accountPanelStatusText, "Unknown server response \"" + text + "\"", Color.red);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void StartSyncAccount()
|
||||
{
|
||||
StartCoroutine(SyncAccount());
|
||||
}
|
||||
|
||||
private void LogoutAccount()
|
||||
{
|
||||
PlayerPrefs.DeleteKey("userID");
|
||||
PlayerPrefs.DeleteKey("gameSession");
|
||||
PlayerPrefs.SetInt("HighScore", 0);
|
||||
PlayerPrefs.SetInt("icon", 1);
|
||||
PlayerPrefs.SetInt("overlay", 0);
|
||||
SwitchScene(1);
|
||||
}
|
||||
|
||||
private void UpdateStatusText(TMP_Text text, string message, Color color)
|
||||
{
|
||||
text.text = message;
|
||||
text.color = color;
|
||||
}
|
||||
}
|
||||
+642
@@ -0,0 +1,642 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class Game : MonoBehaviour
|
||||
{
|
||||
public float spawnRate = 1f;
|
||||
|
||||
private float nextSpawnTime;
|
||||
|
||||
private int score;
|
||||
|
||||
private int highscore;
|
||||
|
||||
private float boostLeft;
|
||||
|
||||
private float slownessLeft;
|
||||
|
||||
private float screenWidth;
|
||||
|
||||
private bool isGrounded;
|
||||
|
||||
public TMP_Text scoreText;
|
||||
|
||||
public TMP_Text highScoreText;
|
||||
|
||||
public TMP_Text boostText;
|
||||
|
||||
public GameObject bird;
|
||||
|
||||
public GameObject pausePanel;
|
||||
|
||||
public Rigidbody2D rb;
|
||||
|
||||
public AudioSource backgroundMusic;
|
||||
|
||||
public TMP_Text fpsCounter;
|
||||
|
||||
private float nextUpdate;
|
||||
|
||||
private float fps;
|
||||
|
||||
public SpriteRenderer overlayRender;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
highscore = PlayerPrefs.GetInt("HighScore", 0);
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Cursor.visible = false;
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
SpriteRenderer component = bird.GetComponent<SpriteRenderer>();
|
||||
int num = PlayerPrefs.GetInt("icon", 1);
|
||||
int num2 = PlayerPrefs.GetInt("overlay", 1);
|
||||
if (num == 1)
|
||||
{
|
||||
if (PlayerPrefs.GetInt("userID", 0) == 1)
|
||||
{
|
||||
component.sprite = Resources.Load<Sprite>("icons/icons/bird_-1");
|
||||
}
|
||||
else if (PlayerPrefs.GetInt("userID", 0) == 2)
|
||||
{
|
||||
component.sprite = Resources.Load<Sprite>("icons/icons/bird_-2");
|
||||
}
|
||||
else if (PlayerPrefs.GetInt("userID", 0) == 4)
|
||||
{
|
||||
component.sprite = Resources.Load<Sprite>("icons/icons/bird_-3");
|
||||
}
|
||||
else if (PlayerPrefs.GetInt("userID", 0) == 6)
|
||||
{
|
||||
component.sprite = Resources.Load<Sprite>("icons/icons/bird_-4");
|
||||
}
|
||||
else
|
||||
{
|
||||
component.sprite = Resources.Load<Sprite>("icons/icons/bird_1");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
component.sprite = Resources.Load<Sprite>("icons/icons/bird_" + num);
|
||||
}
|
||||
if (num2 == 8)
|
||||
{
|
||||
overlayRender.sprite = Resources.Load<Sprite>("icons/overlays/overlay_8");
|
||||
overlayRender.transform.localPosition = new Vector3(-0.35f, 0.3f, 0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
overlayRender.sprite = Resources.Load<Sprite>("icons/overlays/overlay_" + num2);
|
||||
}
|
||||
if (component.sprite == null)
|
||||
{
|
||||
component.sprite = Resources.Load<Sprite>("icons/icons/bird_1");
|
||||
PlayerPrefs.SetInt("icon", 1);
|
||||
}
|
||||
if (overlayRender.sprite == null && num2 != 0)
|
||||
{
|
||||
overlayRender.sprite = Resources.Load<Sprite>("icons/overlays/overlay_1");
|
||||
PlayerPrefs.SetInt("overlay", 1);
|
||||
}
|
||||
PlayerPrefs.Save();
|
||||
backgroundMusic.volume = PlayerPrefs.GetFloat("musicVolume", 1f);
|
||||
screenWidth = Camera.main.orthographicSize * 2f * Camera.main.aspect;
|
||||
GameObject.Find("HighScoreText").GetComponent<TMP_Text>().text = $"High Score: {highscore}";
|
||||
if (PlayerPrefs.GetInt("Setting2", 0) == 1)
|
||||
{
|
||||
GameObject gameObject = new GameObject("LeftArrow");
|
||||
GameObject gameObject2 = new GameObject("RightArrow");
|
||||
GameObject gameObject3 = new GameObject("JumpArrow");
|
||||
GameObject gameObject4 = new GameObject("RestartButton");
|
||||
GameObject gameObject5 = new GameObject("BackButton");
|
||||
gameObject.AddComponent<SpriteRenderer>();
|
||||
gameObject2.AddComponent<SpriteRenderer>();
|
||||
gameObject3.AddComponent<SpriteRenderer>();
|
||||
gameObject4.AddComponent<SpriteRenderer>();
|
||||
gameObject5.AddComponent<SpriteRenderer>();
|
||||
gameObject.GetComponent<SpriteRenderer>().sprite = Resources.Load<Sprite>("textures/Arrow");
|
||||
gameObject2.GetComponent<SpriteRenderer>().sprite = Resources.Load<Sprite>("textures/Arrow");
|
||||
gameObject3.GetComponent<SpriteRenderer>().sprite = Resources.Load<Sprite>("textures/Arrow");
|
||||
gameObject4.GetComponent<SpriteRenderer>().sprite = Resources.Load<Sprite>("textures/Restart");
|
||||
gameObject5.GetComponent<SpriteRenderer>().sprite = Resources.Load<Sprite>("textures/Back");
|
||||
gameObject.transform.rotation = Quaternion.Euler(0f, 0f, 90f);
|
||||
gameObject2.transform.rotation = Quaternion.Euler(0f, 0f, -90f);
|
||||
gameObject.transform.position = new Vector3((0f - screenWidth) / 2.5f, -4f, 0f);
|
||||
gameObject2.transform.position = new Vector3(screenWidth / 2.5f, -4f, 0f);
|
||||
gameObject4.transform.position = new Vector3(screenWidth / 2.3f, Camera.main.orthographicSize - 1.2f, 0f);
|
||||
gameObject5.transform.position = new Vector3((0f - screenWidth) / 2.3f, Camera.main.orthographicSize - 1.2f, 0f);
|
||||
if (PlayerPrefs.GetInt("Setting3", 0) == 1)
|
||||
{
|
||||
gameObject.transform.localScale = new Vector3(screenWidth / 14f, screenWidth / 14f, 1f);
|
||||
gameObject2.transform.localScale = new Vector3(screenWidth / 14f, screenWidth / 14f, 1f);
|
||||
gameObject3.transform.localScale = new Vector3(screenWidth / 14f, screenWidth / 14f, 1f);
|
||||
gameObject4.transform.localScale = new Vector3(screenWidth / 14f, screenWidth / 14f, 1f);
|
||||
gameObject5.transform.localScale = new Vector3(screenWidth / 14f, screenWidth / 14f, 1f);
|
||||
gameObject3.transform.position = new Vector3(screenWidth / 2.5f, -1f, 0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
gameObject.transform.localScale = new Vector3(screenWidth / 20f, screenWidth / 20f, 1f);
|
||||
gameObject2.transform.localScale = new Vector3(screenWidth / 20f, screenWidth / 20f, 1f);
|
||||
gameObject3.transform.localScale = new Vector3(screenWidth / 20f, screenWidth / 20f, 1f);
|
||||
gameObject4.transform.localScale = new Vector3(screenWidth / 20f, screenWidth / 20f, 1f);
|
||||
gameObject5.transform.localScale = new Vector3(screenWidth / 20f, screenWidth / 20f, 1f);
|
||||
gameObject3.transform.position = new Vector3(screenWidth / 2.5f, -2f, 0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void MoveBird()
|
||||
{
|
||||
float num = Camera.main.orthographicSize * 2f * Camera.main.aspect;
|
||||
float num2 = 0.18f * (num / 20.19257f);
|
||||
bool flag = false;
|
||||
bool flag2 = false;
|
||||
bool flag3 = false;
|
||||
bool flag4 = false;
|
||||
bool flag5 = false;
|
||||
float num3 = num2;
|
||||
if (boostLeft > 0f)
|
||||
{
|
||||
num3 = num2 * 1.39f;
|
||||
}
|
||||
else if (slownessLeft > 0f)
|
||||
{
|
||||
num3 = num2 * 0.56f;
|
||||
}
|
||||
CheckIfGrounded();
|
||||
float axisRaw = Input.GetAxisRaw("Horizontal");
|
||||
if (!Application.isMobilePlatform)
|
||||
{
|
||||
if (axisRaw < 0f || Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A))
|
||||
{
|
||||
flag2 = true;
|
||||
}
|
||||
if (axisRaw > 0f || Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D))
|
||||
{
|
||||
flag = true;
|
||||
}
|
||||
if (Input.GetKey(KeyCode.Space) || Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W) || (Input.GetMouseButton(0) && PlayerPrefs.GetInt("Setting2", 0) == 0) || Input.GetKey(KeyCode.JoystickButton0))
|
||||
{
|
||||
flag3 = true;
|
||||
}
|
||||
if (Input.GetKey(KeyCode.R))
|
||||
{
|
||||
flag5 = true;
|
||||
}
|
||||
}
|
||||
if (PlayerPrefs.GetInt("Setting2", 0) == 1)
|
||||
{
|
||||
GameObject gameObject = GameObject.Find("LeftArrow");
|
||||
GameObject gameObject2 = GameObject.Find("RightArrow");
|
||||
GameObject gameObject3 = GameObject.Find("JumpArrow");
|
||||
GameObject gameObject4 = GameObject.Find("RestartButton");
|
||||
GameObject gameObject5 = GameObject.Find("BackButton");
|
||||
if (!Application.isMobilePlatform)
|
||||
{
|
||||
if (Input.GetMouseButton(0))
|
||||
{
|
||||
Vector3 point = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||||
point.z = 0f;
|
||||
if (gameObject.GetComponent<SpriteRenderer>().bounds.Contains(point))
|
||||
{
|
||||
flag2 = true;
|
||||
}
|
||||
if (gameObject2.GetComponent<SpriteRenderer>().bounds.Contains(point))
|
||||
{
|
||||
flag = true;
|
||||
}
|
||||
if (gameObject3.GetComponent<SpriteRenderer>().bounds.Contains(point))
|
||||
{
|
||||
flag3 = true;
|
||||
}
|
||||
}
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
Vector3 point2 = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||||
point2.z = 0f;
|
||||
if (gameObject4.GetComponent<SpriteRenderer>().bounds.Contains(point2))
|
||||
{
|
||||
flag5 = true;
|
||||
}
|
||||
if (gameObject5.GetComponent<SpriteRenderer>().bounds.Contains(point2))
|
||||
{
|
||||
flag4 = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < Input.touchCount; i++)
|
||||
{
|
||||
Touch touch = Input.GetTouch(i);
|
||||
Vector3 point3 = Camera.main.ScreenToWorldPoint(touch.position);
|
||||
point3.z = 0f;
|
||||
if (gameObject.GetComponent<SpriteRenderer>().bounds.Contains(point3))
|
||||
{
|
||||
flag2 = true;
|
||||
}
|
||||
if (gameObject2.GetComponent<SpriteRenderer>().bounds.Contains(point3))
|
||||
{
|
||||
flag = true;
|
||||
}
|
||||
if (gameObject3.GetComponent<SpriteRenderer>().bounds.Contains(point3))
|
||||
{
|
||||
flag3 = true;
|
||||
}
|
||||
if (gameObject4.GetComponent<SpriteRenderer>().bounds.Contains(point3))
|
||||
{
|
||||
flag5 = true;
|
||||
}
|
||||
if (gameObject5.GetComponent<SpriteRenderer>().bounds.Contains(point3))
|
||||
{
|
||||
flag4 = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (flag2 && !flag)
|
||||
{
|
||||
bird.transform.position += new Vector3(0f - num3, 0f, 0f);
|
||||
ClampPosition(num, bird);
|
||||
bird.transform.localScale = new Vector3(1.35f, 1.35f, 1.35f);
|
||||
}
|
||||
if (flag && !flag2)
|
||||
{
|
||||
bird.transform.position += new Vector3(num3, 0f, 0f);
|
||||
ClampPosition(num, bird);
|
||||
bird.transform.localScale = new Vector3(-1.35f, 1.35f, 1.35f);
|
||||
}
|
||||
if (flag3 && isGrounded)
|
||||
{
|
||||
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("sounds/Jump"), Camera.main.transform.position, 0.75f * PlayerPrefs.GetFloat("sfxVolume", 1f));
|
||||
if (boostLeft > 0f)
|
||||
{
|
||||
rb.velocity = Vector2.up * 12f;
|
||||
}
|
||||
else if (slownessLeft > 0f)
|
||||
{
|
||||
rb.velocity = Vector2.up * 6f;
|
||||
}
|
||||
else
|
||||
{
|
||||
rb.velocity = Vector2.up * 9f;
|
||||
}
|
||||
}
|
||||
if (flag4)
|
||||
{
|
||||
TogglePause();
|
||||
}
|
||||
if (flag5)
|
||||
{
|
||||
Respawn();
|
||||
}
|
||||
}
|
||||
|
||||
private void ClampPosition(float screenWidth, GameObject bird)
|
||||
{
|
||||
float num = screenWidth / 2.17f;
|
||||
float x = Mathf.Clamp(bird.transform.position.x, 0f - num, num);
|
||||
bird.transform.position = new Vector3(x, bird.transform.position.y, bird.transform.position.z);
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
SpawnBerries();
|
||||
if (!pausePanel.activeSelf)
|
||||
{
|
||||
MoveBird();
|
||||
if (boostLeft > 0f)
|
||||
{
|
||||
boostLeft -= Time.deltaTime;
|
||||
boostText.GetComponent<TMP_Text>().text = "Boost expires in " + $"{boostLeft:0.0}" + "s";
|
||||
}
|
||||
else if (slownessLeft > 0f)
|
||||
{
|
||||
slownessLeft -= Time.deltaTime;
|
||||
boostText.GetComponent<TMP_Text>().text = "Slowness expires in " + $"{slownessLeft:0.0}" + "s";
|
||||
}
|
||||
else
|
||||
{
|
||||
boostText.GetComponent<TMP_Text>().text = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SpawnBerries()
|
||||
{
|
||||
if (!(Time.time >= nextSpawnTime))
|
||||
{
|
||||
return;
|
||||
}
|
||||
nextSpawnTime = Time.time + 1f / spawnRate;
|
||||
float value = Random.value;
|
||||
if (!pausePanel.activeSelf)
|
||||
{
|
||||
GameObject gameObject;
|
||||
SpriteRenderer spriteRenderer;
|
||||
if (value <= 0.6f)
|
||||
{
|
||||
gameObject = new GameObject("Berry");
|
||||
spriteRenderer = gameObject.AddComponent<SpriteRenderer>();
|
||||
spriteRenderer.sprite = Resources.Load<Sprite>("textures/Berry");
|
||||
gameObject.tag = "Berry";
|
||||
}
|
||||
else if (value <= 0.8f)
|
||||
{
|
||||
gameObject = new GameObject("PoisonBerry");
|
||||
spriteRenderer = gameObject.AddComponent<SpriteRenderer>();
|
||||
spriteRenderer.sprite = Resources.Load<Sprite>("textures/PoisonBerry");
|
||||
gameObject.tag = "PoisonBerry";
|
||||
}
|
||||
else if (value <= 0.9f)
|
||||
{
|
||||
gameObject = new GameObject("SlowBerry");
|
||||
spriteRenderer = gameObject.AddComponent<SpriteRenderer>();
|
||||
spriteRenderer.sprite = Resources.Load<Sprite>("textures/SlowBerry");
|
||||
gameObject.tag = "SlowBerry";
|
||||
}
|
||||
else
|
||||
{
|
||||
gameObject = new GameObject("UltraBerry");
|
||||
spriteRenderer = gameObject.AddComponent<SpriteRenderer>();
|
||||
spriteRenderer.sprite = Resources.Load<Sprite>("textures/UltraBerry");
|
||||
gameObject.tag = "UltraBerry";
|
||||
}
|
||||
spriteRenderer.sortingOrder = -5;
|
||||
float num = Camera.main.orthographicSize * 2f * Camera.main.aspect;
|
||||
float x = Random.Range((0f - num) / 2.17f, num / 2.17f);
|
||||
gameObject.transform.position = new Vector3(x, Camera.main.orthographicSize + 1f, 0f);
|
||||
Rigidbody2D rigidbody2D = gameObject.AddComponent<Rigidbody2D>();
|
||||
rigidbody2D.gravityScale = 0f;
|
||||
rigidbody2D.velocity = new Vector2(0f, -4f);
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (PlayerPrefs.GetInt("Setting4", 0) == 1 && Time.time > nextUpdate)
|
||||
{
|
||||
fps = 1f / Time.deltaTime;
|
||||
fpsCounter.text = "FPS: " + Mathf.Round(fps);
|
||||
nextUpdate = Time.time + 0.25f;
|
||||
}
|
||||
if (screenWidth != Camera.main.orthographicSize * 2f * Camera.main.aspect)
|
||||
{
|
||||
screenWidth = Camera.main.orthographicSize * 2f * Camera.main.aspect;
|
||||
ClampPosition(screenWidth, bird);
|
||||
if (PlayerPrefs.GetInt("Setting2", 0) == 1)
|
||||
{
|
||||
GameObject gameObject = GameObject.Find("LeftArrow");
|
||||
GameObject gameObject2 = GameObject.Find("RightArrow");
|
||||
GameObject gameObject3 = GameObject.Find("JumpArrow");
|
||||
GameObject gameObject4 = GameObject.Find("RestartButton");
|
||||
GameObject gameObject5 = GameObject.Find("BackButton");
|
||||
gameObject.transform.position = new Vector3((0f - screenWidth) / 2.5f, -4f, 0f);
|
||||
gameObject2.transform.position = new Vector3(screenWidth / 2.5f, -4f, 0f);
|
||||
gameObject4.transform.position = new Vector3(screenWidth / 2.3f, Camera.main.orthographicSize - 1.2f, 0f);
|
||||
gameObject5.transform.position = new Vector3((0f - screenWidth) / 2.3f, Camera.main.orthographicSize - 1.2f, 0f);
|
||||
if (PlayerPrefs.GetInt("Setting3", 0) == 1)
|
||||
{
|
||||
gameObject.transform.localScale = new Vector3(screenWidth / 14f, screenWidth / 14f, 1f);
|
||||
gameObject2.transform.localScale = new Vector3(screenWidth / 14f, screenWidth / 14f, 1f);
|
||||
gameObject3.transform.localScale = new Vector3(screenWidth / 14f, screenWidth / 14f, 1f);
|
||||
gameObject4.transform.localScale = new Vector3(screenWidth / 14f, screenWidth / 14f, 1f);
|
||||
gameObject5.transform.localScale = new Vector3(screenWidth / 14f, screenWidth / 14f, 1f);
|
||||
gameObject3.transform.position = new Vector3(screenWidth / 2.5f, -1f, 0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
gameObject.transform.localScale = new Vector3(screenWidth / 20f, screenWidth / 20f, 1f);
|
||||
gameObject2.transform.localScale = new Vector3(screenWidth / 20f, screenWidth / 20f, 1f);
|
||||
gameObject3.transform.localScale = new Vector3(screenWidth / 20f, screenWidth / 20f, 1f);
|
||||
gameObject4.transform.localScale = new Vector3(screenWidth / 20f, screenWidth / 20f, 1f);
|
||||
gameObject5.transform.localScale = new Vector3(screenWidth / 20f, screenWidth / 20f, 1f);
|
||||
gameObject3.transform.position = new Vector3(screenWidth / 2.5f, -2f, 0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
GameObject[] array = GameObject.FindGameObjectsWithTag("Berry");
|
||||
GameObject[] array2 = GameObject.FindGameObjectsWithTag("PoisonBerry");
|
||||
GameObject[] array3 = GameObject.FindGameObjectsWithTag("UltraBerry");
|
||||
GameObject[] array4 = GameObject.FindGameObjectsWithTag("SlowBerry");
|
||||
if (!pausePanel.activeSelf)
|
||||
{
|
||||
CheckIfGrounded();
|
||||
GameObject[] array5 = array;
|
||||
foreach (GameObject gameObject6 in array5)
|
||||
{
|
||||
if (gameObject6.transform.position.y < 0f - Camera.main.orthographicSize - 1f)
|
||||
{
|
||||
Object.Destroy(gameObject6);
|
||||
}
|
||||
else if (Vector3.Distance(bird.transform.position, gameObject6.transform.position) < 1.5f)
|
||||
{
|
||||
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("sounds/Eat"), Camera.main.transform.position, 1.2f * PlayerPrefs.GetFloat("sfxVolume", 1f));
|
||||
Object.Destroy(gameObject6);
|
||||
score++;
|
||||
UpdateScore(score);
|
||||
}
|
||||
gameObject6.GetComponent<Rigidbody2D>().velocity = new Vector2(0f, -4f);
|
||||
}
|
||||
array5 = array2;
|
||||
foreach (GameObject gameObject7 in array5)
|
||||
{
|
||||
if (gameObject7.transform.position.y < 0f - Camera.main.orthographicSize - 1f)
|
||||
{
|
||||
Object.Destroy(gameObject7);
|
||||
}
|
||||
else if (Vector3.Distance(bird.transform.position, gameObject7.transform.position) < 1.5f)
|
||||
{
|
||||
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("sounds/Death"), Camera.main.transform.position, 1.2f * PlayerPrefs.GetFloat("sfxVolume", 1f));
|
||||
Respawn();
|
||||
}
|
||||
gameObject7.GetComponent<Rigidbody2D>().velocity = new Vector2(0f, -4f);
|
||||
}
|
||||
array5 = array3;
|
||||
foreach (GameObject gameObject8 in array5)
|
||||
{
|
||||
if (gameObject8.transform.position.y < 0f - Camera.main.orthographicSize - 1f)
|
||||
{
|
||||
Object.Destroy(gameObject8);
|
||||
}
|
||||
else if (Vector3.Distance(bird.transform.position, gameObject8.transform.position) < 1.5f)
|
||||
{
|
||||
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("sounds/Powerup"), Camera.main.transform.position, 0.35f * PlayerPrefs.GetFloat("sfxVolume", 1f));
|
||||
Object.Destroy(gameObject8);
|
||||
if (slownessLeft > 0f)
|
||||
{
|
||||
slownessLeft = 0f;
|
||||
score++;
|
||||
UpdateScore(score);
|
||||
}
|
||||
else
|
||||
{
|
||||
boostLeft += 10f;
|
||||
score += 5;
|
||||
UpdateScore(score);
|
||||
}
|
||||
}
|
||||
gameObject8.GetComponent<Rigidbody2D>().velocity = new Vector2(0f, -4f);
|
||||
}
|
||||
array5 = array4;
|
||||
foreach (GameObject gameObject9 in array5)
|
||||
{
|
||||
if (gameObject9.transform.position.y < 0f - Camera.main.orthographicSize - 1f)
|
||||
{
|
||||
Object.Destroy(gameObject9);
|
||||
}
|
||||
else if (Vector3.Distance(bird.transform.position, gameObject9.transform.position) < 1.5f)
|
||||
{
|
||||
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("sounds/Downgrade"), Camera.main.transform.position, 0.35f * PlayerPrefs.GetFloat("sfxVolume", 1f));
|
||||
Object.Destroy(gameObject9);
|
||||
boostLeft = 0f;
|
||||
slownessLeft = 10f;
|
||||
if (score > 0)
|
||||
{
|
||||
score--;
|
||||
UpdateScore(score);
|
||||
}
|
||||
}
|
||||
gameObject9.GetComponent<Rigidbody2D>().velocity = new Vector2(0f, -4f);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rb.gravityScale = 0f;
|
||||
rb.velocity = Vector2.zero;
|
||||
GameObject[] array5 = array;
|
||||
for (int i = 0; i < array5.Length; i++)
|
||||
{
|
||||
array5[i].GetComponent<Rigidbody2D>().velocity = Vector2.zero;
|
||||
}
|
||||
array5 = array2;
|
||||
for (int i = 0; i < array5.Length; i++)
|
||||
{
|
||||
array5[i].GetComponent<Rigidbody2D>().velocity = Vector2.zero;
|
||||
}
|
||||
array5 = array3;
|
||||
for (int i = 0; i < array5.Length; i++)
|
||||
{
|
||||
array5[i].GetComponent<Rigidbody2D>().velocity = Vector2.zero;
|
||||
}
|
||||
array5 = array4;
|
||||
for (int i = 0; i < array5.Length; i++)
|
||||
{
|
||||
array5[i].GetComponent<Rigidbody2D>().velocity = Vector2.zero;
|
||||
}
|
||||
}
|
||||
if (!Application.isMobilePlatform && (Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown(KeyCode.JoystickButton7)))
|
||||
{
|
||||
TogglePause();
|
||||
}
|
||||
}
|
||||
|
||||
private void Respawn()
|
||||
{
|
||||
bird.transform.position = new Vector3(0f, -4.3f, 0f);
|
||||
bird.transform.localScale = new Vector3(1.35f, 1.35f, 1.35f);
|
||||
rb.gravityScale = 0f;
|
||||
rb.velocity = Vector2.zero;
|
||||
score = 0;
|
||||
boostLeft = 0f;
|
||||
slownessLeft = 0f;
|
||||
UpdateScore(score);
|
||||
GameObject[] array = GameObject.FindGameObjectsWithTag("Berry");
|
||||
GameObject[] array2 = GameObject.FindGameObjectsWithTag("PoisonBerry");
|
||||
GameObject[] array3 = GameObject.FindGameObjectsWithTag("UltraBerry");
|
||||
GameObject[] array4 = GameObject.FindGameObjectsWithTag("SlowBerry");
|
||||
GameObject[] array5 = array;
|
||||
for (int i = 0; i < array5.Length; i++)
|
||||
{
|
||||
Object.Destroy(array5[i]);
|
||||
}
|
||||
array5 = array2;
|
||||
for (int i = 0; i < array5.Length; i++)
|
||||
{
|
||||
Object.Destroy(array5[i]);
|
||||
}
|
||||
array5 = array3;
|
||||
for (int i = 0; i < array5.Length; i++)
|
||||
{
|
||||
Object.Destroy(array5[i]);
|
||||
}
|
||||
array5 = array4;
|
||||
for (int i = 0; i < array5.Length; i++)
|
||||
{
|
||||
Object.Destroy(array5[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateScore(int score)
|
||||
{
|
||||
if (score > highscore)
|
||||
{
|
||||
highscore = score;
|
||||
}
|
||||
PlayerPrefs.SetInt("HighScore", highscore);
|
||||
PlayerPrefs.Save();
|
||||
scoreText.GetComponent<TMP_Text>().text = "Score: " + score;
|
||||
highScoreText.GetComponent<TMP_Text>().text = "High Score: " + highscore;
|
||||
}
|
||||
|
||||
private void CheckIfGrounded()
|
||||
{
|
||||
GameObject gameObject = GameObject.Find("JumpArrow");
|
||||
isGrounded = bird.transform.position.y <= -4.1299996f;
|
||||
rb.gravityScale = (isGrounded ? 0f : 1.5f);
|
||||
if (bird.transform.position.y < -4.18f)
|
||||
{
|
||||
bird.transform.position = new Vector2(bird.transform.position.x, -4.18f);
|
||||
rb.velocity = new Vector2(rb.velocity.x, 0f);
|
||||
}
|
||||
if (gameObject != null)
|
||||
{
|
||||
Renderer component = gameObject.GetComponent<Renderer>();
|
||||
if (component != null)
|
||||
{
|
||||
component.material.color = (isGrounded ? Color.white : Color.red);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void TogglePause()
|
||||
{
|
||||
if (pausePanel.activeSelf)
|
||||
{
|
||||
DisablePause();
|
||||
}
|
||||
else
|
||||
{
|
||||
EnablePause();
|
||||
}
|
||||
}
|
||||
|
||||
private void EnablePause()
|
||||
{
|
||||
Cursor.visible = true;
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
backgroundMusic.Pause();
|
||||
pausePanel.SetActive(value: true);
|
||||
}
|
||||
|
||||
private void DisablePause()
|
||||
{
|
||||
Cursor.visible = false;
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
backgroundMusic.Play();
|
||||
pausePanel.SetActive(value: false);
|
||||
}
|
||||
|
||||
private void OnApplicationPause()
|
||||
{
|
||||
EnablePause();
|
||||
}
|
||||
|
||||
private void OnApplicationQuit()
|
||||
{
|
||||
Cursor.visible = true;
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
}
|
||||
}
|
||||
+296
@@ -0,0 +1,296 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class Iconkit : MonoBehaviour
|
||||
{
|
||||
public GameObject panel;
|
||||
|
||||
public GameObject iconSelectionPanel;
|
||||
|
||||
public GameObject overlaySelectionPanel;
|
||||
|
||||
public Button backButton;
|
||||
|
||||
public Image defaultIcon;
|
||||
|
||||
public Button placeholderButton;
|
||||
|
||||
public TMP_Text selectionText;
|
||||
|
||||
public Image previewBird;
|
||||
|
||||
public Image previewOverlay;
|
||||
|
||||
public Image overlay0;
|
||||
|
||||
public Image overlay1;
|
||||
|
||||
public Image overlay2;
|
||||
|
||||
public Image overlay3;
|
||||
|
||||
public Image overlay4;
|
||||
|
||||
public Image overlay5;
|
||||
|
||||
public Image overlay6;
|
||||
|
||||
public Image overlay7;
|
||||
|
||||
public Image overlay8;
|
||||
|
||||
public Image overlay9;
|
||||
|
||||
public Image icon1;
|
||||
|
||||
public Image icon2;
|
||||
|
||||
public Image icon3;
|
||||
|
||||
public Image icon4;
|
||||
|
||||
public Image icon5;
|
||||
|
||||
public Image icon6;
|
||||
|
||||
public Image icon7;
|
||||
|
||||
public Image icon8;
|
||||
|
||||
public GameObject previewBirdObject;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
SwitchToIcon();
|
||||
SelectOverlay(PlayerPrefs.GetInt("overlay", Mathf.Clamp(PlayerPrefs.GetInt("overlay", 0), 0, 9)));
|
||||
SelectIcon(PlayerPrefs.GetInt("icon", Mathf.Clamp(PlayerPrefs.GetInt("icon", 0), 1, 8)));
|
||||
if (PlayerPrefs.GetInt("icon", 0) == 7)
|
||||
{
|
||||
SelectOverlay(0);
|
||||
placeholderButton.interactable = false;
|
||||
}
|
||||
if (PlayerPrefs.GetInt("userID", 0) == 1)
|
||||
{
|
||||
defaultIcon.sprite = Resources.Load<Sprite>("icons/icons/bird_-1");
|
||||
}
|
||||
else if (PlayerPrefs.GetInt("userID", 0) == 2)
|
||||
{
|
||||
defaultIcon.sprite = Resources.Load<Sprite>("icons/icons/bird_-2");
|
||||
}
|
||||
else if (PlayerPrefs.GetInt("userID", 0) == 4)
|
||||
{
|
||||
defaultIcon.sprite = Resources.Load<Sprite>("icons/icons/bird_-3");
|
||||
}
|
||||
else if (PlayerPrefs.GetInt("userID", 0) == 6)
|
||||
{
|
||||
defaultIcon.sprite = Resources.Load<Sprite>("icons/icons/bird_-4");
|
||||
}
|
||||
placeholderButton.onClick.AddListener(ToggleKit);
|
||||
backButton.onClick.AddListener(delegate
|
||||
{
|
||||
PlayerPrefs.SetInt("icon", Mathf.Clamp(PlayerPrefs.GetInt("icon", 0), 1, 8));
|
||||
PlayerPrefs.SetInt("overlay", Mathf.Clamp(PlayerPrefs.GetInt("overlay", 0), 0, 9));
|
||||
PlayerPrefs.Save();
|
||||
SceneManager.LoadScene("Menu");
|
||||
});
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (!Application.isMobilePlatform)
|
||||
{
|
||||
if (!Input.GetMouseButton(0))
|
||||
{
|
||||
return;
|
||||
}
|
||||
Vector2 screenPoint = Input.mousePosition;
|
||||
Image[] array = new Image[10] { overlay0, overlay1, overlay2, overlay3, overlay4, overlay5, overlay6, overlay7, overlay8, overlay9 };
|
||||
Image[] array2 = new Image[8] { icon1, icon2, icon3, icon4, icon5, icon6, icon7, icon8 };
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
if (RectTransformUtility.RectangleContainsScreenPoint(array[i].rectTransform, screenPoint) && array[i].IsActive())
|
||||
{
|
||||
SelectOverlay(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < array2.Length; j++)
|
||||
{
|
||||
if (RectTransformUtility.RectangleContainsScreenPoint(array2[j].rectTransform, screenPoint) && array2[j].IsActive())
|
||||
{
|
||||
SelectIcon(j + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Input.touchCount <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Vector2 position = Input.GetTouch(0).position;
|
||||
Image[] array3 = new Image[10] { overlay0, overlay1, overlay2, overlay3, overlay4, overlay5, overlay6, overlay7, overlay8, overlay9 };
|
||||
Image[] array4 = new Image[8] { icon1, icon2, icon3, icon4, icon5, icon6, icon7, icon8 };
|
||||
for (int k = 0; k < array3.Length; k++)
|
||||
{
|
||||
if (RectTransformUtility.RectangleContainsScreenPoint(array3[k].rectTransform, position) && array3[k].IsActive())
|
||||
{
|
||||
SelectOverlay(k);
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (int l = 0; l < array4.Length; l++)
|
||||
{
|
||||
if (RectTransformUtility.RectangleContainsScreenPoint(array4[l].rectTransform, position) && array4[l].IsActive())
|
||||
{
|
||||
SelectIcon(l + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!Application.isMobilePlatform)
|
||||
{
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
Vector2 screenPoint = Input.mousePosition;
|
||||
if (RectTransformUtility.RectangleContainsScreenPoint(previewBirdObject.GetComponent<RectTransform>(), screenPoint))
|
||||
{
|
||||
float x = previewBirdObject.transform.localScale.x;
|
||||
previewBirdObject.transform.localScale = new Vector3((x != 1f) ? 1 : (-1), 1f, 1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
|
||||
{
|
||||
Vector2 position = Input.GetTouch(0).position;
|
||||
if (RectTransformUtility.RectangleContainsScreenPoint(previewBirdObject.GetComponent<RectTransform>(), position))
|
||||
{
|
||||
float x2 = previewBirdObject.transform.localScale.x;
|
||||
previewBirdObject.transform.localScale = new Vector3((x2 != 1f) ? 1 : (-1), 1f, 1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SwitchToIcon()
|
||||
{
|
||||
iconSelectionPanel.SetActive(value: true);
|
||||
overlaySelectionPanel.SetActive(value: false);
|
||||
selectionText.text = "Icon selection";
|
||||
placeholderButton.GetComponentInChildren<TMP_Text>().text = "Overlays";
|
||||
}
|
||||
|
||||
private void SwitchToOverlay()
|
||||
{
|
||||
iconSelectionPanel.SetActive(value: false);
|
||||
overlaySelectionPanel.SetActive(value: true);
|
||||
selectionText.text = "Overlay selection";
|
||||
placeholderButton.GetComponentInChildren<TMP_Text>().text = "Icons";
|
||||
}
|
||||
|
||||
private void ToggleKit()
|
||||
{
|
||||
if (GetCurrentKit() == 1)
|
||||
{
|
||||
SwitchToOverlay();
|
||||
}
|
||||
else if (GetCurrentKit() == 2)
|
||||
{
|
||||
SwitchToIcon();
|
||||
}
|
||||
}
|
||||
|
||||
private int GetCurrentKit()
|
||||
{
|
||||
if (iconSelectionPanel.activeSelf)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (overlaySelectionPanel.activeSelf)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private void SelectIcon(int iconID)
|
||||
{
|
||||
PlayerPrefs.SetInt("icon", iconID);
|
||||
PlayerPrefs.Save();
|
||||
Image[] array = new Image[8] { icon1, icon2, icon3, icon4, icon5, icon6, icon7, icon8 };
|
||||
Color32 color = new Color32(70, 70, 70, byte.MaxValue);
|
||||
Color32 color2 = new Color32(100, 100, 100, byte.MaxValue);
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
array[i].color = ((iconID == i + 1) ? color : color2);
|
||||
}
|
||||
previewBird.sprite = Resources.Load<Sprite>("icons/icons/bird_" + iconID);
|
||||
if (iconID == 1)
|
||||
{
|
||||
if (PlayerPrefs.GetInt("userID", 0) == 1)
|
||||
{
|
||||
previewBird.sprite = Resources.Load<Sprite>("icons/icons/bird_-1");
|
||||
}
|
||||
else if (PlayerPrefs.GetInt("userID", 0) == 2)
|
||||
{
|
||||
previewBird.sprite = Resources.Load<Sprite>("icons/icons/bird_-2");
|
||||
}
|
||||
else if (PlayerPrefs.GetInt("userID", 0) == 4)
|
||||
{
|
||||
previewBird.sprite = Resources.Load<Sprite>("icons/icons/bird_-3");
|
||||
}
|
||||
else if (PlayerPrefs.GetInt("userID", 0) == 6)
|
||||
{
|
||||
previewBird.sprite = Resources.Load<Sprite>("icons/icons/bird_-4");
|
||||
}
|
||||
}
|
||||
if (iconID == 7)
|
||||
{
|
||||
SelectOverlay(0, savePast: false);
|
||||
placeholderButton.interactable = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
SelectOverlay(PlayerPrefs.GetInt("pastOverlay", 0), savePast: false);
|
||||
placeholderButton.interactable = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void SelectOverlay(int overlayID, bool savePast = true)
|
||||
{
|
||||
if (savePast)
|
||||
{
|
||||
PlayerPrefs.SetInt("pastOverlay", PlayerPrefs.GetInt("overlay", 0));
|
||||
}
|
||||
PlayerPrefs.SetInt("overlay", overlayID);
|
||||
PlayerPrefs.Save();
|
||||
Image[] array = new Image[10] { overlay0, overlay1, overlay2, overlay3, overlay4, overlay5, overlay6, overlay7, overlay8, overlay9 };
|
||||
Color32 color = new Color32(70, 70, 70, byte.MaxValue);
|
||||
Color32 color2 = new Color32(100, 100, 100, byte.MaxValue);
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
array[i].color = ((overlayID == i) ? color : color2);
|
||||
}
|
||||
previewOverlay.rectTransform.localPosition = new Vector3(-19f, 28f, 0f);
|
||||
previewOverlay.gameObject.SetActive(value: true);
|
||||
if (overlayID == 8)
|
||||
{
|
||||
previewOverlay.rectTransform.localPosition = new Vector3(-22f, 20f, 0f);
|
||||
}
|
||||
if (overlayID == 0)
|
||||
{
|
||||
previewOverlay.gameObject.SetActive(value: false);
|
||||
previewOverlay.sprite = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
previewOverlay.sprite = Resources.Load<Sprite>("icons/overlays/overlay_" + overlayID);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class Leaderboard : MonoBehaviour
|
||||
{
|
||||
public Canvas canvas;
|
||||
|
||||
public ScrollRect scrollRect;
|
||||
|
||||
public GameObject content;
|
||||
|
||||
public TMP_Dropdown showAmount;
|
||||
|
||||
public TMP_Text statusText;
|
||||
|
||||
public TMP_FontAsset font;
|
||||
|
||||
public Button backButton;
|
||||
|
||||
public Button refreshButton;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
scrollRect.normalizedPosition = new Vector2(0f, 1f);
|
||||
UpdateStatus(enabled: true, "Loading...");
|
||||
StartCoroutine(GetTopPlayers(0));
|
||||
showAmount.onValueChanged.AddListener(delegate (int value)
|
||||
{
|
||||
StartCoroutine(RefreshLeaderboard(value));
|
||||
});
|
||||
backButton.onClick.AddListener(delegate
|
||||
{
|
||||
SceneManager.LoadScene("Menu");
|
||||
});
|
||||
refreshButton.onClick.AddListener(delegate
|
||||
{
|
||||
StartCoroutine(RefreshLeaderboard(showAmount.value));
|
||||
});
|
||||
}
|
||||
|
||||
private IEnumerator RefreshLeaderboard(int value)
|
||||
{
|
||||
int childCount = content.transform.childCount;
|
||||
GameObject[] entries = new GameObject[childCount];
|
||||
for (int i = 0; i < childCount; i++)
|
||||
{
|
||||
entries[i] = content.transform.GetChild(i).gameObject;
|
||||
}
|
||||
yield return StartCoroutine(GetTopPlayers(value));
|
||||
for (int j = 0; j < entries.Length; j++)
|
||||
{
|
||||
UnityEngine.Object.Destroy(entries[j]);
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator GetTopPlayers(int showAmount)
|
||||
{
|
||||
Debug.Log(showAmount);
|
||||
WWWForm wWWForm = new WWWForm();
|
||||
wWWForm.AddField("showAmount", showAmount);
|
||||
using UnityWebRequest request = UnityWebRequest.Post("https://berrydash.lncvrt.xyz/database/getTopPlayers.php", wWWForm);
|
||||
request.SetRequestHeader("User-Agent", "BerryDashClient");
|
||||
request.SetRequestHeader("ClientVersion", "1.33");
|
||||
yield return request.SendWebRequest();
|
||||
if (request.result == UnityWebRequest.Result.Success)
|
||||
{
|
||||
UpdateStatus();
|
||||
string text = request.downloadHandler.text;
|
||||
string[] array = text.Split(new char[1] { ':' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
int num = array.Length / 5;
|
||||
float num2 = 40f;
|
||||
float num3 = 10f;
|
||||
float num4 = content.GetComponent<RectTransform>().rect.height / 2f;
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
GameObject gameObject = new GameObject("Entry_" + i, typeof(RectTransform), typeof(CanvasRenderer));
|
||||
RectTransform component = gameObject.GetComponent<RectTransform>();
|
||||
component.sizeDelta = new Vector2(600f, num2);
|
||||
component.anchoredPosition = new Vector2(0f, num4 - (float)i * (num2 + num3));
|
||||
component.anchorMin = new Vector2(0.5f, 1f);
|
||||
component.anchorMax = new Vector2(0.5f, 1f);
|
||||
component.pivot = new Vector2(0.5f, 1f);
|
||||
GameObject gameObject2 = new GameObject("PlayerName", typeof(RectTransform), typeof(TextMeshProUGUI));
|
||||
GameObject gameObject3 = new GameObject("PlayerIcon", typeof(RectTransform), typeof(Image));
|
||||
GameObject gameObject4 = new GameObject("PlayerIconOverlay", typeof(RectTransform), typeof(Image));
|
||||
GameObject obj = new GameObject("Score", typeof(RectTransform), typeof(TextMeshProUGUI));
|
||||
gameObject2.transform.SetParent(gameObject.transform, worldPositionStays: false);
|
||||
gameObject3.transform.SetParent(gameObject2.transform, worldPositionStays: false);
|
||||
gameObject4.transform.SetParent(gameObject3.transform, worldPositionStays: false);
|
||||
obj.transform.SetParent(gameObject.transform, worldPositionStays: false);
|
||||
Image component2 = gameObject3.GetComponent<Image>();
|
||||
component2.sprite = Resources.Load<Sprite>("icons/icons/bird_" + array[i * 5 + 2]);
|
||||
if (array[i * 5 + 2] == "1")
|
||||
{
|
||||
if (array[i * 5 + 4] == "1")
|
||||
{
|
||||
component2.sprite = Resources.Load<Sprite>("icons/icons/bird_-1");
|
||||
}
|
||||
else if (array[i * 5 + 4] == "2")
|
||||
{
|
||||
component2.sprite = Resources.Load<Sprite>("icons/icons/bird_-2");
|
||||
}
|
||||
else if (array[i * 5 + 4] == "4")
|
||||
{
|
||||
component2.sprite = Resources.Load<Sprite>("icons/icons/bird_-3");
|
||||
}
|
||||
else if (array[i * 5 + 4] == "6")
|
||||
{
|
||||
component2.sprite = Resources.Load<Sprite>("icons/icons/bird_-4");
|
||||
}
|
||||
}
|
||||
component2.rectTransform.sizeDelta = new Vector2(30f, 30f);
|
||||
component2.rectTransform.localScale = new Vector3(-1f, 1f, 1f);
|
||||
component2.rectTransform.anchoredPosition = new Vector2(-125f, 0f);
|
||||
Image component3 = gameObject4.GetComponent<Image>();
|
||||
if (array[i * 5 + 3] == "0")
|
||||
{
|
||||
gameObject4.SetActive(value: false);
|
||||
}
|
||||
if (array[i * 5 + 3] == "8")
|
||||
{
|
||||
component3.rectTransform.anchoredPosition = new Vector2(-8.25f, 7.5f);
|
||||
}
|
||||
else
|
||||
{
|
||||
component3.rectTransform.anchoredPosition = new Vector2(-7.125f, 10.5f);
|
||||
}
|
||||
component3.rectTransform.sizeDelta = new Vector2(13.125f, 5.625f);
|
||||
component3.sprite = Resources.Load<Sprite>("icons/overlays/overlay_" + array[i * 5 + 3]);
|
||||
TextMeshProUGUI component4 = gameObject2.GetComponent<TextMeshProUGUI>();
|
||||
component4.text = array[i * 5] + " (#" + (i + 1) + ")";
|
||||
component4.font = font;
|
||||
component4.fontSize = 14f;
|
||||
component4.alignment = TextAlignmentOptions.Left;
|
||||
component4.rectTransform.sizeDelta = new Vector2(200f, 75f);
|
||||
component4.rectTransform.anchoredPosition = new Vector2(-35f, 0f);
|
||||
TextMeshProUGUI component5 = obj.GetComponent<TextMeshProUGUI>();
|
||||
component5.text = "Score: " + array[i * 5 + 1];
|
||||
component5.font = font;
|
||||
component5.fontSize = 14f;
|
||||
component5.alignment = TextAlignmentOptions.Right;
|
||||
component5.rectTransform.sizeDelta = new Vector2(200f, 75f);
|
||||
component5.rectTransform.anchoredPosition = new Vector2(65f, 0f);
|
||||
gameObject.transform.SetParent(content.transform, worldPositionStays: false);
|
||||
}
|
||||
RectTransform component6 = content.GetComponent<RectTransform>();
|
||||
component6.sizeDelta = new Vector2(component6.sizeDelta.x, (float)num * (num2 + num3));
|
||||
yield break;
|
||||
}
|
||||
UpdateStatus(enabled: true, "Failed to fetch leaderboard stats");
|
||||
foreach (Transform item in content.transform)
|
||||
{
|
||||
UnityEngine.Object.Destroy(item.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateStatus(bool enabled = false, string message = "")
|
||||
{
|
||||
statusText.gameObject.SetActive(enabled);
|
||||
statusText.text = message;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class Loading : MonoBehaviour
|
||||
{
|
||||
public float clientVersion;
|
||||
|
||||
public TMP_Text statusText;
|
||||
|
||||
public Button updateButton;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
QualitySettings.vSyncCount = PlayerPrefs.GetInt("Setting5", 1);
|
||||
Screen.fullScreen = PlayerPrefs.GetInt("Setting1", 1) == 1;
|
||||
if (!Application.isMobilePlatform)
|
||||
{
|
||||
SetIfNone("Setting1", 1);
|
||||
SetIfNone("Setting2", 0);
|
||||
SetIfNone("Setting3", 0);
|
||||
SetIfNone("Setting4", 0);
|
||||
SetIfNone("Setting5", 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetIfNone("Setting1", 1, overrideValue: true);
|
||||
SetIfNone("Setting2", 1, overrideValue: true);
|
||||
SetIfNone("Setting3", 0);
|
||||
SetIfNone("Setting4", 0);
|
||||
SetIfNone("Setting5", 1, overrideValue: true);
|
||||
}
|
||||
PlayerPrefs.SetFloat("latestVersion", clientVersion);
|
||||
SceneManager.LoadScene("Menu");
|
||||
}
|
||||
|
||||
private void SetIfNone(string key, int value, bool overrideValue = false)
|
||||
{
|
||||
if (!PlayerPrefs.HasKey(key) || overrideValue)
|
||||
{
|
||||
PlayerPrefs.SetInt(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class Menu : MonoBehaviour
|
||||
{
|
||||
public Button exitBtn;
|
||||
|
||||
public Button playBtn;
|
||||
|
||||
public Button settingsBtn;
|
||||
|
||||
public Button accountBtn;
|
||||
|
||||
public Button leaderboardBtn;
|
||||
|
||||
public Button iconkitButton;
|
||||
|
||||
public GameObject valueModifier;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Cursor.visible = true;
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
if (PlayerPrefs.GetInt("secretSetting1", 0) == 1)
|
||||
{
|
||||
valueModifier.SetActive(value: true);
|
||||
}
|
||||
if (Application.isMobilePlatform)
|
||||
{
|
||||
exitBtn.gameObject.SetActive(value: false);
|
||||
}
|
||||
exitBtn.onClick.AddListener(delegate
|
||||
{
|
||||
Application.Quit();
|
||||
});
|
||||
playBtn.onClick.AddListener(delegate
|
||||
{
|
||||
SceneManager.LoadScene("Game");
|
||||
});
|
||||
settingsBtn.onClick.AddListener(delegate
|
||||
{
|
||||
SceneManager.LoadScene("Settings");
|
||||
});
|
||||
accountBtn.onClick.AddListener(delegate
|
||||
{
|
||||
SceneManager.LoadScene("Account");
|
||||
});
|
||||
leaderboardBtn.onClick.AddListener(delegate
|
||||
{
|
||||
SceneManager.LoadScene("Leaderboard");
|
||||
});
|
||||
iconkitButton.onClick.AddListener(delegate
|
||||
{
|
||||
SceneManager.LoadScene("Iconkit");
|
||||
});
|
||||
PlayerPrefs.SetInt("icon", Mathf.Clamp(PlayerPrefs.GetInt("icon", 0), 1, 8));
|
||||
PlayerPrefs.SetInt("overlay", Mathf.Clamp(PlayerPrefs.GetInt("overlay", 0), 0, 9));
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class PauseMenu : MonoBehaviour
|
||||
{
|
||||
public GameObject pausePanel;
|
||||
|
||||
public Button menuButton;
|
||||
|
||||
public Button playButton;
|
||||
|
||||
public AudioSource backgroundMusic;
|
||||
|
||||
public Slider musicSlider;
|
||||
|
||||
public Slider sfxSlider;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
menuButton.onClick.AddListener(MenuClick);
|
||||
playButton.onClick.AddListener(TogglePause);
|
||||
musicSlider.onValueChanged.AddListener(UpdateMusicVolume);
|
||||
sfxSlider.onValueChanged.AddListener(UpdateSFXVolume);
|
||||
musicSlider.value = PlayerPrefs.GetFloat("musicVolume", 1f);
|
||||
sfxSlider.value = PlayerPrefs.GetFloat("sfxVolume", 1f);
|
||||
}
|
||||
|
||||
private void TogglePause()
|
||||
{
|
||||
Cursor.visible = false;
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
backgroundMusic.Play();
|
||||
pausePanel.SetActive(value: false);
|
||||
}
|
||||
|
||||
private void MenuClick()
|
||||
{
|
||||
SceneManager.LoadScene("Menu");
|
||||
}
|
||||
|
||||
private void UpdateMusicVolume(float volume)
|
||||
{
|
||||
PlayerPrefs.SetFloat("musicVolume", volume);
|
||||
PlayerPrefs.Save();
|
||||
backgroundMusic.volume = volume;
|
||||
}
|
||||
|
||||
private void UpdateSFXVolume(float volume)
|
||||
{
|
||||
PlayerPrefs.SetFloat("sfxVolume", volume);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class Settings : MonoBehaviour
|
||||
{
|
||||
public Toggle setting1toggle;
|
||||
|
||||
public Toggle setting2toggle;
|
||||
|
||||
public Toggle setting3toggle;
|
||||
|
||||
public Toggle setting4toggle;
|
||||
|
||||
public Toggle setting5toggle;
|
||||
|
||||
public Toggle setting1secrettoggle;
|
||||
|
||||
public Button backbutton;
|
||||
|
||||
public Slider musicSlider;
|
||||
|
||||
public Slider sfxSlider;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
musicSlider.value = PlayerPrefs.GetFloat("musicVolume", 1f);
|
||||
sfxSlider.value = PlayerPrefs.GetFloat("sfxVolume", 1f);
|
||||
if (!Application.isMobilePlatform)
|
||||
{
|
||||
setting1toggle.isOn = PlayerPrefs.GetInt("Setting1", 1) == 1;
|
||||
setting2toggle.isOn = PlayerPrefs.GetInt("Setting2", 0) == 1;
|
||||
setting3toggle.isOn = PlayerPrefs.GetInt("Setting3", 0) == 1;
|
||||
setting4toggle.isOn = PlayerPrefs.GetInt("Setting4", 0) == 1;
|
||||
setting5toggle.isOn = PlayerPrefs.GetInt("Setting5", 1) == 1;
|
||||
setting3toggle.interactable = PlayerPrefs.GetInt("Setting2", 0) == 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
setting1toggle.isOn = true;
|
||||
setting2toggle.isOn = true;
|
||||
setting3toggle.isOn = PlayerPrefs.GetInt("Setting3", 0) == 1;
|
||||
setting4toggle.isOn = PlayerPrefs.GetInt("Setting4", 0) == 1;
|
||||
setting5toggle.isOn = true;
|
||||
setting1toggle.interactable = false;
|
||||
setting2toggle.interactable = false;
|
||||
setting5toggle.interactable = false;
|
||||
}
|
||||
setting1secrettoggle.isOn = PlayerPrefs.GetInt("secretSetting1", 0) == 1;
|
||||
setting1secrettoggle.gameObject.SetActive(PlayerPrefs.GetInt("userID", 0) == 1);
|
||||
backbutton.onClick.AddListener(delegate
|
||||
{
|
||||
SceneManager.LoadScene("Menu");
|
||||
});
|
||||
setting1toggle.onValueChanged.AddListener(delegate
|
||||
{
|
||||
Screen.fullScreen = setting1toggle.isOn;
|
||||
PlayerPrefs.SetInt("Setting1", setting1toggle.isOn ? 1 : 0);
|
||||
});
|
||||
setting2toggle.onValueChanged.AddListener(delegate
|
||||
{
|
||||
PlayerPrefs.SetInt("Setting2", setting2toggle.isOn ? 1 : 0);
|
||||
setting3toggle.interactable = setting2toggle.isOn;
|
||||
setting3toggle.isOn = setting2toggle.isOn && setting3toggle.isOn;
|
||||
PlayerPrefs.SetInt("Setting3", setting3toggle.isOn ? 1 : 0);
|
||||
});
|
||||
setting3toggle.onValueChanged.AddListener(delegate
|
||||
{
|
||||
PlayerPrefs.SetInt("Setting3", setting3toggle.isOn ? 1 : 0);
|
||||
});
|
||||
setting4toggle.onValueChanged.AddListener(delegate
|
||||
{
|
||||
PlayerPrefs.SetInt("Setting4", setting4toggle.isOn ? 1 : 0);
|
||||
});
|
||||
setting5toggle.onValueChanged.AddListener(delegate
|
||||
{
|
||||
PlayerPrefs.SetInt("Setting5", setting5toggle.isOn ? 1 : 0);
|
||||
QualitySettings.vSyncCount = (setting5toggle.isOn ? 1 : 0);
|
||||
});
|
||||
setting1secrettoggle.onValueChanged.AddListener(delegate
|
||||
{
|
||||
PlayerPrefs.SetInt("secretSetting1", setting1secrettoggle.isOn ? 1 : 0);
|
||||
});
|
||||
musicSlider.onValueChanged.AddListener(delegate
|
||||
{
|
||||
PlayerPrefs.SetFloat("musicVolume", musicSlider.value);
|
||||
PlayerPrefs.Save();
|
||||
});
|
||||
sfxSlider.onValueChanged.AddListener(delegate
|
||||
{
|
||||
PlayerPrefs.SetFloat("sfxVolume", sfxSlider.value);
|
||||
PlayerPrefs.Save();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ValueMod : MonoBehaviour
|
||||
{
|
||||
public TMP_InputField ValueToMod;
|
||||
|
||||
public TMP_InputField Value;
|
||||
|
||||
public TMP_Dropdown ModType;
|
||||
|
||||
public Button submit;
|
||||
|
||||
private int modType;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
ValueToMod.onValueChanged.AddListener(delegate
|
||||
{
|
||||
ValueToModInput();
|
||||
});
|
||||
ModType.onValueChanged.AddListener(delegate
|
||||
{
|
||||
modType = ModType.value;
|
||||
ValueToModInput();
|
||||
});
|
||||
submit.onClick.AddListener(delegate
|
||||
{
|
||||
string text = ValueToMod.text;
|
||||
if (modType == 0)
|
||||
{
|
||||
PlayerPrefs.SetString(text, Value.text);
|
||||
}
|
||||
else if (modType == 1)
|
||||
{
|
||||
PlayerPrefs.SetFloat(text, float.Parse(Value.text));
|
||||
}
|
||||
else if (modType == 2)
|
||||
{
|
||||
PlayerPrefs.SetInt(text, int.Parse(Value.text));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void ValueToModInput()
|
||||
{
|
||||
string text = ValueToMod.text;
|
||||
if (modType == 0)
|
||||
{
|
||||
Value.text = PlayerPrefs.GetString(text, "");
|
||||
}
|
||||
else if (modType == 1)
|
||||
{
|
||||
Value.text = PlayerPrefs.GetFloat(text, 0f).ToString();
|
||||
}
|
||||
else if (modType == 2)
|
||||
{
|
||||
Value.text = PlayerPrefs.GetInt(text, 0).ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user