Пример #1
0
 void ShowGridPointSquaresIfWanted(GridPoint point, bool[] isGridPointObstructedArray)
 {
     if (showObstructedGridPointSquares && isGridPointObstructedArray[point.index])
     {
         point.GetComponent <SpriteRenderer>().enabled = true;
     }
 }
Пример #2
0
    void CheckConnectivity()
    {
        // remove any points that are not connected to root node
        Queue <GameObject> toVisit       = new Queue <GameObject>();
        List <GameObject>  removedPoints = new List <GameObject>();

        // establish connectivity
        toVisit.Enqueue(firstPoint);
        while (toVisit.Count > 0)
        {
            GridPoint p = toVisit.Dequeue().GetComponent <GridPoint>();
            p.Connect();
            if (p.forwardGameObject != null && !p.forwardGameObject.GetComponent <GridPoint>().Connected)
            {
                toVisit.Enqueue(p.forwardGameObject);
            }
            if (p.backGameObject != null && !p.backGameObject.GetComponent <GridPoint>().Connected)
            {
                toVisit.Enqueue(p.backGameObject);
            }
            if (p.leftGameObject != null && !p.leftGameObject.GetComponent <GridPoint>().Connected)
            {
                toVisit.Enqueue(p.leftGameObject);
            }
            if (p.rightGameObject != null && !p.rightGameObject.GetComponent <GridPoint>().Connected)
            {
                toVisit.Enqueue(p.rightGameObject);
            }
        }

        // check connectivity, adding points that are not connected to the list to be removed
        foreach (GameObject p in points)
        {
            if (!p.GetComponent <GridPoint>().CheckConnectivity())
            {
                removedPoints.Add(p);
            }
        }

        // remove points from main points list
        foreach (GameObject p in removedPoints)
        {
            points.Remove(p);
        }
    }
Пример #3
0
            private void CreateMeshQuadrant(Quadrant quadrant, GridPoint minGridPoint, GridPoint maxGridPoint, Axis aAxis, Axis bAxis)
            {
                if ((minGridPoint.x == maxGridPoint.x && m_axis != Axis.X) ||
                    (minGridPoint.y == maxGridPoint.y && m_axis != Axis.Y) ||
                    (minGridPoint.z == maxGridPoint.z && m_axis != Axis.Z))
                {
                    // one or more dimensions has 0 area, nothing to draw!
                    // note that components for this axis should be the same since that's the level we're drawing the plane at.
                    return;
                }

                Color minorColor;
                Color majorColor;

                int aMin = minGridPoint.GetComponent(aAxis);
                int bMin = minGridPoint.GetComponent(bAxis);
                int aMax = maxGridPoint.GetComponent(aAxis);
                int bMax = maxGridPoint.GetComponent(bAxis);

                minorColor   = GetAxisColor(m_axis);
                majorColor   = minorColor;
                majorColor.a = GridSettings.instance.majorLineOpacity;

                GridPoint startA = GridPoint.Scale(minGridPoint, AxisUtil.GetVector(aAxis));
                GridPoint startB = GridPoint.Scale(minGridPoint, AxisUtil.GetVector(bAxis));
                GridPoint endA   = GridPoint.Scale(maxGridPoint, AxisUtil.GetVector(aAxis));
                GridPoint endB   = GridPoint.Scale(maxGridPoint, AxisUtil.GetVector(bAxis));

                MeshBuilder gridBuilder = new MeshBuilder();

                Vector3 aAxisVector = AxisUtil.GetVector(aAxis);
                Vector3 bAxisVector = AxisUtil.GetVector(bAxis);

                int line = aMin;

                for (int a = aMin; a < aMax + 1; ++a)
                {
                    Color color = (line % GridSettings.instance.majorLineSpacing) == 0 ? majorColor : minorColor;
                    ++line;

                    GridPoint aPoint = m_gridData.GridPositionToGridPoint(a * aAxisVector);
                    Vector3   start  = m_gridData.GridPointToGridPosition(aPoint + startB);
                    Vector3   end    = m_gridData.GridPointToGridPosition(aPoint + endB);

                    gridBuilder.AddVertex(start, color);
                    gridBuilder.AddVertex(end, color);
                    gridBuilder.AddIndex(gridBuilder.vertexCount - 2);
                    gridBuilder.AddIndex(gridBuilder.vertexCount - 1);
                }

                line = bMin;
                for (int b = bMin; b < bMax + 1; ++b)
                {
                    Color color = (line % GridSettings.instance.majorLineSpacing) == 0 ? majorColor : minorColor;
                    ++line;

                    GridPoint bPoint = m_gridData.GridPositionToGridPoint(b * bAxisVector);
                    Vector3   start  = m_gridData.GridPointToGridPosition(bPoint + startA);
                    Vector3   end    = m_gridData.GridPointToGridPosition(bPoint + endA);

                    gridBuilder.AddVertex(start, color);
                    gridBuilder.AddVertex(end, color);
                    gridBuilder.AddIndex(gridBuilder.vertexCount - 2);
                    gridBuilder.AddIndex(gridBuilder.vertexCount - 1);
                }

                m_quadrantGrids.Add(quadrant, gridBuilder);


                // add outlines
                {
                    MeshBuilder outlineBuilder = new MeshBuilder();

                    Color color = GridSettings.instance.unfocusedColor;

                    Vector3 a = m_gridData.GridPointToGridPosition(startA + startB);
                    Vector3 b = m_gridData.GridPointToGridPosition(startA + endB);
                    Vector3 c = m_gridData.GridPointToGridPosition(endA + endB);
                    Vector3 d = m_gridData.GridPointToGridPosition(endA + startB);

                    outlineBuilder.AddVertex(a, color);
                    outlineBuilder.AddVertex(b, color);
                    outlineBuilder.AddVertex(c, color);
                    outlineBuilder.AddVertex(d, color);

                    outlineBuilder.AddIndex(outlineBuilder.vertexCount - 4);
                    outlineBuilder.AddIndex(outlineBuilder.vertexCount - 3);

                    outlineBuilder.AddIndex(outlineBuilder.vertexCount - 3);
                    outlineBuilder.AddIndex(outlineBuilder.vertexCount - 2);

                    outlineBuilder.AddIndex(outlineBuilder.vertexCount - 2);
                    outlineBuilder.AddIndex(outlineBuilder.vertexCount - 1);

                    outlineBuilder.AddIndex(outlineBuilder.vertexCount - 1);
                    outlineBuilder.AddIndex(outlineBuilder.vertexCount - 4);

                    m_quadrantOutlines.Add(quadrant, outlineBuilder);
                }
            }
