当前位置: 首页>>代码示例>>C#>>正文


C# Camera.GetComponent方法代码示例

本文整理汇总了C#中UnityEngine.Camera.GetComponent方法的典型用法代码示例。如果您正苦于以下问题:C# Camera.GetComponent方法的具体用法?C# Camera.GetComponent怎么用?C# Camera.GetComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEngine.Camera的用法示例。


在下文中一共展示了Camera.GetComponent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DragSelectionBox

        public void DragSelectionBox(Camera main, CursorPanGroup group, CursorButton button, TutorialAIManager manager, float delayTime, string methodName)
        {
            BoxSelector selector = main.GetComponent<BoxSelector>();
            if (selector == null) {
                Debug.LogError("Cannot find Box Selector component from camera, " + main.ToString() + ".");
                return;
            }

            if (button != CursorButton.Left_Click) {
                Debug.LogError("Selection box only works with left mouse button.");
                return;
            }

            selector.StartBoxSelection(group, 0.5f);
            this.icon.SetButton(button);
            this.buttonPressedElapsedTime = 0f;
            this.isButtonPressed = true;
            this.isButtonHeld = true;
            this.isAppearing = true;
            this.panningElapsedTime = 0f;
            this.startingPosition = group.start;
            this.endingPosition = group.end;
            this.rectTransform.position = group.start;

            manager.Invoke(methodName, delayTime);
            this.Invoke("HeldButtonRelease", delayTime);
        }
开发者ID:tommai78101,项目名称:Multiplier,代码行数:27,代码来源:Cursor.cs

示例2: Execute

        public void Execute(Camera cam, Vector3 targetPos, Vector3 targetLookat)
        {
            // Lerp and somesuch
            Vector3 oldPos = cam.transform.position;
            //Vector3 oldLookat = cam.transform.forward;


            Vector3 cameraOffset = cam.GetComponent<CameraController>().CameraOffset;

            Vector3 newPos = Vector3.Lerp(oldPos, targetLookat + cameraOffset, .1f); // hard coded .1f
            Vector3 newTarget = Vector3.Lerp(previousLookat, targetLookat, .1f);

            cam.transform.position = newPos;
            cam.transform.LookAt(newTarget);

            previousLookat = newTarget;

        }
开发者ID:TamaHobbit,项目名称:DMV,代码行数:18,代码来源:ICameraBehaviour.cs

示例3: nCamera

 /**
  * Creates a new orthographic camera
  * <p>
  * Notice that you must 'enable' this camera by setting
  * 'Active' to true, and 'Audio' to true if you want it to
  * be the primary audio listener.
  * <p>
  * The camera is placed at (0, 0, -1) looking down the Z-axis.
  * <p>
  * There MUST be a camera on the scene already to be able create
  * this type of camera, and it inherits all the properties of the
  * main camera; although some of them are reset.
  */
 public nCamera(double height)
 {
     var original = GameObject.FindWithTag("MainCamera");
       _cam = (Camera) UnityEngine.Camera.Instantiate(
     original.camera,
     new Vector3(0, 0, -1),
     Quaternion.FromToRotation(
       new Vector3(0, 0, 0),
       new Vector3(0, 0, 1)
     )
       );
       _cam.orthographicSize = (float) height / 2;
       _cam.orthographic = true;
       _cam.backgroundColor = Color.black;
       _cam.depth = 0;
       _cam.enabled = false;
       _cam.GetComponent<AudioListener>().enabled = false;
       original.camera.enabled = false;
 }
开发者ID:onethousandfaces,项目名称:game-off-2012,代码行数:32,代码来源:nCamera.cs

