Devs sprechen jetzt wenn sie was wollen

This commit is contained in:
klappstuhl24 2024-04-05 17:29:05 +02:00
parent 3a4b2bca76
commit 056a444ed5
9 changed files with 77455 additions and 1853 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 0e0e36fd55fdcbf4a8fbd28d0e7f9166
guid: 4b3e336a6fdfc5d4083d6362f6a3830f
DefaultImporter:
externalObjects: {}
userData:

View File

@ -6,10 +6,12 @@ public class DeveloperNeeds : MonoBehaviour
{
[SerializeField] List<GameObject> Needs = new List<GameObject>();
private Text2Speech _text2speech;
// Start is called before the first frame update
void Start()
{
_text2speech = GetComponent<Text2Speech>();
}
// Update is called once per frame
@ -22,20 +24,25 @@ public class DeveloperNeeds : MonoBehaviour
{
GameObject spawnedNeed = null;
string context = "";
switch (needName)
{
case "coffee":
spawnedNeed = Instantiate(Needs[0], new Vector3(0.0f, 1.5f, 0.0f), Needs[0].transform.rotation);
spawnedNeed = Instantiate(Needs[0], new Vector3(0.0f, 2f, 0.0f), Needs[0].transform.rotation);
context = "Office, The NPC wants coffee";
break;
case "mate":
spawnedNeed = Instantiate(Needs[1], new Vector3(0.0f, 1.5f, 0.0f), Needs[0].transform.rotation);
spawnedNeed = Instantiate(Needs[1], new Vector3(0.0f, 2f, 0.0f), Needs[0].transform.rotation);
context = "Office, The NPC wants a Club Mate";
break;
case "toilet":
spawnedNeed = Instantiate(Needs[2], new Vector3(0.0f, 1.5f, 0.0f), Needs[0].transform.rotation);
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";
break;
case "money":
spawnedNeed = Instantiate(Needs[3], new Vector3(0.0f, 1.5f, 0.0f), Needs[0].transform.rotation);
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";
break;
default:
break;
@ -44,6 +51,8 @@ public class DeveloperNeeds : MonoBehaviour
if (spawnedNeed != null)
{
spawnedNeed.transform.SetParent(transform, false);
spawnedNeed.transform.localScale = new Vector3(0.4f, 0.01f, 0.4f);
_text2speech.Generate(context);
return spawnedNeed;
}
return null;

View File

@ -37,15 +37,16 @@ public class NPC_Behavior : MonoBehaviour
private GameManager _gameManager;
[SerializeField] private bool _deleteManually = false;
[SerializeField] private bool _fullfillNeedManually = false;
[SerializeField] private float _timer;
[SerializeField] private float _newNeedDelay = 3.0f;
[SerializeField] private List<string> _lastTenNeeds = new List<string>();
private DeveloperNeeds _developerNeeds;
private float _timeBetweenEvents;
private GameObject _currentNeed = null;
private bool _justFullfilledNeed = false;
private float _justFullfilledNeedTimer = 2.0f;
private bool _canNeedNewNeed = true;
private float _newNeedDelayTimer = 0.0f;
private float _effectCreationTime;
private GameObject _effect;
/// <summary>
/// The name of the current need
@ -67,42 +68,31 @@ public class NPC_Behavior : MonoBehaviour
// Update is called once per frame
void Update()
{
WatchEffect();
_timer -= Time.deltaTime;
_justFullfilledNeedTimer -= Time.deltaTime;
if (_justFullfilledNeedTimer <= 0 && _justFullfilledNeed)
if (_newNeedDelayTimer <= 0)
{
_canNeedNewNeed = true;
_justFullfilledNeed = false;
_justFullfilledNeedTimer = 2.0f;
}
if (_timer <= 0 && _currentNeed == null && _canNeedNewNeed)
if (_timer <= 0 && _currentNeed == null)
{
// List<string> needs = new List<string>() { "coffee", "mate", "toilet" };
_justFullfilledNeed = false;
_canNeedNewNeed = false;
string need = "coffee";
_currentNeed = _developerNeeds.spawnNeed(need);
HasNeed = true;
_lastTenNeeds.Add(need);
if (_lastTenNeeds.Count > 10 )
{
_lastTenNeeds.RemoveAt(0);
}
GenerateNeed();
ResetTimer();
}
}
else
{
_newNeedDelayTimer -= Time.deltaTime;
}
// for Debugging
if (_deleteManually)
if (_fullfillNeedManually)
{
_deleteManually = false;
_fullfillNeedManually = false;
NeedFullfilled();
}
}
void ResetTimer()
private void ResetTimer()
{
if (eventRate <= 0)
{
@ -111,10 +101,44 @@ public class NPC_Behavior : MonoBehaviour
else
{
_timeBetweenEvents = 60f / (float)eventRate;
_timer = Random.Range(0.5f * _timeBetweenEvents, 1.5f * _timeBetweenEvents);
_timer = Random.Range(0.5f * _timeBetweenEvents, 1.25f * _timeBetweenEvents);
}
}
private void WatchEffect()
{
if (_effect != null && GetEffectLifetime() >= 3.0f)
{
RemoveEffect();
}
}
private float GetEffectLifetime()
{
return Time.time - _effectCreationTime;
}
private bool RemoveEffect()
{
Destroy(_effect);
return _effect != null;
}
public bool GenerateNeed()
{
List<string> needs = new List<string>() { "coffee", "mate", "toilet", "money" };
string need = needs[UnityEngine.Random.Range(0, needs.Count)];
_currentNeed = _developerNeeds.spawnNeed(need);
HasNeed = true;
_lastTenNeeds.Add(need);
if (_lastTenNeeds.Count > 10)
{
_lastTenNeeds.RemoveAt(0);
}
return _currentNeed != null;
}
/// <summary>
/// Deletes the current need and its gameobject.
/// </summary>
@ -125,9 +149,10 @@ public class NPC_Behavior : MonoBehaviour
if (HasNeed)
{
HasNeed = false;
_justFullfilledNeed = true;
_canNeedNewNeed = false;
Instantiate(confettiEffect, new Vector3(0.0f, 1.5f, 0.0f), confettiEffect.transform.rotation).transform.SetParent(transform, false);
_newNeedDelayTimer = _newNeedDelay;
_effect = Instantiate(confettiEffect, new Vector3(0.0f, 1.5f, 0.0f), confettiEffect.transform.rotation);
_effect.transform.SetParent(transform, false);
_effectCreationTime = Time.time;
}
return _currentNeed == null;
}

View File

@ -0,0 +1,37 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NPC_EventStack : MonoBehaviour
{
[SerializeField] private List<string> _eventStack = new List<string>() { "What a great day to develope a game!" };
[SerializeField] private int _maxStackHeight = 5;
public void AddNewContext(string context)
{
_eventStack.Add(context);
if (_eventStack.Count > _maxStackHeight)
{
_eventStack.RemoveAt(0);
}
}
public string GetEntireContext()
{
string output = "";
foreach (string e in _eventStack)
{
output += e + ", ";
}
return output;
}
public string GetLatestContext()
{
if (_eventStack.Count > 0)
{
return _eventStack[_eventStack.Count - 1];
}
return null;
}
}

View File

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

View File

@ -32,13 +32,13 @@ public class Text2Speech : MonoBehaviour
private readonly string _googelCloudApiKey = "AIzaSyDNpkVyAUU4AvSwAErVMlZ1lSvGfpkEs0Q";
private readonly string _google_CloudApiUrl = "https://texttospeech.googleapis.com/v1/text:synthesize";
private readonly string _outputPath = "C:\\Users\\PC\\VoiceTest\\Assets\\Scirpts\\audio.wav";
private readonly string _outputPath = "path/to/audio.wav";
private string _tmpPath = "tmp_audio.wav";
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 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 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: ";
void Start()
{
@ -71,6 +71,12 @@ public class Text2Speech : MonoBehaviour
}
}
public void Generate(string c)
{
context = c;
generate = true;
}
public void GetRandomGermanVoice(string gender, Action<JToken> callback)
{
StartCoroutine(GetRandomGermanVoiceCoroutine(gender, callback));