// --------------------------------------------------- /** * Load data of pathfinding */ public void LoadFile(string _filenamePath) { if (m_hasBeenFileLoaded) { return; } m_hasBeenFileLoaded = true; FileStream file; m_filenamePath = _filenamePath; if (File.Exists(m_filenamePath)) { file = File.OpenRead(m_filenamePath); } else { Debug.LogError("File not found"); return; } BinaryFormatter bf = new BinaryFormatter(); m_vectorPaths = (PrecalculatedData)bf.Deserialize(file); // m_vectorPaths.DebugLog(); file.Close(); }
// --------------------------------------------------- /** * Load data of pathfinding */ public void LoadAsset(TextAsset _fileAsset) { if (m_hasBeenFileLoaded) { return; } m_hasBeenFileLoaded = true; Stream stream = new MemoryStream(_fileAsset.bytes); BinaryFormatter formatter = new BinaryFormatter(); m_vectorPaths = formatter.Deserialize(stream) as PrecalculatedData; }
// --------------------------------------------------- /** * Generation of a new child */ public void CalculateAll(string _filenamePath, bool _raycastFilter = false, params string[] _masksToIgnore) { if (m_calculationCompleted) { return; } m_filenamePath = _filenamePath; if (m_xIterator == -1) { m_vectorPaths = new PrecalculatedData(new CustomVector3[m_rows * m_cols][]); } PathFindingController.Instance.DebugPathPoints = false; if (m_iterationCompleted) { m_iterationCompleted = false; m_xIterator++; if (m_xIterator >= m_rows) { m_xIterator = 0; m_yIterator++; if (m_yIterator >= m_cols) { m_calculationCompleted = true; Debug.LogError("*********************** CALCULATION COMPLETED ***************************"); SavePathfindingData(); return; } } int originatorCell = (m_xIterator * m_cols) + m_yIterator; m_vectorPaths.Data[originatorCell] = new CustomVector3[m_rows * m_cols]; Debug.LogError("++++++++++++ NEW CALCULATION[" + originatorCell + "/" + (m_rows * m_cols) + "]"); } int originCell = (m_xIterator * m_cols) + m_yIterator; if (m_cells[0][originCell] != PathFindingController.CELL_EMPTY) { m_iterationCompleted = true; } else { m_iIterator++; if (m_iIterator >= m_rows) { m_iIterator = 0; m_jIterator++; if (m_jIterator >= m_cols) { m_iIterator = -1; m_jIterator = 0; m_iterationCompleted = true; return; } } int targetCell = (m_iIterator * m_cols) + m_jIterator; m_vectorPaths.Data[originCell][targetCell] = new CustomVector3(); // Debug.LogError("PROGRESS [" + targetCell + "/" + (m_rows * m_cols) + "]"); if (!((m_xIterator == m_iIterator) && (m_yIterator == m_jIterator))) { if (m_cells[0][targetCell] == PathFindingController.CELL_EMPTY) { Vector3 origin = new Vector3(m_xIterator, m_yIterator, 0); Vector3 destination = new Vector3(m_iIterator, m_jIterator, 0); int limitSearch = m_totalCells - 1; m_vectorPaths.Data[originCell][targetCell].SetVector3(SearchAStar(origin, destination, Vector3.zero, Vector3.one, null, true, limitSearch, _raycastFilter, _masksToIgnore)); // Debug.LogError("VALUE[" + m_vectorPaths.Data[originCell][targetCell].ToString() + "]"); // Debug.LogError("..."); } } } }