script added & managers for narration/subtitles
This commit is contained in:
@@ -5,7 +5,7 @@ using UnityEngine.Pool;
|
||||
|
||||
public class BodyManager : MonoBehaviour
|
||||
{
|
||||
public static BodyManager Instance { get; private set; }
|
||||
public static BodyManager _instance { get; private set; }
|
||||
|
||||
public Body m_Rigidbody;
|
||||
public ObjectPool<Body> m_Pool;
|
||||
@@ -17,10 +17,10 @@ public class BodyManager : MonoBehaviour
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance != null)
|
||||
if (_instance != null)
|
||||
Destroy(this);
|
||||
else
|
||||
Instance = this;
|
||||
_instance = this;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
@@ -61,7 +61,7 @@ public class BodyManager : MonoBehaviour
|
||||
|
||||
IEnumerator Spawn()
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(m_SpawnTime);
|
||||
yield return new WaitForSecondsRealtime(Random.Range(3f, 7f));
|
||||
m_Pool.Get();
|
||||
StartCoroutine(Spawn());
|
||||
|
||||
104
Assets/8_Scripts/1_Managers/NarrationManager.cs
Normal file
104
Assets/8_Scripts/1_Managers/NarrationManager.cs
Normal file
@@ -0,0 +1,104 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System.IO;
|
||||
using UnityEngine.Events;
|
||||
using Unity.VisualScripting;
|
||||
|
||||
public class NarrationManager : MonoBehaviour
|
||||
{
|
||||
// Singleton Implementation //
|
||||
public static NarrationManager _instance { get; private set; }
|
||||
|
||||
|
||||
// Variables //
|
||||
private List<string> m_scriptSlices = new List<string>();
|
||||
|
||||
public TextAsset m_Filename;
|
||||
|
||||
private string m_UnprocessedFile;
|
||||
|
||||
private int m_ScriptIndex;
|
||||
|
||||
private float m_SubtitileWaitTime = 8;
|
||||
|
||||
// Unity Events //
|
||||
public delegate void onUpdateSubtitileDelegate(string subtitle, float waitTime);
|
||||
public static onUpdateSubtitileDelegate m_UpdateSubtitile;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (_instance != null)
|
||||
Destroy(this);
|
||||
DontDestroyOnLoad(this);
|
||||
}
|
||||
|
||||
// Read in a text file, split into sentences, and add to list.
|
||||
void Start()
|
||||
{
|
||||
if (m_Filename != null)
|
||||
{
|
||||
m_UnprocessedFile = m_Filename.text;
|
||||
ParseSentences();
|
||||
m_ScriptIndex = 0;
|
||||
StartCoroutine(WaitToStart());
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"No filename given for script.");
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator WaitToStart()
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(5f);
|
||||
updateSubtitle();
|
||||
}
|
||||
|
||||
// Coroutine for subtitles, when to start the next one after a delay
|
||||
IEnumerator SubtitleWait()
|
||||
{
|
||||
m_SubtitileWaitTime = Random.Range(12.5f, 20f);
|
||||
yield return new WaitForSeconds(m_SubtitileWaitTime);
|
||||
updateSubtitle();
|
||||
}
|
||||
|
||||
private void CalculateVariableWaitTime(string sentence)
|
||||
{
|
||||
var temp = Mathf.Ceil(sentence.Length / 5);
|
||||
if (temp <= 0)
|
||||
{
|
||||
m_SubtitileWaitTime = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_SubtitileWaitTime = temp;
|
||||
}
|
||||
}
|
||||
|
||||
// Increments to next index in list, and updates UI.
|
||||
void updateSubtitle()
|
||||
{
|
||||
m_ScriptIndex++;
|
||||
if (m_ScriptIndex == m_scriptSlices.Count)
|
||||
m_ScriptIndex = 0;
|
||||
CalculateVariableWaitTime(m_scriptSlices[m_ScriptIndex]);
|
||||
DisplayText(m_scriptSlices[m_ScriptIndex]);
|
||||
StartCoroutine(SubtitleWait());
|
||||
}
|
||||
|
||||
// Invokes a Unity Event which updates UI.
|
||||
private void DisplayText(string slice)
|
||||
{
|
||||
m_UpdateSubtitile?.Invoke(slice, m_SubtitileWaitTime);
|
||||
}
|
||||
|
||||
// Parse sentences by newlines
|
||||
private void ParseSentences()
|
||||
{
|
||||
m_scriptSlices.AddRange(
|
||||
m_UnprocessedFile.Split("\n"[0]));
|
||||
Debug.Log($"Parsing of text done, line count: {m_scriptSlices.Count}");
|
||||
}
|
||||
}
|
||||
|
||||
11
Assets/8_Scripts/1_Managers/NarrationManager.cs.meta
generated
Normal file
11
Assets/8_Scripts/1_Managers/NarrationManager.cs.meta
generated
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 98836c5e4d194524a9f515b29e1d7db1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
111
Assets/8_Scripts/1_Managers/SubtitleManager.cs
Normal file
111
Assets/8_Scripts/1_Managers/SubtitleManager.cs
Normal file
@@ -0,0 +1,111 @@
|
||||
using Mono.Cecil;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using static UnityEngine.ParticleSystem;
|
||||
|
||||
public class SubtitleManager : MonoBehaviour
|
||||
{
|
||||
[Header("Text")]
|
||||
public TMP_Text m_Text;
|
||||
[Header("Audio")]
|
||||
|
||||
private float m_TimeElapsed;
|
||||
|
||||
private bool m_FirstRun;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
NarrationManager.m_UpdateSubtitile += UpdateText;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
NarrationManager.m_UpdateSubtitile -= UpdateText;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
m_TimeElapsed = 0;
|
||||
m_Text.text = "";
|
||||
m_FirstRun = true;
|
||||
}
|
||||
|
||||
private void UpdateText(string sentence, float waitTime)
|
||||
{
|
||||
//FMOD.Studio.PLAYBACK_STATE state;
|
||||
|
||||
//m_NarrationSFXInst = AudioManager.instance.PlaySound(m_NarrationSFX);
|
||||
|
||||
//m_NarrationSFXInst.getPlaybackState(out state);
|
||||
|
||||
//if (m_FirstRun)
|
||||
//{
|
||||
// m_FirstRun = false;
|
||||
// m_NarrationSFXInst.start();
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// m_NarrationSFXInst.getPlaybackState(out state);
|
||||
// if (state == PLAYBACK_STATE.STOPPED)
|
||||
// {
|
||||
// m_NarrationSFXInst.start();
|
||||
// }
|
||||
//}
|
||||
StartCoroutine(TextScroll(sentence, waitTime));
|
||||
}
|
||||
|
||||
// Wait time, how long the text will stay on the screen for + if the audio stops late, apply an offset
|
||||
private IEnumerator ClearText(float waitTime, bool earlyStop)
|
||||
{
|
||||
var offset = (waitTime - m_TimeElapsed) * Random.Range(0.6f, 0.95f);
|
||||
|
||||
if(offset < 3)
|
||||
{
|
||||
offset = Random.Range(5f, 7f);
|
||||
}
|
||||
|
||||
Debug.Log($"offset{offset}, wt{waitTime}");
|
||||
float earlyOffset = 0;
|
||||
|
||||
if (!earlyStop)
|
||||
{
|
||||
earlyOffset = offset / Random.Range(2, 4);
|
||||
offset -= earlyOffset;
|
||||
yield return new WaitForSecondsRealtime(earlyOffset);
|
||||
//AudioManager.instance.StopSound(m_NarrationSFXInst);
|
||||
}
|
||||
yield return new WaitForSecondsRealtime(offset);
|
||||
m_Text.text = "";
|
||||
m_TimeElapsed = 0;
|
||||
}
|
||||
|
||||
private IEnumerator TextScroll(string sentence, float waitTime)
|
||||
{
|
||||
var characterLength = sentence.ToCharArray().Length;
|
||||
int randomStoppingValue = (int)Random.Range(characterLength * 0.6f, characterLength);
|
||||
var index = 0;
|
||||
bool earlyStop = false;
|
||||
|
||||
if (Random.Range(0f, 10f) > 6) earlyStop = true;
|
||||
|
||||
foreach (char c in sentence.ToCharArray())
|
||||
{
|
||||
index++;
|
||||
m_Text.text += c;
|
||||
float randomInterval = Random.Range(0.001f, 0.002f);
|
||||
yield return new WaitForSecondsRealtime(randomInterval);
|
||||
m_TimeElapsed += randomInterval;
|
||||
|
||||
// Stop audio early based on probability
|
||||
if (randomStoppingValue == index && earlyStop)
|
||||
{
|
||||
//AudioManager.instance.StopSound(m_NarrationSFXInst);
|
||||
}
|
||||
}
|
||||
|
||||
StartCoroutine(ClearText(waitTime, false));
|
||||
}
|
||||
}
|
||||
11
Assets/8_Scripts/1_Managers/SubtitleManager.cs.meta
generated
Normal file
11
Assets/8_Scripts/1_Managers/SubtitleManager.cs.meta
generated
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a056a38641a8da54e8ba4d7c54f2a1cb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/8_Scripts/3_Script.meta
generated
Normal file
8
Assets/8_Scripts/3_Script.meta
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7c74bf51fa1adf645a58644e68981277
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
65
Assets/8_Scripts/3_Script/Howl by Alan Ginsberg.txt
Normal file
65
Assets/8_Scripts/3_Script/Howl by Alan Ginsberg.txt
Normal file
@@ -0,0 +1,65 @@
|
||||
what sphinx of cement and aluminum bashed open their skulls and ate up their brains and imagination?
|
||||
moloch
|
||||
solitude
|
||||
filth
|
||||
ugliness
|
||||
ashcans and unobtainable dollars
|
||||
children screaming under the stairways
|
||||
sobbing in armies, weeping in the parks
|
||||
moloch, moloch
|
||||
nightmare of moloch
|
||||
moloch the loveless
|
||||
mental moloch.
|
||||
moloch the heavy judger of men
|
||||
moloch the incomprehensible prison
|
||||
moloch the crossbone soulless jailhouse
|
||||
congress of sorrows
|
||||
moloch whose buildings are judgment
|
||||
moloch the vast stone of war
|
||||
moloch the stunned governments
|
||||
moloch whose mind is pure machinery
|
||||
moloch whose blood is running money
|
||||
moloch whose fingers are ten armies
|
||||
moloch whose breast is a cannibal dynamo
|
||||
moloch whose ear is a smoking tomb
|
||||
moloch whose eyes are a thousand blind windows
|
||||
moloch whose factories dream and croak in the fog
|
||||
moloch whose smoke-stacks and antennae crown the cities
|
||||
moloch whose love is endless oil and stone
|
||||
moloch whose soul is electricity and banks
|
||||
moloch whose poverty is the specter of genius
|
||||
moloch whose fate is a cloud of sexless hydrogen
|
||||
moloch whose name is the mind
|
||||
moloch in whom I sit lonely
|
||||
moloch in whom I dream angels
|
||||
crazy in moloch
|
||||
lacklove and manless in moloch
|
||||
moloch who entered my soul early
|
||||
moloch in whom I am a consciousness without a body
|
||||
moloch who frightened me out of my natural ecstasy
|
||||
moloch whom I abandon
|
||||
wake up in moloch
|
||||
light streaming out of the sky
|
||||
moloch! moloch!
|
||||
robot apartments
|
||||
invisible suburbs, skeleton treasuries, blind capitals
|
||||
demonic industries
|
||||
spectral nations, invincible madhouses, sceptred kings
|
||||
monstrous bombs
|
||||
they broke their backs lifting moloch to heaven!
|
||||
pavements, trees, radios, tons
|
||||
lifting the city to heaven which exists and is everywhere about us
|
||||
visions.. omens.. hallucinations.. miracles
|
||||
ecstasies, gone down the silicon river
|
||||
dreams, adorations, illuminations, religions
|
||||
the whole boatload of sensitive bullshit
|
||||
breakthroughs, over the river
|
||||
flips and crucifixions, gone down the flood
|
||||
highs! epiphanies! despairs!
|
||||
10 years’ animal screams and suicides
|
||||
minds! new loves! mad generation!
|
||||
down on the rocks of time
|
||||
real holy laughter in the river
|
||||
they saw it all. the wild eyes. the holy yells. they bade farewell!
|
||||
they jumped off the roof.. to solitude! waving, carrying flowers
|
||||
down to the river, into the street
|
||||
7
Assets/8_Scripts/3_Script/Howl by Alan Ginsberg.txt.meta
generated
Normal file
7
Assets/8_Scripts/3_Script/Howl by Alan Ginsberg.txt.meta
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b54b804405d8bff49a578c17dac833a6
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user