Example #1
0
        /// <summary>
        /// This method allows to check if the part enters in the terrain.
        /// </summary>
        public bool CheckTerrainClipping()
        {
            if (!AdvancedFeatures)
            {
                return(false);
            }

            if (!UseTerrainPrevention)
            {
                return(false);
            }

            Collider[] Colliders = PhysicExtension.GetNeighborsTypesByBox <Collider>(GetWorldPartTerrainBounds().center,
                                                                                     TerrainBounds.extents, transform.rotation, Physics.AllLayers);

            for (int i = 0; i < Colliders.Length; i++)
            {
                if (Colliders[i] as TerrainCollider || Colliders[i].GetComponentInParent <VoxelandCollider>())
                {
                    return(true);
                }
            }

            return(false);
        }
Example #2
0
        /// <summary>
        /// This method allows to change the state all the sockets which hit the part bounds.
        /// </summary>
        public void ChangeAreaState(OccupancyType type)
        {
            SocketBehaviour[] Sockets = PhysicExtension.GetNeighborsTypesByBox <SocketBehaviour>(GetWorldPartMeshBounds().center, GetWorldPartMeshBounds().extents,
                                                                                                 transform.rotation, LayerMask.NameToLayer(Constants.LAYER_SOCKET.ToLower()), QueryTriggerInteraction.Collide);

            for (int i = 0; i < Sockets.Length; i++)
            {
                if (Sockets[i] != null)
                {
                    if (Sockets[i].AttachedPart != this)
                    {
                        if (Sockets[i].AllowPart(this) && type == OccupancyType.Busy)
                        {
                            Sockets[i].ChangeAreaState(type,
                                                       LayerMask.NameToLayer(Constants.LAYER_DEFAULT.ToLower()),
                                                       LayerMask.NameToLayer(Constants.LAYER_SOCKET.ToLower()), Sockets[i].AttachedPart);

                            Sockets[i].ChangeState(type, this);
                        }
                        else if (type == OccupancyType.Free)
                        {
                            Sockets[i].ChangeAreaState(type,
                                                       LayerMask.NameToLayer(Constants.LAYER_DEFAULT.ToLower()),
                                                       LayerMask.NameToLayer(Constants.LAYER_SOCKET.ToLower()), Sockets[i].AttachedPart);

                            Sockets[i].ChangeState(type, this);
                        }
                    }
                }
            }
        }
Example #3
0
        /// <summary>
        /// This method allows to check if the part is stable.
        /// </summary>
        public bool CheckStability()
        {
            if (BuildManager.Instance != null)
            {
                if (!BuildManager.Instance.UsePhysics)
                {
                    return(true);
                }
            }

            if (!AdvancedFeatures)
            {
                return(true);
            }

            if (!UseConditionalPhysics)
            {
                return(true);
            }

            if (CustomDetections.Length != 0)
            {
                bool[] Results = new bool[CustomDetections.Length];

                for (int i = 0; i < CustomDetections.Length; i++)
                {
                    if (CustomDetections[i] != null)
                    {
                        PartBehaviour[] Parts = PhysicExtension.GetNeighborsTypesByBox <PartBehaviour>(transform.TransformPoint(CustomDetections[i].Position),
                                                                                                       CustomDetections[i].Size, transform.rotation, PhysicsLayers);

                        for (int p = 0; p < Parts.Length; p++)
                        {
                            PartBehaviour Part = Parts[p].GetComponent <PartBehaviour>();

                            if (Part != null)
                            {
                                if (Part != this)
                                {
                                    if (!Part.AffectedByPhysics && Part.CurrentState != StateType.Queue && CustomDetections[i].CheckType((int)Part.Type))
                                    {
                                        Results[i] = true;
                                    }
                                }
                            }
                        }

                        Collider[] Colliders = PhysicExtension.GetNeighborsTypesByBox <Collider>(transform.TransformPoint(CustomDetections[i].Position),
                                                                                                 CustomDetections[i].Size, transform.rotation, PhysicsLayers);

                        for (int x = 0; x < Colliders.Length; x++)
                        {
                            bool UseTerrain = Application.isPlaying == true ? BuildManager.Instance.BuildingSupport == SupportType.TerrainCollider
                                : BuildManager.Instance.BuildingSupport == SupportType.TerrainCollider;

                            if (UseTerrain)
                            {
                                if (CustomDetections[i].RequiredSupports.Contains(SurfaceType.TerrainCollider))
                                {
                                    if (CustomDetections[i].RequiredSupports.ToList().Find(entry => entry == SurfaceType.TerrainCollider) == SurfaceType.TerrainCollider)
                                    {
                                        if (Colliders[x] as TerrainCollider)
                                        {
                                            Results[i] = true;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (BuildManager.Instance.BuildingSupport == SupportType.SurfaceCollider && CustomDetections[i].RequiredSupports.ToList().Contains(SurfaceType.SurfaceCollider))
                                {
                                    if (Colliders[x].GetComponent <SurfaceCollider>() != null)
                                    {
                                        Results[i] = true;
                                    }
                                }

                                if (CustomDetections[i].RequiredSupports.ToList().Contains(SurfaceType.AllCollider))
                                {
                                    Results[i] = true;
                                }
                            }
                        }
                    }
                }

                return(Results.All(result => result));
            }

            return(false);
        }