/// <summary> /// Opens the entered leaderboard /// </summary> /// <param name="Board"></param> public void OpenLeaderboard(LeaderboardGroup Board) { if (movingRoutine == null) { LoadLeaderboard(Board); if (SelectView.gameObject.activeInHierarchy) { movingRoutine = StartCoroutine(Replacing(SelectView, LeaderboardView)); } else { movingRoutine = StartCoroutine(Opening(LeaderboardView)); } } }
/// <summary> /// Copies a old leaderboardgroup, without setting a name /// </summary> /// <param name="old"></param> public LeaderboardGroup(LeaderboardGroup old = null) { if (old != null) { EnableAllTime = old.EnableAllTime; AllTime = new Leaderboard(old.AllTime.Limit); EnableWeekly = old.EnableWeekly; Weekly = new Leaderboard(old.Weekly.Limit); EnableDaily = old.EnableDaily; Daily = new Leaderboard(old.Daily.Limit); } else { AllTime = new Leaderboard(); Weekly = new Leaderboard(); Daily = new Leaderboard(); } }
/// <summary> /// Loads the select menu /// </summary> void LoadSelect() { Transform par = SelectView.GetComponentInChildren <VerticalLayoutGroup>().transform; for (int i = par.childCount - 1; i >= 0; i--) { Destroy(par.GetChild(i).gameObject); } for (int i = 0; i < LBM.Leaderboards.Count; i++) { GameObject go = Instantiate(SelectedStyle.Prefab_Button, par); LeaderboardGroup lb = LBM.Leaderboards[i]; go.GetComponentInChildren <Text>().text = lb.Name; go.GetComponentInChildren <Button>().onClick.AddListener(() => OpenLeaderboard(lb)); } Button[] allBut = SelectView.GetComponentsInChildren <Button>(true); allBut[allBut.Length - 1].onClick.AddListener(() => CloseLeaderboard()); }
public void WriteToLeaderboard(LeaderboardGroup leaderboard, float score) => WriteToLeaderboard(leaderboard, playerEntry.Score = score);
/// <summary> /// Removes a leaderboard from the leaderboards list /// </summary> /// <param name="group"></param> public void RemoveLeaderboard(LeaderboardGroup group) => Leaderboards.Remove(group);
public override void OnInspectorGUI() { //bool to show/hide the custom bit custom = EditorGUILayout.ToggleLeft("Custom Inspector", custom); if (custom) { //The players entry EditorGUILayout.Space(); EditorGUILayout.LabelField("Player entry:"); EditorGUILayout.BeginHorizontal(); scr.playerEntry.Name = EditorGUILayout.TextField(scr.playerEntry.Name); scr.playerEntry.Score = EditorGUILayout.FloatField(scr.playerEntry.Score); EditorGUILayout.EndHorizontal(); //Button that sends the current entry to the leaderboard if (GUILayout.Button("Write Entry")) { scr.WriteToLeaderboard(scr.playerEntry); } //Showing the highscore if (scr.playerHigh != null) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Highscore:", GUILayout.Width(125)); EditorGUILayout.LabelField(scr.playerHigh.Name, GUILayout.Width(125)); EditorGUILayout.LabelField(scr.playerHigh.Score.ToString(), GUILayout.Width(125)); EditorGUILayout.EndHorizontal(); } EditorGUILayout.Space(); GUILayout.BeginHorizontal(); setName = EditorGUILayout.TextField(setName, GUILayout.Width(200)); if (GUILayout.Button("Create Leaderboard")) { scr.AddLeaderboard(setName); } GUILayout.EndHorizontal(); for (int i = 0; i < scr.Leaderboards.Count; i++) { LeaderboardGroup lbg = scr.Leaderboards[i]; GUILayout.BeginHorizontal(); lbg.Show = EditorGUILayout.BeginFoldoutHeaderGroup(lbg.Show, lbg.Name); if (GUILayout.Button("Remove Leaderboard", GUILayout.Width(175))) { scr.RemoveLeaderboard(lbg); } GUILayout.EndHorizontal(); if (lbg.Show) { EditorGUI.indentLevel = 1; lbg.Name = EditorGUILayout.TextField("Name:", lbg.Name); EditorGUILayout.Space(); //showing the closest in alltime if (lbg.closestOverall != null) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Closest Overall:", GUILayout.Width(125)); EditorGUILayout.LabelField(lbg.closestOverall.Name, GUILayout.Width(125)); EditorGUILayout.LabelField(lbg.closestOverall.Score.ToString(), GUILayout.Width(125)); EditorGUILayout.EndHorizontal(); } //showing the closest in alltime if (lbg.closestAllTime != null) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Closest Alltime:", GUILayout.Width(125)); EditorGUILayout.LabelField(lbg.closestAllTime.Name, GUILayout.Width(125)); EditorGUILayout.LabelField(lbg.closestAllTime.Score.ToString(), GUILayout.Width(125)); EditorGUILayout.EndHorizontal(); } //showing the closest in weekly if (lbg.closestWeekly != null) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Closest Weekly:", GUILayout.Width(125)); EditorGUILayout.LabelField(lbg.closestWeekly.Name, GUILayout.Width(125)); EditorGUILayout.LabelField(lbg.closestWeekly.Score.ToString(), GUILayout.Width(125)); EditorGUILayout.EndHorizontal(); } //showing the closest in daily if (lbg.closestDaily != null) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Closest Daily:", GUILayout.Width(125)); EditorGUILayout.LabelField(lbg.closestDaily.Name, GUILayout.Width(125)); EditorGUILayout.LabelField(lbg.closestDaily.Score.ToString(), GUILayout.Width(125)); EditorGUILayout.EndHorizontal(); } EditorGUILayout.Space(); //Separating based on if the game is playing, to hide the settings you're not allowed to touch if (!Application.isPlaying) { //Toggeling the leaderboards and showing their specific settings lbg.EnableAllTime = EditorGUILayout.Toggle("Enable AllTime Leaderboard", lbg.EnableAllTime); if (lbg.EnableAllTime) { EditorGUI.indentLevel = 1; lbg.AllTime.Limit = EditorGUILayout.IntField("Alltime limit", lbg.AllTime.Limit); EditorGUI.indentLevel = 0; } lbg.EnableWeekly = EditorGUILayout.Toggle("Enable Weekly Leaderboard", lbg.EnableWeekly); if (lbg.EnableWeekly) { EditorGUI.indentLevel = 1; lbg.Weekly.Limit = EditorGUILayout.IntField("Weekly limit", lbg.Weekly.Limit); EditorGUI.indentLevel = 0; } lbg.EnableDaily = EditorGUILayout.Toggle("Enable Daily Leaderboard", lbg.EnableDaily); if (lbg.EnableDaily) { EditorGUI.indentLevel = 1; lbg.Daily.Limit = EditorGUILayout.IntField("Daily limit", lbg.Daily.Limit); EditorGUI.indentLevel = 0; } } else { //checking if leaderboard is enabled if (lbg.EnableAllTime) { //Basic foldout to allow you to hide it lbg.ShowAllTime = EditorGUILayout.Foldout(lbg.ShowAllTime, "AllTime Leaderboard"); if (lbg.ShowAllTime) { //indent the leaderboard, cause fancy EditorGUI.indentLevel = 1; //The signifier part, EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("nr.", GUILayout.Width(30)); EditorGUILayout.LabelField("Name:", GUILayout.Width(150)); EditorGUILayout.LabelField("Score:", GUILayout.Width(150)); EditorGUILayout.EndHorizontal(); //Scrollarea setup lbg.allScrollPos = EditorGUILayout.BeginScrollView(lbg.allScrollPos, false, false, GUILayout.Height(Mathf.Clamp(21 * lbg.AllTime.Limit, 0, 300)), GUILayout.Width(330)); //going through all leaderboard entries and displaying them for (int k = 0; k < lbg.AllTime.board.Count; k++) { //making the current players highscore green if (scr.playerEntry.ID == lbg.AllTime.board[k].ID) { GUI.contentColor = Color.green; } //horizontaly displaying the entry EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField((k + 1).ToString() + ".", GUILayout.Width(50)); EditorGUILayout.LabelField(lbg.AllTime.board[k].Name, GUILayout.Width(125)); EditorGUILayout.LabelField(lbg.AllTime.board[k].Score.ToString(), GUILayout.Width(125)); EditorGUILayout.EndHorizontal(); //stop being green GUI.contentColor = Color.white; } //scrollarea end EditorGUILayout.EndScrollView(); //stop indent EditorGUI.indentLevel = 0; } EditorGUILayout.EndFoldoutHeaderGroup(); } //same as above, not commenting the samey stuff if (lbg.EnableWeekly) { lbg.ShowWeekly = EditorGUILayout.Foldout(lbg.ShowWeekly, "Weekly Leaderboard"); if (lbg.ShowWeekly) { EditorGUI.indentLevel = 1; EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("nr.", GUILayout.Width(50)); EditorGUILayout.LabelField("Name:", GUILayout.Width(125)); EditorGUILayout.LabelField("Score:", GUILayout.Width(125)); EditorGUILayout.EndHorizontal(); lbg.WeekScrollPos = EditorGUILayout.BeginScrollView(lbg.WeekScrollPos, false, false, GUILayout.Height(Mathf.Clamp(21 * lbg.Weekly.Limit, 0, 300)), GUILayout.Width(330)); for (int k = 0; k < lbg.Weekly.board.Count; k++) { if (scr.playerEntry.ID == lbg.Weekly.board[k].ID) { GUI.contentColor = Color.green; } EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField((k + 1).ToString() + ".", GUILayout.Width(50)); EditorGUILayout.LabelField(lbg.Weekly.board[k].Name, GUILayout.Width(125)); EditorGUILayout.LabelField(lbg.Weekly.board[k].Score.ToString(), GUILayout.Width(125)); EditorGUILayout.EndHorizontal(); GUI.contentColor = Color.white; } EditorGUILayout.EndScrollView(); EditorGUI.indentLevel = 0; } EditorGUILayout.EndFoldoutHeaderGroup(); } //same as above, not commenting the samey stuff if (lbg.EnableDaily) { lbg.ShowDaily = EditorGUILayout.Foldout(lbg.ShowDaily, "Daily Leaderboard"); if (lbg.ShowDaily) { EditorGUI.indentLevel = 1; EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("nr.", GUILayout.Width(50)); EditorGUILayout.LabelField("Name:", GUILayout.Width(125)); EditorGUILayout.LabelField("Score:", GUILayout.Width(125)); EditorGUILayout.EndHorizontal(); lbg.dayScrollPos = EditorGUILayout.BeginScrollView(lbg.dayScrollPos, false, false, GUILayout.Height(Mathf.Clamp(21 * lbg.Daily.Limit, 0, 300)), GUILayout.Width(330)); for (int k = 0; k < lbg.Daily.board.Count; k++) { if (scr.playerEntry.ID == lbg.Daily.board[k].ID) { GUI.contentColor = Color.green; } EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField((k + 1).ToString() + ".", GUILayout.Width(50)); EditorGUILayout.LabelField(lbg.Daily.board[k].Name, GUILayout.Width(125)); EditorGUILayout.LabelField(lbg.Daily.board[k].Score.ToString(), GUILayout.Width(125)); EditorGUILayout.EndHorizontal(); GUI.contentColor = Color.white; } EditorGUILayout.EndScrollView(); EditorGUI.indentLevel = 0; } EditorGUILayout.EndFoldoutHeaderGroup(); } } EditorGUI.indentLevel = 0; } EditorGUILayout.EndFoldoutHeaderGroup(); } if (!Application.isPlaying) { EditorGUILayout.Space(); //The settings foldout, serves to have them separated and hidden when they're not in use settings = EditorGUILayout.BeginFoldoutHeaderGroup(settings, "Settings:"); if (settings) { EditorGUI.indentLevel = 1; EditorGUILayout.HelpBox("Only change these if the leaderboards are empty", MessageType.Info); scr.ReverseScore = EditorGUILayout.Toggle("Reverse boards", scr.ReverseScore); scr.IncludeProductName = EditorGUILayout.Toggle("Include Name", scr.IncludeProductName); scr.IncludeVersion = EditorGUILayout.Toggle("Include version", scr.IncludeVersion); scr.databaseUrl = EditorGUILayout.TextField("Database Url", scr.databaseUrl); EditorGUI.indentLevel = 0; } EditorGUILayout.EndFoldoutHeaderGroup(); } } else { //Show the base if it's not in custom mode EditorGUILayout.Space(); base.OnInspectorGUI(); } //Mark any changes for saving if (GUI.changed) { EditorUtility.SetDirty(scr); } }
/// <summary> /// Finds the closest entry in the sent leaderboard /// </summary> /// <param name="Leaderboard"></param> /// <param name="entry"></param> public void FindClosest(LeaderboardGroup Leaderboard, LeaderboardEntry entry) => Leaderboard.FindClosest(entry);
public void FindClosest(LeaderboardGroup leaderboard, float score) => FindClosest(leaderboard, playerEntry.Score = score);
/// <summary> /// Writes to the selectedLeaderboard, by leaderboard /// </summary> /// <param name="Leaderboard"></param> /// <param name="entry"></param> public void WriteToLeaderboard(LeaderboardGroup Leaderboard, LeaderboardEntry entry) => Leaderboard.WriteToLeaderboard(entry);
/// <summary> /// Loads the leaderboard ui to the specified board /// </summary> /// <param name="Board"></param> void LoadLeaderboard(LeaderboardGroup Board) { OpenGroup = Board; if ((Board.EnableAllTime ? 1 : 0) + (Board.EnableWeekly ? 1 : 0) + (Board.EnableDaily ? 1 : 0) == 1) { if (viewButtonHolder == null) { viewButtonHolder = LeaderboardView.GetComponentInChildren <HorizontalLayoutGroup>().gameObject; } viewButtonHolder.SetActive(false); } else { if (viewButtonHolder == null) { viewButtonHolder = LeaderboardView.GetComponentInChildren <HorizontalLayoutGroup>().gameObject; } viewButtonHolder.SetActive(true); } for (int i = viewButtonHolder.transform.childCount - 1; i >= 0; i--) { Destroy(viewButtonHolder.transform.GetChild(i).gameObject); } if (Board.EnableAllTime) { Button but = Instantiate(SelectedStyle.Prefab_Button, viewButtonHolder.transform).GetComponent <Button>(); but.GetComponentInChildren <Text>().text = SelectedStyle.AllName; but.onClick.AddListener(() => ChangeBoard(0)); but.GetComponent <Image>().color = SelectedStyle.ActiveColor; allBut = but; } if (Board.EnableWeekly) { Button but = Instantiate(SelectedStyle.Prefab_Button, viewButtonHolder.transform).GetComponent <Button>(); but.GetComponentInChildren <Text>().text = SelectedStyle.WeekName; but.onClick.AddListener(() => ChangeBoard(1)); weekBut = but; if (!Board.EnableAllTime) { activeLeaderboard = ActiveBoard.Week; but.GetComponent <Image>().color = SelectedStyle.ActiveColor; } } if (Board.EnableDaily) { Button but = Instantiate(SelectedStyle.Prefab_Button, viewButtonHolder.transform).GetComponent <Button>(); but.GetComponentInChildren <Text>().text = SelectedStyle.DayName; but.onClick.AddListener(() => ChangeBoard(2)); dayBut = but; if (!Board.EnableAllTime && !Board.EnableWeekly) { activeLeaderboard = ActiveBoard.Day; but.GetComponent <Image>().color = SelectedStyle.ActiveColor; } } Button[] allButtons = LeaderboardView.GetComponentsInChildren <Button>(); if (LBM.Leaderboards.Count > 1) { allButtons[allButtons.Length - 1].onClick.AddListener(() => OpenSelect()); allButtons[allButtons.Length - 1].GetComponentInChildren <Text>().text = "Back"; } else { allButtons[allButtons.Length - 1].onClick.AddListener(() => CloseLeaderboard()); allButtons[allButtons.Length - 1].GetComponentInChildren <Text>().text = "Exit"; } ChangeBoard((int)activeLeaderboard); }