Esempio n. 1
0
        /// <summary>
        /// Add a new camera to the robot using the default position (0, 0.5, 0) and rotation
        /// </summary>
        /// <returns></returns>
        public GameObject AddCamera(SimulatorRobot robot, Transform anchor)
        {
            GameObject newCamera = new GameObject("RobotCamera_" + robotCameraList.Count);

            newCamera.AddComponent <UnityEngine.Camera>();

            newCamera.transform.parent        = anchor;
            newCamera.transform.localPosition = new Vector3(0f, 0f, 0f);
            newCamera.transform.localRotation = Quaternion.identity;

            RobotCamera configuration = newCamera.AddComponent <RobotCamera>();

            configuration.UpdateConfiguration();
            //Set the camera parent robot, which is necessary when changing robot and restoring the configuration
            configuration.SetParentRobot(robot);

            newCamera.SetActive(false);
            //Make sure current camera is the first one on the list
            if (robotCameraList.Count == 0)
            {
                CurrentCamera = newCamera;
            }

            robotCameraList.Add(newCamera);

            return(newCamera);
        }
Esempio n. 2
0
        /// <summary>
        /// Add a new camera to the robot
        /// </summary>
        /// <param name="anchor"></param> The robot node to which the camera attaches
        /// <param name="positionOffset"></param>
        /// <param name="rotationOffset"></param>
        /// <returns></returns>
        public GameObject AddCamera(SimulatorRobot robot, Transform anchor, Vector3 positionOffset, Vector3 rotationOffset)
        {
            GameObject newCamera = new GameObject("RobotCamera_" + robotCameraList.Count);

            newCamera.AddComponent <UnityEngine.Camera>();

            newCamera.transform.parent        = anchor;
            newCamera.transform.localPosition = positionOffset;
            newCamera.transform.localRotation = Quaternion.Euler(rotationOffset);
            newCamera.GetComponent <UnityEngine.Camera>().fieldOfView = 60;

            RobotCamera configuration = newCamera.AddComponent <RobotCamera>();

            configuration.UpdateConfiguration();
            //Set the camera parent robot, which is necessary when changing robot and restoring the configuration
            configuration.SetParentRobot(robot);

            newCamera.SetActive(false);
            if (robotCameraList.Count == 0)
            {
                CurrentCamera = newCamera;
            }

            robotCameraList.Add(newCamera);

            return(newCamera);
        }