Browse Source

basic level select screen

A
Josh 2 years ago
parent
commit
0caaecbcfb
  1. 2
      namedropper/Assets/Resources/categories.yaml
  2. 1050
      namedropper/Assets/Scenes/CategorySelect.unity
  3. 7
      namedropper/Assets/Scenes/CategorySelect.unity.meta
  4. 73
      namedropper/Assets/Scripts/Game.cs
  5. 51
      namedropper/Assets/Scripts/GameDataManager.cs
  6. 11
      namedropper/Assets/Scripts/GameDataManager.cs.meta
  7. 17
      namedropper/Assets/Scripts/Player.cs
  8. 21
      namedropper/Assets/Scripts/TopicBox.cs
  9. 11
      namedropper/Assets/Scripts/TopicBox.cs.meta
  10. 37
      namedropper/Assets/Scripts/TopicSelect.cs
  11. 11
      namedropper/Assets/Scripts/TopicSelect.cs.meta
  12. 10
      namedropper/ProjectSettings/EditorBuildSettings.asset

2
namedropper/Assets/Resources/categories.yaml

@ -268,7 +268,7 @@ Topics:
- Juice - Juice
- Good as Hell - Good as Hell
- Rumors - Rumors
- Topic: Videogames Characters - Topic: Videogame Characters
Categories: Categories:
- Category: Super Mario Bros. - Category: Super Mario Bros.
Elements: Elements:

1050
namedropper/Assets/Scenes/CategorySelect.unity

File diff suppressed because it is too large

7
namedropper/Assets/Scenes/CategorySelect.unity.meta

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 91a4af9a6af9fc840b522128085513da
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

73
namedropper/Assets/Scripts/Game.cs

