コード例 #1
0
        public NodeAIRoute(AISegmentNodeConnection con, SegmentAIRoute target, NodeAIPath[] paths)
        {
            this.con    = con;
            this.target = target;
            Paths       = paths;

            con2 = target.GetStart();
        }
コード例 #2
0
        private IEnumerable <NodeAIPath> create(SegmentAIRoute incoming, SegmentAIRoute outgoing)
        {
            var from = incoming.GetEnd();
            var to   = outgoing.GetStart();

            var inPaths  = incoming.Paths.OrderBy(t => Mathf.Abs(t.SideOffsetStart)).ToArray();
            var outPaths = outgoing.Paths.OrderBy(t => Mathf.Abs(t.SideOffsetStart)).ToArray();


            if (inPaths.Length == outPaths.Length)
            {
                for (int i = 0; i < inPaths.Length; i++)
                {
                    var iPath = inPaths[i];
                    var oPath = outPaths[i];



                    yield return(new NodeAIPath(iPath, oPath, createLineLoft(iPath, from, oPath, to)));
                }
            }
            else
            {
                float angle = getAngle(from, to);

                int index = Mathf.RoundToInt(angle * 16 / (2 * Mathf.PI));

                if (index < 0)
                {
                    index += 16;
                }
                if (index >= 16)
                {
                    index -= 16;
                }

                foreach (var iPath in incoming.Paths)
                {
                    var turn = iPath.Lane.Turn;

                    var angleMap = getAngleMap(turn);

                    bool accept = angleMap == null || angleMap[index];
                    if (accept)
                    {
                        foreach (var oPath in outgoing.Paths)
                        {
                            if (iPath.LoftPath != null && oPath.LoftPath != null)
                            {
                                yield return(new NodeAIPath(iPath, oPath, createLineLoft(iPath, from, oPath, to)));
                            }
                        }
                    }
                }
            }
        }