public void DestroyCollisionMaterial(ObiCollisionMaterialHandle handle) { if (collisionMaterials != null && handle != null && handle.isValid && handle.index < materialHandles.Count) { int index = handle.index; int lastIndex = materialHandles.Count - 1; // swap all collider info: materialHandles.Swap(index, lastIndex); collisionMaterials.Swap(index, lastIndex); // update the index of the handle we swapped with: materialHandles[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: materialHandles.RemoveAt(lastIndex); collisionMaterials.count--; DestroyIfUnused(); } }
public ObiCollisionMaterialHandle CreateCollisionMaterial() { var handle = new ObiCollisionMaterialHandle(materialHandles.Count); materialHandles.Add(handle); collisionMaterials.Add(new CollisionMaterial()); return(handle); }
protected void CreateMaterialIfNeeded() { if (materialHandle == null || !materialHandle.isValid) { var world = ObiColliderWorld.GetInstance(); // create the material: materialHandle = world.CreateCollisionMaterial(); materialHandle.owner = this; // copy material data from this material (use materialHandle instead of handle, to not retrigger CreateMaterialIfNeeded) var mat = world.collisionMaterials[materialHandle.index]; mat.FromObiCollisionMaterial(this); world.collisionMaterials[materialHandle.index] = mat; } }