@ -1,8 +1,6 @@
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using System.IO;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
public class Game : MonoBehaviour public class Game : MonoBehaviour
@ -14,27 +12,15 @@ public class Game : MonoBehaviour
[SerializeField] Text RedScoreCounter; [SerializeField] Text RedScoreCounter;
Category[] _categories; Category[] _categories;
GameData _gameData = new GameData();
// Start is called before the first frame update // Start is called before the first frame update
void Awake() void Awake()
{ {
Deserializer deserializer = new Deserializer();
string yamlText = File.ReadAllText(Application.dataPath + "/Resources/categories.yaml");
_gameData = deserializer.Deserialize<GameData>(yamlText);
_categories = FindObjectsOfType<Category>(); _categories = FindObjectsOfType<Category>();
int topicIndex = Random.Range(0, _gameData.Topics.Count);
TopicData topicData = _gameData.Topics[topicIndex];
_gameData.Topics.RemoveAt(topicIndex);
foreach (Category category in _categories) foreach (Category category in _categories)
{ {
int categoryIndex = Random.Range(0, topicData.Categories.Count); CategoryData categoryData = GameDataManager.Instance.GetRandomCategoryData(GameDataManager.Instance.CurrentTopic);
CategoryData categoryData = topicData.Categories[categoryIndex];
topicData.Categories.RemoveAt(categoryIndex);
category.Name = categoryData.Category; category.Name = categoryData.Category;
category.Elements = categoryData.Elements; category.Elements = categoryData.Elements;
@ -42,61 +28,6 @@ public class Game : MonoBehaviour
} }
} }
/*
void OldUnusedDataGenerator()
{
TopicData td = new TopicData();
td.Topic = "TV";
CategoryData cd = new CategoryData();
cd.Category = "White Lotus";
cd.Elements.Add("Tanya");
cd.Elements.Add("Portia");
td.Categories.Add(cd);
cd = new CategoryData();
cd.Category = "SNL";
cd.Elements.Add("Pete");
cd.Elements.Add("Josh");
td.Categories.Add(cd);
_gameData.Data.Add(td);
//
td = new TopicData();
td.Topic = "Hip Hop";
cd = new CategoryData();
cd.Category = "Biggie";
cd.Elements.Add("Ready to Die");
cd.Elements.Add("Juicy");
td.Categories.Add(cd);
cd = new CategoryData();
cd.Category = "Pac";
cd.Elements.Add("All Eyez");
cd.Elements.Add("HIt Em Up");
td.Categories.Add(cd);
_gameData.Data.Add(td);
var serializer = new SerializerBuilder()
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.Build();
string yaml = serializer.Serialize(_gameData);
Debug.Log("Game data: " + yaml);
string json = JsonUtility.ToJson(_gameData, true);
Debug.Log("Game data: " + json);
File.WriteAllText(Application.persistentDataPath + "/categories.json", json);
File.WriteAllText(Application.persistentDataPath + "/categories.yaml", yaml);
}
*/
private void Start() private void Start()
{ {
UpdateScores(); UpdateScores();

51
namedropper/Assets/Scripts/GameDataManager.cs

@ -0,0 +1,51 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
using System.IO;
public class GameDataManager {
private static GameDataManager _instance = null;
GameData _gameData = new GameData();
TopicData _currentTopic = null;
public GameDataManager() {
Deserializer deserializer = new Deserializer();
string yamlText = File.ReadAllText(Application.dataPath + "/Resources/categories.yaml");
_gameData = deserializer.Deserialize<GameData>(yamlText);
}
public TopicData GetRandomTopicData()
{
int topicIndex = Random.Range(0, _gameData.Topics.Count);
TopicData topicData = _gameData.Topics[topicIndex];
_gameData.Topics.RemoveAt(topicIndex);
return topicData;
}
public CategoryData GetRandomCategoryData(TopicData topicData)
{
int categoryIndex = Random.Range(0, topicData.Categories.Count);
CategoryData categoryData = topicData.Categories[categoryIndex];
topicData.Categories.RemoveAt(categoryIndex);
return categoryData;
}
public static GameDataManager Instance
{
get
{
if (_instance == null)
{
_instance =new GameDataManager();
}
return _instance;
}
}
public TopicData CurrentTopic { get => _currentTopic; set => _currentTopic = value; }
}

11
namedropper/Assets/Scripts/GameDataManager.cs.meta

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 24a77fac7c75b804da62577166dfd0a4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

17
namedropper/Assets/Scripts/Player.cs

@ -2,10 +2,10 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class Player : MonoBehaviour public class Player : MonoBehaviour
{ {
const float SPEED = 1200f; const float SPEED = 1500f;
[SerializeField] KeyCode _keyLeft; [SerializeField] KeyCode _keyLeft;
[SerializeField] KeyCode _keyRight; [SerializeField] KeyCode _keyRight;
[SerializeField] KeyCode _keyDown; [SerializeField] KeyCode _keyDown;
@ -44,8 +44,8 @@ public class Player : MonoBehaviour
{ {
Category category = collision.gameObject.GetComponent<Category>(); Category category = collision.gameObject.GetComponent<Category>();
if (category == null) if (category != null)
return; {
if (category.Elements.Contains(_text.text)) if (category.Elements.Contains(_text.text))
{ {
@ -61,6 +61,15 @@ public class Player : MonoBehaviour
PickNewWord(); PickNewWord();
} }
TopicBox topicBox = collision.gameObject.GetComponent<TopicBox>();
if (topicBox != null)
{
GameDataManager.Instance.CurrentTopic = topicBox.TopicData;
SceneManager.LoadScene("Game");
}
}
// Update is called once per frame // Update is called once per frame
void Update() void Update()
{ {

21
namedropper/Assets/Scripts/TopicBox.cs

@ -0,0 +1,21 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class TopicBox : MonoBehaviour
{
public string Name;
public TopicData TopicData;
// Start is called before the first frame update
void Start()
{
transform.Find("Text").GetComponent<Text>().text = Name;
}
// Update is called once per frame
void Update()
{
}
}

11
namedropper/Assets/Scripts/TopicBox.cs.meta

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ae3cf3ee1d381b544985a421e4ecbc64
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

37
namedropper/Assets/Scripts/TopicSelect.cs

@ -0,0 +1,37 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class TopicSelect : MonoBehaviour
{
[SerializeField] TopicBox _topic1Box;
[SerializeField] TopicBox _topic2Box;
[SerializeField] Text _title;
int round = 1;
// Start is called before the first frame update
void Awake()
{
InitRound();
}
void InitRound()
{
_title.text = "Round " + round + "\nPick a Topic!";
_topic1Box.TopicData = GameDataManager.Instance.GetRandomTopicData();
_topic2Box.TopicData = GameDataManager.Instance.GetRandomTopicData();
_topic1Box.Name = _topic1Box.TopicData.Topic;
_topic2Box.Name = _topic2Box.TopicData.Topic;
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.R))
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}
}

11
namedropper/Assets/Scripts/TopicSelect.cs.meta

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0a576bc4a288add46aa64939a69432e5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

10
namedropper/ProjectSettings/EditorBuildSettings.asset

@ -5,7 +5,13 @@ EditorBuildSettings:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
serializedVersion: 2 serializedVersion: 2
m_Scenes: m_Scenes:
- enabled: 0
path:
guid: 00000000000000000000000000000000
- enabled: 1 - enabled: 1
path: Assets/Scenes/SampleScene.unity path: Assets/Scenes/CategorySelect.unity
guid: 2cda990e2423bbf4892e6590ba056729 guid: 91a4af9a6af9fc840b522128085513da
- enabled: 1
path: Assets/Scenes/Game.unity
guid: fc389e04780671f498562f1d56f81afb
m_configObjects: {} m_configObjects: {}

Loading…
Cancel
Save