// initialization when collection scene is loaded void Start() { PopUp.GetInstance().ShowPopUp("Collection", false); // hide popup if (CollectionNumber > 0) { if (CollectionNumber < 7) { GameObject content = GameObject.Find("CollectionA"); CollectionName = content.transform.Find("Collection" + CollectionNumber + "/CollectionName").GetComponent <Text>(); } else { GameObject content = GameObject.Find("CollectionB"); CollectionName = content.transform.Find("Collection" + CollectionNumber + "/CollectionName").GetComponent <Text>(); } // check collection is opened if (Collection.GetInstance().Opened(CollectionNumber)) { CollectionName.text = Collection.GetInstance().GetString("name", CollectionNumber); // if opened, get collection name CollectionButton.interactable = true; } else // if not opened, collection button is inactivated, and collection name is also unknown { CollectionName.text = "???"; } } buttonClick = GameObject.Find("ButtonClickSound").GetComponent <AudioSource>(); }
private string answer = string.Empty; // string variable which stores answer(Yes / No) async void Start() { if (SceneManager.GetActiveScene().name == "PrologueScene") { Button skipButton = GameObject.Find("SkipButton").GetComponent <Button>(); // close all popups PopUp.GetInstance().ShowPopUp("Prologue", false); PopUp.GetInstance().ShowPopUp("Answer", false); PopUp.GetInstance().ShowPopUp("GameStart", false); // when language setting needed, set language if (GameSettings.GetInstance().GetLanguage() == string.Empty) { PopUp.GetInstance().ShowPopUp("Language", true); skipButton.interactable = false; // since language setting is mendatory, skip is not permitted during language setting while (GameSettings.GetInstance().GetLanguage() == string.Empty) { await Task.Delay(300); } } // open prologue popup PopUp.GetInstance().ShowPopUp("Language", false); skipButton.interactable = true; PopUp.GetInstance().ShowPopUp("Prologue", true); // Get script according to language this.script = GetScript("prologue", GameSettings.GetInstance().GetLanguage()); this.length = this.script.Length; // Show prologue script await ShowScript(); } }
// On cancel button , close bug popup public void OnCancelButtonClick() { buttonClick = GameObject.Find("ButtonClickSound").GetComponent <AudioSource>(); buttonClick.Play(); Debug.Log("Cancel Button Click"); PopUp.GetInstance().ShowPopUp("Bug", false); }
// on language popup close button click, hide popup public void OnLanguagePopUpCloseButtonClick() { buttonClick = GameObject.Find("ButtonClickSound").GetComponent <AudioSource>(); buttonClick.Play(); Debug.Log("Language PopUp Close button clicked!"); PopUp.GetInstance().ShowPopUp("Language", false); }
// on language setting button click, show gamesetting popup public void OnGameSettingsButtonClick() { buttonClick = GameObject.Find("ButtonClickSound").GetComponent <AudioSource>(); buttonClick.Play(); Debug.Log("GameSettings button clicked!"); PopUp.GetInstance().ShowPopUp("GameSettings", true); }
// when ok button in popup window is clicked public void OnOKButtonClick() { buttonClick.Play(); Debug.Log("OK Button Click"); // hide popup PopUp.GetInstance().ShowPopUp("Collection", false); }
// on ending popup click, reset clover information public void OnEndingPopUpResetClick() { buttonClick = GameObject.Find("ButtonClickSound").GetComponent <AudioSource>(); buttonClick.Play(); CloverDirector.GetInstance().Reset(); CloverDirector.GetInstance().endingPopupOn = false; PopUp.GetInstance().ShowPopUp("Ending", false); }
// on All reset button click, close setting popup and reset clover and collection data public void OnAllResetButtonClick() { buttonClick = GameObject.Find("ButtonClickSound").GetComponent <AudioSource>(); buttonClick.Play(); Debug.Log("All Reset button clicked!"); PopUp.GetInstance().ShowPopUp("GameSettings", false); CloverDirector.GetInstance().Reset(); Collection.GetInstance().Reset(); }
// On english button click, set language to english, and set collection script into english and close language popup public void OnEnglishButtonClick() { buttonClick = GameObject.Find("ButtonClickSound").GetComponent <AudioSource>(); buttonClick.Play(); Debug.Log("English Button Click"); GameSettings.GetInstance().SetLanguage("eng"); Collection.GetInstance().SetScript(); PopUp.GetInstance().ShowPopUp("Language", false); }
// when collection button is clicked public void OnCollectionButtonClick() { buttonClick.Play(); Debug.Log("Click Collection Button " + CollectionNumber); // show popup PopUp.GetInstance().ShowPopUp("Collection", true); // the window text is changed to collection information PopUp.GetInstance().FindText("Collection").text = Collection.GetInstance().GetString("info", CollectionNumber); PopUp.GetInstance().FindImage("Collection").sprite = Collection.GetInstance().GetImage(CollectionNumber); }
// on tutorial button click, show tutorial popup and load first text // text depends on language public void OnTutorialButtonClick() { buttonClick = GameObject.Find("ButtonClickSound").GetComponent <AudioSource>(); buttonClick.Play(); Debug.Log("Tutorial button clicked!"); PopUp.GetInstance().ShowPopUp("Tutorial", true); tutorialScripts = Prologue.GetInstance().GetScript("tutorial", GameSettings.GetInstance().GetLanguage()); this.length = tutorialScripts.Length; currentLine = 0; string T_mark = "<Text>"; PopUp.GetInstance().FindText("Tutorial").text = tutorialScripts[currentLine].Substring(T_mark.Length); }
// Check if clover met any of ending conditions // If ending conditions are met, load EndingPopUp and reset clover public void CheckEnding() { int ending_number = 0; if (GetStat("water") <= 0) { //thirsty print("Died of thirst"); ending_number = 1; } else if (GetStat("water") >= 100) { //drown print("Drown"); ending_number = 2; } else if (GetStat("sun") <= 0) { //too cold print("Freezed"); ending_number = 3; } else if (GetStat("sun") >= 100) { //too hot print("Dried"); ending_number = 4; } else if (GetStat("level") == 6) { //survived successfully print("Congratulations!"); ending_number = 5; } if (ending_number > 0) { // EndingDirector.GetInstance().EndingFunctionOn(false); // random event ending off UpdateStats(); WeatherFunctionOn(false); // weather change off CloverDirector.GetInstance().endingPopupOn = true; SetBugID(-1); // bug timer off Debug.Log("Ending : " + ending_number); PopUp.GetInstance().FindText("Ending").text = Collection.GetInstance().GetString("info", ending_number); PopUp.GetInstance().FindImage("Ending").sprite = Collection.GetInstance().GetImage(ending_number); PopUp.GetInstance().ShowPopUp("Ending", true); Collection.GetInstance().SetOpened(ending_number); } }
// on tutorial next button click, if tutorial script is not last line, load next line of script public void OnTutorialNextButtonClick() { buttonClick = GameObject.Find("ButtonClickSound").GetComponent <AudioSource>(); buttonClick.Play(); Debug.Log("Tutorial Next button clicked!"); if (currentLine < this.length - 1) { string T_mark = "<Text>"; currentLine += 1; PopUp.GetInstance().FindText("Tutorial").text = tutorialScripts[currentLine].Substring(T_mark.Length); } else { Debug.Log("Can't get next script"); } }
// If clover can generate molecules, set random bugID // Close bug popup public void OnGenerateMoleculeButtonClick() { buttonClick = GameObject.Find("ButtonClickSound").GetComponent <AudioSource>(); buttonClick.Play(); Debug.Log("Generate Molecule Button Click"); // code for molecule generation bool canGenerate = CloverDirector.GetInstance().GetStat("energy") > energy_convert_ratio; canGenerate = canGenerate && CloverDirector.GetInstance().GetBugID() == -1; if (canGenerate) { Debug.Log("use energy to generate molecule"); CloverDirector.GetInstance().SetStat("energy", -energy_convert_ratio); int RandomBug = (int)Random.Range(0, 4); // 0~3 CloverDirector.GetInstance().SetBugID(RandomBug); } PopUp.GetInstance().ShowPopUp("Bug", false); }
// Initialize clover data and corresponding UIs // And show name pop up to restart public async void Reset() { myClover.c_level = 1; myClover.c_sun_stat = 50; myClover.c_water_stat = 50; myClover.c_energy_stat = 20; myClover.c_name = string.Empty; myClover.c_weather_ID = 0; myClover.c_energy_requirement = 100; SetBugID(-1); SetBugTime(60); await Task.Run(SetData); UpdateStats(); BugTimer.Getbugtimer().UpdateBugTimer(-1); WeatherFunctionOn(false); await PopUp.GetInstance().ShowNamePopUp(); Debug.Log("Reset!"); }
// Makes CloverDirector DontDestroyOnLoad async void Awake() { if (SceneManager.GetActiveScene().name == "GameScene") { // If clover doesn't have name on GameScene, make NamePopUp if (myClover.c_name == string.Empty) { Debug.Log("name is null"); await PopUp.GetInstance().ShowNamePopUp(); } } CloverDirector.GetInstance().weatherRunning = false; // Initialize weatherRunning variable //DontDestroyOnLoad if (myCloverDirector == null) { DontDestroyOnLoad(gameObject); myCloverDirector = this; } else if (myCloverDirector != this) { Destroy(gameObject); } }
// Generate random ending event void RandomEnding() { // Probability of random ending(unit : %) int chickenProbability = 10; int rabbitProbability = 10; int horseProbability = 10; int mowerProbability = 10; int tornadoProbability = 10; int aphidProbability = 10; int boyProbability = 10; float[] endingProbabilities = new float[7]; endingProbabilities[0] = chickenProbability; endingProbabilities[1] = endingProbabilities[0] + rabbitProbability; endingProbabilities[2] = endingProbabilities[1] + horseProbability; endingProbabilities[3] = endingProbabilities[2] + mowerProbability; endingProbabilities[4] = endingProbabilities[3] + tornadoProbability; endingProbabilities[5] = endingProbabilities[4] + aphidProbability; endingProbabilities[6] = endingProbabilities[5] + boyProbability; int ending = (int)Random.Range(0, 100); int ending_number = 0; if (ending < endingProbabilities[0]) { print("Chicken Ending"); ending_number = 6; } else if (ending < endingProbabilities[1]) { print("Rabbit Ending"); ending_number = 7; } else if (ending < endingProbabilities[2]) { print("Horse Ending"); ending_number = 8; } else if (ending < endingProbabilities[3]) { print("Lawn mower Ending"); ending_number = 9; } else if (ending < endingProbabilities[4]) { print("Tornado Ending"); ending_number = 10; } else if (ending < endingProbabilities[5] && CloverDirector.GetInstance().GetBugID() == 3) { print("Aphid Ending"); ending_number = 11; } else if (ending < endingProbabilities[6]) { print("Boy Ending"); ending_number = 12; } if (ending_number > 0) { EndingFunctionOn(false); // random event ending off CloverDirector.GetInstance().endingPopupOn = true; CloverDirector.GetInstance().WeatherFunctionOn(false); // weather change off CloverDirector.GetInstance().SetBugID(-1); // bug timer off Debug.Log("Ending : " + ending_number); PopUp.GetInstance().FindText("Ending").text = Collection.GetInstance().GetString("info", ending_number); PopUp.GetInstance().FindImage("Ending").sprite = Collection.GetInstance().GetImage(ending_number); PopUp.GetInstance().ShowPopUp("Ending", true); Collection.GetInstance().SetOpened(ending_number); } }
public void OnSubmitButtonClicked() { buttonClick.Play(); PopUp.GetInstance().SetName(); }
// Task which Shows prologue script private async Task ShowScript() { // our text files are splited into line by line, which has a mark at the beginning of sentence // there are 4 marks in here string T_mark = "<Text>"; // common script mark string Q_mark = "<Q>"; // question mark string Y_mark = "<Yes>"; // yes mark string N_mark = "<No>"; // no mark while (needAnswer == false) { // if this script is first script, hide prev button if (current_script == 0) { Debug.Log("prev button false"); PopUp.GetInstance().ShowButton("Prev", false); } else { Debug.Log("prev button true"); PopUp.GetInstance().ShowButton("Prev", true); } if (this.script[current_script].StartsWith(T_mark, false, null)) // if this script is not question { PopUp.GetInstance().FindText("Prologue").text = this.script[current_script].Substring(T_mark.Length); } else if (this.script[current_script].StartsWith(Q_mark, false, null)) // if this script is question { needAnswer = true; PopUp.GetInstance().ShowPopUp("Prologue", false); // close prologue popup PopUp.GetInstance().ShowPopUp("Answer", true); // open answer popup PopUp.GetInstance().FindText("Answer").text = this.script[current_script].Substring(Q_mark.Length); } await Task.Delay(100); } // question answer handling while (answer == string.Empty) { await Task.Delay(100); } current_script++; // after get answer, show gamestart popup PopUp.GetInstance().ShowPopUp("Answer", false); PopUp.GetInstance().ShowPopUp("GameStart", true); // current script differs according to answer if (answer == Y_mark) { while (current_script < length && !this.script[current_script].StartsWith(Y_mark, false, null)) { current_script++; } PopUp.GetInstance().ShowButton("Quit", false); } else if (answer == N_mark) { while (current_script < length && !this.script[current_script].StartsWith(N_mark, false, null)) { current_script++; } } else { Debug.Log("invalid answer"); } // Set Popup text PopUp.GetInstance().FindText("GameStart").text = this.script[current_script].Substring(answer.Length); }