Ejemplo n.º 1
0
 public void DisconnectFrom(NavNodeMinor n)
 {
     if (data._DisconnectFrom(n) && n.navNodeMajor != navNodeMajor)
     {
         navNodeMajor.RemoveMajorToMajorConnection(this, n.navNodeMajor);
     }
 }
Ejemplo n.º 2
0
 public void ConnectTo(NavNodeMinor n, NavNodeConnection.NavConnectionType connectionType)
 {
     if (data._ConnectTo(n, connectionType) && n.navNodeMajor != navNodeMajor)
     {
         navNodeMajor.FormMajorToMajorConnection(this, n.navNodeMajor);
     }
 }
Ejemplo n.º 3
0
        public void FormMajorToMajorConnection(NavNodeMinor fromMinor, NavNodeMajor toMajor)
        {
            int index = m_majorNodeMinorNodeConnectionPointsKeys.IndexOf(toMajor);

            if (index == -1)
            {
                m_majorNodeMinorNodeConnectionPointsKeys.Add(toMajor);
                m_majorNodeMinorNodeConnectionPointsValues.Add(new ListOfNavNodeMinors());
                index = m_majorNodeMinorNodeConnectionPointsValues.Count - 1;
            }

            m_majorNodeMinorNodeConnectionPointsValues[index].list.Add(fromMinor);

            if (m_majorNodeMinorNodeConnectionPointsValues[index].list.Count == 1)
            {
                data._ConnectTo(toMajor, NavNodeConnection.NavConnectionType.Standard);
            }
        }
Ejemplo n.º 4
0
        public void RemoveMajorToMajorConnection(NavNodeMinor fromMinor, NavNodeMajor toMajor)
        {
            int index = m_majorNodeMinorNodeConnectionPointsKeys.IndexOf(toMajor);

            if (index == -1)
            {
                Debug.LogError("Can't disconnect from a Major that you have not connected to.");
                return;
            }

            m_majorNodeMinorNodeConnectionPointsValues[index].list.Remove(fromMinor);


            if (m_majorNodeMinorNodeConnectionPointsValues[index].list.Count == 0)
            {
                m_majorNodeMinorNodeConnectionPointsKeys.RemoveAt(index);
                m_majorNodeMinorNodeConnectionPointsValues.RemoveAt(index);
                data._DisconnectFrom(toMajor);
            }
        }
Ejemplo n.º 5
0
 public bool IsConnectedTo(NavNodeMinor n)
 {
     return(data.ConnectedTo(n));
 }
Ejemplo n.º 6
0
        public List <NavNodeData> GetPath(NavNodeMinor start, NavNodeMinor end)
        {
            if (PathingMethod == MethodOfPathing.Standard)
            {
                return(GetPathWorker(start.data, end.data));
            }
            else if (PathingMethod == MethodOfPathing.MajorAndMinorGrid)
            {
                List <NavNodeMajor> majorPath = GetPathWorker(start.navNodeMajor.data, end.navNodeMajor.data).Select(a => a.node).Cast <NavNodeMajor>().ToList();

                List <NavNodeData> finalPath = new List <NavNodeData>();

                for (int i = 0; i < majorPath.Count; i++)
                {
                    NavNodeMinor _s = null;
                    NavNodeMinor _e = null;

                    if (i == 0)
                    {
                        _s = start;
                    }
                    else
                    {
                        _s = majorPath[i].NavNodeMinorForMajor(majorPath[i - 1]);
                    }


                    if (i == majorPath.Count - 1)
                    {
                        _e = end;
                    }
                    else
                    {
                        _e = majorPath[i].NavNodeMinorForMajor(majorPath[i + 1]);
                    }

                    if (_s == null || _e == null)
                    {
                        break;
                    }
                    List <NavNodeData> subPath = GetPathWorker(_s.data, _e.data);
                    if (subPath == null)
                    {
                        break;
                    }

                    finalPath.AddRange(subPath);
                }

                return(finalPath);
            }
            else if (PathingMethod == MethodOfPathing.MajorAndMinorGridThreaded)
            {
                List <NavNodeMajor>     majorPath = GetPathWorker(start.navNodeMajor.data, end.navNodeMajor.data).Select(a => a.node).Cast <NavNodeMajor>().ToList();
                List <ManualResetEvent> endEvents = new List <ManualResetEvent>();
                _threadedNodeSegments = new List <List <NavNodeData> >();

                for (int i = 0; i < majorPath.Count; i++)
                {
                    NavNodeMinor _s = null;
                    NavNodeMinor _e = null;

                    if (i == 0)
                    {
                        _s = start;
                    }
                    else
                    {
                        _s = majorPath[i].NavNodeMinorForMajor(majorPath[i - 1]);
                    }


                    if (i == majorPath.Count - 1)
                    {
                        _e = end;
                    }
                    else
                    {
                        _e = majorPath[i].NavNodeMinorForMajor(majorPath[i + 1]);
                    }

                    if (_s == null || _e == null)
                    {
                        break;
                    }

                    _threadedNodeSegments.Add(new List <NavNodeData>());
                    endEvents.Add(new ManualResetEvent(false));

                    ThreadData td = new ThreadData
                    {
                        start        = _s.data,
                        end          = _e.data,
                        threadNumber = i,
                        startEvent   = new ManualResetEvent(false),
                        finishEvent  = endEvents[endEvents.Count - 1],
                    };

                    ThreadPool.QueueUserWorkItem(GetPathThreadWorker, td);
                    td.startEvent.WaitOne();
                }

                WaitHandle.WaitAll(endEvents.ToArray(), 1);

                List <NavNodeData> finalPath = new List <NavNodeData>();
                foreach (List <NavNodeData> segment in _threadedNodeSegments)
                {
                    finalPath.AddRange(segment);
                }

                _threadedNodeSegments.Clear();
                return(finalPath);
            }

            return(null);
        }