Text - Code Documentation



(use ctrl-f)


Variables


initiateDialogButton
public string initiateDialogButton

This is the button you want to use to interact with npcs/items/etc/whatever will have dialog





initiateConvoDisplay
public GameObject initiateConvoDisplay

Holds an image to be displayed when your character is close enough to the speaker to initaite conversation





dialogCanvas
public GameObject dialogCanvas

The canvas that holds the speech UI. Stored as a gameObject to be turned off/on when needed





speakerName
public string speakerName

this is the string that holds the name of the speaker





nameDisplay
public Text nameDisplay

Takes a UnityUI Text GameObject that will display the speaker's name, if applicable





speakerSprite
public Sprite speakerSprite

Takes a UnityUI Sprite GameObject that will display an image depicting the speaker, if applicable





speakerSpriteDisplayer
public Image speakerSpriteDisplayer

Takes a UnityUI Image Gameobject that will provide the image to the speakerSprite object to display, if applicable





pressedAction
bool pressedAction

Indicates whether you have pressed the action button when you are within interaction range with a speaker.  The range can be modified by changing the sphere collider's radius on the *speaker*'s VoiceBox





finishedTalking
bool finishedTalking

a boolean indicating whether or not the *speaker*'s dialog has completed





dialogueDisplay
public Text dialogueDisplay

Takes a UnityUI Text GameObject that will display the dialog text





nextSentenceButtonDisplay
public GameObject nextSentenceButtonDisplay

Holds an image to be displayed when the *speaker*'s sentences has ended, indicating to push the action button to continue





dialogItems
public List<SentenceHolder> dialogItems

This is a list of SentenceHolders that will hold the dialog for the speaker to display





sentences
private string[] sentences

these are the sentences held by the speaker to be displayed to screen these are passed from the more general dialog holder (SentenceHolder) into their own array for individual processing





sentenceIndex
int sentenceIndex

the index of the current sentence in the sentence array





typingDelay
public float typingDelay

the length in seconds of the delay between letters typed to screen





typingDelayCopy
float typingDelayCopy

a copy of the typing delay speed is stored for when the sentence speed is temporarily changed to display it all at once (when action is pressed during display)





dialogsIndex
int dialogsIndex

Points to a dialog object inside the dialog asset





checkString
private string checkString

Used to compare the displayed string to the user-given string. They are compared to see if the sentence has been displayed fully.





vowelString
string vowelString

Used for checking vowels in the string processinhg





Types


SoundModes
public enum SoundModes
noSound

Plays no sound

perSyllable

Plays a sound at each syllable

perCharacter

plays a sound each charcater





Variables


voiceSoundMode
public SoundModes voiceSoundMode

the variable that the user selects to indicate which sound mode from the SoundModes enum is selected





soundModeIndex
int soundModeIndex

The index in the SoundMode enum that is selected by the user





Types


MusicScales
public enum MusicScales

These are the musical scales used for the voice.  Scales can be added by adding their intervals to the scales array bellow Once the intervals have been added, the scale should be added here with its index correspoding to its intervals index in the scales array





Variables


vocalScale
public MusicScales vocalScale

the variable that the user selects to indicate which scale from the MusicScales enum is selected





scaleIndex
int scaleIndex

The index in the vocalScale enum that is selected by the user


scales
int[][] scales




newScale
List<int> newScale

An int list that holds interval values for a scale





Types


RootNotes
public enum RootNotes

This is the list of chromatic notes starting with C and going up an octave





Variables


rootNote
public RootNotes rootNote

The root note of selected from the RootNotes enum





rootNoteIndex
int rootNoteIndex

The index of the selected root note in the RootNotes enum





Types


PlayStyles
public enum PlayStyles
randomOrder

Plays the notes of the scale in a random order

ascendingOrder

Plays the notes of the scale in ascending order

descendingOrder

Plays the notes of the scale in descending order

rootOnly

Plays only the root note of the scale





Variables


voiceNotePlayStyle
public PlayStyles voiceNotePlayStyle

the Selected note play style





playStyleIndex
int playStyleIndex

the index of the selected play style from the enum PlayStyles





startTag
string startTag

the string that will hold the "start" tag for rich text example... <color=red>





closeTag
string closeTag

the string that will hold the "closing" tag for rich text example... </color>





openCount
int openCount

Keep count of tag openings ("<")





richTextCharCount
int richTextCharCount

Keeps count of the number of charcaters that are rich text





displayLetter
bool displayLetter

To tell whether or not to display the characters of a sentence.  example... You wouldn't display the characters for rich text tags





recordLettersAsTag

To tell whether the code should be storing the sentence characters as rich text tags or not





recordLetterAsTag
bool recordLetterAsTag




recordBetweenTags
bool recordBetweenTags

To tell whether the string between the < or >'s should be stored in the display string or not





generatedClosingTag
string generatedClosingTag

This is the closing tag (of the form </>) that is generated by the code





displayString
string displayString

the string to be displayed to the screen





myAudio
AudioSource myAudio

An AudioSource GameObject Component, this will be what plays the voice sound





voiceSoundClip
public AudioClip voiceSoundClip

The audio clip to be played by the AudioSource myAudio Provided by the user





transpose
int transpose

an int associated with transposing the notes





orderedNoteIndexAsc
int orderedNoteIndexAsc

the index of the note when its playmode is ascending





orderedNoteIndexDes
int orderedNoteIndexDes

