Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| wiki:menu_scripts_code [2022/08/01 16:05] – [RankingSystem.cs] admin | wiki:menu_scripts_code [2022/08/04 11:05] (current) – removed admin | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | {{ : | ||
| - | |||
| - | ====== PasswordChange.cs ====== | ||
| - | |||
| - | <code CSharp | Full Script> | ||
| - | using System.Collections; | ||
| - | using System.Collections.Generic; | ||
| - | using UnityEngine; | ||
| - | using UnityEngine.Networking; | ||
| - | using TMPro; | ||
| - | |||
| - | public class PasswordChange : MonoBehaviour | ||
| - | { | ||
| - | public TMP_InputField current_password; | ||
| - | public TMP_InputField new_password; | ||
| - | public TMP_InputField new_password_confirm; | ||
| - | public TextMeshProUGUI username; | ||
| - | |||
| - | public PopUpSystem popUp; | ||
| - | |||
| - | public void ButtonChangePassword() | ||
| - | { | ||
| - | if (new_password.text != new_password_confirm.text) | ||
| - | { | ||
| - | popUp.OpenPopUp(" | ||
| - | return; | ||
| - | } | ||
| - | |||
| - | if (new_password.text.Length <= 6) | ||
| - | { | ||
| - | popUp.OpenPopUp(" | ||
| - | } | ||
| - | |||
| - | if (current_password.text == "" | ||
| - | { | ||
| - | popUp.OpenPopUp(" | ||
| - | return; | ||
| - | } | ||
| - | |||
| - | StartCoroutine(Upload()); | ||
| - | } | ||
| - | |||
| - | IEnumerator Upload() | ||
| - | { | ||
| - | WWWForm form = new WWWForm(); | ||
| - | form.AddField(" | ||
| - | form.AddField(" | ||
| - | form.AddField(" | ||
| - | |||
| - | using (UnityWebRequest www = UnityWebRequest.Post(" | ||
| - | { | ||
| - | yield return www.SendWebRequest(); | ||
| - | |||
| - | if (www.result != UnityWebRequest.Result.Success) | ||
| - | { | ||
| - | Debug.Log(www.error); | ||
| - | } | ||
| - | else | ||
| - | { | ||
| - | if(www.downloadHandler.text.Equals(" | ||
| - | { | ||
| - | popUp.OpenPopUp(" | ||
| - | } | ||
| - | |||
| - | if (www.downloadHandler.text.Equals(" | ||
| - | { | ||
| - | popUp.OpenPopUp(" | ||
| - | |||
| - | } | ||
| - | |||
| - | if (www.downloadHandler.text.Equals(" | ||
| - | { | ||
| - | popUp.OpenPopUp(" | ||
| - | } | ||
| - | |||
| - | Debug.Log(www.downloadHandler.text); | ||
| - | |||
| - | } | ||
| - | } | ||
| - | } | ||
| - | } | ||
| - | |||
| - | </ | ||
| - | |||
| - | <file | public void ButtonChangePassword() > | ||
| - | Client side password checker. | ||
| - | </ | ||
| - | |||
| - | <file | IEnumerator Upload() > | ||
| - | Upload password into database and check error. | ||
| - | </ | ||
| - | ====== RankingSystem.cs ====== | ||
| - | |||
| - | <code CSharp | Full Script> | ||
| - | using Sirenix.OdinInspector; | ||
| - | using System.Collections; | ||
| - | using System.Collections.Generic; | ||
| - | using TMPro; | ||
| - | using UnityEngine; | ||
| - | |||
| - | public class RankingSystem : MonoBehaviour | ||
| - | { | ||
| - | public GameObject RankParent; | ||
| - | public GameObject rankFirst; | ||
| - | public GameObject rankSecond; | ||
| - | public GameObject rankThird; | ||
| - | public GameObject rankNorm; | ||
| - | public GameObject scoreUI; | ||
| - | |||
| - | public SandBoxRequestPHP sandBoxRequestPHP; | ||
| - | |||
| - | bool toggleRankingList = true; | ||
| - | |||
| - | [Button] | ||
| - | public void ButtonOpenRankingList() | ||
| - | { | ||
| - | scoreUI.SetActive(true); | ||
| - | |||
| - | if (toggleRankingList == false) return; | ||
| - | toggleRankingList = false; | ||
| - | var playerlist = sandBoxRequestPHP.getPlayerList(); | ||
| - | |||
| - | int i = 0; | ||
| - | foreach (var item in playerlist) | ||
| - | { | ||
| - | GameObject newItem; | ||
| - | if (i == 0) | ||
| - | { | ||
| - | newItem = Instantiate(rankFirst, | ||
| - | newItem.transform.SetParent(RankParent.transform); | ||
| - | } | ||
| - | else if (i == 1) | ||
| - | { | ||
| - | newItem = Instantiate(rankSecond, | ||
| - | newItem.transform.SetParent(RankParent.transform); | ||
| - | } | ||
| - | else if (i == 2) | ||
| - | { | ||
| - | newItem = Instantiate(rankThird, | ||
| - | newItem.transform.SetParent(RankParent.transform); | ||
| - | } | ||
| - | else | ||
| - | { | ||
| - | newItem = Instantiate(rankNorm, | ||
| - | newItem.transform.SetParent(RankParent.transform); | ||
| - | } | ||
| - | |||
| - | |||
| - | try | ||
| - | { | ||
| - | var split = item.Split(':' | ||
| - | |||
| - | newItem.transform.Find(" | ||
| - | newItem.transform.Find(" | ||
| - | |||
| - | if (i >= 3) newItem.transform.Find(" | ||
| - | } | ||
| - | catch (System.Exception) | ||
| - | { | ||
| - | Destroy(newItem); | ||
| - | // | ||
| - | } | ||
| - | |||
| - | i++; | ||
| - | } | ||
| - | |||
| - | } | ||
| - | |||
| - | } | ||
| - | |||
| - | |||
| - | </ | ||
| - | |||
| - | <file | public void ButtonOpenRankingList() > | ||
| - | When button clicked it with fetch all the player list String convert it example name: | ||
| - | iterate through all the users | ||
| - | instantiate object for ever iteration and assign it | ||
| - | due to the list already sort it self by player score in sQL query so we will not sort it here all done in server side.. | ||
| - | </ | ||
| - | |||