/// <summary> /// Method that generates an instruction element to clear the dialogue box /// </summary> /// <returns></returns> public static DialogueInstructionElement Clear() { DialogueInstructionElement dialogueInstruction = new DialogueInstructionElement(); dialogueInstruction.type = DialogueInstructionElementType.CLEAR; return(dialogueInstruction); }
private bool UpdateCharacterDialogueClearInstruction(DialogueInstructionElement active_element, ref float delta_time) { for (int i = 0; i < character_array.Length; i++) { character_array[i].SetActive(false); } return(true); }
/// <summary> /// Wait for an amount of time /// </summary> /// <param name="s"></param> /// <returns></returns> public static DialogueInstructionElement Wait(float s) { DialogueInstructionElement dialogueInstruction = new DialogueInstructionElement(); dialogueInstruction.type = DialogueInstructionElementType.WAIT; dialogueInstruction.wait_s = s; return(dialogueInstruction); }
/// <summary> /// Speed static constructor /// </summary> /// <param name="speed"></param> /// <returns></returns> public static DialogueInstructionElement Speed(float speed) { DialogueInstructionElement dialogueInstruction = new DialogueInstructionElement(); dialogueInstruction.type = DialogueInstructionElementType.SET_SPEED; dialogueInstruction.speed = speed; return(dialogueInstruction); }
/// <summary> /// Word static constructor /// </summary> /// <param name="word"></param> /// <returns></returns> public static DialogueInstructionElement Text(string word) { DialogueInstructionElement dialogueInstruction = new DialogueInstructionElement(); dialogueInstruction.type = DialogueInstructionElementType.TEXT; dialogueInstruction.word = word; return(dialogueInstruction); }
private bool UpdateCharacterDialogueWaitInstruction(DialogueInstructionElement active_element, ref float delta_time) { float elapsed_time = processing_data.time_elapsed - delta_time; float total_elapsed_time = processing_data.time_elapsed; processing_data.time_elapsed = total_elapsed_time; if (processing_data.time_elapsed >= active_element.wait_s) { delta_time -= active_element.wait_s; return(true); } return(false); }
void Awake() { character_array = new GameObject[CHARACTER_CAPACITY]; sprite_empty.SetActive(false); for (int i = 0; i < CHARACTER_CAPACITY; i++) { character_array[i] = GameObject.Instantiate(sprite_empty); character_array[i].transform.parent = dialog_sprite.transform; } DialogueInstructionElement element = DialogueInstructionElement.Text(statement); DialogueInstructionElement wait = DialogueInstructionElement.Wait(1); //active_instruction = new DialogueInstruction(new DialogueInstructionElement[] { wait, element }, true); }
private bool UpdateCharacterDialogueTextInstruction(DialogueInstructionElement word_element, ref float delta_time) { float elapsed_time = processing_data.time_elapsed - delta_time; float total_elapsed_time = processing_data.time_elapsed; processing_data.time_elapsed = total_elapsed_time; int low_index = (int)Mathf.Floor(elapsed_time * dialogue_speed); int high_index = (int)Mathf.Floor(total_elapsed_time * dialogue_speed); if (high_index == word_element.word.Length + 1) { delta_time = ((total_elapsed_time * dialogue_speed) - high_index) / dialogue_speed; return(true); } float root_x = GlobalUtils.PixelsToFloat(8.5f * 7f); float y_offset = GlobalUtils.PixelsToFloat(1.1f * 11f); float root_y = y_offset - .55f; if (low_index != high_index && high_index > 0) { char c = word_element.word[high_index - 1]; if (c < ' ' || c > 'z') { throw new System.Exception("Illegal character " + (char)c); } if (c != ' ') { c -= ' '; int display_index = processing_data.display_array_index; GameObject character_obj = character_array[processing_data.display_array_index]; character_obj.SetActive(true); character_obj.GetComponent <SpriteRenderer>().sprite = sprites[c]; int column = display_index % ROW_SIZE; int row = display_index / ROW_SIZE; character_obj.transform.position = new Vector3(-root_x + GlobalUtils.PixelsToFloat(7) * column, 0, root_y - y_offset * row); } processing_data.display_array_index++; } return(false); }
private void UpdateCharacterDialogueInstruction(float delta_time) { if ((active_instruction == null && dialogue_instruction_queue.Count > 0)) { active_instruction = dialogue_instruction_queue.Dequeue(); processing_data = new DialogueInstructionProcessingData(); } processing_data.time_elapsed += delta_time; if (active_instruction != null) { DialogueInstructionElement active_element = active_instruction.Value.elements[processing_data.instruction_index]; bool iterate = false; switch (active_element.type) { case DialogueInstructionElementType.CLEAR: iterate = UpdateCharacterDialogueClearInstruction(active_element, ref delta_time); break; case DialogueInstructionElementType.TEXT: iterate = UpdateCharacterDialogueTextInstruction(active_element, ref delta_time); break; case DialogueInstructionElementType.SET_SPEED: iterate = UpdateCharacterDialogueSpeedInstruction(active_element, ref delta_time); break; case DialogueInstructionElementType.WAIT: iterate = UpdateCharacterDialogueWaitInstruction(active_element, ref delta_time); break; } if (iterate == true) { processing_data.instruction_index++; processing_data.time_elapsed = 0; active_instruction = processing_data.instruction_index >= active_instruction.Value.elements.Length ? null : active_instruction; UpdateCharacterDialogueInstruction(delta_time); } } }
private DialogueInstruction TransformInstruction(string instruction) { List <DialogueInstructionElement> element_list = new List <DialogueInstructionElement>(); element_list.Add(DialogueInstructionElement.Clear()); string original_instruction = instruction; while (instruction != null && instruction.IndexOf('{') != -1) { int index = instruction.IndexOf('{'); if (index > 0) { string text = instruction.Substring(0, index); Debug.Log("Found text bit: " + text); element_list.Add(DialogueInstructionElement.Text(text)); instruction = instruction.Substring(index); } index = instruction.IndexOf('}'); if (index == -1) { throw new System.Exception("Closing character '}' not found in instruction: " + original_instruction); } element_list.Add(ProcessCommand(instruction.Substring(1, index - 1))); instruction = instruction.Length == index + 1 ? null : instruction.Substring(index + 1); } if (instruction != null) { element_list.Add(DialogueInstructionElement.Text(instruction)); } return(new DialogueInstruction(element_list.ToArray(), true)); }
private bool UpdateCharacterDialogueSpeedInstruction(DialogueInstructionElement active_element, ref float delta_time) { dialogue_speed = active_element.speed; return(true); }
private DialogueInstructionElement ParseWaitCommand(string command_string) { string[] args = command_string.Split(':', ','); return(DialogueInstructionElement.Wait(Single.Parse(args[1]))); }