public void DestroyRigidbody(ObiRigidbodyHandle handle) { if (rigidbodies != null && handle != null && handle.isValid && handle.index < rigidbodyHandles.Count) { int index = handle.index; int lastIndex = rigidbodyHandles.Count - 1; // swap all collider info: rigidbodyHandles.Swap(index, lastIndex); rigidbodies.Swap(index, lastIndex); // update the index of the handle we swapped with: rigidbodyHandles[index].index = index; // invalidate our handle: // (after updating the swapped one! // in case there's just one handle in the array, // we need to write -1 after 0) handle.Invalidate(); // remove last index: rigidbodyHandles.RemoveAt(lastIndex); rigidbodies.count--; DestroyIfUnused(); } }
public ObiRigidbodyHandle CreateRigidbody() { var handle = new ObiRigidbodyHandle(rigidbodyHandles.Count); rigidbodyHandles.Add(handle); rigidbodies.Add(new ColliderRigidbody()); return(handle); }
public virtual void Awake() { handle = ObiColliderWorld.GetInstance().CreateRigidbody(); handle.owner = this; UpdateIfNeeded(); }