Пример #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);
        }
Пример #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);
        }
Пример #3
0
        /// <summary>
        /// Return a list of robot cameras attached to a given robot
        /// </summary>
        /// <param name="parent"></param> A robot on which cameras are attached to
        /// <returns></returns> A list of camera attach to that robot
        public List <GameObject> GetRobotCamerasFromRobot(SimulatorRobot parent)
        {
            List <GameObject> camerasOnRobot = new List <GameObject>();

            foreach (GameObject camera in robotCameraList)
            {
                RobotCamera config = camera.GetComponent <RobotCamera>();
                if (config.robot.Equals(parent))
                {
                    camerasOnRobot.Add(camera);
                }
            }
            return(camerasOnRobot);
        }