public override void initData(CreatureManager creature_manager, CreatureAsset creature_asset) { var cur_char = creature_manager.GetCreature(); m_isValid = false; m_numIndices = cur_char.total_num_indices; }
void FillAnimationNames() { CreatureAsset creature_asset = (CreatureAsset)target; CreatureManager creature_manager = creature_asset.GetCreatureManager(); if (creature_manager == null) { return; } Dictionary <string, CreatureModule.CreatureAnimation> all_animations = creature_manager.animations; animation_names.Clear(); foreach (string cur_name in all_animations.Keys) { animation_names.Add(cur_name); } animation_clip_overrides = creature_asset.animation_clip_overides; if (animation_clip_overrides.Count == 0) { foreach (string cur_name in all_animations.Keys) { var cur_animation = all_animations[cur_name]; animation_clip_overrides.Add(cur_name, new CreatureAnimationAssetData((int)cur_animation.start_time, (int)cur_animation.end_time)); } } }
public static void EnableSkinSwap( String swap_name_in, bool active, CreatureManager creature_manager, CreatureAsset creature_asset, ref bool skin_swap_active, ref string skin_swap_name, ref int[] skin_swap_triangles, ref List <int> final_skin_swap_indices) { skin_swap_active = active; if (!skin_swap_active) { skin_swap_name = ""; skin_swap_triangles = null; final_skin_swap_indices = null; } else { skin_swap_name = swap_name_in; if (creature_asset.creature_meta_data != null) { final_skin_swap_indices = new List <int>(); creature_asset.creature_meta_data.buildSkinSwapIndices( skin_swap_name, creature_manager.GetCreature().render_composition, final_skin_swap_indices); skin_swap_triangles = new int[final_skin_swap_indices.Count]; } } }
string GetLiveSyncType() { CreatureAsset creature_asset = (CreatureAsset)target; if (!creature_asset.useFlatDataAsset) { TextAsset text_asset = (TextAsset)creatureJSON.objectReferenceValue; if (text_asset) { if (text_asset.text.Length > 0) { return("REQUEST_JSON"); } } } else { TextAsset flat_text_asset = (TextAsset)flatCreatureData.objectReferenceValue; if (flat_text_asset) { if (flat_text_asset.text.Length > 0) { return("REQUEST_BYTES"); } } } return(""); }
public void Create_Implementation() { var asset = new CreatureAsset(_assetId, _components); Assert.True(asset.ContainsComponent <ParametersComponent>()); Assert.Equal(_assetId, asset.Id); Assert.Equal(_assetId, asset.GetHashCode()); Assert.Same(_components[0], asset.GetComponent <ParametersComponent>()); Assert.Same(_components[0], asset.Parameters); }
public void Add_GroupContains_CreatedAfter() { var asset = new CreatureAsset(0, BuildComponent <ParametersComponent>()); Measure(() => _assetContext.Add(asset)); var creatures = _assetContext.GetGroup <CreatureAsset>(); Assert.True(creatures.Contains(asset)); }
override public void OnInspectorGUI() { serializedObject.Update(); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(creature_asset); EditorGUILayout.PropertyField(local_time_scale); EditorGUILayout.PropertyField(region_offsets_z); EditorGUILayout.PropertyField(counter_clockwise); bool did_change = EditorGUI.EndChangeCheck(); // new assignment if ((creature_asset.objectReferenceValue != null) && did_change) { UpdateData(); } if (creature_asset.objectReferenceValue != null) { CreatureAsset cur_asset = (CreatureAsset)creature_asset.objectReferenceValue; // asset changed if (cur_asset.GetIsDirty()) { UpdateData(); cur_asset.SetIsDirty(false); } // animations if (cur_asset.creature_manager != null) { string[] animation_names = new string[cur_asset.creature_manager.animations.Keys.Count]; int i = 0; foreach (string cur_name in cur_asset.creature_manager.animations.Keys) { animation_names[i] = cur_name; i++; } animation_choice_index.intValue = EditorGUILayout.Popup("Animation:", animation_choice_index.intValue, animation_names); should_loop.boolValue = EditorGUILayout.Toggle("Loop", should_loop.boolValue); if (!Application.isPlaying) { updateTargetAnimation(); } serializedObject.ApplyModifiedProperties(); } } }
public void Group() { var creatureAsset = new CreatureAsset(1, BuildComponent <ParametersComponent>()); var notCreatureAsset = BuildAsset(0); _assetContext.Add(creatureAsset); _assetContext.Add(notCreatureAsset); var assetGroup = _assetContext.GetGroup <CreatureAsset>(); Assert.True(assetGroup.Contains(creatureAsset)); Assert.Equal(1, assetGroup.Length); }
void UpdateData() { CreatureAsset creature_asset = (CreatureAsset)target; TextAsset text_asset = (TextAsset)creatureJSON.objectReferenceValue; if (text_asset) { if (text_asset.text.Length > 0) { creature_asset.ResetState(); creature_asset.creatureJSON = text_asset; FillAnimationNames(); } } TextAsset compressed_text_asset = (TextAsset)compressedCreatureJSON.objectReferenceValue; if (compressed_text_asset) { if (compressed_text_asset.text.Length > 0) { creature_asset.ResetState(); creature_asset.compressedCreatureJSON = compressed_text_asset; FillAnimationNames(); } } TextAsset flat_text_asset = (TextAsset)flatCreatureData.objectReferenceValue; if (flat_text_asset) { if (flat_text_asset.text.Length > 0) { creature_asset.ResetState(); creature_asset.flatCreatureData = flat_text_asset; FillAnimationNames(); } } TextAsset meta_text_asset = (TextAsset)creatureMetaJSON.objectReferenceValue; if (meta_text_asset) { if (meta_text_asset.text.Length > 0) { creature_asset.creature_manager = null; creature_asset.creatureMetaJSON = meta_text_asset; } } }
public static bool AddSkinSwap(CreatureAsset creature_asset, String swap_name, HashSet <String> swap_set) { if (creature_asset.creature_meta_data == null) { return(false); } if (creature_asset.creature_meta_data.skin_swaps.ContainsKey(swap_name)) { return(false); } creature_asset.creature_meta_data.skin_swaps[swap_name] = swap_set; return(true); }
public void SaveCompressedFile() { var path = EditorUtility.SaveFilePanel( "Save data as compressed file", "", "characterCompressed.bytes", "bytes"); if (path.Length != 0) { CreatureAsset creature_asset = (CreatureAsset)target; TextAsset text_asset = (TextAsset)creatureJSON.objectReferenceValue; string save_text = text_asset.text; creature_asset.SaveCompressedText(path, save_text); } }
public virtual 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) { }
public void CreateStateMachine() { CreatureAsset creature_asset = (CreatureAsset)target; string create_name = "Assets/" + creature_asset.name + "_StateMachineTransitions.controller"; // Creates the controller var controller = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPath(create_name); var rootStateMachine = controller.layers[0].stateMachine; // Add states CreatureManager creature_manager = creature_asset.GetCreatureManager(); Dictionary <string, CreatureModule.CreatureAnimation> all_animations = creature_manager.animations; animation_names.Clear(); foreach (string cur_name in all_animations.Keys) { var new_state = rootStateMachine.AddState(cur_name); new_state.AddStateMachineBehaviour <CreatureStateMachineBehavior>(); CreatureStateMachineBehavior cur_behavior = (CreatureStateMachineBehavior)new_state.behaviours[0]; cur_behavior.play_animation_name = cur_name; } }
void updateTargetAnimation() { CreatureRenderer creature_renderer = (CreatureRenderer)target; CreatureAsset cur_asset = (CreatureAsset)creature_asset.objectReferenceValue; int i = 0; string set_name = null; foreach (string cur_name in cur_asset.creature_manager.animations.Keys) { if (i == animation_choice_index.intValue) { set_name = cur_name; break; } i++; } if (creature_renderer.active_animation_name.Equals(set_name) == false) { creature_renderer.SetActiveAnimation(set_name); active_animation_name.stringValue = creature_renderer.active_animation_name; } }
public virtual void initData(CreatureManager creature_manager, CreatureAsset creature_asset) { }
public static void UpdateWithParticlesForRenderingData( CreatureParticlesAsset particles_asset, 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) { particles_asset.mesh_modifier.update( creature_manager, counter_clockwise, ref vertices, ref normals, ref tangents, ref colors, ref uvs, creature_asset, region_overlap_z_delta, skin_swap_active, skin_swap_name, active_animation_name, ref final_indices, ref final_skin_swap_indices, ref triangles, ref skin_swap_triangles); float normal_z = 1.0f; if (counter_clockwise) { normal_z = -1.0f; } for (int i = 0; i < vertices.Length; i++) { normals[i].x = 0; normals[i].y = 0; normals[i].z = normal_z; tangents[i].x = 1.0f; tangents[i].y = 0; tangents[i].z = 0; } for (int i = 0; i < triangles.Length; i++) { triangles[i] = 0; } SetIndexBuffer(final_indices, triangles, counter_clockwise); }
override public void OnInspectorGUI() { CreatureAsset creature_asset = (CreatureAsset)target; serializedObject.Update(); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(creatureJSON); EditorGUILayout.PropertyField(compressedCreatureJSON); EditorGUILayout.PropertyField(flatCreatureData); EditorGUILayout.PropertyField(creatureMetaJSON); bool did_change = EditorGUI.EndChangeCheck(); creature_asset.useCompressedAsset = EditorGUILayout.Toggle("Use Compressed Asset: ", creature_asset.useCompressedAsset); creature_asset.useFlatDataAsset = EditorGUILayout.Toggle("Use Flat Data Asset: ", creature_asset.useFlatDataAsset); if ((creatureJSON.objectReferenceValue || compressedCreatureJSON.objectReferenceValue || flatCreatureData.objectReferenceValue) && did_change) { UpdateData(); } if (creatureJSON.objectReferenceValue || compressedCreatureJSON.objectReferenceValue | flatCreatureData.objectReferenceValue) { FillAnimationNames(); int i = 1; foreach (string cur_name in animation_names) { EditorGUILayout.LabelField("Animation Clip #" + i.ToString() + ":", cur_name); var cur_start_time = animation_clip_overrides[cur_name].start_frame; var cur_end_time = animation_clip_overrides[cur_name].end_frame; bool make_point_cache = animation_clip_overrides[cur_name].make_point_cache; var cache_approximation = animation_clip_overrides[cur_name].cache_approximation; EditorGUILayout.BeginHorizontal(GUILayout.MaxHeight(20)); EditorGUILayout.LabelField("Frame Range:", GUILayout.MaxWidth(100)); int new_start_frame = EditorGUILayout.IntField(cur_start_time, GUILayout.MaxWidth(50)); EditorGUILayout.LabelField("to", GUILayout.MaxWidth(20)); int new_end_frame = EditorGUILayout.IntField(cur_end_time, GUILayout.MaxWidth(50)); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginVertical(GUILayout.MaxHeight(50)); make_point_cache = EditorGUILayout.Toggle("Point Cache:", make_point_cache); EditorGUILayout.BeginHorizontal(GUILayout.MaxHeight(20)); EditorGUILayout.LabelField("Cache Approximation:", GUILayout.MaxWidth(150)); cache_approximation = EditorGUILayout.IntSlider(cache_approximation, 1, 10); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); animation_clip_overrides[cur_name].start_frame = new_start_frame; animation_clip_overrides[cur_name].end_frame = new_end_frame; animation_clip_overrides[cur_name].make_point_cache = make_point_cache; animation_clip_overrides[cur_name].cache_approximation = cache_approximation; i++; } } if (GUILayout.Button("Build State Machine")) { CreateStateMachine(); } EditorGUILayout.LabelField("Compression Options", GUILayout.MaxHeight(20)); if (GUILayout.Button("Export as Compressed File")) { SaveCompressedFile(); } }
public static bool shouldSkinSwap(CreatureAsset creature_asset, bool skin_swap_active, ref int[] skin_swap_triangles) { return((creature_asset.creature_meta_data != null) && skin_swap_active && (skin_swap_triangles != null)); }
public static void UpdateRenderingData( CreatureManager creature_manager, bool counter_clockwise, ref Vector3[] vertices, ref Vector3[] normals, ref Vector4[] tangents, ref Color32[] colors, ref Vector2[] uvs, CreatureAsset creature_asset, bool skin_swap_active, string active_animation_name, ref List <int> final_indices, ref List <int> final_skin_swap_indices, ref int[] triangles, ref int[] skin_swap_triangles) { int pt_index = 0; int uv_index = 0; int color_index = 0; List <float> render_pts = creature_manager.target_creature.render_pts; List <float> render_uvs = creature_manager.target_creature.global_uvs; List <byte> render_colors = creature_manager.target_creature.render_colours; float normal_z = 1.0f; if (counter_clockwise) { normal_z = -1.0f; } for (int i = 0; i < creature_manager.target_creature.total_num_pts; i++) { vertices[i].x = render_pts[pt_index + 0]; vertices[i].y = render_pts[pt_index + 1]; vertices[i].z = render_pts[pt_index + 2]; normals[i].x = 0; normals[i].y = 0; normals[i].z = normal_z; tangents[i].x = 1.0f; tangents[i].y = 0; tangents[i].z = 0; uvs[i].x = render_uvs[uv_index + 0]; uvs[i].y = 1.0f - render_uvs[uv_index + 1]; colors[i].r = render_colors[color_index + 0]; colors[i].g = render_colors[color_index + 1]; colors[i].b = render_colors[color_index + 2]; colors[i].a = render_colors[color_index + 3]; pt_index += 3; uv_index += 2; color_index += 4; } List <int> render_indices = creature_manager.target_creature.global_indices; // index re-ordering if (creature_asset.creature_meta_data != null) { if (!shouldSkinSwap(creature_asset, skin_swap_active, ref skin_swap_triangles)) { // do index re-ordering var real_run_time = creature_manager.run_time; if (creature_manager.do_blending && creature_manager.active_blend_run_times.ContainsKey(active_animation_name)) { real_run_time = creature_manager.active_blend_run_times[active_animation_name]; } creature_asset.creature_meta_data.updateIndicesAndPoints( final_indices, render_indices, render_pts, 0, creature_manager.target_creature.total_num_indices, creature_manager.target_creature.total_num_pts, active_animation_name, (int)real_run_time); } } else { // plain copy for (int i = 0; i < render_indices.Count; i++) { final_indices[i] = render_indices[i]; } } if (shouldSkinSwap(creature_asset, skin_swap_active, ref skin_swap_triangles)) { SetIndexBuffer(final_skin_swap_indices, skin_swap_triangles, counter_clockwise); } else { SetIndexBuffer(final_indices, triangles, counter_clockwise); } }
override public void OnInspectorGUI() { CreatureAsset creature_asset = (CreatureAsset)target; serializedObject.Update(); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(creatureJSON); EditorGUILayout.PropertyField(compressedCreatureJSON); EditorGUILayout.PropertyField(flatCreatureData); EditorGUILayout.PropertyField(creatureMetaJSON); bool did_change = EditorGUI.EndChangeCheck(); creature_asset.useCompressedAsset = EditorGUILayout.Toggle("Use Compressed Asset: ", creature_asset.useCompressedAsset); creature_asset.useFlatDataAsset = EditorGUILayout.Toggle("Use Flat Data Asset: ", creature_asset.useFlatDataAsset); if ((creatureJSON.objectReferenceValue || compressedCreatureJSON.objectReferenceValue || flatCreatureData.objectReferenceValue) && did_change) { UpdateData(); } if (creatureJSON.objectReferenceValue || compressedCreatureJSON.objectReferenceValue | flatCreatureData.objectReferenceValue) { FillAnimationNames(); int i = 1; foreach (string cur_name in animation_names) { EditorGUILayout.Space(); EditorGUILayout.LabelField("Animation Clip #" + i.ToString() + ":", cur_name); var cur_start_time = animation_clip_overrides[cur_name].start_frame; var cur_end_time = animation_clip_overrides[cur_name].end_frame; bool make_point_cache = animation_clip_overrides[cur_name].make_point_cache; var cache_approximation = animation_clip_overrides[cur_name].cache_approximation; EditorGUILayout.BeginHorizontal(GUILayout.MaxHeight(20)); EditorGUILayout.LabelField("Frame Range:", GUILayout.MaxWidth(100)); int new_start_frame = EditorGUILayout.IntField(cur_start_time, GUILayout.MaxWidth(50)); EditorGUILayout.LabelField("to", GUILayout.MaxWidth(20)); int new_end_frame = EditorGUILayout.IntField(cur_end_time, GUILayout.MaxWidth(50)); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginVertical(GUILayout.MaxHeight(50)); make_point_cache = EditorGUILayout.Toggle("Point Cache:", make_point_cache); EditorGUILayout.BeginHorizontal(GUILayout.MaxHeight(20)); EditorGUILayout.LabelField("Cache Approximation:", GUILayout.MaxWidth(150)); cache_approximation = EditorGUILayout.IntSlider(cache_approximation, 1, 10); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); animation_clip_overrides[cur_name].start_frame = new_start_frame; animation_clip_overrides[cur_name].end_frame = new_end_frame; animation_clip_overrides[cur_name].make_point_cache = make_point_cache; animation_clip_overrides[cur_name].cache_approximation = cache_approximation; i++; } } if (Application.platform == RuntimePlatform.WindowsEditor) { EditorGUILayout.Space(); EditorGUILayout.LabelField("Live Sync Options", EditorStyles.boldLabel); if (GUILayout.Button("Live Sync")) { RunLiveSync(); } } EditorGUILayout.Space(); EditorGUILayout.LabelField("Animation State Options", EditorStyles.boldLabel); if (GUILayout.Button("Build State Machine")) { CreateStateMachine(); } if (creature_asset.physics_assets.Count > 0) { EditorGUILayout.Space(); EditorGUILayout.LabelField("Bend Physics Chains", EditorStyles.boldLabel); foreach (var cur_chain in creature_asset.physics_assets) { EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(GUILayout.MaxHeight(20)); EditorGUILayout.LabelField("Motor Name:", GUILayout.MaxWidth(100)); EditorGUILayout.LabelField(cur_chain.motor_name, GUILayout.MaxWidth(100)); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(GUILayout.MaxHeight(20)); EditorGUILayout.LabelField("Anim Clip:", GUILayout.MaxWidth(100)); EditorGUILayout.LabelField(cur_chain.anim_clip_name, GUILayout.MaxWidth(100)); EditorGUILayout.EndHorizontal(); bool chain_active = cur_chain.active; EditorGUILayout.BeginHorizontal(GUILayout.MaxHeight(20)); chain_active = EditorGUILayout.Toggle("Active:", chain_active); EditorGUILayout.EndHorizontal(); cur_chain.active = chain_active; EditorGUILayout.BeginHorizontal(GUILayout.MaxHeight(20)); EditorGUILayout.LabelField("Num Bones:", GUILayout.MaxWidth(100)); EditorGUILayout.LabelField(cur_chain.num_bones.ToString(), GUILayout.MaxWidth(100)); EditorGUILayout.EndHorizontal(); float chain_stiffness = cur_chain.stiffness; EditorGUILayout.BeginHorizontal(GUILayout.MaxHeight(20)); EditorGUILayout.LabelField("Stiffness:", GUILayout.MaxWidth(100)); chain_stiffness = EditorGUILayout.FloatField(chain_stiffness, GUILayout.MaxWidth(50)); EditorGUILayout.EndHorizontal(); cur_chain.stiffness = chain_stiffness; float chain_damping = cur_chain.damping; EditorGUILayout.BeginHorizontal(GUILayout.MaxHeight(20)); EditorGUILayout.LabelField("Damping:", GUILayout.MaxWidth(100)); chain_damping = EditorGUILayout.FloatField(chain_damping, GUILayout.MaxWidth(50)); EditorGUILayout.EndHorizontal(); cur_chain.damping = chain_damping; } } if (creature_asset.skin_swap_names.Count > 0) { EditorGUILayout.Space(); EditorGUILayout.LabelField("Skin Swaps", EditorStyles.boldLabel); foreach (var cur_swap_name in creature_asset.skin_swap_names) { EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(GUILayout.MaxHeight(20)); EditorGUILayout.LabelField(cur_swap_name, GUILayout.MaxWidth(100)); EditorGUILayout.EndHorizontal(); } } if (creature_asset.morph_poses.Count > 0) { EditorGUILayout.Space(); EditorGUILayout.LabelField("Morph Target Poses", EditorStyles.boldLabel); foreach (var cur_pose_name in creature_asset.morph_poses) { EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(GUILayout.MaxHeight(20)); EditorGUILayout.LabelField(cur_pose_name, GUILayout.MaxWidth(100)); EditorGUILayout.EndHorizontal(); } } if (creature_asset.vertex_attachments.Count > 0) { EditorGUILayout.Space(); EditorGUILayout.LabelField("Vertex Attachments", EditorStyles.boldLabel); foreach (var cur_attachment_name in creature_asset.vertex_attachments) { EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(GUILayout.MaxHeight(20)); EditorGUILayout.LabelField(cur_attachment_name, GUILayout.MaxWidth(100)); EditorGUILayout.EndHorizontal(); } } }
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; }
public void RunLiveSync() { CreatureAsset creature_asset = (CreatureAsset)target; if (Application.platform == RuntimePlatform.WindowsEditor) { if (!LiveSync.creatureClient_isConnected()) { var can_connect = LiveSync.creatureClient_startConnection(); if (!can_connect) { LiveSync.creatureClient_stopConnection(); } } if (LiveSync.creatureClient_isConnected()) { var sync_type = GetLiveSyncType(); if (sync_type.Length > 0) { System.IntPtr raw_ptr = LiveSync.creatureClient_retrieveRequestExportFilename(sync_type); string response_str = Marshal.PtrToStringAnsi(raw_ptr); if (response_str.Length == 0) { UnityEditor.EditorUtility.DisplayDialog("Creature Live Sync Error", "Make sure Creature Pro is running in Animate Mode to Live Sync!", "Ok"); } else { if (sync_type == "REQUEST_JSON") { string file_contents = System.IO.File.ReadAllText(response_str); TextAsset text_asset = (TextAsset)creatureJSON.objectReferenceValue; File.WriteAllText(AssetDatabase.GetAssetPath(text_asset), file_contents); EditorUtility.SetDirty(text_asset); creature_asset.creature_manager = null; UpdateData(); creature_asset.SetIsDirty(true); } else if (sync_type == "REQUEST_BYTES") { byte[] file_contents = System.IO.File.ReadAllBytes(response_str); TextAsset flat_text_asset = (TextAsset)flatCreatureData.objectReferenceValue; File.WriteAllBytes(AssetDatabase.GetAssetPath(flat_text_asset), file_contents); EditorUtility.SetDirty(flat_text_asset); creature_asset.creature_manager = null; UpdateData(); creature_asset.SetIsDirty(true); } AssetDatabase.Refresh(); } } } else { UnityEditor.EditorUtility.DisplayDialog("Creature Live Sync Error", "Make sure Creature Pro is running in Animate Mode to Live Sync!", "Ok"); } } }