示例4: UpdateCameraModes

        protected void UpdateCameraModes(Camera src, Camera dest)
        {
            if (!dest)
            return;

            //set portal camera to act like the current camera

            // This doesn't fully work in all Unity versions work for some reason (I haven't had a good reason to figure out why, either)
            // So we'll start with that, and then make sure things actually work.
            dest.CopyFrom(src);

            //NB: Render to the full frame, irrespective of what the source camera does:
            dest.rect = new Rect(0, 0, 1, 1);

            dest.clearFlags = src.clearFlags;
            dest.backgroundColor = src.backgroundColor;
            if (src.clearFlags == CameraClearFlags.Skybox) {
            Skybox sky = src.GetComponent<Skybox>();
            Skybox mysky = dest.GetComponent<Skybox>();
            if (!sky || !sky.material) {
                mysky.enabled = false;
            } else {
                mysky.enabled = true;
                mysky.material = sky.material;
            }
            }

            // update other values to match current camera.
            // even if we are supplying custom camera & projection matrices,
            // some of values are used elsewhere (e.g. sky box uses far plane)
            dest.farClipPlane = src.farClipPlane;
            dest.nearClipPlane = src.nearClipPlane;
            dest.orthographic = src.orthographic;
            dest.fieldOfView = src.fieldOfView;
            dest.aspect = src.aspect;
            dest.orthographicSize = src.orthographicSize;
        }
开发者ID:mmandel,项目名称:8Nights2,代码行数:37,代码来源:Portal.cs

示例5: ApplyConfig

        public static void ApplyConfig(Camera cam, Profile prof)
        {
            if(cam==null) { return; }

            var ssao = cam.GetComponent<UnityStandardAssets.ImageEffects.ScreenSpaceAmbientOcclusion>();
            if(ssao!=null)
            {
                switch(prof)
                {
                    case Profile.Fastest:
                        ssao.enabled = false;
                        break;
                    case Profile.Fast:
                        ssao.enabled = true;
                        ssao.m_SampleCount = UnityStandardAssets.ImageEffects.ScreenSpaceAmbientOcclusion.SSAOSamples.Low;
                        ssao.m_Downsampling = 4;
                        break;
                    case Profile.Medium:
                        ssao.enabled = true;
                        ssao.m_SampleCount = UnityStandardAssets.ImageEffects.ScreenSpaceAmbientOcclusion.SSAOSamples.Low;
                        ssao.m_Downsampling = 2;
                        break;
                    case Profile.High:
                        ssao.enabled = true;
                        ssao.m_SampleCount = UnityStandardAssets.ImageEffects.ScreenSpaceAmbientOcclusion.SSAOSamples.Medium;
                        ssao.m_Downsampling = 2;
                        break;
                    case Profile.VeryHigh:
                        ssao.enabled = true;
                        ssao.m_SampleCount = UnityStandardAssets.ImageEffects.ScreenSpaceAmbientOcclusion.SSAOSamples.High;
                        ssao.m_Downsampling = 2;
                        break;
                }
            }

            var ssr = cam.GetComponent<ScreenSpaceReflections>();
            if (ssr != null)
            {
                switch (prof)
                {
                    case Profile.Fastest:
                    case Profile.Fast:
                        ssr.enabled = false;
                        break;
                    case Profile.Medium:
                        ssr.enabled = true;
                        ssr.m_sample_count = ScreenSpaceReflections.SampleCount.Low;
                        ssr.m_downsampling = 2;
                        break;
                    case Profile.High:
                        ssr.enabled = true;
                        ssr.m_sample_count = ScreenSpaceReflections.SampleCount.Medium;
                        ssr.m_downsampling = 2;
                        break;
                    case Profile.VeryHigh:
                        ssr.enabled = true;
                        ssr.m_sample_count = ScreenSpaceReflections.SampleCount.High;
                        ssr.m_downsampling = 2;
                        break;
                }
            }

            var bloom = cam.GetComponent<UnityStandardAssets.ImageEffects.Bloom>();
            if (bloom != null)
            {
                switch (prof)
                {
                    case Profile.Fastest:
                    case Profile.Fast:
                        bloom.enabled = true;
                        bloom.quality = UnityStandardAssets.ImageEffects.Bloom.BloomQuality.Cheap;
                        break;
                    case Profile.Medium:
                    case Profile.High:
                    case Profile.VeryHigh:
                        bloom.enabled = true;
                        bloom.quality = UnityStandardAssets.ImageEffects.Bloom.BloomQuality.High;
                        break;
                }
            }

            var dof = cam.GetComponent<UnityStandardAssets.ImageEffects.DepthOfField>();
            if (dof != null)
            {
                switch (prof)
                {
                    case Profile.Fastest:
                    case Profile.Fast:
                    case Profile.Medium:
                        dof.enabled = false;
                        break;
                    case Profile.High:
                    case Profile.VeryHigh:
                        dof.enabled = true;
                        break;
                }
            }
        }
