Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix undo when creating collisions #7

Merged
merged 1 commit into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix undo when creating collisions
  • Loading branch information
Gann4Life committed Jul 12, 2023
commit b80f9463191ffc6253b405d3473b26e1fcc9cbf4
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,15 @@ public override void Create()
collisionObject.transform.localPosition = Vector3.zero;
collisionObject.transform.forward = objB.position - objA.position;
collisionObject.transform.localScale = Vector3.one;
BoxCollider _selectedBoxCollider = Undo.AddComponent<BoxCollider>(collisionObject);
BoxCollider _selectedBoxCollider = collisionObject.AddComponent<BoxCollider>();
_selectedBoxCollider.center = Vector3.forward * height;
_selectedBoxCollider.size = new Vector3(Context.boxColliderWidth, Context.boxColliderDepth, distance);

Context.boxColliderLength = height;

Undo.RegisterCreatedObjectUndo(collisionObject, "Created Box Collider Object");
Undo.RegisterCompleteObjectUndo(Context, "Created Box Collider Object");


Select(_selectedBoxCollider);
Undo.RegisterCompleteObjectUndo(Context, "Created Box Collider Object");
}

public override void ConvertTo(Component component)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,23 @@ public override void Create()
// throw new Exception("The second bone must be child of the first bone!");

float distance = Vector3.Distance(objA.position, objB.position);

GameObject collisionObject = new GameObject(objA.name + " - " + objB.name);
collisionObject.transform.SetParent(objA);
collisionObject.transform.localPosition = Vector3.zero;
collisionObject.transform.forward = objB.position - objA.position;
collisionObject.transform.localScale = Vector3.one;
CapsuleCollider selectedCapsuleCollider = Undo.AddComponent<CapsuleCollider>(collisionObject);
CapsuleCollider selectedCapsuleCollider = collisionObject.AddComponent<CapsuleCollider>();
selectedCapsuleCollider.direction = 2;
selectedCapsuleCollider.radius = Context.capsuleColliderRadius;
selectedCapsuleCollider.center = Vector3.forward * distance / 2;
selectedCapsuleCollider.height = distance + selectedCapsuleCollider.radius;

Context.capsuleColliderLength = distance;

Undo.RegisterCompleteObjectUndo(Context, "Created Capsule Collider Object");

Undo.RegisterCreatedObjectUndo(collisionObject, "Created Capsule Collider Object");
Select(selectedCapsuleCollider);
Undo.RegisterCompleteObjectUndo(Context, "Created Capsule Collider Object");
}

public override void ConvertTo(Component component)
Expand Down