Beispiel #1
0
    private void OnAffectedPart(PartBehaviour part)
    {
        if (part != Part)
        {
            return;
        }

        if (!Part.CheckStability())
        {
            InstantiateObjects();
        }
    }
    /// <summary>
    /// This method allows to upgrade the base part.
    /// </summary>
    public void Upgrade(string tag)
    {
        Part.AppearanceIndex++;

        gameObject.ChangeAllMaterialsInChildren(Part.Renderers.ToArray(), Part.InitialsRenders);

        Elements.FirstOrDefault(x => !x.gameObject.activeSelf && x.tag == tag).gameObject.SetActive(true);

        PickableController.Instance.TempElements.Remove(tag);

        if (IsCompleted())
        {
            Part.DisableAllTriggers();

            Destroy(Preview);

            for (int i = 0; i < Elements.Length; i++)
            {
                if (Part != null)
                {
                    Elements[i].gameObject.SetActive(true);
                }
            }

            Part.ChangeState(StateType.Placed);

            if (Part.UseConditionalPhysics)
            {
                if (!Part.CheckStability())
                {
                    Part.ApplyPhysics();
                }
            }
        }
    }
Beispiel #3
0
    private void OnDestroyedPart(PartBehaviour part)
    {
        if (part != Part)
        {
            return;
        }

        if (!Part.CheckStability())
        {
            DetachChildren();
        }
    }
Beispiel #4
0
        /// <summary>
        /// This method allows to check if the preview has collision(s).
        /// </summary>
        public bool HasCollision()
        {
            if (CurrentPreview.CheckTerrainClipping())
            {
                return(true);
            }

            if (!HasSocket)
            {
                if (CurrentPreview.CheckBuildSurface())
                {
                    return(true);
                }
            }

            if (CurrentPreview.AvoidClipping && !HasSocket)
            {
                if (CurrentPreview.CheckElementsClipping())
                {
                    return(true);
                }
            }
            else if (CurrentPreview.AvoidClippingOnSocket && HasSocket)
            {
                if (CurrentPreview.CheckElementsClippingOnSocket())
                {
                    return(true);
                }
            }

            if (CurrentPreview.CheckAreas())
            {
                return(true);
            }

            if (CurrentPreview.UseConditionalPhysics && CurrentPreview.PhysicsOnlyStablePlacement)
            {
                if (!CurrentPreview.CheckStability())
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #5
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);
                            }
                        }
                    }
                }
            }
        }