示例#1
0
        public void SetTargetVisible(bool bVisible)
        {
            CameraTarget t = camera.gameObject.GetComponent <CameraTarget>();

            t.ShowTarget = bVisible;
        }
示例#2
0
        public void SetTarget(Vector3f newTarget)
        {
            CameraTarget t = camera.gameObject.GetComponent <CameraTarget>();

            t.TargetPoint = newTarget;
        }
示例#3
0
        public Vector3f GetTarget()
        {
            CameraTarget t = camera.gameObject.GetComponent <CameraTarget>();

            return(t.TargetPoint);
        }
示例#4
0
        public static void SetTarget(this UnityEngine.Camera c, Vector3 newTarget)
        {
            CameraTarget t = c.gameObject.GetComponent <CameraTarget>();

            t.TargetPoint = newTarget;
        }
示例#5
0
        // Use this for initialization
        public void Initialize(FContext controller)
        {
            this.controller = controller;

            // find main camera
            GameObject[] mainCameras = GameObject.FindGameObjectsWithTag("MainCamera");
            if (mainCameras.Length == 0)
            {
                throw new MissingComponentException("CameraTracking.Initialize: could not find camera with tag MainCamera");
            }
            var mainCameraObj = mainCameras[0];

            if (mainCameras.Length > 1)
            {
                DebugUtil.Log(2, "CameraTracking.Initialize: there are multiple objects with tag MainCamera. Using the one named " + mainCameraObj.GetName());
            }
            mainCamera = mainCameraObj.GetComponent <Camera> () as Camera;

            // on Vive the MainCamera will have some child cameras that are a problem,
            // so get rid of them
            if (gs.VRPlatform.CurrentVRDevice == gs.VRPlatform.Device.HTCVive)
            {
                List <GameObject> children = new List <GameObject>(mainCameraObj.Children());
                foreach (var child in children)
                {
                    mainCameraObj.RemoveChild(child);
                    GameObject.Destroy(child);
                }
            }

            List <Camera> newCameras = new List <Camera>();

            // create camera for 3D widgets layer
            widgetCamera = Camera.Instantiate(mainCamera);
            widgetCamera.SetName("WidgetCamera");
            widgetCamera.transform.position = mainCamera.transform.position;
            widgetCamera.transform.rotation = mainCamera.transform.rotation;
            newCameras.Add(widgetCamera);

            // create camera for HUD layer
            hudCamera = Camera.Instantiate(mainCamera);
            hudCamera.SetName("HUDCamera");
            hudCamera.transform.position = mainCamera.transform.position;
            hudCamera.transform.rotation = mainCamera.transform.rotation;
            newCameras.Add(hudCamera);

            // create camera for UI
            uiCamera = Camera.Instantiate(mainCamera);
            uiCamera.SetName("UICamera");
            uiCamera.transform.position = mainCamera.transform.position;
            uiCamera.transform.rotation = mainCamera.transform.rotation;
            uiCamera.orthographic       = true;
            uiCamera.orthographicSize   = 0.5f;
            newCameras.Add(uiCamera);

            // create camera for cursor
            cursorCamera = Camera.Instantiate(mainCamera);
            cursorCamera.SetName("CursorCamera");
            cursorCamera.transform.position = mainCamera.transform.position;
            cursorCamera.transform.rotation = mainCamera.transform.rotation;
            newCameras.Add(cursorCamera);

            // configure these cameras
            //   - must disable audio listener if it exists
            //   - do depth clear so we can draw on top of other layers
            foreach (Camera cam in newCameras)
            {
                AudioListener listener = cam.GetComponent <AudioListener>();
                if (listener != null)
                {
                    listener.enabled = false;
                }

                cam.clearFlags = CameraClearFlags.Depth;
            }


            // set up camera masks

            // this camera only renders 3DWidgetOverlay layer, and mainCam does not!
            int nWidgetLayer = FPlatform.WidgetOverlayLayer;
            int nHUDLayer    = FPlatform.HUDLayer;
            int nUILayer     = FPlatform.UILayer;
            int nCursorLayer = FPlatform.CursorLayer;

            widgetCamera.cullingMask = (1 << nWidgetLayer);
            hudCamera.cullingMask    = (1 << nHUDLayer);
            uiCamera.cullingMask     = (1 << nUILayer);
            cursorCamera.cullingMask = (1 << nCursorLayer);

            mainCamera.cullingMask &= ~(1 << nWidgetLayer);
            mainCamera.cullingMask &= ~(1 << nHUDLayer);
            mainCamera.cullingMask &= ~(1 << nUILayer);
            mainCamera.cullingMask &= ~(1 << nCursorLayer);

            // attach camera animation object to main camera
            CameraAnimator anim = mainCamera.gameObject.AddComponent <CameraAnimator>();

            anim.UseCamera = mainCamera;
            anim.UseScene  = this.controller.Scene;

            // add target point to camera
            CameraTarget target = mainCamera.gameObject.AddComponent <CameraTarget>();

            target.TargetPoint = new Vector3(
                0.0f, mainCamera.transform.position[1], 0.0f);
            target.context = this.controller;

            // add camera manipulator to camera
            mainCamera.gameObject.AddComponent <CameraManipulator>();
        }
示例#6
0
        // extension methods to Camera
        public static Vector3 GetTarget(this UnityEngine.Camera c)
        {
            CameraTarget t = c.gameObject.GetComponent <CameraTarget>();

            return(t.TargetPoint);
        }