/**
         * reset
         */
        public void Reset()
        {
            PathFinding.AStarAgent agent = _agent as PathFinding.AStarAgent;
            if (agent != null && agent._asm != null)
            {
                _goal = null;
            }
            _goal    = null; //.Reset();
            _map     = null; //.Reset();
            _storage = null; //.Reset();
#if UNITY_EDITOR && !MULTI_THREAD
            if (PathFinding.PathFindingManager.DEBUG)
            {
                if (_agent != null && ((PathFinding.AStarAgent)_agent)._asm == this)
                {
                    // UnityEngine.Debug.LogError("reset path error");
                }
            }
#endif
            _inQueue        = false;
            _revsCurrentRun = 0;
            _curPosIdx      = -1;
            _agent          = null;
            _maxRevolutions = C_MaxRevolutions;
            ResetMachineData();
#if ASTARDEBUG
            _totalRevs = 0;
#endif
        }
        /// <summary>
        /// RunAStar
        /// </summary>
        public void RunAStar()
        {
            _revsCurrentRun = 0;
            PathFinding.AStarAgent agent = _agent as PathFinding.AStarAgent;
            _curPosIdx = -1;
            IInt2 curPos = IInt2.zero;

            if (agent != null)
            {
                curPos.x   = -1;
                curPos.y   = -1;
                _curPosIdx = agent._map.GetGridNodeId(agent._behaviour.position);
                curPos     = agent._map.GetGridPos(_curPosIdx);
            }
            while (_goal != null)
            {
                //Get the node with the min f from Storage
                _goal.CurrentNode = _storage.RemoveCheapestOpenNode(_map);
#if UNITY_EDITOR && !MULTI_THREAD
                if (PathFinding.PathFindingManager.DEBUG)
                {
                    if (_goal.CurrentNode != null)
                    {
                        UnityEngine.Vector3 pos = CustomMath.TsVecToVector3(((PathFinding.GridMap)_map).GetWorldPosition(_goal.CurrentNode.NodeID));
                        UnityEngine.Debug.DrawLine(pos - UnityEngine.Vector3.right * 0.2f, pos + UnityEngine.Vector3.right * 0.2f, UnityEngine.Color.red, 1);
                    }
                }
#endif
                if (_totalRevs > MAX_REVS)//need find another target
                {
                    _goal.CurrentNode = null;
                }
                //Add the node to the closed list
                if (_goal.CurrentNode != null && _map.CheckNodeValid(_goal.CurrentNode))
                {
                    _storage.AddToClosedSet(_goal.CurrentNode, _map);
                }
                else
                {
                    IsWorking = false;
                    break;
                }
                //_currentNode = newNode;
                if (_goal.IsAStarFinished(_goal.CurrentNode))
                {
                    IsWorking = false;
                    break;
                }
                int numberOfNeighbours = _map.GetNeighboursCount(_goal.CurrentNode);

                //scan its neighbours
                for (short i = 0; i < numberOfNeighbours; i++)
                {
                    AStarNode neighbour = _storage.GetAStarNeighbour(_goal.CurrentNode, i, _searchId, _map, curPos);
                    if (neighbour != null)
                    {
                        LinkChild(_goal.CurrentNode, neighbour, i);
                    }
                }
#if ASTARDEBUG
                _totalRevs++;
#endif
                if (_maxRevolutions >= 0 && _revsCurrentRun++ >= _maxRevolutions)
                {
                    break;
                }
                if (ShouldPause(_revsCurrentRun))
                {
                    break;
                }
            }
        }