Ejemplo n.º 1
0
        private void CheckContacts()
        {
            Collider[] Colliders = PhysicExtension.GetNeighborsTypesBySphere <Collider>(transform.position, Radius, LayerMask.NameToLayer(Constants.LAYER_SOCKET.ToLower()));

            for (int i = 0; i < Colliders.Length; i++)
            {
                SocketBehaviour Socket = Colliders[i].GetComponent <SocketBehaviour>();

                if (Socket != null)
                {
                    if (Socket != this)
                    {
                        if (Socket.AllowPart(Socket.AttachedPart))
                        {
                            for (int x = 0; x < BusySpaces.Count; x++)
                            {
                                Socket.AddOccupancy(BusySpaces[x].Part);
                            }
                        }
                    }
                }
            }

            if (DisableOnGroundContact)
            {
                Colliders = PhysicExtension.GetNeighborsTypesBySphere <Collider>(transform.position, Radius,
                                                                                 LayerMask.NameToLayer(Constants.LAYER_DEFAULT.ToLower()));

                for (int i = 0; i < Colliders.Length; i++)
                {
                    if (Colliders[i] as TerrainCollider || Colliders[i].GetComponentInParent <VoxelandCollider>() ||
                        Colliders[i].GetComponentInParent <VoxelandCollider>())
                    {
                        DisableCollider();
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This method allows to change all around connected socket(s) state.
        /// </summary>
        public void ChangeAreaState(OccupancyType state, LayerMask freeLayer, LayerMask socketLayer, PartBehaviour placedPart)
        {
            if (placedPart == null)
            {
                return;
            }

            if (placedPart.UseConditionalPhysics)
            {
                if (!placedPart.CheckStability())
                {
                    return;
                }
            }

            Collider[] Colliders = Physics.OverlapBox(placedPart.GetWorldPartMeshBounds().center,
                                                      placedPart.GetWorldPartMeshBounds().extents,
                                                      placedPart.transform.rotation, socketLayer, QueryTriggerInteraction.Collide);

            for (int i = 0; i < Colliders.Length; i++)
            {
                SocketBehaviour Socket = Colliders[i].GetComponent <SocketBehaviour>();

                if (Socket != null)
                {
                    if (state == OccupancyType.Busy)
                    {
                        if (Socket.AllowPart(placedPart) && Socket.CheckState(freeLayer, placedPart) == OccupancyType.Busy)
                        {
                            if (Vector3.Distance(placedPart.transform.position, Socket.transform.position) < placedPart.MeshBounds.extents.magnitude)
                            {
                                placedPart.LinkPart(Socket.AttachedPart);

                                Socket.ChangeState(OccupancyType.Busy, placedPart);
                            }
                        }
                    }
                    else
                    {
                        Socket.ChangeState(OccupancyType.Free, placedPart);
                    }
                }
            }

            Colliders = Physics.OverlapSphere(transform.position, Radius, freeLayer);

            for (int i = 0; i < Colliders.Length; i++)
            {
                if (Colliders[i].GetComponent <SocketBehaviour>() == null)
                {
                    PartBehaviour Part = Colliders[i].GetComponentInParent <PartBehaviour>();

                    if (Part != null)
                    {
                        if (Part != AttachedPart)
                        {
                            if (AllowPart(Part))
                            {
                                ChangeState(OccupancyType.Busy, Part);
                            }
                        }
                    }
                }
            }
        }