Пример #4
0
            private float SnapPositionInternal(GridPoint snapTo, Vector3 gridspacePosition, Axis axis, bool snapEvenIfDisabled)
            {
                float gridspaceComponent = gridspacePosition.GetComponent(axis);

                AxisProperties properties = GetAxisProperties(axis);

                if (!properties.isSnapEnabled && !snapEvenIfDisabled)
                {
                    return(gridspaceComponent);
                }

                float snapToComponent = snapTo.GetComponent(axis);

                switch (m_edgeType)
                {
                case EdgeType.Infinite:
                    // no changes, just snap to nearest
                    return(snapToComponent);

                case EdgeType.Free:
                    return(IsOutsideGrid(snapTo) ? gridspaceComponent : snapToComponent);

                case EdgeType.Clamp:
                {
                    int gridMin = GetGridMin().GetComponent(axis);
                    int gridMax = GetGridMax().GetComponent(axis);
                    if (snapToComponent < gridMin)
                    {
                        return(gridMin);
                    }
                    else if (snapToComponent > gridMax)
                    {
                        return(gridMax);
                    }
                    else
                    {
                        return(snapToComponent);
                    }
                }

                case EdgeType.Wrap:
                {
                    // while loops will bring snapTo in range of grid and wrap w/ overflow instead of clamping
                    // e.g. on a 1-10 grid, a value of 13 would wrap to 2 (13 - gridSize of 10 = 3, -1 for the 'invisible'
                    // grid space between edges)

                    int gridMin = GetGridMin().GetComponent(axis);
                    int gridMax = GetGridMax().GetComponent(axis);
                    while (snapToComponent < gridMin)
                    {
                        snapToComponent += gridSize + 1;
                    }

                    while (snapToComponent > gridMax)
                    {
                        snapToComponent -= gridSize + 1;
                    }
                    return(snapToComponent);
                }

                default:
                    Debug.LogError(string.Format("Grids MX -- Unknown Edge Type: {0}", m_edgeType));
                    return(gridspaceComponent);
                }
            }