Ejemplo n.º 1
0
        private static void AddCollider(MeshColliderConf colliderConf, GameObject go, LazyActionRunner lazyRunner, Collider originalCollider)
        {
            Profiler.BeginSample("AddCollider");
            UnityEngine.Object.Destroy(originalCollider);


            var action = new Action(() =>
            {
                Profiler.BeginSample("Action: AddCollider");

                var collider            = go.AddComponent <MeshCollider>();
                collider.sharedMaterial = colliderConf.Material;
                collider.sharedMesh     = colliderConf.Mesh;
                collider.inflateMesh    = true;

                var convexResult = new ConvexSetResult();
                convexResult.SetConvex(collider);

                Profiler.EndSample();
            });

            lazyRunner.AddLazyAction(action);

            Profiler.EndSample();
        }
Ejemplo n.º 2
0
        private static void AddCollider(MeshColliderConf colliderConf, GameObject go, Collider originalCollider)
        {
            Profiler.BeginSample("Action: AddCollider");

            UnityEngine.Object.Destroy(originalCollider);
            var collider = go.AddComponent <MeshCollider>();

            collider.sharedMaterial = colliderConf.Material;
            collider.convex         = true;
            collider.sharedMesh     = colliderConf.Mesh;

            Profiler.EndSample();
        }
Ejemplo n.º 3
0
        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();
        }
        private static MeshCollider AddCollider(MeshColliderConf colliderConf, GameObject go)
        {
            var collider = go.AddComponent <MeshCollider>();

            collider.sharedMaterial = colliderConf.Material;
            collider.sharedMesh     = colliderConf.Mesh;
            collider.inflateMesh    = true;

            var convexResult = new ConvexSetResult();

            convexResult.SetConvex(collider);

            if (convexResult.Success)
            {
                return(collider);
            }

            UnityEngine.Object.Destroy(collider);
            return(null);
        }
        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();
                }
            }
        }