From 2f5f25d0bddb449e569c9223f70bde65a9d2fe17 Mon Sep 17 00:00:00 2001 From: klappstuhl24 Date: Sat, 6 Apr 2024 20:02:57 +0200 Subject: [PATCH] Mehr reden --- 3d Prototyp/Assets/Scripts/Developer.cs | 60 +++++++++++++------ 3d Prototyp/Assets/Scripts/DeveloperNeeds.cs | 2 +- 3d Prototyp/Assets/Scripts/Text2Speech.cs | 19 ++++++ .../Assets/Scripts/Utility/GoodVoices.txt | 10 ++++ .../Scripts/Utility/GoodVoices.txt.meta | 7 +++ .../Scripts/Utility/WantedConsumable.cs | 31 ++++++++++ .../Scripts/Utility/WantedConsumable.cs.meta | 11 ++++ 7 files changed, 120 insertions(+), 20 deletions(-) create mode 100644 3d Prototyp/Assets/Scripts/Utility/GoodVoices.txt create mode 100644 3d Prototyp/Assets/Scripts/Utility/GoodVoices.txt.meta create mode 100644 3d Prototyp/Assets/Scripts/Utility/WantedConsumable.cs create mode 100644 3d Prototyp/Assets/Scripts/Utility/WantedConsumable.cs.meta diff --git a/3d Prototyp/Assets/Scripts/Developer.cs b/3d Prototyp/Assets/Scripts/Developer.cs index 9e577ab5..543fe054 100644 --- a/3d Prototyp/Assets/Scripts/Developer.cs +++ b/3d Prototyp/Assets/Scripts/Developer.cs @@ -93,17 +93,6 @@ public class Developer : MonoBehaviour public double CurrentEfficiency => _currentEfficiency; public string Name => _name; - - [Serializable, Flags] - public enum WantedConsumable - { - None, - Food = 0x01, - Drink = 0x02, - Coffee = Drink | 0x04, - Mate = Drink | 0x08, - Pizza = Food | 0x10 - } [SerializeField] private GameObject _caffeineNeed; @@ -122,6 +111,8 @@ public class Developer : MonoBehaviour private float _talkPauseTime = 15.0f; [SerializeField, ShowOnly] private float _talkTimer; + private bool _hasTalkedWhileHyperactive = false; + private bool _hasTalkedWhileOvercaffeinated = false; private List _needList = new List(); @@ -191,9 +182,15 @@ public class Developer : MonoBehaviour { // TODO: Wie wäre es damit, das nicht fest zu coden? if (drinkType == _wantedDrink) + { + Talk($"The Devolper thanks Gottfried for the {drinkType.GetAsString()}"); _happiness += 0.2; + } else + { + Talk($"The Devolper blames Gottfried for bringing {drinkType.GetAsString()} but he actaully wanted a {_wantedDrink.GetAsString()}"); _happiness -= 0.2; + } } else { @@ -217,6 +214,7 @@ public class Developer : MonoBehaviour _needList.Remove(_hungerNeed); NeedFullfilled(_hungerNeed); _hungerNeed = null; + Talk("The Developer thanks Gottfried for the Pizza"); } if (_wantedFood != WantedConsumable.None) @@ -249,6 +247,7 @@ public class Developer : MonoBehaviour _needList.Remove(_toiletNeed); NeedFullfilled(_toiletNeed); _toiletNeed = null; + Talk("The Developer finally can go to the toilet"); } if (onToilet) @@ -269,10 +268,10 @@ public class Developer : MonoBehaviour _urgeToUrinateLevel = Math.Max(_urgeToUrinateLevel, 0.0); _happiness = Math.Max(_happiness, 0.0); - _isHyperactive = _caffeineLevel > 1.0; + _isHyperactive = _caffeineLevel > 1.0 && _caffeineLevel <= 1.5; _isOvercaffeinated = _caffeineLevel > 1.5; _isSleeping = _caffeineLevel <= 0.0; - + if (_caffeineLevel < GameManager.Instance.NeedNotificationThreshold && _caffeineNeed == null) { // TODO: Wir können hier anhand von Präferenz gewichten. @@ -351,13 +350,33 @@ public class Developer : MonoBehaviour if (_isSleeping) return 0.0; - // Die Formel hat schon recht vielversprechendes Verhalten im Bereich > 1 - //if (_isHyperactive) - // return 1.0 + (_caffeineLevel - 1.0) * (_caffeineLevel - 1.0); + if (_isHyperactive) + { + if (!_hasTalkedWhileHyperactive) + { + Talk("The Developer is surprisingly productive right now duo to caffeine"); + _hasTalkedWhileHyperactive = true; + } + } + else + { + _hasTalkedWhileHyperactive = false; + } if (_isOvercaffeinated) + { + if (!_hasTalkedWhileOvercaffeinated) + { + Talk("The Developer drank too much caffeine, The Developer needs a break immediately"); + _hasTalkedWhileOvercaffeinated = true; + } return 0.0; - + } + else + { + _hasTalkedWhileOvercaffeinated = false; + } + // https://easings.net/#easeOutCubic return 1.0 - Math.Pow(1.0 - _caffeineLevel, 3.0); } @@ -423,9 +442,12 @@ public class Developer : MonoBehaviour /// /// Dev starts talking. /// - public void Talk() + public void Talk(string context = null) { - string context = GameManager.Instance.GetContextAsString(); + if (context == null) + { + context = GameManager.Instance.GetContextAsString(); + } if (!_audioSource.isPlaying) { GetComponent().Generate(context); diff --git a/3d Prototyp/Assets/Scripts/DeveloperNeeds.cs b/3d Prototyp/Assets/Scripts/DeveloperNeeds.cs index 4d087633..c0d89483 100644 --- a/3d Prototyp/Assets/Scripts/DeveloperNeeds.cs +++ b/3d Prototyp/Assets/Scripts/DeveloperNeeds.cs @@ -49,7 +49,7 @@ public class DeveloperNeeds : MonoBehaviour break; case "toilet": spawnedNeed = Instantiate(Needs[2], new Vector3(0.0f, 2f + (numNeeds * 0.5f), 0.0f), Needs[0].transform.rotation); - context = "The Developer wants to go to the toilet, toilet is clogged and dirty"; + context = "The Developer wants to go to the toilet"; break; case "hunger": spawnedNeed = Instantiate(Needs[3], new Vector3(0.0f, 2f + (numNeeds * 0.5f), 0.0f), Needs[0].transform.rotation); diff --git a/3d Prototyp/Assets/Scripts/Text2Speech.cs b/3d Prototyp/Assets/Scripts/Text2Speech.cs index 50095cb6..d0c60f19 100644 --- a/3d Prototyp/Assets/Scripts/Text2Speech.cs +++ b/3d Prototyp/Assets/Scripts/Text2Speech.cs @@ -11,6 +11,7 @@ using OpenAI_API.Models; using System.Threading.Tasks; using Newtonsoft.Json.Linq; using System.Collections.Generic; +using Google.Cloud.TextToSpeech.V1; [Serializable] public class TextToSpeechResponse @@ -21,12 +22,22 @@ public class TextToSpeechResponse public class Text2Speech : MonoBehaviour { + [SerializeField] public string context = "going for a walk, falling, explosion, blood"; + [SerializeField] public string gender = "MALE"; + [SerializeField] public JToken voice = null; + [SerializeField] public double speakingSpeed = 1.1; + [SerializeField] public bool playSound = false; + [SerializeField] public bool generate = false; + [SerializeField] + public bool newVoiceAndGenerate = false; + [SerializeField] + public string Voice; private AudioSource _audioSource; @@ -60,6 +71,7 @@ public class Text2Speech : MonoBehaviour { GetRandomGermanVoice(gender, (v) => { voice = v; + Voice = voice.ToString(); //Debug.Log($"GoogleCloud: Choosen voice is\n{voice}"); StartCoroutine(GenerateAndSynthesizeText(context)); }); @@ -69,6 +81,13 @@ public class Text2Speech : MonoBehaviour StartCoroutine(GenerateAndSynthesizeText(context)); } } + if (newVoiceAndGenerate) + { + newVoiceAndGenerate = false; + voice = null; + Voice = null; + generate = true; + } } public void Generate(string c) diff --git a/3d Prototyp/Assets/Scripts/Utility/GoodVoices.txt b/3d Prototyp/Assets/Scripts/Utility/GoodVoices.txt new file mode 100644 index 00000000..b172982d --- /dev/null +++ b/3d Prototyp/Assets/Scripts/Utility/GoodVoices.txt @@ -0,0 +1,10 @@ +{ + "languageCodes": [ + "en-AU" + ], + "name": "en-AU-News-G", + "ssmlGender": "MALE", + "naturalSampleRateHertz": 24000, + "pitch": -2 +} + diff --git a/3d Prototyp/Assets/Scripts/Utility/GoodVoices.txt.meta b/3d Prototyp/Assets/Scripts/Utility/GoodVoices.txt.meta new file mode 100644 index 00000000..bc17d056 --- /dev/null +++ b/3d Prototyp/Assets/Scripts/Utility/GoodVoices.txt.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 23e2a6475b913ee4b8746739f66bccfe +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/3d Prototyp/Assets/Scripts/Utility/WantedConsumable.cs b/3d Prototyp/Assets/Scripts/Utility/WantedConsumable.cs new file mode 100644 index 00000000..b17a28a0 --- /dev/null +++ b/3d Prototyp/Assets/Scripts/Utility/WantedConsumable.cs @@ -0,0 +1,31 @@ +using System; + +namespace Utility +{ + [Serializable, Flags] + public enum WantedConsumable + { + None, + Food = 0x01, + Drink = 0x02, + Coffee = Drink | 0x04, + Mate = Drink | 0x08, + Pizza = Food | 0x10 + } + + public static class WantedConsumableExtension + { + + public static string GetAsString(this WantedConsumable wantedConsumable) => + wantedConsumable switch + { + WantedConsumable.None => "None", + WantedConsumable.Food => "Food", + WantedConsumable.Drink => "Drink", + WantedConsumable.Coffee => "Coffee", + WantedConsumable.Mate => "Blub Mate", + WantedConsumable.Pizza => "Pizza", + _ => "" + }; + } +} \ No newline at end of file diff --git a/3d Prototyp/Assets/Scripts/Utility/WantedConsumable.cs.meta b/3d Prototyp/Assets/Scripts/Utility/WantedConsumable.cs.meta new file mode 100644 index 00000000..453ca6ea --- /dev/null +++ b/3d Prototyp/Assets/Scripts/Utility/WantedConsumable.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7aa5732bd4e078f4aafd3188c4976d5c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: