Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using System.IO;
- using System.Linq;
- public class Main_Controller : MonoBehaviour
- {
- //Toggles
- [Header("TOGGLES")]
- public Toggle _ObjectToggle;
- public Toggle _QualityObjectToggle;
- public Toggle _QualityPlaceToggle;
- public Toggle _PlaceToggle;
- public Toggle _ZoneToggle;
- public Toggle _DesignToggle;
- //Container for objects
- public List<string> _Objects;
- public List<string> _Qualities;
- public List<string> _Places;
- public List<string> _PlacesQualities;
- public List<string> _Design;
- public List<string> _Zones;
- //Display the Objects
- public Text _ObjectBox;
- protected StreamReader _ObjectReader = null;
- protected StreamReader _QualityReader = null;
- protected StreamReader _PlacesQualityReader = null;
- protected StreamReader _PlaceReader = null;
- protected StreamReader _DesignReader = null;
- protected StreamReader _ZoneReader = null;
- private int _ObjectsCount;
- private int _QualityCount;
- private int _PlaceCount;
- private int _DesignCount;
- private int _ZoneCount;
- private int _placesQualityCount;
- // Start is called before the first frame update
- void Start()
- {
- _ObjectReader = new StreamReader("Assets/TextSource/Objects.txt");
- _ObjectsCount = File.ReadAllLines(@"Assets/TextSource/Objects.txt").Length;
- _QualityReader = new StreamReader("Assets/TextSource/Qualities.txt");
- _QualityCount = File.ReadAllLines(@"Assets/TextSource/Qualities.txt").Length;
- _PlaceReader = new StreamReader("Assets/TextSource/Places.txt");
- _PlaceCount = File.ReadAllLines(@"Assets/TextSource/Places.txt").Length;
- _DesignReader = new StreamReader("Assets/TextSource/Design.txt");
- _DesignCount = File.ReadAllLines(@"Assets/TextSource/Design.txt").Length;
- _ZoneReader = new StreamReader("Assets/TextSource/Zones.txt");
- _ZoneCount = File.ReadAllLines(@"Assets/TextSource/Zones.txt").Length;
- _PlacesQualityReader = new StreamReader("Assets/TextSource/PlaceQualities.txt");
- _placesQualityCount = File.ReadAllLines(@"Assets/TextSource/PlaceQualities.txt").Length;
- for (int i = 0; i < _ObjectsCount; i++)
- {
- _Objects.Add(_ObjectReader.ReadLine());
- }
- for (int i = 0; i < _QualityCount; i++)
- {
- _Qualities.Add(_QualityReader.ReadLine());
- }
- for (int i = 0; i < _PlaceCount; i++)
- {
- _Places.Add(_PlaceReader.ReadLine());
- }
- for (int i = 0; i < _DesignCount; i++)
- {
- _Design.Add(_DesignReader.ReadLine());
- }
- for (int i = 0; i < _ZoneCount; i++)
- {
- _Zones.Add(_ZoneReader.ReadLine());
- }
- for (int i = 0; i < _placesQualityCount; i++)
- {
- _PlacesQualities.Add(_PlacesQualityReader.ReadLine());
- }
- }
- // Update is called once per frame
- void Update()
- {
- if(Input.GetKeyDown(KeyCode.Escape))
- {
- QuitApplication();
- }
- }
- public void Generate()
- {
- _ObjectBox.text = "";
- //Adds a quality to object
- //adds object
- if (_ObjectToggle.isOn)
- {
- string text;
- if (_QualityObjectToggle.isOn)
- {
- text = _Qualities[Random.Range(0, _QualityCount - 1)];
- if (StartWithVowel(text))
- {
- _ObjectBox.text += "An ";
- }
- else
- {
- _ObjectBox.text += "A ";
- }
- _ObjectBox.text += text;
- _ObjectBox.text += " ";
- _ObjectBox.text += _Objects[Random.Range(0, _ObjectsCount - 1)];
- }
- else
- {
- text = _Objects[Random.Range(0, _QualityCount - 1)];
- if (StartWithVowel(text))
- {
- _ObjectBox.text += "An ";
- }
- else
- {
- _ObjectBox.text += "A ";
- }
- _ObjectBox.text += text;
- }
- }
- if (_ObjectToggle.isOn && _PlaceToggle.isOn)
- {
- _ObjectBox.text += " found in ";
- }
- //adds place
- if (_PlaceToggle.isOn)
- {
- string text;
- if (_QualityPlaceToggle.isOn)
- {
- text = _PlacesQualities[Random.Range(0, _placesQualityCount - 1)];
- if (StartWithVowel(text))
- {
- _ObjectBox.text += "An ";
- }
- else
- {
- _ObjectBox.text += "A ";
- }
- _ObjectBox.text += text;
- _ObjectBox.text += " ";
- _ObjectBox.text += _Places[Random.Range(0, _PlaceCount - 1)];
- }
- else
- {
- text = _Places[Random.Range(0, _PlaceCount - 1)];
- if (StartWithVowel(text))
- {
- _ObjectBox.text += "An ";
- }
- else
- {
- _ObjectBox.text += "A ";
- }
- _ObjectBox.text += text;
- }
- if(_ZoneToggle.isOn)
- {
- _ObjectBox.text += " located ";
- _ObjectBox.text += _Zones[Random.Range(0, _ZoneCount - 1)];
- }
- }
- if (_DesignToggle.isOn)
- {
- string text;
- _ObjectBox.text += ".\n Inspired by ";
- text = _Design[Random.Range(0, _DesignCount - 1)];
- if (StartWithVowel(text))
- {
- _ObjectBox.text += "an ";
- }
- else
- {
- _ObjectBox.text += "a ";
- }
- _ObjectBox.text += text;
- }
- }
- private bool StartWithVowel(string word)
- {
- char[] initial;
- initial = word.ToCharArray();
- if (initial[0] == 'A' || initial[0] == 'E' || initial[0] == 'I' || initial[0] == 'O' || initial[0] == 'U')
- {
- return true;
- }
- else return false;
- }
- public void QuitApplication()
- {
- Application.Quit();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement