Skip to content

Commit

Permalink
feat laps rigidbody, enable, disable, set kinematic, dynamic slots
Browse files Browse the repository at this point in the history
  • Loading branch information
seyahdoo committed Jun 21, 2021
1 parent 4b1c4de commit 1f3868d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
8 changes: 8 additions & 0 deletions Assets/Laps/Runtime/Components/Physics/LapsRigidbody.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@ public override object HandleInput(int slotId, object parameter, LapsComponent e
switch (slotId) {
case 0: return GetComponent<Rigidbody>();
case 1: return transform;
case 2: gameObject.SetActive(true); return null;
case 3: gameObject.SetActive(false); return null;
case 4: GetComponent<Rigidbody>().isKinematic = true; return null;
case 5: GetComponent<Rigidbody>().isKinematic = false; return null;
default: return null;
}
}
public override void GetInputSlots(SlotList slots) {
slots.Add("body", 0, null, typeof(Rigidbody));
slots.Add("transform", 1, null, typeof(Transform));
slots.Add("enable", 2);
slots.Add("disable", 3);
slots.Add("set kinematic", 4);
slots.Add("set dynamic", 5);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,59 @@ public void Setup() {
go.AddComponent<Rigidbody>();
comp3D = go.AddComponent<LapsRigidbody>();
}
[TearDown]
public void Teardown() {
Object.DestroyImmediate(comp3D.gameObject);
}
[Test]
public void LapsRigidbodyReturnsTheRigidbodyOfTheObject() {
var coll3D = comp3D.GetComponent<Rigidbody>();
public void Body() {
var body = comp3D.GetComponent<Rigidbody>();
var r3d = comp3D.HandleInput(0, null, null);
Assert.AreEqual(coll3D, r3d);
Assert.AreEqual(body, r3d);
}
[Test]
public void Transform() {
var trans3d = comp3D.transform;
var t3d = comp3D.HandleInput(1, null, null);
Assert.AreEqual(trans3d, t3d);
}
[Test]
public void Enable() {
comp3D.gameObject.SetActive(false);
comp3D.HandleInput(2, null, null);
Assert.AreEqual(true, comp3D.gameObject.activeSelf);
}
[Test]
public void Disable() {
comp3D.gameObject.SetActive(true);
comp3D.HandleInput(3, null, null);
Assert.AreEqual(false, comp3D.gameObject.activeSelf);
}
[Test]
public void SetKinematic() {
var body = comp3D.GetComponent<Rigidbody>();
body.isKinematic = false;
comp3D.HandleInput(4, null, null);
Assert.AreEqual(true, body.isKinematic);
}
[Test]
public void SetDynamic() {
var body = comp3D.GetComponent<Rigidbody>();
body.isKinematic = true;
comp3D.HandleInput(5, null, null);
Assert.AreEqual(false, body.isKinematic);
}
[Test]
public void Slots() {
var slots = new SlotList();
comp3D.GetInputSlots(slots);
Assert.AreEqual(6, slots.Count);
Assert.AreEqual(new LogicSlot("body", 0, null, typeof(Rigidbody)), slots[0]);
Assert.AreEqual(new LogicSlot("transform", 1, null, typeof(Transform)), slots[1]);
Assert.AreEqual(new LogicSlot("enable", 2), slots[2]);
Assert.AreEqual(new LogicSlot("disable", 3), slots[3]);
Assert.AreEqual(new LogicSlot("set kinematic", 4), slots[4]);
Assert.AreEqual(new LogicSlot("set dynamic", 5), slots[5]);
slots.Clear();
comp3D.GetOutputSlots(slots);
Assert.AreEqual(0, slots.Count);
Expand Down

0 comments on commit 1f3868d

Please sign in to comment.