void SetupCamera(Transform parentTransform)
        {
            if(!parentTransform)
            {
                Debug.Log ("Targeting camera tried setup but parent transform is null");
                return;
            }

            if(cameraTransform == null)
            {
                cameraTransform = (new GameObject("targetCamObject")).transform;
            }

            Debug.Log ("Setting target camera parent");
            cameraTransform.parent = parentTransform;
            cameraTransform.localPosition = Vector3.zero;
            cameraTransform.localRotation = Quaternion.identity;

            if(targetCamRenderTexture == null)
            {
                int res = Mathf.RoundToInt(BDArmorySettings.TARGET_CAM_RESOLUTION);
                targetCamRenderTexture = new RenderTexture(res,res,24);
                targetCamRenderTexture.antiAliasing = 1;
                targetCamRenderTexture.Create();

            }

            if(cameras != null && cameras[0] != null)
            {
                return;
            }

            //cam setup
            cameras = new Camera[4];

            Camera fCamNear = FlightCamera.fetch.cameras[0];
            Camera fCamFar = FlightCamera.fetch.cameras[1];

            //flight cameras
            //nearCam
            GameObject cam1Obj = new GameObject();
            Camera nearCam = cam1Obj.AddComponent<Camera>();
            nearCam.CopyFrom(fCamNear);
            nearCam.transform.parent = cameraTransform;
            nearCam.transform.localRotation = Quaternion.identity;
            nearCam.transform.localPosition = Vector3.zero;
            nearCam.transform.localScale = Vector3.one;
            nearCam.targetTexture = targetCamRenderTexture;
            cameras[0] = nearCam;

            TGPCameraEffects ge1 = cam1Obj.AddComponent<TGPCameraEffects>();
            ge1.textureRamp = GameDatabase.Instance.GetTexture("BDArmory/Textures/grayscaleRamp", false);
            ge1.rampOffset = 0;
            camEffects = ge1;

            //farCam
            GameObject cam2Obj = new GameObject();
            Camera farCam = cam2Obj.AddComponent<Camera>();
            farCam.CopyFrom(fCamFar);
            farCam.transform.parent = cameraTransform;
            farCam.transform.localRotation = Quaternion.identity;
            farCam.transform.localPosition = Vector3.zero;
            farCam.transform.localScale = Vector3.one;
            farCam.targetTexture = targetCamRenderTexture;
            cameras[1] = farCam;

            /*
            var cbr2 = cam2Obj.AddComponent<CameraBulletRenderer>();
            cbr2.resizeFactor = 3f;
            */

            //skybox camera
            GameObject skyCamObj = new GameObject();
            Camera skyCam = skyCamObj.AddComponent<Camera>();
            Camera mainSkyCam = FindCamera("Camera ScaledSpace");
            skyCam.CopyFrom(mainSkyCam);
            skyCam.transform.parent = mainSkyCam.transform;
            skyCam.transform.localRotation = Quaternion.identity;
            skyCam.transform.localPosition = Vector3.zero;
            skyCam.transform.localScale = Vector3.one;
            skyCam.targetTexture = targetCamRenderTexture;
            cameras[cameras.Length-2] = skyCam;
            skyCamObj.AddComponent<TGPCamRotator>();

            //galaxy camera
            GameObject galaxyCamObj = new GameObject();
            Camera galaxyCam = galaxyCamObj.AddComponent<Camera>();
            Camera mainGalaxyCam = FindCamera("GalaxyCamera");
            galaxyCam.CopyFrom(mainGalaxyCam);
            galaxyCam.transform.parent = mainGalaxyCam.transform;
            galaxyCam.transform.position = Vector3.zero;
            galaxyCam.transform.localRotation = Quaternion.identity;
            galaxyCam.transform.localScale = Vector3.one;
            galaxyCam.targetTexture = targetCamRenderTexture;
            cameras[cameras.Length-1] = galaxyCam;
            galaxyCamObj.AddComponent<TGPCamRotator>();

            nvLight = new GameObject().AddComponent<Light>();
            nvLight.transform.parent = cameraTransform;
            nvLight.transform.localPosition = Vector3.zero;
            nvLight.transform.localRotation = Quaternion.identity;
            nvLight.type = LightType.Directional;
            nvLight.intensity = 2;
            nvLight.shadows = LightShadows.None;

            nvLight.cullingMask = 1 << 0;
            nvLight.enabled = false;
        }
Exemple #2
0
        void SetupCamera(Transform parentTransform)
        {
            if (!parentTransform)
            {
                Debug.Log("Targeting camera tried setup but parent transform is null");
                return;
            }

            if (cameraTransform == null)
            {
                cameraTransform = (new GameObject("targetCamObject")).transform;
            }

            Debug.Log("Setting target camera parent");
            cameraTransform.parent        = parentTransform;
            cameraTransform.localPosition = Vector3.zero;
            cameraTransform.localRotation = Quaternion.identity;

            if (targetCamRenderTexture == null)
            {
                int res = Mathf.RoundToInt(BDArmorySettings.TARGET_CAM_RESOLUTION);
                targetCamRenderTexture = new RenderTexture(res, res, 24);
                targetCamRenderTexture.antiAliasing = 1;
                targetCamRenderTexture.Create();
            }


            if (cameras != null && cameras[0] != null)
            {
                return;
            }

            //cam setup
            cameras = new Camera[4];


            Camera fCamNear = FlightCamera.fetch.cameras[0];
            Camera fCamFar  = FlightCamera.fetch.cameras[1];


            //flight cameras
            //nearCam
            GameObject cam1Obj = new GameObject();
            Camera     nearCam = cam1Obj.AddComponent <Camera>();

            nearCam.CopyFrom(fCamNear);
            nearCam.transform.parent        = cameraTransform;
            nearCam.transform.localRotation = Quaternion.identity;
            nearCam.transform.localPosition = Vector3.zero;
            nearCam.transform.localScale    = Vector3.one;
            nearCam.targetTexture           = targetCamRenderTexture;
            cameras[0] = nearCam;


            TGPCameraEffects ge1 = cam1Obj.AddComponent <TGPCameraEffects>();

            ge1.textureRamp = GameDatabase.Instance.GetTexture("BDArmory/Textures/grayscaleRamp", false);
            ge1.rampOffset  = 0;
            camEffects      = ge1;

            //farCam
            GameObject cam2Obj = new GameObject();
            Camera     farCam  = cam2Obj.AddComponent <Camera>();

            farCam.CopyFrom(fCamFar);
            farCam.transform.parent        = cameraTransform;
            farCam.transform.localRotation = Quaternion.identity;
            farCam.transform.localPosition = Vector3.zero;
            farCam.transform.localScale    = Vector3.one;
            farCam.targetTexture           = targetCamRenderTexture;
            cameras[1] = farCam;

            /*
             * var cbr2 = cam2Obj.AddComponent<CameraBulletRenderer>();
             * cbr2.resizeFactor = 3f;
             */

            //skybox camera
            GameObject skyCamObj  = new GameObject();
            Camera     skyCam     = skyCamObj.AddComponent <Camera>();
            Camera     mainSkyCam = FindCamera("Camera ScaledSpace");

            skyCam.CopyFrom(mainSkyCam);
            skyCam.transform.parent        = mainSkyCam.transform;
            skyCam.transform.localRotation = Quaternion.identity;
            skyCam.transform.localPosition = Vector3.zero;
            skyCam.transform.localScale    = Vector3.one;
            skyCam.targetTexture           = targetCamRenderTexture;
            cameras[cameras.Length - 2]    = skyCam;
            skyCamObj.AddComponent <TGPCamRotator>();

            //galaxy camera
            GameObject galaxyCamObj  = new GameObject();
            Camera     galaxyCam     = galaxyCamObj.AddComponent <Camera>();
            Camera     mainGalaxyCam = FindCamera("GalaxyCamera");

            galaxyCam.CopyFrom(mainGalaxyCam);
            galaxyCam.transform.parent        = mainGalaxyCam.transform;
            galaxyCam.transform.position      = Vector3.zero;
            galaxyCam.transform.localRotation = Quaternion.identity;
            galaxyCam.transform.localScale    = Vector3.one;
            galaxyCam.targetTexture           = targetCamRenderTexture;
            cameras[cameras.Length - 1]       = galaxyCam;
            galaxyCamObj.AddComponent <TGPCamRotator>();

            nvLight = new GameObject().AddComponent <Light>();
            nvLight.transform.parent        = cameraTransform;
            nvLight.transform.localPosition = Vector3.zero;
            nvLight.transform.localRotation = Quaternion.identity;
            nvLight.type      = LightType.Directional;
            nvLight.intensity = 2;
            nvLight.shadows   = LightShadows.None;

            nvLight.cullingMask = 1 << 0;
            nvLight.enabled     = false;
        }