开发者ID:davidlawson,项目名称:ggj2016,代码行数:98,代码来源:PostEffectPresets.cs

示例6: UpdateCameraModes

 void UpdateCameraModes(Camera src, Camera dest)
 {
     if (dest == null)
     {
         return;
     }
     // set water camera to clear the same way as current camera
     dest.clearFlags = src.clearFlags;
     dest.backgroundColor = src.backgroundColor;
     if (src.clearFlags == CameraClearFlags.Skybox)
     {
         Skybox sky = src.GetComponent<Skybox>();
         Skybox mysky = dest.GetComponent<Skybox>();
         if (!sky || !sky.material)
         {
             mysky.enabled = false;
         }
         else
         {
             mysky.enabled = true;
             mysky.material = sky.material;
         }
     }
     // update other values to match current camera.
     // even if we are supplying custom camera&projection matrices,
     // some of values are used elsewhere (e.g. skybox uses far plane)
     dest.farClipPlane = src.farClipPlane;
     dest.nearClipPlane = src.nearClipPlane;
     dest.orthographic = src.orthographic;
     dest.fieldOfView = src.fieldOfView;
     dest.aspect = src.aspect;
     dest.orthographicSize = src.orthographicSize;
 }
开发者ID:Miformat,项目名称:GlobalGameJam,代码行数:33,代码来源:Water1.cs

示例7: setUp

        public void setUp(Actions             actions,
							  MouseLook           mouseLook,
							  FOVKick             fovKick,
							  CurveControlledBob  headBob,
							  LerpControlledBob   jumpBob,
							  AttackController    attackController)
        {
            this.actions=actions;
                this.mouseLook=mouseLook;
                this.fovKick=fovKick;
                this.headBob=headBob;
                this.jumpBob=jumpBob;
                this.attackController=attackController;

                this.mainCameraObject    = SingletonNames.getMainCamera();
                this.playerObject        = SingletonNames.getPlayer();
                this.audioSource         = playerObject.gameObject.AddComponent<AudioSource>();
                this.audioData           = playerObject.GetComponent<MovementAudioData>();
                this.characterController = playerObject.GetComponent<CharacterController>();

                objectsSelector = mainCameraObject.GetComponent<ObjectsSelector>();

                originalCameraPosition = mainCameraObject.transform.localPosition;

                fovKick.Setup(mainCameraObject);
                headBob.Setup(mainCameraObject, stepInterval);
                mouseLook.Init(playerObject.transform, mainCameraObject.transform);

                stepCycle = 0f;
                nextStep = stepCycle / 2f;
                isJumping = false;
        }
开发者ID:Baensi,项目名称:Assets,代码行数:32,代码来源:IngroundMovements.cs

示例8: IsUFPSCamera

 /**
  * <summary>Checks if a supplied Camera has the vp_FPCamera component attached.</summary>
  * <returns>Checks if a supplied Camera has the vp_FPCamera component attached.</returns>
  */
 public static bool IsUFPSCamera(Camera camera)
 {
     #if UltimateFPSIsPresent
     if (camera != null && camera.GetComponent <vp_FPCamera>())
     {
         return true;
     }
     #endif
     return false;
 }
