public void PlayerSquadMove(int breach, int state, bool sync) { gameObject.GetComponent <LineRenderer>().positionCount = 0; placing = false; PointMarker thisPoint = Instantiate(pointMarker, tempPos, Quaternion.identity).GetComponent <PointMarker>(); thisPoint.SetColumn(true, tempColor); PlayerRemovePoint(playerSelect); for (int k = 0; k < 3; k++) { if (playerSelect[k]) { playerLastPoint[k] = thisPoint.transform; playerSquad[k].SetOrder(false); } } PlayerUpdateLeaders(); int firstSelect = -1; for (int i = 0; i < 3; i++) { if (playerSelect[i]) { if (firstSelect == -1) { firstSelect = i; } m_gui.SetText(i, "MOVING"); if (breach != -1) { SquadMember.DoorState thisState = (SquadMember.DoorState)breach; string stateString = thisState.ToString(); stateString = stateString.Replace("DOOR_", ""); if (sync) { stateString = "SYNC " + stateString; } else { stateString += "ING DOOR"; } m_gui.SetText(i, stateString); } player.SetFollowing(i, false); } } if (PlayerGetLeader(firstSelect) == -1) { return; } else { if (state == (int)SquadMember.GoalState.GOAL_OBJECTIVE) { playerSquad[PlayerGetLeader(firstSelect)].SetObjective(tempObjective); } playerSquad[PlayerGetLeader(firstSelect)].SetWaypoint(thisPoint.transform, state); if (breach != -1) { playerSquad[PlayerGetLeader(firstSelect)].EnterDoor(tempDoor, tempSide, breach); playerSquad[PlayerGetLeader(firstSelect)].SetSync(sync); } } }
void DrawPath(bool setPath) { UnityEngine.AI.NavMeshPath testPath = new UnityEngine.AI.NavMeshPath(); UnityEngine.AI.NavMeshAgent agent = squad[squadSelect, 0].GetComponent <UnityEngine.AI.NavMeshAgent>(); Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { agent.CalculatePath(hit.point, testPath); Vector3 prevCorner = testPath.corners[0]; Vector3 spawnPos = prevCorner; float lifeSpan = 2.0f; for (int i = 1; i < testPath.corners.Length; i++) { Vector3 curCorner = testPath.corners[i]; Vector3 dir = Vector3.Normalize((curCorner + Vector3.up) - (prevCorner + Vector3.up)); for (float j = 0.0f; j < Vector3.Distance(prevCorner, curCorner); j += 1.0f) { if (!Physics.Raycast(prevCorner + (j - 1) * dir, dir, out hit, 1.0f, (1 << 12))) { if (!setPath) { PointMarker thisPoint = Instantiate(pointMarker, prevCorner + Vector3.Normalize(curCorner - prevCorner) * j, Quaternion.identity).GetComponent <PointMarker>(); thisPoint.SetLifespan(0.005f); thisPoint.SetColorMult(lifeSpan); thisPoint.SetColor(colors[squadSelect]); lifeSpan += 0.15f; } else if (j >= (Vector3.Distance(prevCorner, curCorner) - 1.0f) && i >= testPath.corners.Length - 1) { PointMarker thisPoint = Instantiate(pointMarker, prevCorner + Vector3.Normalize(curCorner - prevCorner) * j, Quaternion.identity).GetComponent <PointMarker>(); thisPoint.SetColumn(true, colors[squadSelect]); if (lastPoint[squadSelect] != null) { Destroy(lastPoint[squadSelect].gameObject); } lastPoint[squadSelect] = thisPoint.transform; SquadMove(thisPoint.transform); } } else { i = 90000; if (setPath) { PointMarker thisPoint = Instantiate(pointMarker, prevCorner + Vector3.Normalize(curCorner - prevCorner) * (j - 1.0f), Quaternion.identity).GetComponent <PointMarker>(); thisPoint.SetColumn(true, colors[squadSelect]); if (lastPoint[squadSelect] != null) { Destroy(lastPoint[squadSelect].gameObject); } lastPoint[squadSelect] = thisPoint.transform; SquadMove(thisPoint.transform); } break; } } prevCorner = curCorner; } } }