private void ReplaceColliders(ColliderSliceResult[] colliders, GameObject duplicate) { for (int i = 0; i < colliders.Length; i++) { var collider = colliders[i]; var componentNeg = collider.OriginalCollider; var componentPos = BzSlicerHelper.GetSameComponentForDuplicate(componentNeg, this.gameObject, duplicate); var goNeg = collider.OriginalCollider.gameObject; var goPos = componentPos.gameObject; if (collider.SliceResult == SliceResult.Sliced) { AddCollider(collider.MeshDissector.SliceResultNeg.GenerateMesh(), collider.OriginalCollider.material, goNeg); AddCollider(collider.MeshDissector.SliceResultPos.GenerateMesh(), collider.OriginalCollider.material, goPos); Destroy(componentNeg); Destroy(componentPos); continue; } if (collider.SliceResult == SliceResult.Neg) { Destroy(componentPos); continue; } if (collider.SliceResult == SliceResult.Pos) { Destroy(componentNeg); continue; } throw new InvalidOperationException(); } }
protected void RepairColliders(GameObject resultNeg, GameObject resultPos, List <Collider> collidersNeg, List <Collider> collidersPos) { Profiler.BeginSample("RepairColliders"); var lazyRunnerNeg = resultNeg.GetComponent <LazyActionRunner>(); var lazyRunnerPos = resultPos.GetComponent <LazyActionRunner>(); for (int i = 0; i < _colliderResults.Length; i++) { var collider = _colliderResults[i]; Collider colliderNeg = BzSlicerHelper.GetSameComponentForDuplicate(collider.OriginalCollider, _originalObject, resultNeg); Collider colliderPos = BzSlicerHelper.GetSameComponentForDuplicate(collider.OriginalCollider, _originalObject, resultPos); var goNeg = colliderNeg.gameObject; var goPos = colliderPos.gameObject; if (collider.SliceResult == SliceResult.Sliced) { Mesh resultMeshNeg = collider.meshDissector.SliceResultNeg.GenerateMesh(); Mesh resultMeshPos = collider.meshDissector.SliceResultPos.GenerateMesh(); var SlicedColliderNeg = new MeshColliderConf(resultMeshNeg, collider.OriginalCollider.material); var SlicedColliderPos = new MeshColliderConf(resultMeshPos, collider.OriginalCollider.material); AddCollider(SlicedColliderNeg, goNeg, lazyRunnerNeg, colliderNeg); AddCollider(SlicedColliderPos, goPos, lazyRunnerPos, colliderPos); } if (collider.SliceResult == SliceResult.Sliced) { collidersNeg.Add(colliderNeg); collidersPos.Add(colliderPos); } else if (collider.SliceResult == SliceResult.Neg) { collidersNeg.Add(colliderNeg); UnityEngine.Object.Destroy(colliderPos); } else if (collider.SliceResult == SliceResult.Pos) { collidersPos.Add(colliderPos); UnityEngine.Object.Destroy(colliderNeg); } else { throw new InvalidOperationException(); } } Profiler.EndSample(); }
protected void RepairColliders(GameObject resultObjA, GameObject resultObjB, List <Collider> resultNeg, List <Collider> resultPos) { for (int i = 0; i < _colliderResults.Length; i++) { var collider = _colliderResults[i]; Collider colliderNeg = BzSlicerHelper.GetSameComponentForDuplicate(collider.OriginalCollider, _originalObject, resultObjA); Collider colliderPos = BzSlicerHelper.GetSameComponentForDuplicate(collider.OriginalCollider, _originalObject, resultObjB); var goNeg = colliderNeg.gameObject; var goPos = colliderPos.gameObject; Collider colliderNegSliced = null; Collider colliderPosSliced = null; if (collider.SliceResult == SliceResult.Sliced) { Mesh resultMeshNeg = collider.meshDissector.SliceResultNeg.GenerateMesh(); Mesh resultMeshPos = collider.meshDissector.SliceResultPos.GenerateMesh(); var SlicedColliderNeg = new MeshColliderConf(resultMeshNeg, collider.OriginalCollider.material); var SlicedColliderPos = new MeshColliderConf(resultMeshPos, collider.OriginalCollider.material); colliderNegSliced = AddCollider(SlicedColliderNeg, goNeg); colliderPosSliced = AddCollider(SlicedColliderPos, goPos); if (((object)colliderNegSliced) == null) { collider.SliceResult = SliceResult.Pos; UnityEngine.Object.Destroy(colliderPosSliced); } if (((object)colliderPosSliced) == null) { collider.SliceResult = SliceResult.Neg; UnityEngine.Object.Destroy(colliderNegSliced); } } if (collider.SliceResult == SliceResult.Sliced) { resultNeg.Add(colliderNegSliced); resultPos.Add(colliderPosSliced); UnityEngine.Object.Destroy(colliderNeg); UnityEngine.Object.Destroy(colliderPos); } else if (collider.SliceResult == SliceResult.Neg) { resultNeg.Add(colliderNeg); UnityEngine.Object.Destroy(colliderPos); } else if (collider.SliceResult == SliceResult.Pos) { resultPos.Add(colliderPos); UnityEngine.Object.Destroy(colliderNeg); } else { throw new InvalidOperationException(); } } }