void UpdateData() { CreatureRenderer creature_renderer = (CreatureRenderer)target; creature_renderer.creature_asset = (CreatureAsset)creature_asset.objectReferenceValue; creature_renderer.animation_choice_index = animation_choice_index.intValue; creature_renderer.should_loop = should_loop.boolValue; creature_renderer.local_time_scale = local_time_scale.floatValue; creature_renderer.region_offsets_z = region_offsets_z.floatValue; creature_renderer.counter_clockwise = counter_clockwise.boolValue; creature_renderer.InitData(); creature_renderer.CreateRenderingData(); }
public void CreateGameColliders() { if (creature_renderer == null) { return; } if (transform.childCount > 0) { Debug.Log("Please remove all children game colliders before running CreateGameColliders!"); return; } creature_renderer.InitData(); MeshBone root_bone = GetRootBone(); // Create a base rigid body that actually participates in simulation for the creature_renderer var parent_obj = creature_renderer.gameObject; Rigidbody2D parent_rbd = parent_obj.AddComponent <Rigidbody2D>(); parentRBD = parent_rbd; parent_rbd.isKinematic = false; BoxCollider2D parent_collider = parent_obj.AddComponent <BoxCollider2D>(); parent_collider.size = new UnityEngine.Vector2(simColliderWidth, simColliderHeight); // Create rigid bodies for all the bones List <MeshBone> all_children = root_bone.getAllChildren(); foreach (MeshBone cur_child in all_children) { // Create new GameObject GameObject new_obj = new GameObject(cur_child.key); // Add components XnaGeometry.Vector4 spawn_center = (cur_child.getWorldStartPt() + cur_child.getWorldEndPt()) * 0.5f; float colliderWidth = (float)(cur_child.getWorldRestEndPt() - cur_child.getWorldRestStartPt()).Length(); XnaGeometry.Vector4 spawn_dir = (cur_child.getWorldRestEndPt() - cur_child.getWorldRestStartPt()); spawn_dir.Normalize(); // Get the direction in the renderer's space UnityEngine.Vector3 u_spawn_dir = new UnityEngine.Vector3((float)spawn_dir.X, (float)spawn_dir.Y, (float)0); u_spawn_dir = TransformToCreatureDir(u_spawn_dir); float startAngle = (float)Math.Atan2((double)u_spawn_dir.y, (double)u_spawn_dir.x) * Mathf.Rad2Deg; UnityEngine.Vector3 local_pos = new UnityEngine.Vector3((float)spawn_center.X, (float)spawn_center.Y, (float)0); Rigidbody2D new_rbd = new_obj.AddComponent <Rigidbody2D>(); new_rbd.isKinematic = true; BoxCollider2D new_collider = new_obj.AddComponent <BoxCollider2D>(); new_collider.size = new UnityEngine.Vector2(colliderWidth, colliderHeight); // set the position using the renderer's parent transform new_obj.transform.position = TransformToCreaturePt(local_pos); new_obj.transform.rotation = UnityEngine.Quaternion.AngleAxis(startAngle, new UnityEngine.Vector3(0, 0, 1)); // Make new object child of the parent new_obj.transform.parent = gameObject.transform; } }