diff --git a/3d Prototyp/Assets/Scenes/NPC_Test.unity b/3d Prototyp/Assets/Scenes/NPC_Test.unity index fbcc815c..10baea8b 100644 --- a/3d Prototyp/Assets/Scenes/NPC_Test.unity +++ b/3d Prototyp/Assets/Scenes/NPC_Test.unity @@ -1066,6 +1066,9 @@ PrefabInstance: - targetCorrespondingSourceObject: {fileID: 6540681369557983152, guid: d77999c19b7f3294599d4029e5b08ace, type: 3} insertIndex: -1 addedObject: {fileID: 30470410} + - targetCorrespondingSourceObject: {fileID: 6540681369557983152, guid: d77999c19b7f3294599d4029e5b08ace, type: 3} + insertIndex: -1 + addedObject: {fileID: 30470414} m_SourcePrefab: {fileID: 100100000, guid: d77999c19b7f3294599d4029e5b08ace, type: 3} --- !u!4 &30470408 stripped Transform: @@ -1107,8 +1110,9 @@ MonoBehaviour: _happinessLevel: 100 _baseDevelopementPower: 100 _developementPower: 100 - eventRate: 2 - _deleteManually: 0 + eventRate: 1 + _talk: 0 + _fullfillNeedManually: 0 _timer: 0 _newNeedDelay: 3 _lastTenNeeds: [] @@ -1226,6 +1230,21 @@ AudioSource: m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 +--- !u!114 &30470414 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 21686472} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: a5cc0d7ecd7b47f48b2444cff2eb207d, type: 3} + m_Name: + m_EditorClassIdentifier: + _eventStack: + - What a great day to develope a game! + _maxStackHeight: 5 --- !u!1 &33191261 GameObject: m_ObjectHideFlags: 0 @@ -16403,6 +16422,9 @@ PrefabInstance: - targetCorrespondingSourceObject: {fileID: 6839065564630337043, guid: 950f64c9c1d51e14b84b4e4d4a7b775a, type: 3} insertIndex: -1 addedObject: {fileID: 1077881944} + - targetCorrespondingSourceObject: {fileID: 6839065564630337043, guid: 950f64c9c1d51e14b84b4e4d4a7b775a, type: 3} + insertIndex: -1 + addedObject: {fileID: 1077881948} m_SourcePrefab: {fileID: 100100000, guid: 950f64c9c1d51e14b84b4e4d4a7b775a, type: 3} --- !u!4 &523081034 stripped Transform: @@ -34278,8 +34300,9 @@ MonoBehaviour: _happinessLevel: 100 _baseDevelopementPower: 100 _developementPower: 100 - eventRate: 2 - _deleteManually: 0 + eventRate: 1 + _talk: 0 + _fullfillNeedManually: 0 _timer: 0 _newNeedDelay: 3 _lastTenNeeds: [] @@ -34397,6 +34420,21 @@ AudioSource: m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 +--- !u!114 &1077881948 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1077881942} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: a5cc0d7ecd7b47f48b2444cff2eb207d, type: 3} + m_Name: + m_EditorClassIdentifier: + _eventStack: + - What a great day to develope a game! + _maxStackHeight: 5 --- !u!1 &1083890274 GameObject: m_ObjectHideFlags: 0 @@ -45807,6 +45845,9 @@ PrefabInstance: - targetCorrespondingSourceObject: {fileID: 5436741564957258347, guid: 6c7f06c6a702d4d41bba4b5576adc82c, type: 3} insertIndex: -1 addedObject: {fileID: 1502578690} + - targetCorrespondingSourceObject: {fileID: 5436741564957258347, guid: 6c7f06c6a702d4d41bba4b5576adc82c, type: 3} + insertIndex: -1 + addedObject: {fileID: 1502578692} m_SourcePrefab: {fileID: 100100000, guid: 6c7f06c6a702d4d41bba4b5576adc82c, type: 3} --- !u!4 &1502578684 stripped Transform: @@ -45961,12 +46002,30 @@ MonoBehaviour: _happinessLevel: 100 _baseDevelopementPower: 100 _developementPower: 100 - eventRate: 2 - _deleteManually: 0 + eventRate: 1 + _talk: 1 + _fullfillNeedManually: 0 _timer: 0 _newNeedDelay: 3 _lastTenNeeds: [] HasNeed: 0 +--- !u!114 &1502578692 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 615669723} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: a5cc0d7ecd7b47f48b2444cff2eb207d, type: 3} + m_Name: + m_EditorClassIdentifier: + _eventStack: + - Bugs + - Struggle + - Questioning life + _maxStackHeight: 5 --- !u!1001 &1502597417 PrefabInstance: m_ObjectHideFlags: 0 @@ -65034,6 +65093,9 @@ PrefabInstance: - targetCorrespondingSourceObject: {fileID: 360020996318003118, guid: c161c997c07308740af96a685231f764, type: 3} insertIndex: -1 addedObject: {fileID: 2100999000} + - targetCorrespondingSourceObject: {fileID: 360020996318003118, guid: c161c997c07308740af96a685231f764, type: 3} + insertIndex: -1 + addedObject: {fileID: 2100999004} m_SourcePrefab: {fileID: 100100000, guid: c161c997c07308740af96a685231f764, type: 3} --- !u!4 &2100998998 stripped Transform: @@ -65075,8 +65137,9 @@ MonoBehaviour: _happinessLevel: 100 _baseDevelopementPower: 100 _developementPower: 100 - eventRate: 2 - _deleteManually: 0 + eventRate: 1 + _talk: 0 + _fullfillNeedManually: 0 _timer: 0 _newNeedDelay: 3 _lastTenNeeds: [] @@ -65194,6 +65257,21 @@ AudioSource: m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 +--- !u!114 &2100999004 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 997355948} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: a5cc0d7ecd7b47f48b2444cff2eb207d, type: 3} + m_Name: + m_EditorClassIdentifier: + _eventStack: + - What a great day to develope a game! + _maxStackHeight: 5 --- !u!1 &2101876026 GameObject: m_ObjectHideFlags: 0 diff --git a/3d Prototyp/Assets/Scripts/DeveloperNeeds.cs b/3d Prototyp/Assets/Scripts/DeveloperNeeds.cs index 985d7881..bc40777f 100644 --- a/3d Prototyp/Assets/Scripts/DeveloperNeeds.cs +++ b/3d Prototyp/Assets/Scripts/DeveloperNeeds.cs @@ -7,11 +7,13 @@ public class DeveloperNeeds : MonoBehaviour [SerializeField] List Needs = new List(); private Text2Speech _text2speech; + private AudioSource _audioSource; // Start is called before the first frame update void Start() { _text2speech = GetComponent(); + _audioSource = GetComponent(); } // Update is called once per frame @@ -30,19 +32,19 @@ public class DeveloperNeeds : MonoBehaviour { case "coffee": spawnedNeed = Instantiate(Needs[0], new Vector3(0.0f, 2f, 0.0f), Needs[0].transform.rotation); - context = "Office, The NPC wants coffee"; + context = "The NPC wants coffee"; break; case "mate": spawnedNeed = Instantiate(Needs[1], new Vector3(0.0f, 2f, 0.0f), Needs[0].transform.rotation); - context = "Office, The NPC wants a Club Mate"; + context = "The NPC wants a Club Mate"; break; case "toilet": spawnedNeed = Instantiate(Needs[2], new Vector3(0.0f, 2f, 0.0f), Needs[0].transform.rotation); - context = "Office, The NPC wants to go to the toilet, toilet is clogged and dirty"; + context = "The NPC wants to go to the toilet, toilet is clogged and dirty"; break; case "money": spawnedNeed = Instantiate(Needs[3], new Vector3(0.0f, 2f, 0.0f), Needs[0].transform.rotation); - context = "Office, The NPC wants a raise, The NPC needs more money"; + context = "The NPC wants a raise, The NPC needs more money"; break; default: break; @@ -52,7 +54,10 @@ public class DeveloperNeeds : MonoBehaviour { spawnedNeed.transform.SetParent(transform, false); spawnedNeed.transform.localScale = new Vector3(0.4f, 0.01f, 0.4f); - _text2speech.Generate(context); + if (!_audioSource.isPlaying) + { + _text2speech.Generate(context); + } return spawnedNeed; } return null; diff --git a/3d Prototyp/Assets/Scripts/NPC_Behavior.cs b/3d Prototyp/Assets/Scripts/NPC_Behavior.cs index 748839cd..4ac56626 100644 --- a/3d Prototyp/Assets/Scripts/NPC_Behavior.cs +++ b/3d Prototyp/Assets/Scripts/NPC_Behavior.cs @@ -36,7 +36,11 @@ public class NPC_Behavior : MonoBehaviour public double DevelopmentPower => _developementPower; private GameManager _gameManager; + private NPC_EventStack _eventStack; + private Text2Speech _text2Speech; + private AudioSource _audioSource; + [SerializeField] private bool _talk = false; [SerializeField] private bool _fullfillNeedManually = false; [SerializeField] private float _timer; [SerializeField] private float _newNeedDelay = 3.0f; @@ -62,6 +66,9 @@ public class NPC_Behavior : MonoBehaviour { _gameManager = GameManager.Instance; _developerNeeds = GetComponent(); + _eventStack = GetComponent(); + _text2Speech = GetComponent(); + _audioSource = GetComponent(); ResetTimer(); } @@ -90,6 +97,11 @@ public class NPC_Behavior : MonoBehaviour _fullfillNeedManually = false; NeedFullfilled(); } + if (_talk) + { + _talk = false; + Talk(); + } } private void ResetTimer() @@ -192,4 +204,13 @@ public class NPC_Behavior : MonoBehaviour } } } + + public void Talk() + { + //if (!_audioSource.isPlaying) + //{ + string context = _eventStack.GetEntireContext(); + _text2Speech.Generate(context); + //} + } } diff --git a/3d Prototyp/Assets/Scripts/NPC_EventStack.cs b/3d Prototyp/Assets/Scripts/NPC_EventStack.cs index 1d252c67..1bbeec55 100644 --- a/3d Prototyp/Assets/Scripts/NPC_EventStack.cs +++ b/3d Prototyp/Assets/Scripts/NPC_EventStack.cs @@ -7,6 +7,8 @@ public class NPC_EventStack : MonoBehaviour [SerializeField] private List _eventStack = new List() { "What a great day to develope a game!" }; [SerializeField] private int _maxStackHeight = 5; + private Text2Speech _text2speech; + public void AddNewContext(string context) { _eventStack.Add(context); @@ -34,4 +36,16 @@ public class NPC_EventStack : MonoBehaviour } return null; } + + public void GenerateVoice() + { + if ( _eventStack.Count == 0 ) + { + return; + } + else + { + _text2speech.Generate(GetEntireContext()); + } + } } diff --git a/3d Prototyp/Assets/Scripts/Text2Speech.cs b/3d Prototyp/Assets/Scripts/Text2Speech.cs index 24f92bb8..9af5cae1 100644 --- a/3d Prototyp/Assets/Scripts/Text2Speech.cs +++ b/3d Prototyp/Assets/Scripts/Text2Speech.cs @@ -38,7 +38,7 @@ public class Text2Speech : MonoBehaviour private OpenAIAPI _openAiApi; private Conversation? _conversation; private readonly string _openAiApiKey = "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"; - private readonly string _prompt = "Write a short text for an NPC in a game. The NPC works at a small gamedevelopement office and his Manager is called Gottfried. The text should be based on the following bullet-point context, which describes the events of the last moments. Remember to only respond with the short text that the ONE NPC should speak! The context is: "; + private readonly string _prompt = "Write a short text for an NPC in a game. The NPC works at a small gamedevelopement office and its manager is called Gottfried who is responsable for all the NPCs needs. The text should be based on the following bullet-point context, which describes the events of the last moments. Remember to only respond with the short text that only this ONE NPC should speak and nothing else! The context is: "; void Start() {