// Sets the animation to the specified animation clip name public void SetActiveAnimation(string animation_name, bool already_active_check = false) { if (already_active_check) { if (active_animation_name == animation_name) { return; } } active_animation_name = animation_name; creature_manager.SetAutoBlending(false); bool can_set = creature_manager.SetActiveAnimationName(active_animation_name); if (!can_set) { creature_manager.SetActiveAnimationName(creature_manager.GetAnimationNames()[0]); active_animation_name = creature_manager.GetActiveAnimationName(); animation_choice_index = 0; } local_time = creature_manager.animations [creature_manager.GetActiveAnimationName()].start_time; if (game_controller) { game_controller.AnimClipChangeEvent(); } }
// Sets the animation to the specified animation clip name public void SetActiveAnimation(string animation_name, bool already_active_check = false) { if (already_active_check) { if (active_animation_name == animation_name) { return; } } active_animation_name = animation_name; bool can_set = creature_manager.SetActiveAnimationName(active_animation_name); if (!can_set) { creature_manager.SetActiveAnimationName(creature_manager.GetAnimationNames()[0]); active_animation_name = creature_manager.GetActiveAnimationName(); animation_choice_index = 0; } local_time = creature_manager.animations [creature_manager.GetActiveAnimationName()].start_time; }
public override void update( CreatureManager creature_manager, bool counter_clockwise, ref Vector3[] vertices, ref Vector3[] normals, ref Vector4[] tangents, ref Color32[] colors, ref Vector2[] uvs, CreatureAsset creature_asset, float region_overlap_z_delta, bool skin_swap_active, string skin_swap_name, string active_animation_name, ref List <int> final_indices, ref List <int> final_skin_swap_indices, ref int[] triangles, ref int[] skin_swap_triangles) { m_isValid = false; var meta_data = creature_asset.creature_meta_data; if (meta_data == null) { // Meta Data not loaded return; } var cur_anim_name = creature_manager.GetActiveAnimationName(); if (!p_asset.m_ClipDataOffsets.ContainsKey(cur_anim_name)) { // No animation return; } // Copy over Character data first var cur_char = creature_manager.GetCreature(); int char_num_pts = cur_char.total_num_pts; var char_pts = cur_char.render_pts; CopyFloatsToVec3Array(char_pts, 0, char_pts.Count, ref vertices, 0); var char_uvs = cur_char.global_uvs; CopyFloatsToUVArray(char_uvs, 0, char_uvs.Count, ref uvs, 0); CopyBytesToColorArray(cur_char.render_colours, 0, cur_char.render_colours.Count, ref colors, 0); // Generate Particle data var pack_objs = p_asset.m_PackData; var clip_data = p_asset.m_ClipDataOffsets[cur_anim_name]; var cur_anim = creature_manager.GetAnimation(cur_anim_name); var delta_frames = (int)(Math.Round(creature_manager.getActualRuntime() - cur_anim.start_time)); int clip_runtime = Math.Min(Math.Max(0, delta_frames), clip_data.num_frames - 1); var frame_data = clip_data.particles_lookup[clip_runtime]; // Now start mesh generation int pt_offset = char_num_pts * 3; int uv_offset = char_num_pts * 2; int colors_offset = char_num_pts; int indices_offset = 0; m_numIndices = 0; var all_regions = cur_char.render_composition.getRegions(); // Go through each mesh region and check to see if we need to process it considering SkinSwaps as well float region_z = 0.0f; foreach (var cur_region in all_regions) { bool is_valid = true; if (skin_swap_active) { is_valid = (meta_data.skin_swaps[skin_swap_name].Contains(cur_region.getName())); } if (is_valid) { // Copy over base region indices CopyIntsToIntArray(cur_region.store_indices, cur_region.getStartIndex(), cur_region.getNumIndices(), ref final_indices, indices_offset); indices_offset += cur_region.getNumIndices(); // Set base region z for (int i = 0; i < cur_region.getNumIndices(); i++) { vertices[cur_region.store_indices[i + cur_region.getStartIndex()]].z = region_z; } int layer_idx = cur_region.getTagId(); if (frame_data.ContainsKey(cur_region.getTagId())) { // Process Particles for layer Start var layer_data = frame_data[cur_region.getTagId()]; for (int i = 0; i < layer_data.num_particles; i++) { int rel_offset = layer_data.offset + (i * 5); var p_pos_list = (object[])pack_objs[rel_offset]; float p_angle = (float)pack_objs[rel_offset + 1]; int p_sprite_idx = -(int)pack_objs[rel_offset + 2]; var p_size = (object[])pack_objs[rel_offset + 3]; var p_color = (object[])pack_objs[rel_offset + 4]; var p_sprite_uvs = meta_data.uvs_data[p_sprite_idx]; var b_uv0 = new Vector2(p_sprite_uvs.uv0.x, p_sprite_uvs.uv0.y); var b_uv1 = new Vector2(p_sprite_uvs.uv1.x, p_sprite_uvs.uv1.y); var b_color = new Vector4((float)p_color[0], (float)p_color[1], (float)p_color[2], (float)p_color[3]); region_z += region_overlap_z_delta * 0.1f; if (p_pos_list.Length == 2) { // No Trail int idx_pt_offset = pt_offset / 3; var b_pos = new Vector2((float)p_pos_list[0], (float)p_pos_list[1]); setVertData( b_pos + rotVec2D(new Vector2(-(float)p_size[0], -(float)p_size[1]), p_angle), region_z, new Vector2(b_uv0.x, b_uv0.y), b_color, ref pt_offset, ref uv_offset, ref colors_offset, ref vertices, ref uvs, ref colors ); setVertData( b_pos + rotVec2D(new Vector2(-(float)p_size[0], (float)p_size[1]), p_angle), region_z, new Vector2(b_uv0.x, b_uv1.y), b_color, ref pt_offset, ref uv_offset, ref colors_offset, ref vertices, ref uvs, ref colors ); setVertData( b_pos + rotVec2D(new Vector2((float)p_size[0], (float)p_size[1]), p_angle), region_z, new Vector2(b_uv1.x, b_uv1.y), b_color, ref pt_offset, ref uv_offset, ref colors_offset, ref vertices, ref uvs, ref colors ); setVertData( b_pos + rotVec2D(new Vector2((float)p_size[0], -(float)p_size[1]), p_angle), region_z, new Vector2(b_uv1.x, b_uv0.y), b_color, ref pt_offset, ref uv_offset, ref colors_offset, ref vertices, ref uvs, ref colors ); // Indices setIndiceData(ref indices_offset, idx_pt_offset + 2, ref final_indices); setIndiceData(ref indices_offset, idx_pt_offset + 1, ref final_indices); setIndiceData(ref indices_offset, idx_pt_offset, ref final_indices); setIndiceData(ref indices_offset, idx_pt_offset + 2, ref final_indices); setIndiceData(ref indices_offset, idx_pt_offset, ref final_indices); setIndiceData(ref indices_offset, idx_pt_offset + 3, ref final_indices); } else if (p_pos_list.Length > 2) { // With Trail int idx_pt_offset = pt_offset / 3; int trail_num = p_pos_list.Length / 2; var dir_p = new Vector2(0, 0); var rot_p = new Vector2(0, 0); var diff_p = new Vector2(0, 0); var delta_uvs = b_uv1 - b_uv0; for (int j = 0; j < trail_num; j++) { var p1 = GetParticlePos(p_pos_list, j); if (j < (trail_num - 1)) { diff_p = GetParticlePos(p_pos_list, j + 1) - GetParticlePos(p_pos_list, j); } else { diff_p = GetParticlePos(p_pos_list, trail_num - 1) - GetParticlePos(p_pos_list, trail_num - 2); } if (diff_p.magnitude > 0) { dir_p = diff_p.normalized; } rot_p = rotVec2D_90(dir_p) * (float)p_size[1]; var cur_uv = new Vector2(0, 0); float sub_alpha = Math.Min(1.0f / (float)(trail_num) * (float)(j), 1.0f); if (j < (trail_num - 1)) { cur_uv.x = delta_uvs.x / (float)(trail_num) * (float)(j) + b_uv0.x; cur_uv.y = b_uv0.y; setVertData( p1 + rot_p, region_z, cur_uv, b_color * sub_alpha, ref pt_offset, ref uv_offset, ref colors_offset, ref vertices, ref uvs, ref colors ); cur_uv.y = b_uv1.y; setVertData( p1 - rot_p, region_z, cur_uv, b_color * sub_alpha, ref pt_offset, ref uv_offset, ref colors_offset, ref vertices, ref uvs, ref colors ); } else { // Final trail pos cur_uv.x = b_uv1.x; cur_uv.y = b_uv0.y; setVertData( p1 + diff_p + rot_p, region_z, cur_uv, b_color * sub_alpha, ref pt_offset, ref uv_offset, ref colors_offset, ref vertices, ref uvs, ref colors ); cur_uv.y = b_uv1.y; setVertData( p1 + diff_p + rot_p, region_z, cur_uv, b_color * sub_alpha, ref pt_offset, ref uv_offset, ref colors_offset, ref vertices, ref uvs, ref colors ); } } // Indices int delta_trail_indices = 0; for (int j = 0; j < trail_num - 1; j++) { setIndiceData(ref indices_offset, idx_pt_offset + 2 + delta_trail_indices, ref final_indices); setIndiceData(ref indices_offset, idx_pt_offset + delta_trail_indices, ref final_indices); setIndiceData(ref indices_offset, idx_pt_offset + 1 + delta_trail_indices, ref final_indices); setIndiceData(ref indices_offset, idx_pt_offset + 2 + delta_trail_indices, ref final_indices); setIndiceData(ref indices_offset, idx_pt_offset + 1 + delta_trail_indices, ref final_indices); setIndiceData(ref indices_offset, idx_pt_offset + 3 + delta_trail_indices, ref final_indices); delta_trail_indices += 2; } } } // Process Particles for layer End } } region_z += region_overlap_z_delta; } m_numIndices = indices_offset; m_isValid = true; }