the index of the note when its playmode is descending





newNote
int newNote

a temporary holder for notes being created that are added to the scale being generated





Functions




Start
void Start()

The default Unity Start method. Initializes variables, adds needed components, creates a new scale for the speaker voice by calling the method GenerateScale, sets the speakers sentences by calling the method GetNewSentences.





GetNewSentences
public void GetNewSentences(
string[] newSentences
)

Sets the class variable sentences to the string[] newSentences. Can be called from outside to update or change the needed dialog as the situation requires.

Parameters
newSentences
string[]

The string[] of new sentences to be displayed





GetNewDialog
public void GetNewDialog(
List<SentenceHolder> newDialog
)

Sets the class variable dialogItems to the list newDialog The SentenceHolder is a custom asset that is an object that holds a string[]

Parameters
newDialog
List<SentenceHolder>

The List of sentenceHolders, each dialog element being its own set of sentences.





OnTriggerStay
void OnTriggerStay(
Collider other
)

If the player is within the radius of the collider, allows the player to initiate dialog by pushing the initiateDialogButton designated by the user.  If an initiate conversation display GameObject has been provided in the inspector, it will be displayed when the player enters the radius.

Parameters
other
Collider

the other collider involved in the collision, usually the player





OnTriggerExit
void OnTriggerExit(
Collider other
)

If the player exits the radius of the collider and an initiate conversation display GameObject has been provided, it will be hidden.

Parameters
other
Collider

the other collider involved in the collision, usually the player





InitiateConvo
void InitiateConvo()

This method starts the conversation (the dialog display). It checks that the dialog system isnt already 'speaking", then checks that the initiate dialog button has been pressed again. If the button has not been hit again, it makes the UI canvas active, and starts the sentences "typing" using the selected sound Mode.  If the button has been hit again, it decreases the delay between characters being displayed so that the sentence can complete displaying near instantly.

When the sentence has finished displaying, the next sentence button display will become active, indicating to the player that a button press is required to move the dialog along. Once the player has pressed the button, the dialog will call the NextSentence method.





TypeWithSoundOnSyllables
IEnumerator TypeWithSoundOnSyllables()

This method, processes the sentences stored in the class variable string[] sentences.  This method breaks the string down into a char array, then iterates through that first looking for rich text tags, then looking for syllables. As it is scanning the sentence, it is displaying each (non-tag) letter to the screen, and playing the provided sound at each syllable.





GenerateCloseTagFromOpen
public string GenerateCloseTagFromOpen(
string passedTag
)

This method takes a rich text "opening tag" (ex: <color=red>) and generates a "closing tag" (ex:</color>) This allows us to display rich text strings, per letter.

Parameters
passedTag
string

this is the "opening tag" that will be used to generate the "closing tag"

Returns
toReturn

the string containing the "closing tag"





TypeWithSoundEachLetter
IEnumerator TypeWithSoundEachLetter()

Processes the sentences stored in the class variable string[] sentences.  First it breaks the string down into a char array, then iterates through that looking for rich text tags.  As it is scanning the sentence, it is displaying each (non-tag) letter to the screen, and playing the provided sound at each typed letter.





TypeNoSound
IEnumerator TypeNoSound()

This method processes the sentences stored in the class variable string[] sentences.  This method breaks the string down into a char array, then iterates through that looking for rich text tags.  It is displaying each (non-tag) letter to the screen.





NextSentence
public void NextSentence()

This method checks if the sentences[] has completed, if it hasnt, it loads the next sentences and speaks it, if there are no more sentences, the dialog is closed and the method to reset the dialog is called (with a 1 second delay so it doesn't reopen instantly).





PlayInMode
public void PlayInMode()

This method checks the selected scale play mode (random order, ascending, descending, specific note) and calls the appropriate method to display the dialog.





PlayRandomNote
public void PlayRandomNote()

This method plays a random note from the scale newScale.





PlayOrderedNoteAsc
public void PlayOrderedNoteAsc()

This method plays the notes from scale newScale in ascending order. It uses the class int orderedNoteIndexAsc to keep track of where it is in the scale.





PlayOrderedNoteDes
public void PlayOrderedNoteDes()

This method plays the notes from scale newScale in descending order. It uses the class int orderedNoteIndexDes to keep track of where it is in the scale.





PlayNote
public void PlayNote(
int note
)

This method plays the specific note indicated by the parameter. The note is chosen from the chromatic scale starting and ending with C, numbered 0 - 12

Paramters
note

the number indicating which note from the chromatic scale is to be played.





GenerateScale
public List<int> GenerateScale (
int root,
int scale
)

This method generates a scale with a specific key for the voice. The scale is returned as a list.

Parameters
root
int

this is the key the newly generated scale will be in

scale
int

this is the type of scale it will be. The number indicates the scale type in the class int[][] scales.

Returns
noteScale

the newly generated scale, stored as a List<int>





PlayMyNote
IEnumerator PlayMyNote (
int note
)

This method plays the note specified in the parameter. The number represents the note on the chromatic scale, starting and ending with C, numbered 0 - 12

Parameters
note
int

the number of the note on the chromatic scale, to play.





ResetDialogBetween
IEnumerator ResetDialogBetween ()

This method waits for 1 second before resetting the UI, strings, counters, variables, etc associated with the dialog.  The delay is to allow a slight cool down period between dialog to prevent any errors.