예제 #1
0
            public void SetCellToEdge(GenerationCellInfo cell)
            {
                Vector3 closest;

                SomeMath.ClosestToSegmentTopProjection(data.leftV3, data.rightV3, cell.centerV2, out closest);

                if (SomeMath.LinePointSideMathf(data.leftV2, data.rightV2, cell.centerV2) > 0)
                {
                    //Debuger_K.AddLine(closest, cell.centerV3, Color.white);
                    //Debuger_K.AddLabel(SomeMath.MidPoint(closest, cell.centerV3), "Up");
                    upCell = cell;
                }
                else
                {
                    //Debuger_K.AddLine(closest, cell.centerV3, Color.white);
                    //Debuger_K.AddLabel(SomeMath.MidPoint(closest, cell.centerV3), "Down");
                    downCell = cell;
                }

                if (upCell != null & downCell != null)
                {
                    Vector3 intersection;
                    SomeMath.ClampedRayIntersectXZ(upCell.centerV3, downCell.centerV3 - upCell.centerV3, data.leftV3, data.rightV3, out intersection);
                    float upCellCost   = Vector3.Distance(upCell.centerV3, intersection) * upCell.cell.area.cost;
                    float downCellCost = Vector3.Distance(downCell.centerV3, intersection) * downCell.cell.area.cost;

                    downCell.SetConnection(new CellContentData(data.leftV3, data.rightV3), upCell.cell, downCellCost, upCellCost, intersection);
                    upCell.SetConnection(new CellContentData(data.rightV3, data.leftV3), downCell.cell, upCellCost, downCellCost, intersection);
                }
            }
예제 #2
0
        private static void SetInterconnection(Graph graph1, Graph graph2, Cell cell1, Cell cell2, Vector3 node1, Vector3 node2)
        {
            Vector3 intersection;

            SomeMath.ClampedRayIntersectXZ(cell1.centerVector3, cell2.centerVector3 - cell1.centerVector3, node1, node2, out intersection);
            float cell1Cost = Vector3.Distance(cell1.centerVector3, intersection) * cell1.area.cost;
            float cell2Cost = Vector3.Distance(cell2.centerVector3, intersection) * cell2.area.cost;

            Vector3 leftPos, rightPos;

            if (SomeMath.LinePointSideMathf(new Vector2(node1.x, node1.z), new Vector2(node2.x, node2.z), cell1.centerVector2) > 0)
            {
                leftPos  = node2;
                rightPos = node1;
            }
            else
            {
                leftPos  = node1;
                rightPos = node2;
            }

            //Debuger_K.AddLabel(SomeMath.MidPoint(leftPos, cell1.centerV3), "L");
            //Debuger_K.AddLabel(SomeMath.MidPoint(rightPos, cell1.centerV3), "R");

            //Debuger_K.AddLabel(SomeMath.MidPoint(rightPos, cell2.centerV3), "L");
            //Debuger_K.AddLabel(SomeMath.MidPoint(leftPos, cell2.centerV3), "R");

            CellContentData C1C2data = new CellContentData(leftPos, rightPos);
            CellContentData C2C1data = new CellContentData(rightPos, leftPos);

            CellContentGenericConnection C1C2 = new CellContentGenericConnection(C1C2data, cell1, cell2, true, cell1Cost, cell2Cost, intersection);
            CellContentGenericConnection C2C1 = new CellContentGenericConnection(C2C1data, cell2, cell1, true, cell2Cost, cell1Cost, intersection);

            cell1.SetContent(C1C2);
            cell2.SetContent(C2C1);

            cell1.graph.AddEdgeToMap(cell1, cell2, C1C2data);
            cell2.graph.AddEdgeToMap(cell2, cell1, C2C1data);

#if UNITY_EDITOR
            if (Debuger_K.doDebug)
            {
                Debuger_K.AddEdgesInterconnected(graph1.x, graph1.z, graph1.properties, C1C2);
                Debuger_K.AddEdgesInterconnected(graph2.x, graph2.z, graph2.properties, C2C1);
            }
#endif
        }