Ejemplo n.º 1
0
    void SortGridPointsPrElevation()
    {
        //Finds starting grid point
        GridPoint CurrentGridPoint = FindCornerPoint(Grid, true);

        GridPoint NextGridPoint = CurrentGridPoint;

        List <GridPoint> SelectedElevation = FindAllPointsOfSameElevation(CurrentGridPoint, Grid);
        List <GridPoint> RunThrughList     = CloneList(SelectedElevation);

        bool IsBreaking = false;

        while (RunThrughList.Count > 0)
        {
            IsBreaking = false;
            if (CurrentGridPoint.Type == PointType.Filler)
            {
                Debug.LogWarning("FIlle is chosen"); break;
            }

            //Looks thrugh Unsorted to find neighbor
            if (!CurrentGridPoint.IsPointPlaceable())
            {
                for (int i = 0; i < DirectionArray.Length; i++)
                {
                    GridPoint FullNeighbor = CurrentGridPoint.GetNeighbor(DirectionArray[i], SelectedElevation);
                    GridPoint HalfNeighbor = CurrentGridPoint.GetNeighbor(DirectionArray[i] * 0.5f, SelectedElevation);
                    if (FullNeighbor != null && FullNeighbor.IsPointValid() && FullNeighbor.Type == PointType.Unsorted)
                    {
                        if (HalfNeighbor != null && HalfNeighbor.Type != PointType.Filler)
                        {
                            if (CurrentGridPoint.GetNeighbor(new Vector3(0, 1f, 0), Grid) != null)
                            {
                                CurrentGridPoint.Type = PointType.Wall;
                                HalfNeighbor.Type     = PointType.None_SkipWall;
                            }
                            else
                            {
                                CurrentGridPoint.Type = PointType.Roof;
                                HalfNeighbor.Type     = PointType.None_SkipRoof;
                            }

                            RunThrughList.Remove(HalfNeighbor);

                            CurrentGridPoint.Dir = DirectionArray[i];
                            NextGridPoint        = FullNeighbor;
                            IsBreaking           = true;
                            break;
                        }
                    }
                }

                //checks thrugh fulls to find neighthbor
                for (int i = 0; i < DirectionArray.Length; i++)
                {
                    if (IsBreaking)
                    {
                        break;
                    }

                    GridPoint FullNeighbor = CurrentGridPoint.GetNeighbor(DirectionArray[i], SelectedElevation);
                    GridPoint HalfNeighbor = CurrentGridPoint.GetNeighbor(DirectionArray[i] * 0.5f, SelectedElevation);
                    if (FullNeighbor != null && FullNeighbor.IsPointValid())
                    {
                        if (HalfNeighbor != null && HalfNeighbor.Type != PointType.Filler && FullNeighbor.Dir * -1 != DirectionArray[i])
                        {
                            if (CurrentGridPoint.GetNeighbor(new Vector3(0, 1f, 0), Grid) != null)
                            {
                                CurrentGridPoint.Type = PointType.Wall;
                                HalfNeighbor.Type     = PointType.None_SkipWall;
                            }
                            else
                            {
                                CurrentGridPoint.Type = PointType.Roof;
                                HalfNeighbor.Type     = PointType.None_SkipRoof;
                            }

                            RunThrughList.Remove(HalfNeighbor);

                            CurrentGridPoint.Dir = DirectionArray[i];
                            NextGridPoint        = FullNeighbor;
                            IsBreaking           = true;
                            break;
                        }
                    }
                }

                //looks thrugh halfs to find neighbor
                for (int i = 0; i < DirectionArray.Length; i++)
                {
                    if (IsBreaking)
                    {
                        break;
                    }

                    GridPoint HalfNeighbor = CurrentGridPoint.GetNeighbor(DirectionArray[i] * 0.5f, SelectedElevation);
                    if (HalfNeighbor != null && HalfNeighbor.IsPointValid() && HalfNeighbor.Dir * -1 != DirectionArray[i])
                    {
                        if (CurrentGridPoint.GetNeighbor(new Vector3(0, 1f, 0), Grid) != null)
                        {
                            CurrentGridPoint.Type = PointType.HalfWall;
                        }
                        else
                        {
                            CurrentGridPoint.Type = PointType.HalfRoof;
                        }

                        CurrentGridPoint.Dir = DirectionArray[i];
                        NextGridPoint        = HalfNeighbor;
                        break;
                    }
                }
            }

            RunThrughList.Remove(CurrentGridPoint);
            if (NextGridPoint != null)
            {
                if (NextGridPoint.Type == PointType.Unsorted)
                {
                    CurrentGridPoint = NextGridPoint;
                    continue;
                }
            }
            if (RunThrughList.Count != 0)
            {
                CurrentGridPoint = FindCornerPoint(RunThrughList, true);
            }
        }
    }