示例#1
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
        }