public void THDeselectRobot()
 {
     selectedRobot   = null;
     timeInput       = 0;
     selectedCommand = Command.AvailableCommands.None;
     HideCursorText();
     DestroyPreviewTrails();
     StopCoroutineIfNotNull(previewTrajectoryAndGiveRobotCommand);
     if (selectedCommandWheel != null)
     {
         Destroy(selectedCommandWheel);
     }
     if (movingPreviews.Count > 0)
     {
         movingPreviews[selectedRobotIndex].SetActive(false);
     }
 }
 //TH prefix to indicate that these are passed through PlayBehaviour
 public void THSelectCommand(Command.AvailableCommands command)
 {
     selectedCommand = command;
     if (selectedCommand != Command.AvailableCommands.None)         //StartCoroutine(PreviewBallTrajectory());?
     {
         movingPreviews[selectedRobotIndex].SetActive(true);
         setAndDisplayTimeInput = StartCoroutine(SetAndDisplayTimeInput());
         previewTrajectoryAndGiveRobotCommand = StartCoroutine(PreviewTrajectoryAndGiveRobotCommand());
     }
     else
     {
         movingPreviews[selectedRobotIndex].SetActive(false);
         HideCursorText();
         DestroyPreviewTrails();
         StopCoroutineIfNotNull(previewTrajectoryAndGiveRobotCommand);
     }
 }
 void Awake()
 {
     //pm = GameObject.Find("PreviewMarker").GetComponent<PreviewMarker>();
     //ball = FindObjectOfType<Ball>().gameObject;
     selectedCommand = Command.AvailableCommands.Move;
     moves           = new List <Move>();
     robots          = new List <GameObject>();
     FindRobots();
     movingPreviews    = new List <GameObject>();
     robotMovingTrails = new List <List <MovingTrail> >();
     ballMovingTrails  = new List <List <MovingTrail> >();
     for (int i = 0; i < robots.Count; i++)
     {
         movingPreviews.Add(new GameObject());
         movingPreviews[i].name = "Moving Previews";
         movingPreviews[i].SetActive(false);
         robotMovingTrails.Add(new List <MovingTrail>());
         ballMovingTrails.Add(new List <MovingTrail>());
     }
     turns = 1;
 }
    IEnumerator PreviewTrajectoryAndGiveRobotCommand()
    {
        Vector3 prevCursorPosition   = Vector3.zero;
        Vector3 cursorPosition       = Input.mousePosition;
        Vector3 cursorScreenPosition = Camera.main.ScreenToWorldPoint(cursorPosition);
        Command previewCommand       = null;

        GameObject lastRobot = null;
        GameObject previewRobot;
        float      timeBetweenPreivews = 0.1f;

        System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
        Command.AvailableCommands    prevSelectedCommand = selectedCommand;

        timer.Start();
        while (selectedRobot != null)
        {
            cursorPosition       = Input.mousePosition;
            cursorScreenPosition = Camera.main.ScreenToWorldPoint(cursorPosition);
            if (timeInput <= selectedRobot.GetComponent <RobotBehaviour>().freeTime&& timer.Elapsed.TotalSeconds > timeBetweenPreivews)
            {
                if (prevCursorPosition != cursorPosition || prevSelectedCommand != selectedCommand || RevertCommand() || lastRobot != selectedRobot)
                {
                    timer.Reset();
                    timer.Start();
                    DestroyLatestPreviewTrail();
                    if (robotMovingTrails[selectedRobotIndex].Count > 0)
                    {
                        previewRobot = robotMovingTrails[selectedRobotIndex].Last().Node;
                    }
                    else
                    {
                        previewRobot = selectedRobot;
                    }
                    cursorPosition = Input.mousePosition;

                    cursorScreenPosition = Camera.main.ScreenToWorldPoint(cursorPosition);

                    if (selectedCommand == Command.AvailableCommands.Move)
                    {
                        previewCommand = new MoveCommand(previewRobot, cursorScreenPosition, timeInput, Turns);
                    }
                    else if (selectedCommand == Command.AvailableCommands.Push && timeInput <= selectedRobot.GetComponent <RobotBehaviour>().freeTime - shockWavePrefab.GetComponent <ShockwaveBehaviour>().intendedLifetime)
                    {
                        previewCommand = new PushCommand(previewRobot, cursorScreenPosition, timeInput, Turns);
                    }
                    else
                    {
                        Debug.Log("No command selected!");
                    }
                    latestRobotTrail = new MovingTrail(previewCommand, timeInput, previewRobot.GetComponent <RobotBehaviour>().prevVelocity);

                    //Not done yet!
                    //if (latestRobotTrail != null && latestRobotTrail.Node != null)
                    //{
                    //    directionPointer = Instantiate(Resources.Load<GameObject>("Prefabs/Prototype stuff (remove or rework)/Direction Arrow")) as GameObject;
                    //    //directionPointer.transform.position = latestBallTrail.Node.transform.position;
                    //    //directionPointer.transform.parent = latestBallTrail.Node.transform;
                    //    float AngleRad = Mathf.Atan2(cursorPosition.y - directionPointer.transform.position.y, cursorPosition.x - directionPointer.transform.position.x);
                    //    float AngleDeg = (180 / Mathf.PI) * AngleRad;
                    //    directionPointer.transform.rotation = Quaternion.Euler(0, 0, AngleDeg);

                    //    directionPointer.name = "Direction Pointer";

                    //}
                }
                if (Input.GetMouseButtonDown(1) && latestRobotTrail != null)
                {
                    latestRobotTrail.TrailGameObject.transform.parent = movingPreviews[selectedRobotIndex].transform;
                    robotMovingTrails[selectedRobotIndex].Add(latestRobotTrail);
                    latestRobotTrail = null;

                    GiveRobotCommand(previewCommand);
                }
            }
            if (selectedRobot != lastRobot)
            {
                DestroyLatestPreviewTrail();
            }
            prevCursorPosition  = cursorPosition;
            prevSelectedCommand = selectedCommand;
            lastRobot           = selectedRobot;
            yield return(new WaitForSeconds(0.005f));
        }
        DestroyLatestPreviewTrail();
    }
 public void SelectCommand(Command.AvailableCommands command)
 {
     currentActiveTurnhandler.THSelectCommand(command);
 }
 public void SelectCommand(Command.AvailableCommands c)
 {
     playerTurnhandler.THSelectCommand(c);
 }