/**
     * Crea una posición (objeto) y la válida. El nombre se obtiene del campo la interfaz gráfica.
     * @param fromCommand Si es para el comando "defp".
     * @return Transform
     */
    public void RecordPosition(bool fromCommand)
    {
        Transform addedTarget = null;

        InputField targetNameInput = this.targetNameInput;

        if (fromCommand)
        {
            targetNameInput = this.DefpNameInput;
        }
        stateMessageControl.NewBlock();
        // No positions recorded
        if (targetControl.Count() == 0)
        {
            CreateDefaultTarget(targetNameInput.text);
        }
        else // Already at least one point
        {
            GameObject prevSelectedObject = selectionControl.SearchContainTag("Target");

            if (prevSelectedObject != null)
            {
                prevSelectedObject = prevSelectedObject.transform.parent.gameObject;

                // Validate target
                Vector3 newPos = prevSelectedObject.transform.position;
                if (!ValidTarget(targetNameInput.text, prevSelectedObject.transform, newPos))
                {
                    return;
                }

                // Add target
                addedTarget = targetControl.Add(targetNameInput.text, newPos, robot.GetAnglesFromCopy());
                addedTarget.GetComponent <TargetModel>().SetValid(true);
                selectionControl.SetActiveAxis(addedTarget, false);
                selectionControl.SelectedObject(prevSelectedObject);

                stateMessageControl.WriteMessage("Done. Recorded position \"" + targetNameInput.text + "\"", true);

                UpdateTargets(targetControl.GetNames());
                targetNameInput.text = "";
            }
            else
            {
                CreateDefaultTarget(targetNameInput.text);
            }
        }

        stateMessageControl.UpdatePositionLog();
    }
Exemple #2
0
    public void RecordPosition()
    {
        Transform newTarget = Instantiate(targetPrefab).transform;

        // No points recorded
        if (targetControl.Count() == 0)
        {
            //ValidTarget(newTarget);
            if (targetNameInput.text.Equals("") || targetNameInput.text == null)
            {
                stateOutput.text = "Name required";
                Destroy(newTarget.gameObject);
                return;
            }


            Vector3 recordedPos = defaultPosition;
            newTarget.position = recordedPos;

            // Check if it's an unreachable point
            if (!robot.TargetInRange(newTarget.transform))
            {
                Destroy(newTarget.gameObject);
                stateOutput.text = "Unreachable point";
                return;
            }

            stateOutput.text = "OK";

            // Add target
            Transform addedTarget = targetControl.Add(targetNameInput.text, recordedPos, robot.GetAnglesFromCopy());
            selectionControl.SetActiveAxis(addedTarget, true);
            selectionControl.SelectedObject(addedTarget.gameObject);
            SetTarget(addedTarget);

            UpdateTargets(targetControl.GetNames());
            targetNameInput.text = "";
            //DrawTrayectory();
        }
        else // Already at least one point
        {
            GameObject prevSelectedObject = selectionControl.SearchContainTag("Target");

            if (prevSelectedObject != null)
            {
                prevSelectedObject = prevSelectedObject.transform.parent.gameObject;

                if (targetNameInput.text.Equals("") || targetNameInput.text == null)
                {
                    stateOutput.text = "Name required";
                    Destroy(newTarget.gameObject);
                    return;
                }


                Vector3 recordedPos = prevSelectedObject.transform.position;
                newTarget.position = recordedPos;

                // Check if it's an unreachable point
                if (!robot.TargetInRange(prevSelectedObject.transform))
                {
                    Destroy(newTarget.gameObject);
                    stateOutput.text = "Unreachable point";
                    return;
                }

                stateOutput.text = "OK";

                // Add target
                Transform addedTarget = targetControl.Add(targetNameInput.text, recordedPos, robot.GetAnglesFromCopy());
                selectionControl.SetActiveAxis(addedTarget, false);
                selectionControl.SelectedObject(prevSelectedObject);

                UpdateTargets(targetControl.GetNames());

                targetNameInput.text = "";

                //DrawTrayectory();
            }
        }

        Destroy(newTarget.gameObject);
    }