Devs sprechen jetzt wenn sie was wollen
This commit is contained in:
parent
3a4b2bca76
commit
056a444ed5
File diff suppressed because it is too large
Load Diff
|
@ -1,5 +1,5 @@
|
||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 0e0e36fd55fdcbf4a8fbd28d0e7f9166
|
guid: 4b3e336a6fdfc5d4083d6362f6a3830f
|
||||||
DefaultImporter:
|
DefaultImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
userData:
|
userData:
|
||||||
|
|
|
@ -6,10 +6,12 @@ public class DeveloperNeeds : MonoBehaviour
|
||||||
{
|
{
|
||||||
[SerializeField] List<GameObject> Needs = new List<GameObject>();
|
[SerializeField] List<GameObject> Needs = new List<GameObject>();
|
||||||
|
|
||||||
|
private Text2Speech _text2speech;
|
||||||
|
|
||||||
// Start is called before the first frame update
|
// Start is called before the first frame update
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
|
_text2speech = GetComponent<Text2Speech>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
|
@ -22,20 +24,25 @@ public class DeveloperNeeds : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
|
||||||
GameObject spawnedNeed = null;
|
GameObject spawnedNeed = null;
|
||||||
|
string context = "";
|
||||||
|
|
||||||
switch (needName)
|
switch (needName)
|
||||||
{
|
{
|
||||||
case "coffee":
|
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;
|
break;
|
||||||
case "mate":
|
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;
|
break;
|
||||||
case "toilet":
|
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;
|
break;
|
||||||
case "money":
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -44,6 +51,8 @@ public class DeveloperNeeds : MonoBehaviour
|
||||||
if (spawnedNeed != null)
|
if (spawnedNeed != null)
|
||||||
{
|
{
|
||||||
spawnedNeed.transform.SetParent(transform, false);
|
spawnedNeed.transform.SetParent(transform, false);
|
||||||
|
spawnedNeed.transform.localScale = new Vector3(0.4f, 0.01f, 0.4f);
|
||||||
|
_text2speech.Generate(context);
|
||||||
return spawnedNeed;
|
return spawnedNeed;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -37,15 +37,16 @@ public class NPC_Behavior : MonoBehaviour
|
||||||
|
|
||||||
private GameManager _gameManager;
|
private GameManager _gameManager;
|
||||||
|
|
||||||
[SerializeField] private bool _deleteManually = false;
|
[SerializeField] private bool _fullfillNeedManually = false;
|
||||||
[SerializeField] private float _timer;
|
[SerializeField] private float _timer;
|
||||||
|
[SerializeField] private float _newNeedDelay = 3.0f;
|
||||||
[SerializeField] private List<string> _lastTenNeeds = new List<string>();
|
[SerializeField] private List<string> _lastTenNeeds = new List<string>();
|
||||||
private DeveloperNeeds _developerNeeds;
|
private DeveloperNeeds _developerNeeds;
|
||||||
private float _timeBetweenEvents;
|
private float _timeBetweenEvents;
|
||||||
private GameObject _currentNeed = null;
|
private GameObject _currentNeed = null;
|
||||||
private bool _justFullfilledNeed = false;
|
private float _newNeedDelayTimer = 0.0f;
|
||||||
private float _justFullfilledNeedTimer = 2.0f;
|
private float _effectCreationTime;
|
||||||
private bool _canNeedNewNeed = true;
|
private GameObject _effect;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The name of the current need
|
/// The name of the current need
|
||||||
|
@ -67,42 +68,31 @@ public class NPC_Behavior : MonoBehaviour
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
|
WatchEffect();
|
||||||
_timer -= Time.deltaTime;
|
_timer -= Time.deltaTime;
|
||||||
_justFullfilledNeedTimer -= Time.deltaTime;
|
|
||||||
|
|
||||||
if (_justFullfilledNeedTimer <= 0 && _justFullfilledNeed)
|
if (_newNeedDelayTimer <= 0)
|
||||||
{
|
{
|
||||||
_canNeedNewNeed = true;
|
if (_timer <= 0 && _currentNeed == null)
|
||||||
_justFullfilledNeed = false;
|
|
||||||
_justFullfilledNeedTimer = 2.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_timer <= 0 && _currentNeed == null && _canNeedNewNeed)
|
|
||||||
{
|
{
|
||||||
// List<string> needs = new List<string>() { "coffee", "mate", "toilet" };
|
GenerateNeed();
|
||||||
_justFullfilledNeed = false;
|
|
||||||
_canNeedNewNeed = false;
|
|
||||||
|
|
||||||
string need = "coffee";
|
|
||||||
_currentNeed = _developerNeeds.spawnNeed(need);
|
|
||||||
HasNeed = true;
|
|
||||||
_lastTenNeeds.Add(need);
|
|
||||||
if (_lastTenNeeds.Count > 10 )
|
|
||||||
{
|
|
||||||
_lastTenNeeds.RemoveAt(0);
|
|
||||||
}
|
|
||||||
ResetTimer();
|
ResetTimer();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_newNeedDelayTimer -= Time.deltaTime;
|
||||||
|
}
|
||||||
|
|
||||||
// for Debugging
|
// for Debugging
|
||||||
if (_deleteManually)
|
if (_fullfillNeedManually)
|
||||||
{
|
{
|
||||||
_deleteManually = false;
|
_fullfillNeedManually = false;
|
||||||
NeedFullfilled();
|
NeedFullfilled();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResetTimer()
|
private void ResetTimer()
|
||||||
{
|
{
|
||||||
if (eventRate <= 0)
|
if (eventRate <= 0)
|
||||||
{
|
{
|
||||||
|
@ -111,10 +101,44 @@ public class NPC_Behavior : MonoBehaviour
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_timeBetweenEvents = 60f / (float)eventRate;
|
_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>
|
/// <summary>
|
||||||
/// Deletes the current need and its gameobject.
|
/// Deletes the current need and its gameobject.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -125,9 +149,10 @@ public class NPC_Behavior : MonoBehaviour
|
||||||
if (HasNeed)
|
if (HasNeed)
|
||||||
{
|
{
|
||||||
HasNeed = false;
|
HasNeed = false;
|
||||||
_justFullfilledNeed = true;
|
_newNeedDelayTimer = _newNeedDelay;
|
||||||
_canNeedNewNeed = false;
|
_effect = Instantiate(confettiEffect, new Vector3(0.0f, 1.5f, 0.0f), confettiEffect.transform.rotation);
|
||||||
Instantiate(confettiEffect, new Vector3(0.0f, 1.5f, 0.0f), confettiEffect.transform.rotation).transform.SetParent(transform, false);
|
_effect.transform.SetParent(transform, false);
|
||||||
|
_effectCreationTime = Time.time;
|
||||||
}
|
}
|
||||||
return _currentNeed == null;
|
return _currentNeed == null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: a5cc0d7ecd7b47f48b2444cff2eb207d
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -32,7 +32,7 @@ public class Text2Speech : MonoBehaviour
|
||||||
|
|
||||||
private readonly string _googelCloudApiKey = "AIzaSyDNpkVyAUU4AvSwAErVMlZ1lSvGfpkEs0Q";
|
private readonly string _googelCloudApiKey = "AIzaSyDNpkVyAUU4AvSwAErVMlZ1lSvGfpkEs0Q";
|
||||||
private readonly string _google_CloudApiUrl = "https://texttospeech.googleapis.com/v1/text:synthesize";
|
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 string _tmpPath = "tmp_audio.wav";
|
||||||
|
|
||||||
private OpenAIAPI _openAiApi;
|
private OpenAIAPI _openAiApi;
|
||||||
|
@ -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)
|
public void GetRandomGermanVoice(string gender, Action<JToken> callback)
|
||||||
{
|
{
|
||||||
StartCoroutine(GetRandomGermanVoiceCoroutine(gender, callback));
|
StartCoroutine(GetRandomGermanVoiceCoroutine(gender, callback));
|
||||||
|
|
Loading…
Reference in New Issue