Devs Sprechen jetzt wenn man in der nähe ist

This commit is contained in:
2024-04-06 16:47:41 +02:00
parent 522f206977
commit 5cab2c6912
1208 changed files with 178165 additions and 240 deletions

View File

@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using UnityEngine;
using UnityEngine.Serialization;
using Utility;
@ -72,7 +73,10 @@ public class Developer : MonoBehaviour
[SerializeField]
private DeveloperNeeds _developerNeeds;
[SerializeField]
private float _talkRange = 2.0f;
/// <summary>
/// Gibt die Grunddaten des Entwicklers zurück.
/// </summary>
@ -114,13 +118,33 @@ public class Developer : MonoBehaviour
[SerializeField]
private GameObject _toiletNeed;
private AudioSource _audioSource;
private float _talkPauseTime = 15.0f;
[SerializeField, ShowOnly]
private float _talkTimer;
void Start()
{
_developerNeeds = gameObject.GetComponent<DeveloperNeeds>();
_audioSource = GetComponent<AudioSource>();
_talkTimer = UnityEngine.Random.Range(5.0f, 15.0f);
_fingersLeft = _baseStats.Fingers;
}
private void Update()
{
if (!_audioSource.isPlaying)
{
_talkTimer -= Time.deltaTime;
if (_talkTimer < 0.0f)
{
_talkTimer = _talkPauseTime;
TalkIfInRange();
}
}
}
[ContextMenu("Give Coffee")]
private void TestCoffee()
{
@ -349,4 +373,33 @@ public class Developer : MonoBehaviour
{
Debug.Log($"{Name} ist verreckt.");
}
private bool IsGottfriedInRange()
{
float distanceToPlayer = Vector3.Distance(transform.position, GameManager.Instance.PlayerTransform.position);
return distanceToPlayer <= _talkRange;
}
/// <summary>
/// Starts talking when player is near to the Dev.
/// </summary>
public void TalkIfInRange()
{
if (IsGottfriedInRange())
{
Talk();
}
}
/// <summary>
/// Dev starts talking.
/// </summary>
public void Talk()
{
string context = GameManager.Instance.GetContextAsString();
if (!_audioSource.isPlaying)
{
GetComponent<Text2Speech>().Generate(context);
}
}
}

View File

@ -5,13 +5,17 @@ using System.Linq;
using UnityEditor;
using UnityEngine;
using Utility;
using Microsoft.VisualStudio.Utilities;
public partial class GameManager : MonoBehaviourSingleton<GameManager>
{
[SerializeField] private Difficulty _difficulty = Difficulty.Medium;
public GameObject NeedFullfilledParticleEffect;
[SerializeField]
private GameObject _player;
[SerializeField]
private double _totalGameDurationSeconds;
@ -35,10 +39,23 @@ public partial class GameManager : MonoBehaviourSingleton<GameManager>
[SerializeField]
private DifficultySettings _difficultySettings;
[SerializeField]
private int _maxContextBufferSize = 5;
[SerializeField]
private CircularBuffer<string> _contextBuffer;
public CircularBuffer<string> ContextBuffer => _contextBuffer;
public Difficulty Difficulty => _difficulty;
public double NeedNotificationThreshold => _needNotificationThreshold;
/// <summary>
/// Die Transform des Spielers.
/// </summary>
public Transform PlayerTransform => _player.transform;
/// <summary>
/// Wie weit das Spiel bereits fortgeschritten ist.
@ -71,6 +88,8 @@ public partial class GameManager : MonoBehaviourSingleton<GameManager>
{
TimeManager.Instance.Init();
_contextBuffer = new CircularBuffer<string>(_maxContextBufferSize);
_difficultySettings = _difficulty.GetSettings();
_totalGameDurationSeconds = TimeManager.Instance.CalculateActualDeveloperTime(_difficultySettings, 4);
@ -168,4 +187,31 @@ public partial class GameManager : MonoBehaviourSingleton<GameManager>
// Entwickler Effizienz ist im Grunde wie viele Entwicklersekunden wir pro Sekunde verrichten können.
_remainingGameDurationSeconds -= _currentEfficiency;
}
/// <summary>
/// Returns the context stored in the contextBuffer seperated with ',' as a string
/// </summary>
/// <returns></returns>
public string GetContextAsString()
{
if (_contextBuffer.Count != 0)
{
string output = "";
foreach (string context in _contextBuffer)
{
output += context + ", ";
}
return output;
}
return null;
}
/// <summary>
/// Adds the given string to the context
/// </summary>
/// <param name="context"></param>
public void AddContext(string context)
{
_contextBuffer.Add(context);
}
}

View File

@ -10,7 +10,6 @@ public class NPC_Behavior : MonoBehaviour
[SerializeField] double eventRate = 1.0; // max 60, min 0 -> how many events are fired per minute
[SerializeField] private float _startTime = 30.0f;
private GameManager _gameManager;
private NPC_EventStack _eventStack;
private Text2Speech _text2Speech;
private AudioSource _audioSource;
@ -39,7 +38,6 @@ public class NPC_Behavior : MonoBehaviour
// Start is called before the first frame update
void Start()
{
_gameManager = GameManager.Instance;
_developerNeeds = GetComponent<DeveloperNeeds>();
_eventStack = GetComponent<NPC_EventStack>();
_text2Speech = GetComponent<Text2Speech>();

View File

@ -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 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: ";
private readonly string _prompt = "Write a short text for a Developer as an NPC in a game. The Developer works at a small gamedevelopement office and its manager is called Gottfried who is responsable for all the Developers 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 Developer should speak and nothing else! The context is: ";
void Start()
{