开发者ID:Davetheallthing,项目名称:Space-Walk,代码行数:14,代码来源:UltimateFPSIntegration.cs

示例9: Start

        // Use this for initialization
        void Start()
        {
            //initialize the player character
            Vector3 charPos = new Vector3(25.5f, -1.8f, 2.0f);
            characters.Add((GameObject)Instantiate(Character, charPos, Quaternion.identity));

            //set camera to follow the Camera Target
            Vector3 camPos = new Vector3(25.5f, -1.8f, 0.0f);
            cameraTargets.Add((GameObject)Instantiate(CamTarget, camPos, Quaternion.identity));

            Transform targetTransform = cameraTargets[0].transform;
            mainCam = Camera.allCameras[0];
            mainCam.GetComponent<SmoothFollow>().target = targetTransform;

            //Find the light
            light = GameObject.Find("Directional Light");

            //initialize the front wall
            Vector3 wallPos = mainCam.ViewportToWorldPoint(new Vector3(1.0f, 0.0f, 0.0f));
            wallPos.z = 2.0f; // resets to platform Z
            wallPos.y = -3.0f; // brings wall to ground
            wallPos.x *= 1.6f; // moves wall half of screen width away from camera
            frontWalls.Add((GameObject)Instantiate(FrontWall, wallPos, Quaternion.identity));
            frontWalls[0].transform.Rotate(0.0f, 0.0f, 90.0f);

            //initialize the kill zone
            Vector3 killZonePos = mainCam.ScreenToViewportPoint(new Vector3(0.0f, 0.0f, 2.0f));
            killZonePos.x += 7.0f; // move slightly right from current lock location
            KillZones.Add((GameObject)Instantiate(KillZone, killZonePos, Quaternion.identity));
            killZones[0].transform.Rotate(0.0f, 0.0f, 90.0f);

            // create bottom killzone
            Vector3 underworld = new Vector3(0.0f, -11.5f, 2.0f);
            killZones.Add((GameObject)Instantiate(KillZone, underworld, Quaternion.identity));

            // create knife
            knifeSpawn = new Vector3(killZonePos.x, killZonePos.y, killZonePos.z);
            knifeSpawn.x += 2.0f; // move slightly right from current lock location
            knife = (GameObject)Instantiate(Knife, knifeSpawn, Quaternion.identity);
            knife.transform.localScale = new Vector3(0.6f, 0.6f, 0.6f);
            thrown = false;

            // create chef
            chefSpawn = new Vector3(killZonePos.x, killZonePos.y, killZonePos.z);
            chefSpawn.x += 2.0f; // move slightly right from current lock location
            Chef = (GameObject)Instantiate(Chef, chefSpawn, Quaternion.identity);
            chefOnScreen = false;
            chefMovingOut = false;

            mainCam.aspect = (1920f / 910f);

            //initialize the game fragments
            for (int i = 0; i < numFrags; i++)
            {
                Vector3 fragPos = new Vector3(i * 25.0f, -3.5f, 2.0f);
                //make the first two fragments flat
                if (i == 0 || i == 1) fragments.Add((GameObject)Instantiate(GameFragments[0], fragPos, Quaternion.identity));
                else
                {
                    float fragType = Random.Range(0.0f, (float)GameFragments.Count);
                    if (fragType >= 0 && fragType < 1)
                    {
                        fragPos = new Vector3(i * 25.0f, -3.5f, 2.0f);
                        fragments.Add((GameObject)Instantiate(GameFragments[0], fragPos, Quaternion.identity));
                    }
                    else if (fragType >= 1 && fragType < 2)
                    {
                        fragPos = new Vector3(i * 25.0f, -3.5f, 2.0f);
                        fragments.Add((GameObject)Instantiate(GameFragments[1], fragPos, Quaternion.identity));
                    }
                    else if (fragType >= 2 && fragType < 3)
                    {
                        fragPos = new Vector3(i * 25.0f, -3.5f, 2.0f);
                        fragments.Add((GameObject)Instantiate(GameFragments[2], fragPos, Quaternion.identity));
                    }
                    else if (fragType >= 3 && fragType < 4)
                    {
                        fragPos = new Vector3(i * 25.0f, -3.5f, 2.0f);
                        fragments.Add((GameObject)Instantiate(GameFragments[3], fragPos, Quaternion.identity));
                    }
                    else if (fragType >= 4 && fragType < 5)
                    {
                        fragPos = new Vector3(i * 25.0f, -3.5f, 2.0f);
                        fragments.Add((GameObject)Instantiate(GameFragments[4], fragPos, Quaternion.identity));
                    }
                    else if (fragType >= 5 && fragType < 6)
                    {
                        fragPos = new Vector3(i * 25.0f, -3.5f, 2.0f);
                        fragments.Add((GameObject)Instantiate(GameFragments[5], fragPos, Quaternion.identity));
                    }
                    else if (fragType >= 6 && fragType < 7)
                    {
                        fragPos = new Vector3(i * 25.0f, -3.5f, 2.0f);
                        fragments.Add((GameObject)Instantiate(GameFragments[6], fragPos, Quaternion.identity));
                    }
                    else if (fragType >= 7 && fragType < 8)
                    {
                        fragPos = new Vector3(i * 25.0f, -3.5f, 2.0f);
                        fragments.Add((GameObject)Instantiate(GameFragments[7], fragPos, Quaternion.identity));
//.........这里部分代码省略.........
开发者ID:mfasman95,项目名称:WildPotatoGDD2Digital,代码行数:101,代码来源:GameManager.cs

示例10: Awake

        void Awake()
        {
            playerEnterExit = GetComponent<PlayerEnterExit>();
            if (!playerEnterExit)
                throw new Exception("PlayerEnterExit not found.");

            playerCamera = GetComponentInChildren<Camera>();
            if (!playerCamera)
                throw new Exception("Player Camera not found.");

            playerMouseLook = playerCamera.GetComponent<PlayerMouseLook>();
            if (!playerMouseLook)
                throw new Exception("PlayerMouseLook not found.");

            playerMotor = GetComponent<PlayerMotor>();
            if (!playerMotor)
                throw new Exception("PlayerMotor not found.");

            playerEntityBehaviour = GetComponent<DaggerfallEntityBehaviour>();
            if (!playerEntityBehaviour)
                throw new Exception("PlayerEntityBehaviour not found.");

            SaveLoadManager.RegisterSerializableGameObject(this);
        }
开发者ID:my0pic,项目名称:daggerfall-unity,代码行数:24,代码来源:SerializablePlayer.cs

示例11: OceanOnPostRender

		/// <summary>
		/// Called after the camera renders the ocean.
		/// </summary>
		void OceanOnPostRender(Camera cam)
		{

			if(cam.GetComponent<IgnoreOceanEvents>() != null) return;

            CameraData data = FindCameraData(cam);

			if(Grid != null)
				Grid.OceanOnPostRender(cam, data);
			
			if(Spectrum != null)
				Spectrum.OceanOnPostRender(cam, data);
			
			if(Reflection != null)
				Reflection.OceanOnPostRender(cam, data);
			
			if(UnderWater != null)
				UnderWater.OceanOnPostRender(cam, data);
		}
开发者ID:BenjaminLovegrove,项目名称:ATR,代码行数:22,代码来源:Ocean.cs

示例12: FindCameraData

        /// <summary>
        /// Finds the camera data for this camera.
        /// If no data exists then create new data
        /// object and return it.
        /// </summary>
		public CameraData FindCameraData(Camera cam)
		{

            if (cam == null)
                throw new InvalidOperationException("Can not find camera data for null camera");

            if (!m_cameraData.ContainsKey(cam))
                m_cameraData.Add(cam, new CameraData());

            CameraData data = m_cameraData[cam];

            data.settings = cam.GetComponent<OceanCameraSettings>();

            return data;
		}
开发者ID:BenjaminLovegrove,项目名称:ATR,代码行数:20,代码来源:Ocean.cs

示例13: workerMethod

        protected override IEnumerator workerMethod()
        {
			var textureMerge = umaGenerator.textureMerge;
			for (int atlasIndex = umaData.generatedMaterials.materials.Count-1; atlasIndex >= 0; atlasIndex--)
            {
                var atlas = umaData.generatedMaterials.materials[atlasIndex];

                //Rendering Atlas
                int moduleCount = 0;

                //Process all necessary TextureModules
                for (int i = 0; i < atlas.materialFragments.Count; i++)
                {
                    if (!atlas.materialFragments[i].isRectShared)
                    {
                        moduleCount++;
                        moduleCount = moduleCount + atlas.materialFragments[i].overlays.Length;
                    }
                }
				textureMerge.EnsureCapacity(moduleCount);

                var slotData = atlas.materialFragments[0].slotData;
				resultingTextures = new Texture[slotData.asset.material.channels.Length];
				for (int textureType = slotData.asset.material.channels.Length - 1; textureType >= 0; textureType--)
                {
					switch(slotData.asset.material.channels[textureType].channelType )
					{
						case UMAMaterial.ChannelType.Texture:
						case UMAMaterial.ChannelType.NormalMap:
						{
							textureMerge.Reset();
							for (int i = 0; i < atlas.materialFragments.Count; i++)
							{
								textureMerge.SetupModule(atlas, i, textureType);
							}

							//last element for this textureType
							moduleCount = 0;

							umaGenerator.textureMerge.gameObject.SetActive(true);

							int width = Mathf.FloorToInt(atlas.cropResolution.x);
							int height = Mathf.FloorToInt(atlas.cropResolution.y);
							destinationTexture = new RenderTexture(Mathf.FloorToInt(atlas.cropResolution.x * umaData.atlasResolutionScale), Mathf.FloorToInt(atlas.cropResolution.y * umaData.atlasResolutionScale), 0, slotData.asset.material.channels[textureType].textureFormat, RenderTextureReadWrite.Linear);
							destinationTexture.filterMode = FilterMode.Point;
							destinationTexture.useMipMap = umaGenerator.convertMipMaps && !umaGenerator.convertRenderTexture;
							renderCamera = umaGenerator.textureMerge.myCamera;
							renderCamera.targetTexture = destinationTexture;
							renderCamera.orthographicSize = height >> 1;
							var camTransform = renderCamera.GetComponent<Transform>();
							camTransform.localPosition = new Vector3(width >> 1, height >> 1, 3);
							camTransform.localRotation = Quaternion.Euler(0, 180, 180);
							renderCamera.Render();
							renderCamera.gameObject.SetActive(false);
							renderCamera.targetTexture = null;

							if (umaGenerator.convertRenderTexture)
							{
								#region Convert Render Textures
								yield return 25;
								Texture2D tempTexture;
								tempTexture = new Texture2D(destinationTexture.width, destinationTexture.height, TextureFormat.ARGB32, umaGenerator.convertMipMaps);
								int xblocks = destinationTexture.width / 512;
								int yblocks = destinationTexture.height / 512;
								if (xblocks == 0 || yblocks == 0)
								{
									RenderTexture.active = destinationTexture;
									tempTexture.ReadPixels(new Rect(0, 0, destinationTexture.width, destinationTexture.height), 0, 0, umaGenerator.convertMipMaps);
									RenderTexture.active = null;
								}
								else
								{
									// figures that ReadPixels works differently on OpenGL and DirectX, someday this code will break because Unity fixes this bug!
									if (IsOpenGL())
									{
										for (int x = 0; x < xblocks; x++)
										{
											for (int y = 0; y < yblocks; y++)
											{
												RenderTexture.active = destinationTexture;
												tempTexture.ReadPixels(new Rect(x * 512, y * 512, 512, 512), x * 512, y * 512, umaGenerator.convertMipMaps);
												RenderTexture.active = null;
												yield return 8;
											}
										}
									}
									else
									{
										for (int x = 0; x < xblocks; x++)
										{
											for (int y = 0; y < yblocks; y++)
											{
												RenderTexture.active = destinationTexture;
												tempTexture.ReadPixels(new Rect(x * 512, destinationTexture.height - 512 - y * 512, 512, 512), x * 512, y * 512, umaGenerator.convertMipMaps);
												RenderTexture.active = null;
												yield return 8;
											}
										}
									}
								}
//.........这里部分代码省略.........
开发者ID:NotYours180,项目名称:UMA,代码行数:101,代码来源:TextureProcessPROCoroutine.cs

示例14: RenderBlob

        public void RenderBlob(Camera blobCam, BlobSizeComputation ComputeBlobSize, float falloff, float blurFactor, float textureSize)
        {
            // Resize blob, remember to counter root scale
            Vector2 blobSize = ComputeBlobSize(ModelBounds);
            Vector3 rootScale = transform.localScale;
            BlobRenderer.transform.localScale = new Vector3(blobSize.x / rootScale.x, 1.0f / rootScale.y, blobSize.y / rootScale.z);

            // Resize blob texture
            int width, height; float textureDownScale;
            CalcTextureSize(blobSize, textureSize, out width, out height, out textureDownScale);
            if (BlobShadow == null || BlobShadow.width != width || BlobShadow.height != height) {
            if (BlobShadow != null) Texture2D.DestroyImmediate(BlobShadow);
            BlobShadow = new Texture2D(width, height);
            BlobShadow.filterMode = FilterMode.Trilinear;
            BlobShadow.hideFlags = HideFlags.HideInInspector | HideFlags.DontSave;
            BlobRenderer.sharedMaterial.mainTexture = BlobShadow;
            }

            // Setup blob camera
            RenderTexture targetTex = blobCam.targetTexture;
            Vector2 blobTexScale = new Vector2((float)targetTex.width / (float)BlobShadow.width,
                                           (float)targetTex.height / (float)BlobShadow.height);

            // Magic! Can't remember whats gaoing on here anymore. The margin start
            // copmutes the distance to where the margin should start (I think!) but
            // I've no idea what margin end is. An inverse lerp is used in the
            // shader to compute the intensity.
            Vector2 marginEnd =
            new Vector2(1.0f - (float)(targetTex.width  - BlobShadow.width)  / (float)targetTex.width,
                        1.0f - (float)(targetTex.height - BlobShadow.height) / (float)targetTex.height);

            Vector2 marginStart = blobCam.GetComponent<BlobBlur>().MarginStart =
            new Vector2(marginEnd.x / blobSize.x * ModelBounds.size.x,
                        marginEnd.y / blobSize.y * ModelBounds.size.z);

            blobCam.GetComponent<BlobBlur>().MarginEnd = new Vector2(Mathf.Max(marginEnd.x, marginStart.x),
                                                                 Mathf.Max(marginEnd.y, marginStart.y));

            // Place camera so it can see the model
            blobCam.transform.position = new Vector3(ModelBounds.center.x, ModelBounds.min.y - 0.01f * ModelBounds.size.y, ModelBounds.center.z);
            blobCam.orthographicSize = blobSize.y * 0.5f * blobTexScale.y;
            blobCam.aspect = 1.0f;

            // Convert texture size to mipmap max offset.
            // If the texture size had to be scaled due to originally exceeding 4096 pixels,
            // the scale is also applied to the texture size to keep the shadow relatively consistent.
            float modelSize = textureSize * Mathf.Max(ModelBounds.size.x, ModelBounds.size.z);
            blobCam.GetComponent<BlobBlur>().MipOffset = Mathf.Log(blurFactor * modelSize * textureDownScale, 2.0f);

            // Render blob
            Shader.SetGlobalFloat("_BlobFalloffExponent", falloff);
            blobCam.Render();

            // Copy from target tex to BlobShadow
            RenderTexture oldActive = RenderTexture.active;
            RenderTexture.active = targetTex;
            BlobShadow.ReadPixels(new Rect((targetTex.width - BlobShadow.width) / 2, (targetTex.height - BlobShadow.height) / 2,
                                       BlobShadow.width, BlobShadow.height), 0, 0);
            BlobShadow.Apply();
            RenderTexture.active = oldActive;
        }
开发者ID:shadercoder,项目名称:Unity3D-experiments,代码行数:61,代码来源:ABlobModel.cs

示例15: RenderReflectionFor

        void RenderReflectionFor(Camera cam, Camera reflectCamera)
        {
            if (!reflectCamera)
            {
                return;
            }

            if (m_SharedMaterial && !m_SharedMaterial.HasProperty(reflectionSampler))
            {
                return;
            }

            reflectCamera.cullingMask = reflectionMask & ~(1 << LayerMask.NameToLayer("Water"));

            SaneCameraSettings(reflectCamera);

            reflectCamera.backgroundColor = clearColor;
            reflectCamera.clearFlags = reflectSkybox ? CameraClearFlags.Skybox : CameraClearFlags.SolidColor;
            if (reflectSkybox)
            {
                if (cam.gameObject.GetComponent(typeof(Skybox)))
                {
                    Skybox sb = (Skybox)reflectCamera.gameObject.GetComponent(typeof(Skybox));
                    if (!sb)
                    {
                        sb = (Skybox)reflectCamera.gameObject.AddComponent(typeof(Skybox));
                    }
                    sb.material = ((Skybox)cam.GetComponent(typeof(Skybox))).material;
                }
            }

            GL.invertCulling = true;

            Transform reflectiveSurface = transform; //waterHeight;

            Vector3 eulerA = cam.transform.eulerAngles;

            reflectCamera.transform.eulerAngles = new Vector3(-eulerA.x, eulerA.y, eulerA.z);
            reflectCamera.transform.position = cam.transform.position;

            Vector3 pos = reflectiveSurface.transform.position;
            pos.y = reflectiveSurface.position.y;
            Vector3 normal = reflectiveSurface.transform.up;
            float d = -Vector3.Dot(normal, pos) - clipPlaneOffset;
            Vector4 reflectionPlane = new Vector4(normal.x, normal.y, normal.z, d);

            Matrix4x4 reflection = Matrix4x4.zero;
            reflection = CalculateReflectionMatrix(reflection, reflectionPlane);
            m_Oldpos = cam.transform.position;
            Vector3 newpos = reflection.MultiplyPoint(m_Oldpos);

            reflectCamera.worldToCameraMatrix = cam.worldToCameraMatrix * reflection;

            Vector4 clipPlane = CameraSpacePlane(reflectCamera, pos, normal, 1.0f);

            Matrix4x4 projection = cam.projectionMatrix;
            projection = CalculateObliqueMatrix(projection, clipPlane);
            reflectCamera.projectionMatrix = projection;

            reflectCamera.transform.position = newpos;
            Vector3 euler = cam.transform.eulerAngles;
            reflectCamera.transform.eulerAngles = new Vector3(-euler.x, euler.y, euler.z);

            reflectCamera.Render();

            GL.invertCulling = false;
        }
开发者ID:markkleeb,项目名称:ArcadeCabs2016,代码行数:67,代码来源:PlanarReflection.cs


注:本文中的UnityEngine.Camera.GetComponent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。