public void ContinueAction(float animation_timer, LetterAnimation animation, AnimatePerOptions animate_per) { if (m_anim_state_vars.m_waiting_to_sync) { m_anim_state_vars.m_break_delay = 0; m_anim_state_vars.m_waiting_to_sync = false; // reset timer offset to compensate for the sync-up wait time m_anim_state_vars.m_timer_offset = animation_timer; // Progress letter animation index to next, and break out of the loop int prev_action_idx = m_anim_state_vars.m_action_index; // Set next action index SetNextActionIndex(animation); if (m_anim_state_vars.m_active) { if (!m_anim_state_vars.m_reverse && m_anim_state_vars.m_action_index_progress > m_anim_state_vars.m_action_index) { // Repeating the action again; check for unqiue random variable requests. animation.GetAction(m_anim_state_vars.m_action_index).SoftReset(animation.GetAction(prev_action_idx), m_progression_variables, animate_per); } if (prev_action_idx != m_anim_state_vars.m_action_index) { UpdateLoopList(animation); } } } }
public void SetMeshState(int action_idx, float action_progress, LetterAnimation animation, AnimatePerOptions animate_per, EffectManager effect_manager) { if (action_idx >= 0 && action_idx < animation.NumActions) { SetupMesh(animation.GetAction(action_idx), action_idx > 0 ? animation.GetAction(action_idx - 1) : null, Mathf.Clamp(action_progress, 0, 1), m_progression_variables, animate_per, Mathf.Clamp(action_progress, 0, 1), effect_manager); } else { // action not found for this letter. Position letter in its default position if (mesh_verts == null || mesh_verts.Length == 0) { mesh_verts = new Vector3[4]; } for (int idx = 0; idx < 4; idx++) { mesh_verts[idx] = m_base_vertices[idx] + m_base_offset; } m_mesh.vertices = mesh_verts; m_mesh.colors = new Color[] { Color.white, Color.white, Color.white, Color.white }; } }
public static int ImportLegacyData(this LetterAnimation letter_anim, List <object> data_list, int index_offset = 0) { KeyValuePair <string, string> value_pair; string key, value; int idx; int loop_idx = 0, action_idx = 0; for (idx = index_offset; idx < data_list.Count; idx++) { value_pair = (KeyValuePair <string, string>)data_list[idx]; key = value_pair.Key; value = value_pair.Value; if (key.Equals("ANIM_DATA_END")) { // reached end of this animations import data break; } switch (key) { case "m_letters_to_animate": List <object> letter_list = value.StringToList(';'); letter_anim.m_letters_to_animate = new List <int>(); if (letter_list != null) { foreach (object obj in letter_list) { letter_anim.m_letters_to_animate.Add(int.Parse(obj.ToString())); } } break; case "m_letters_to_animate_custom_idx": letter_anim.m_letters_to_animate_custom_idx = int.Parse(value); break; case "m_letters_to_animate_option": letter_anim.m_letters_to_animate_option = (LETTERS_TO_ANIMATE)int.Parse(value); break; // LOOP DATA IMPORT case "LOOP_DATA_START": if (loop_idx == letter_anim.NumLoops) { letter_anim.AddLoop(); } break; case "LOOP_DATA_END": loop_idx++; break; case "m_delay_first_only": letter_anim.GetLoop(loop_idx).m_delay_first_only = bool.Parse(value); break; case "m_end_action_idx": letter_anim.GetLoop(loop_idx).m_end_action_idx = int.Parse(value); break; case "m_loop_type": letter_anim.GetLoop(loop_idx).m_loop_type = (LOOP_TYPE)int.Parse(value); break; case "m_number_of_loops": letter_anim.GetLoop(loop_idx).m_number_of_loops = int.Parse(value); break; case "m_start_action_idx": letter_anim.GetLoop(loop_idx).m_start_action_idx = int.Parse(value); break; // ACTION DATA IMPORT case "ACTION_DATA_START": if (action_idx == letter_anim.NumActions) { letter_anim.AddAction(); } idx = letter_anim.GetAction(action_idx).ImportLegacyData(data_list, idx + 1); action_idx++; break; } } // Remove any extra LoopData or LetterAction instances that existed prior to importing if (letter_anim.NumLoops > loop_idx) { letter_anim.RemoveLoops(loop_idx, letter_anim.NumLoops - loop_idx); } if (letter_anim.NumActions > action_idx) { letter_anim.RemoveActions(action_idx, letter_anim.NumActions - action_idx); } return(idx); }
// Animates the letter mesh and return the current action index in use public LETTER_ANIMATION_STATE AnimateMesh( bool force_render, float timer, TextAnchor text_anchor, int lowest_action_progress, LetterAnimation animation, AnimatePerOptions animate_per, float delta_time, EffectManager effect_manager) { m_last_animate_per = animate_per; m_effect_manager_handle = effect_manager; if(animation.NumActions > 0 && m_anim_state_vars.m_action_index < animation.NumActions) { if(!m_anim_state_vars.m_active && !force_render) { return LETTER_ANIMATION_STATE.STOPPED; } if(m_anim_state_vars.m_action_index != m_anim_state_vars.m_prev_action_index) { SetCurrentLetterAction(animation.GetAction(m_anim_state_vars.m_action_index), animate_per); m_anim_state_vars.m_started_action = false; } else if(m_current_letter_action == null) { SetCurrentLetterAction(animation.GetAction(m_anim_state_vars.m_action_index), animate_per); } m_anim_state_vars.m_prev_action_index = m_anim_state_vars.m_action_index; if(force_render) { SetupMesh(m_current_letter_action, m_anim_state_vars.m_action_index > 0 ? animation.GetAction(m_anim_state_vars.m_action_index-1) : null, m_anim_state_vars.m_action_progress, m_progression_variables, animate_per, m_anim_state_vars.m_linear_progress, m_effect_manager_handle); } if(m_anim_state_vars.m_waiting_to_sync) { if(m_current_letter_action.m_action_type == ACTION_TYPE.BREAK) { if(!force_render && m_anim_state_vars.m_break_delay > 0) { m_anim_state_vars.m_break_delay -= delta_time; if(m_anim_state_vars.m_break_delay <= 0) { ContinueAction(timer, animation, animate_per); return LETTER_ANIMATION_STATE.PLAYING; } } return LETTER_ANIMATION_STATE.WAITING; } else if(lowest_action_progress < m_anim_state_vars.m_action_index_progress) { return LETTER_ANIMATION_STATE.PLAYING; } else if(!force_render) { m_anim_state_vars.m_waiting_to_sync = false; // reset timer offset to compensate for the sync-up wait time m_anim_state_vars.m_timer_offset = timer; } } else if(!force_render && (m_current_letter_action.m_action_type == ACTION_TYPE.BREAK || (!m_anim_state_vars.m_reverse && m_current_letter_action.m_force_same_start_time && lowest_action_progress < m_anim_state_vars.m_action_index_progress))) { // Force letter to wait for rest of letters to be in sync m_anim_state_vars.m_waiting_to_sync = true; m_anim_state_vars.m_break_delay = Mathf.Max(m_current_letter_action.m_duration_progression.GetValue(m_progression_variables, animate_per), 0); return LETTER_ANIMATION_STATE.PLAYING; } if(force_render) { return m_anim_state_vars.m_active ? LETTER_ANIMATION_STATE.PLAYING : LETTER_ANIMATION_STATE.STOPPED; } m_anim_state_vars.m_action_progress = 0; m_anim_state_vars.m_linear_progress = 0; m_action_timer = timer - m_anim_state_vars.m_timer_offset; if((m_anim_state_vars.m_reverse || m_action_timer > m_action_delay)) { m_anim_state_vars.m_linear_progress = (m_action_timer - (m_anim_state_vars.m_reverse ? 0 : m_action_delay)) / m_action_duration; if(m_anim_state_vars.m_reverse) { if(m_action_timer >= m_action_duration) { m_anim_state_vars.m_linear_progress = 0; } else { m_anim_state_vars.m_linear_progress = 1 - m_anim_state_vars.m_linear_progress; } } if(!m_anim_state_vars.m_started_action) { // Trigger any action onStart audio or particle effects TriggerAudioEffect(animate_per, PLAY_ITEM_EVENTS.ON_START); TriggerParticleEffects(animate_per, PLAY_ITEM_EVENTS.ON_START); m_anim_state_vars.m_started_action = true; } m_anim_state_vars.m_action_progress = EasingManager.GetEaseProgress(m_current_letter_action.m_ease_type, m_anim_state_vars.m_linear_progress); if((!m_anim_state_vars.m_reverse && m_anim_state_vars.m_linear_progress >= 1) || (m_anim_state_vars.m_reverse && m_action_timer >= m_action_duration + m_action_delay)) { m_anim_state_vars.m_action_progress = m_anim_state_vars.m_reverse ? 0 : 1; m_anim_state_vars.m_linear_progress = m_anim_state_vars.m_reverse ? 0 : 1; if(!m_anim_state_vars.m_reverse && m_anim_state_vars.m_action_index != -1) { TriggerParticleEffects(animate_per, PLAY_ITEM_EVENTS.ON_FINISH); TriggerAudioEffect(animate_per, PLAY_ITEM_EVENTS.ON_FINISH); } int prev_action_idx = m_anim_state_vars.m_action_index; float prev_delay = m_action_delay; // Set next action index SetNextActionIndex(animation); if(m_anim_state_vars.m_active) { if(!m_anim_state_vars.m_reverse) { m_anim_state_vars.m_started_action = false; } if(!m_anim_state_vars.m_reverse && m_anim_state_vars.m_action_index_progress > m_anim_state_vars.m_action_index) { // Repeating the action again; check for unqiue random variable requests. animation.GetAction(m_anim_state_vars.m_action_index).SoftReset(animation.GetAction(prev_action_idx), m_progression_variables, animate_per, m_anim_state_vars.m_action_index == 0); } else if(m_anim_state_vars.m_reverse) { animation.GetAction(m_anim_state_vars.m_action_index).SoftResetStarts(animation.GetAction(prev_action_idx), m_progression_variables, animate_per); } // Add to the timer offset m_anim_state_vars.m_timer_offset += prev_delay + m_action_duration; if(prev_action_idx != m_anim_state_vars.m_action_index) { UpdateLoopList(animation); } else { SetCurrentLetterAction(animation.GetAction(m_anim_state_vars.m_action_index), animate_per); } } } } SetupMesh(m_current_letter_action, m_anim_state_vars.m_action_index > 0 ? animation.GetAction(m_anim_state_vars.m_action_index-1) : null, m_anim_state_vars.m_action_progress, m_progression_variables, animate_per, m_anim_state_vars.m_linear_progress, m_effect_manager_handle); } else { // no actions found for this letter. Position letter in its default position if(mesh_verts == null || mesh_verts.Length == 0) mesh_verts = new Vector3[4]; for(int idx=0; idx < 4; idx++) { mesh_verts[idx] = m_base_vertices[idx] + m_base_offset; } m_mesh.vertices = mesh_verts; m_anim_state_vars.m_active = false; } return m_anim_state_vars.m_active ? LETTER_ANIMATION_STATE.PLAYING : LETTER_ANIMATION_STATE.STOPPED; }
public void ContinueAction(float animation_timer, LetterAnimation animation, AnimatePerOptions animate_per) { if(m_anim_state_vars.m_waiting_to_sync) { m_anim_state_vars.m_break_delay = 0; m_anim_state_vars.m_waiting_to_sync= false; // reset timer offset to compensate for the sync-up wait time m_anim_state_vars.m_timer_offset = animation_timer; // Progress letter animation index to next, and break out of the loop int prev_action_idx = m_anim_state_vars.m_action_index; // Set next action index SetNextActionIndex(animation); if(m_anim_state_vars.m_active) { if(!m_anim_state_vars.m_reverse && m_anim_state_vars.m_action_index_progress > m_anim_state_vars.m_action_index) { // Repeating the action again; check for unqiue random variable requests. animation.GetAction(m_anim_state_vars.m_action_index).SoftReset(animation.GetAction(prev_action_idx), m_progression_variables, animate_per); } if(prev_action_idx != m_anim_state_vars.m_action_index) { UpdateLoopList(animation); } } } }
public void SetMeshState(int action_idx, float action_progress, LetterAnimation animation, AnimatePerOptions animate_per, EffectManager effect_manager) { if(action_idx >= 0 && action_idx < animation.NumActions) { SetupMesh(animation.GetAction(action_idx), action_idx > 0 ? animation.GetAction(action_idx-1) : null, Mathf.Clamp(action_progress, 0,1), m_progression_variables, animate_per, Mathf.Clamp(action_progress, 0,1), effect_manager); } else { // action not found for this letter. Position letter in its default position if(mesh_verts == null || mesh_verts.Length == 0) mesh_verts = new Vector3[4]; for(int idx=0; idx < 4; idx++) { mesh_verts[idx] = m_base_vertices[idx] + m_base_offset; } m_mesh.vertices = mesh_verts; m_mesh.colors = new Color[]{Color.white, Color.white, Color.white, Color.white}; } }
// Animates the letter mesh and return the current action index in use public LETTER_ANIMATION_STATE AnimateMesh(bool force_render, float timer, TextAnchor text_anchor, int lowest_action_progress, LetterAnimation animation, AnimatePerOptions animate_per, float delta_time, EffectManager effect_manager) { m_last_animate_per = animate_per; m_effect_manager_handle = effect_manager; if (animation.NumActions > 0 && m_anim_state_vars.m_action_index < animation.NumActions) { if (!m_anim_state_vars.m_active && !force_render) { return(LETTER_ANIMATION_STATE.STOPPED); } if (m_anim_state_vars.m_action_index != m_anim_state_vars.m_prev_action_index) { SetCurrentLetterAction(animation.GetAction(m_anim_state_vars.m_action_index), animate_per); m_anim_state_vars.m_started_action = false; } else if (m_current_letter_action == null) { SetCurrentLetterAction(animation.GetAction(m_anim_state_vars.m_action_index), animate_per); } m_anim_state_vars.m_prev_action_index = m_anim_state_vars.m_action_index; if (force_render) { SetupMesh(m_current_letter_action, m_anim_state_vars.m_action_index > 0 ? animation.GetAction(m_anim_state_vars.m_action_index - 1) : null, m_anim_state_vars.m_action_progress, m_progression_variables, animate_per, m_anim_state_vars.m_linear_progress, m_effect_manager_handle); } if (m_anim_state_vars.m_waiting_to_sync) { if (m_current_letter_action.m_action_type == ACTION_TYPE.BREAK) { if (!force_render && m_anim_state_vars.m_break_delay > 0) { m_anim_state_vars.m_break_delay -= delta_time; if (m_anim_state_vars.m_break_delay <= 0) { ContinueAction(timer, animation, animate_per); return(LETTER_ANIMATION_STATE.PLAYING); } } return(LETTER_ANIMATION_STATE.WAITING); } else if (lowest_action_progress < m_anim_state_vars.m_action_index_progress) { return(LETTER_ANIMATION_STATE.PLAYING); } else if (!force_render) { m_anim_state_vars.m_waiting_to_sync = false; // reset timer offset to compensate for the sync-up wait time m_anim_state_vars.m_timer_offset = timer; } } else if (!force_render && (m_current_letter_action.m_action_type == ACTION_TYPE.BREAK || (!m_anim_state_vars.m_reverse && m_current_letter_action.m_force_same_start_time && lowest_action_progress < m_anim_state_vars.m_action_index_progress))) { // Force letter to wait for rest of letters to be in sync m_anim_state_vars.m_waiting_to_sync = true; m_anim_state_vars.m_break_delay = Mathf.Max(m_current_letter_action.m_duration_progression.GetValue(m_progression_variables, animate_per), 0); return(LETTER_ANIMATION_STATE.PLAYING); } if (force_render) { return(m_anim_state_vars.m_active ? LETTER_ANIMATION_STATE.PLAYING : LETTER_ANIMATION_STATE.STOPPED); } m_anim_state_vars.m_action_progress = 0; m_anim_state_vars.m_linear_progress = 0; m_action_timer = timer - m_anim_state_vars.m_timer_offset; if ((m_anim_state_vars.m_reverse || m_action_timer > m_action_delay)) { m_anim_state_vars.m_linear_progress = (m_action_timer - (m_anim_state_vars.m_reverse ? 0 : m_action_delay)) / m_action_duration; if (m_anim_state_vars.m_reverse) { if (m_action_timer >= m_action_duration) { m_anim_state_vars.m_linear_progress = 0; } else { m_anim_state_vars.m_linear_progress = 1 - m_anim_state_vars.m_linear_progress; } } if (!m_anim_state_vars.m_started_action) { // Trigger any action onStart audio or particle effects TriggerAudioEffect(animate_per, PLAY_ITEM_EVENTS.ON_START); TriggerParticleEffects(animate_per, PLAY_ITEM_EVENTS.ON_START); m_anim_state_vars.m_started_action = true; } m_anim_state_vars.m_action_progress = EasingManager.GetEaseProgress(m_current_letter_action.m_ease_type, m_anim_state_vars.m_linear_progress); if ((!m_anim_state_vars.m_reverse && m_anim_state_vars.m_linear_progress >= 1) || (m_anim_state_vars.m_reverse && m_action_timer >= m_action_duration + m_action_delay)) { m_anim_state_vars.m_action_progress = m_anim_state_vars.m_reverse ? 0 : 1; m_anim_state_vars.m_linear_progress = m_anim_state_vars.m_reverse ? 0 : 1; if (!m_anim_state_vars.m_reverse && m_anim_state_vars.m_action_index != -1) { TriggerParticleEffects(animate_per, PLAY_ITEM_EVENTS.ON_FINISH); TriggerAudioEffect(animate_per, PLAY_ITEM_EVENTS.ON_FINISH); } int prev_action_idx = m_anim_state_vars.m_action_index; float prev_delay = m_action_delay; // Set next action index SetNextActionIndex(animation); if (m_anim_state_vars.m_active) { if (!m_anim_state_vars.m_reverse) { m_anim_state_vars.m_started_action = false; } if (!m_anim_state_vars.m_reverse && m_anim_state_vars.m_action_index_progress > m_anim_state_vars.m_action_index) { // Repeating the action again; check for unqiue random variable requests. animation.GetAction(m_anim_state_vars.m_action_index).SoftReset(animation.GetAction(prev_action_idx), m_progression_variables, animate_per, m_anim_state_vars.m_action_index == 0); } else if (m_anim_state_vars.m_reverse) { animation.GetAction(m_anim_state_vars.m_action_index).SoftResetStarts(animation.GetAction(prev_action_idx), m_progression_variables, animate_per); } // Add to the timer offset m_anim_state_vars.m_timer_offset += prev_delay + m_action_duration; if (prev_action_idx != m_anim_state_vars.m_action_index) { UpdateLoopList(animation); } else { SetCurrentLetterAction(animation.GetAction(m_anim_state_vars.m_action_index), animate_per); } } } } SetupMesh(m_current_letter_action, m_anim_state_vars.m_action_index > 0 ? animation.GetAction(m_anim_state_vars.m_action_index - 1) : null, m_anim_state_vars.m_action_progress, m_progression_variables, animate_per, m_anim_state_vars.m_linear_progress, m_effect_manager_handle); } else { // no actions found for this letter. Position letter in its default position if (mesh_verts == null || mesh_verts.Length == 0) { mesh_verts = new Vector3[4]; } for (int idx = 0; idx < 4; idx++) { mesh_verts[idx] = m_base_vertices[idx] + m_base_offset; } m_mesh.vertices = mesh_verts; m_anim_state_vars.m_active = false; } return(m_anim_state_vars.m_active ? LETTER_ANIMATION_STATE.PLAYING : LETTER_ANIMATION_STATE.STOPPED); }