コード例 #1
0
        //The fact that we're building sections only from the NE, E, and SE
        //cell edges is very important. A lot of the code here is structured
        //as it is to deal with this reality.
        public void RefreshRiverSections()
        {
            sections.Clear();
            SectionBetweenCells.Clear();

            CellEdgeContourCanon.Clear();

            foreach (var cell in Grid.Cells)
            {
                for (HexDirection direction = HexDirection.NE; direction <= HexDirection.SE; direction++)
                {
                    if (RiverCanon.HasRiverAlongEdge(cell, direction))
                    {
                        var neighbor = Grid.GetNeighbor(cell, direction);

                        Vector3 start = cell.AbsolutePosition + RenderConfig.GetFirstCorner(direction);
                        Vector3 end   = cell.AbsolutePosition + RenderConfig.GetSecondCorner(direction);

                        RiverFlow flow = RiverCanon.GetFlowOfRiverAtEdge(cell, direction);

                        //Our control points need to operate differently if we're at endpoints,
                        //and both ControlOne and ControlTwo might have alternate behavior.
                        //We need to check both ends of the section for endpoints
                        bool previousCellRiver     = RiverCanon.HasRiverAlongEdge(cell, direction.Previous());
                        bool previousNeighborRiver = RiverCanon.HasRiverAlongEdge(neighbor, direction.Previous2());

                        bool hasPreviousEndpoint =
                            !previousCellRiver &&
                            !previousNeighborRiver;

                        bool hasNextEndpoint =
                            !RiverCanon.HasRiverAlongEdge(cell, direction.Next()) &&
                            !RiverCanon.HasRiverAlongEdge(neighbor, direction.Next2());

                        var newRiverSection = new RiverSection()
                        {
                            AdjacentCellOne  = cell,
                            AdjacentCellTwo  = neighbor,
                            DirectionFromOne = direction,
                            Start            = start,
                            End                 = end,
                            FlowFromOne         = flow,
                            HasPreviousEndpoint = hasPreviousEndpoint,
                            HasNextEndpoint     = hasNextEndpoint
                        };

                        SectionBetweenCells[new Tuple <IHexCell, IHexCell>(cell, neighbor)] = newRiverSection;

                        sections.Add(newRiverSection);
                    }
                }
            }
        }
コード例 #2
0
        private void OnDrawGizmos_Contours()
        {
            Vector3 lineOne = Vector3.zero, lineTwo = Vector3.zero;

            foreach (var cell in Grid.Cells)
            {
                Vector3 center = cell.AbsolutePosition;

                foreach (var direction in EnumUtil.GetValues <HexDirection>())
                {
                    var contour = CellEdgeContourCanon.GetContourForCellEdge(cell, direction);

                    if (contour.Count == 0)
                    {
                        continue;
                    }

                    for (int i = 0; i < contour.Count - 1; i++)
                    {
                        Gizmos.color = Color.white;

                        lineOne.x = contour[i].x;
                        lineOne.z = contour[i].y;

                        lineTwo.x = contour[i + 1].x;
                        lineTwo.z = contour[i + 1].y;

                        Gizmos.DrawLine(lineOne, lineTwo);

                        Gizmos.color = Color.gray;

                        lineTwo.x = contour[i].x;
                        lineTwo.z = contour[i].y;

                        Gizmos.DrawLine(center, lineTwo);
                    }

                    lineTwo.x = contour.Last().x;
                    lineTwo.z = contour.Last().y;

                    Gizmos.DrawLine(center, lineTwo);

                    Gizmos.color = Color.red;
                    Gizmos.DrawLine(center, center + RenderConfig.GetFirstCorner(direction));
                    Gizmos.DrawLine(center, center + RenderConfig.GetSecondCorner(direction));
                }
            }
        }
コード例 #3
0
        public void RepositionIcons()
        {
            if (Camera.main == null)
            {
                return;
            }

            foreach (var cellWithSlot in SlotOfCell.Keys)
            {
                Vector3 centerOfNWCorner = cellWithSlot.AbsolutePosition + (
                    HexMapRenderConfig.GetFirstCorner(HexDirection.NW) + HexMapRenderConfig.GetSecondCorner(HexDirection.NW)
                    ) / 2f;

                var cornerInScreen = Camera.main.WorldToScreenPoint(centerOfNWCorner);

                SlotOfCell[cellWithSlot].RectTransform.position = cornerInScreen;
            }
        }
コード例 #4
0
        private void TriangulateCellWeights_NoRiver(
            IHexCell center, IHexCell right, HexDirection direction, IHexMesh weightsMesh
            )
        {
            if (right == null)
            {
                weightsMesh.AddTriangle(
                    center.AbsolutePosition,
                    center.AbsolutePosition + RenderConfig.GetFirstCorner(direction),
                    center.AbsolutePosition + RenderConfig.GetSecondCorner(direction)
                    );
                weightsMesh.AddTriangleColor(CenterWeights);

                return;
            }

            Vector3 firstEdgeInner  = center.AbsolutePosition + RenderConfig.GetFirstSolidCorner(direction);
            Vector3 secondEdgeInner = center.AbsolutePosition + RenderConfig.GetSecondSolidCorner(direction);

            //Solid center region
            weightsMesh.AddTriangle(center.AbsolutePosition, firstEdgeInner, secondEdgeInner);
            weightsMesh.AddTriangleColor(CenterWeights);

            Vector3 firstEdgeOuter  = (firstEdgeInner + right.AbsolutePosition + RenderConfig.GetSecondSolidCorner(direction.Opposite())) / 2f;
            Vector3 secondEdgeOuter = (secondEdgeInner + right.AbsolutePosition + RenderConfig.GetFirstSolidCorner(direction.Opposite())) / 2f;

            //The edge between Center and Right, going up to the dividing line
            weightsMesh.AddQuad(firstEdgeInner, secondEdgeInner, firstEdgeOuter, secondEdgeOuter);
            weightsMesh.AddQuadColor(CenterWeights, CenterRightWeights);

            //Previous corner out to the edge of the cell
            weightsMesh.AddTriangle(firstEdgeInner, center.AbsolutePosition + RenderConfig.GetFirstCorner(direction), firstEdgeOuter);
            weightsMesh.AddTriangleColor(CenterWeights, CenterLeftRightWeights, CenterRightWeights);

            //Next corner out to the edge of the cell
            weightsMesh.AddTriangle(secondEdgeInner, secondEdgeOuter, center.AbsolutePosition + RenderConfig.GetSecondCorner(direction));
            weightsMesh.AddTriangleColor(CenterWeights, CenterRightWeights, CenterRightNextRightWeights);
        }