Skip to content
Snippets Groups Projects
Commit b2afe575 authored by Tim Gaefgen's avatar Tim Gaefgen
Browse files

Merge branch 'main' of gitlab.uni-koblenz.de:sjanski/SARSCollosseum

parents a6c4be1b 657621c1
No related branches found
No related tags found
No related merge requests found
Showing
with 28101 additions and 0 deletions
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class HighscoreTable : MonoBehaviour
{
private Transform entryContainer;
private Transform entryTemplate;
private List<HighscoreEntry> highscoreEntryList;
private List<Transform> highscoreEntryTransformList;
private void Awake()
{
//entryContainer = transform.Find("highscoreEntryContainer");
//entryTemplate = transform.Find("highscoreEntryTemplate");
entryContainer = GameObject.Find("highscoreEntryContainer").transform;
entryTemplate = GameObject.Find("highscoreEntryTemplate").transform;
entryTemplate.gameObject.SetActive(false);
highscoreEntryList = new List<HighscoreEntry>()
{
new HighscoreEntry{score = 53628, name = "AAA"},
new HighscoreEntry{score = 27843, name = "JOE"},
new HighscoreEntry{score = 26283, name = "MIA"},
new HighscoreEntry{score = 23913, name = "LIO"},
new HighscoreEntry{score = 34937, name = "NIO"},
new HighscoreEntry{score = 89236, name = "RIO"},
new HighscoreEntry{score = 81263, name = "FILO"},
new HighscoreEntry{score = 73641, name = "TOM"},
new HighscoreEntry{score = 13782, name = "RON"},
};
/*
AddHighscoreEntry(10000, "BBB");
string jsonString = PlayerPrefs.GetString("highscoreTable");
Highscores highscores = JsonUtility.FromJson<Highscores>(jsonString);
for (int i = 0; i < highscores.highscoreEntryList.Count; i++)
{
for (int j = i+1; j < highscores.highscoreEntryList.Count; j++)
{
if (highscores.highscoreEntryList[j].score > highscores.highscoreEntryList[i].score)
{
HighscoreEntry tmp = highscores.highscoreEntryList[i];
highscores.highscoreEntryList[i] = highscores.highscoreEntryList[j];
highscores.highscoreEntryList[j] = tmp;
}
}
}*/
highscoreEntryTransformList = new List<Transform>();
foreach (HighscoreEntry highscoreEntry in highscoreEntryList)
{
CreateHighscoreEntryTransform(highscoreEntry, entryContainer, highscoreEntryTransformList);
}
}
private void CreateHighscoreEntryTransform (HighscoreEntry highscoreEntry, Transform container, List<Transform> transformList)
{
float templateHeight = 30f;
Transform entryTransform = Instantiate(entryTemplate, container);
RectTransform entryRectTransform = entryTransform.GetComponent<RectTransform>();
entryRectTransform.anchoredPosition = new Vector2(0, -templateHeight * transformList.Count);
entryTransform.gameObject.SetActive(true);
int rank = transformList.Count +1;
string rankString;
switch(rank)
{
default:
rankString = rank + "TH";
break;
case 1:
rankString = "1ST";
break;
case 2:
rankString = "2ND";
break;
case 3:
rankString = "3RD";
break;
}
//entryTemplate = GameObject.Find("highscoreEntryTemplate").transform;
GameObject.Find("PosText").GetComponent<Text>().text = rankString;
//entryTransform.Find("PosText").GetComponent<Text>().text = rankString;
int score = highscoreEntry.score;
//entryTransform.Find("ScoreText").GetComponent<Text>().text = score.ToString();
GameObject.Find("ScoreText").GetComponent<Text>().text = score.ToString();
string name = highscoreEntry.name;
GameObject.Find("NameText").GetComponent<Text>().text = name;
//entryTransform.Find("background").gameObject.SetActive(rank % 2 == 1);
/*
if (rank == 1)
{
entryTransform.Find("NameText").GetComponent<Text>().color = Color.green;
}*/
transformList.Add(entryTransform);
}
/*
private void AddHighscoreEntry(int score, string name)
{
HighscoreEntry highscoreEntry = new HighscoreEntry{score = score, name = name};
string jsonString = PlayerPrefs.GetString("highscoreTable");
Highscores highscores = JsonUtility.FromJson<Highscores>(jsonString);
highscores.highscoreEntryList.Add(highscoreEntry);
string json = JsonUtility.ToJson(highscores);
PlayerPrefs.SetString("highscoreTable", json);
PlayerPrefs.Save();
}
private class Highscores
{
public List<HighscoreEntry> highscoreEntryList;
}*/
[System.Serializable]
private class HighscoreEntry
{
public int score;
public string name;
}
}
fileFormatVersion: 2
guid: 28b3712f58c20264f8d31fd34f4d4172
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class MainMenu : MonoBehaviour
{
public Animator anim;
public void Start()
{
anim = GetComponent<Animator>();
}
public void PlayGame()
{
SceneManager.LoadScene("PlayScreeen");
}
/*
public void Confetti()
{
scoreUI
}
/*
public void ShowHighscore()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex+3);
}
*/
public void QuitGame()
{
Debug.Log("QUIT");
Application.Quit();
}
public void EnterMainMenu()
{
SceneManager.LoadScene("MainMenuUI");
}
public void EnterName()
{
SceneManager.LoadScene("NameScreen");
}
public void Back()
{
SceneManager.LoadScene("MainMenuUI");
}
public void GameOver()
{
SceneManager.LoadScene("GameOver");
anim.SetTrigger("gameOver");
}
}
fileFormatVersion: 2
guid: 8e7d86d4eeb517f4ca0e240f7df69853
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
public class RowUI : MonoBehaviour
{
public Text rank;
public Text name;
public Text score;
public Text wave;
}
fileFormatVersion: 2
guid: 071fbc7d247b0ff4d83121a6fe389688
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Saving : MonoBehaviour
{
public InputField inputText;
public Text OutText;
string nameText;
void Start()
{
nameText = PlayerPrefs.GetString("SAVE");
inputText.text = nameText;
}
public void SaveThis()
{
nameText = inputText.text;
PlayerPrefs.SetString("SAVE", nameText);
}
public void SetGet()
{
OutText.text = inputText.text;
}
}
fileFormatVersion: 2
guid: ebc39febca8e6a842bd5c0733bfc05a4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[SerializeField]
public class Score
{
public string name;
public float score;
public int wave;
public Score(string name, float score, int wave)
{
this.name = name;
this.score = score;
this.wave = wave;
}
}
fileFormatVersion: 2
guid: 3cb219097580be74cbbd5d579926a899
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[SerializeField]
public class ScoreData
{
public List<Score> scores;
public ScoreData()
{
scores = new List<Score>();
}
}
fileFormatVersion: 2
guid: b7c065af85e6c20478941001a19d307c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class ScoreManager : MonoBehaviour
{
private ScoreData sd;
void Awake()
{
var json = PlayerPrefs.GetString("scores", "{}");
sd = JsonUtility.FromJson<ScoreData>(json);
}
public IEnumerable<Score> GetHighScores()
{
return sd.scores.OrderByDescending(x => x.score);
}
public void AddScore (Score score)
{
sd.scores.Add(score);
}
public void OnDestroy()
{
SaveScore();
}
public void SaveScore()
{
var json = JsonUtility.ToJson(sd);
Debug.Log(json);
PlayerPrefs.SetString("scores", json);
}
}
fileFormatVersion: 2
guid: f3685354834fdc6408a2403f0baa3ef6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
public class ScoreUI : MonoBehaviour
{
public RowUI rowUI;
public ScoreManager scoreManager;
public Animator anim;
public ParticleSystem ps1;
public ParticleSystem ps2;
public ParticleSystem ps3;
public InputField input;
void Start()
{
anim = GetComponent<Animator>();
ps1.gameObject.SetActive(false);
ps2.gameObject.SetActive(false);
ps3.gameObject.SetActive(false);
scoreManager.AddScore(new Score(name: "A", score: 60000, wave: 5));
scoreManager.AddScore(new Score(name: "B", score: 50000, wave: 4));
scoreManager.AddScore(new Score(name: "C", score: 40000, wave: 3));
scoreManager.AddScore(new Score(name: "D", score: 30000, wave: 3));
scoreManager.AddScore(new Score(name: "E", score: 20000, wave: 3));
scoreManager.AddScore(new Score(name: "F", score: 10000, wave: 3));
scoreManager.AddScore(new Score(name: "G", score: 9000, wave: 2));
scoreManager.AddScore(new Score(name: "H", score: 8000, wave: 2));
scoreManager.AddScore(new Score(name: "I", score: 7000, wave: 2));
var scores = scoreManager.GetHighScores().ToArray();
string pos;
for (int i = 0; i < scores.Length; i++)
{
if (i > 15)
{
break;
}
var row = Instantiate(rowUI, transform).GetComponent<RowUI>();
if (i == 0)
{
pos = "st";
anim.SetTrigger("First");
//if (row.name.text == input.text)
//{
ps1.gameObject.SetActive(true);
ps1.Play();
//}
}
else if (i == 1)
{
pos = "nd";
anim.SetTrigger("Second");
if (row.name.text == input.text)
{
ps2.gameObject.SetActive(true);
}
}
else if (i == 2)
{
pos = "rd";
anim.SetTrigger("Third");
if (row.name.text == input.text)
{
ps3.gameObject.SetActive(true);
}
}
else
{
pos = "th";
}
row.rank.text = (i+1).ToString() + pos;
row.name.text = scores[i].name;
row.score.text = scores[i].score.ToString();
row.wave.text = scores[i].wave.ToString();
}
}
}
fileFormatVersion: 2
guid: 6dca01fc634eb8848b441dc46e9d8afa
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
fileFormatVersion: 2
guid: 5a2f1ca329591624e8f5afeebda0e2f7
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
fileFormatVersion: 2
guid: 0e1e9e7099040d249956d3c1b3a79863
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment