public void Explose() { Debug.Log("Explose"); m_ExplosionIndex = m_PathGrid.GetPathNodeIndex(this.gameObject.transform.position); m_ExplosionList.Clear(); m_Index2PathGridPosList.Clear(); //add the first one List <Vector3> firstPosList = new List <Vector3>(1); firstPosList.Add(m_PathGrid.GetPathNodePos(m_ExplosionIndex)); m_Index2PathGridPosList.Add(firstPosList); //add others for (int i = 0; i < (int)PathGrid.eNeighborDirection.kNumNeighbors; i++) { List <Vector3> positions = CommonHelper.PositionsByDirection(m_ExplosionIndex, m_length, (PathGrid.eNeighborDirection)i, m_PathGrid); m_Index2PathGridPosList.Add(positions); } foreach (List <Vector3> PathGridPosList in m_Index2PathGridPosList) { foreach (Vector3 PathGridPos in PathGridPosList) { GameObject gameObject = m_ExplosionPoolInstance.DequeueFromPool(); gameObject.transform.position = PathGridPos; gameObject.GetComponent <Animator>().SetTrigger("Explosion"); m_ExplosionList.Add(gameObject); } } // // //add the first one // GameObject gameObject = m_ExplosionPoolInstance.DequeueFromPool(); // gameObject.transform.position = m_PathGrid.GetPathNodePos(m_ExplosionIndex); // gameObject.GetComponent<Animator>().SetTrigger("Explosion"); // m_ExplosionList.Add(gameObject); // // //add others // for (int i = 0; i < (int)PathGrid.eNeighborDirection.kNumNeighbors; i++) { // Vector3[] positions = CommonHelper.PositionsByDirection(m_ExplosionIndex, m_length, (PathGrid.eNeighborDirection) i, m_PathGrid); // for (int j = 0; j < m_length; j++) { // gameObject = m_ExplosionPoolInstance.DequeueFromPool(); // gameObject.transform.position = positions[j]; // gameObject.GetComponent<Animator>().SetTrigger("Explosion"); // //Debug.Log("Set Explosion: pos" + gameObject.transform.position ); // m_ExplosionList.Add(gameObject); // } // } }
public static List <Vector3> PositionsByDirection(int gridIndex, int length, PathGrid.eNeighborDirection dirction, PathGrid grid) { // UnityEngine.Debug.Log("Origin PosIndex:" + gridIndex); List <Vector3> Positions = new List <Vector3>(); for (int i = 0; i < length; i++) { gridIndex = grid.GetNeighbor(gridIndex, dirction); if (grid.IsBlocked(gridIndex)) { return(Positions); } Positions.Add(grid.GetPathNodePos(gridIndex)); // UnityEngine.Debug.Log("Search PosIndex:" + gridIndex); } return(Positions); }