protected virtual void Awake() { // Create the render texture. int horizontalResolution = Mathf.RoundToInt(RenderTextureAspectRatio * _renderTextureResolution); RenderTexture = new RenderTexture(horizontalResolution, _renderTextureResolution, 0) { format = RenderTextureFormat.ARGB32 }; RenderTexture.Create(); // Configure the render texture camera. RenderTextureCamera = GetComponent <Camera>(); RenderTextureCamera.aspect = RenderTextureAspectRatio; RenderTextureCamera.orthographicSize = CameraVerticalSize; RenderTextureCamera.targetTexture = RenderTexture; RenderTextureCamera.enabled = false; // Disable automatic updates RenderTextureCamera.Render(); // Create and orient the objects container. _renderTextureObjectsContainer = new GameObject("Objects") { layer = (int)CullingLayer.RenderToTexture, }; _renderTextureObjectsContainer.transform.SetParent(transform, false); _renderTextureObjectsContainer.transform.localPosition = new Vector3(-CameraVerticalSize * RenderTextureAspectRatio, -CameraVerticalSize, 1); }
void Awake() { camera.targetTexture = new RenderTexture(camera.targetTexture); camera.targetTexture.filterMode = FilterMode.Point; renderTextureCamera = GetComponent <RenderTextureCamera>(); renderTextureCamera.ResizeRenderTexture(); }
public void UpdateTexture(bool force = false) { if (force) { RenderTextureCamera.Render(); } _textureUpdateRequired = !force; }
private void LateUpdate() { if (_textureUpdateRequired) { RenderTextureCamera.Render(); _textureUpdateRequired = false; } }
protected override void OnEditorExist() { base.OnEditorExist(); if (RenderPipelineInfo.Type != RPType.HDRP || RenderPipelineInfo.ForceUseRenderTextures) { return; } m_cameraUtility = GetComponent <IRenderPipelineCameraUtility>(); m_outlineManager = gameObject.AddComponent <OutlineManagerHDRP>(); m_outlineManager.SelectionMaterial = m_selectionMaterial; IRTE rte = IOC.Resolve <IRTE>(); IRTEAppearance appearance = IOC.Resolve <IRTEAppearance>(); if (appearance != null) { Canvas foregroundCanvas = appearance.UIForegroundScaler.GetComponent <Canvas>(); Camera foregroundCamera = foregroundCanvas.worldCamera; if (foregroundCamera != null) { if (m_cameraUtility != null) { m_cameraUtility.EnablePostProcessing(foregroundCamera, false); m_cameraUtility.SetBackgroundColor(foregroundCamera, new Color(0, 0, 0, 0)); } GameObject foregroundLayer = new GameObject("ForegroundLayer"); foregroundLayer.transform.SetParent(rte.Root, false); foregroundCanvas = foregroundLayer.AddComponent <Canvas>(); foregroundCanvas.renderMode = RenderMode.ScreenSpaceOverlay; foregroundCamera.gameObject.SetActive(false); m_foregroundOutput = new GameObject("Output"); m_foregroundOutput.transform.SetParent(foregroundCanvas.transform, false); m_foregroundOutput.AddComponent <RectTransform>().Stretch(); RenderTextureCamera renderTextureCamera = foregroundCamera.gameObject.AddComponent <RenderTextureCamera>(); renderTextureCamera.OutputRoot = foregroundCanvas.gameObject.GetComponent <RectTransform>(); renderTextureCamera.Output = m_foregroundOutput.AddComponent <RawImage>(); renderTextureCamera.OverlayMaterial = new Material(Shader.Find("Battlehub/HDRP/RTEditor/UIForeground")); foregroundCamera.gameObject.SetActive(true); foregroundCanvas.sortingOrder = -1; } Canvas backgroundCanvas = IOC.Resolve <IRTEAppearance>().UIBackgroundScaler.GetComponent <Canvas>(); if (backgroundCanvas != null) { Camera backgroundCamera = backgroundCanvas.worldCamera; if (m_cameraUtility != null) { m_cameraUtility.EnablePostProcessing(backgroundCamera, false); m_cameraUtility.SetBackgroundColor(backgroundCamera, new Color(0, 0, 0, 0)); } } } }
private void CreateRenderTextureCamera(GameViewCamera gameViewCamera) { GameObject gameViewCameraGo = gameViewCamera.gameObject; bool wasActive = gameViewCameraGo.activeSelf; gameViewCameraGo.SetActive(false); RenderTextureCamera renderTextureCamera = gameViewCameraGo.AddComponent <RenderTextureCamera>(); renderTextureCamera.OutputRoot = m_renderTextureOutput; m_renderTextureCameras.Add(renderTextureCamera); gameViewCameraGo.SetActive(wasActive); }
public void InstantiateRCFishInAquarium() { RenderTextureCamera renderTextureCamera = fishPrefab.transform.parent.GetComponent <ColoringTrackingHandler>().RC.GetComponent <RenderTextureCamera>(); GameObject fish = (GameObject)Instantiate(fishPrefab, fishPrefab.transform.position, fishPrefab.transform.rotation); fish.transform.parent = aquariumBehavior.fishHolder.transform; fish.transform.localPosition = new Vector3(Random.Range(-0.3f, 0.3f), Random.Range(0.08f, 0.3f), Random.Range(-0.18f, 0.15f)); while (Vector3.Distance(fish.transform.localPosition, aquariumBehavior.forbiddenArea.transform.localPosition) < 0.2f) { fish.transform.localPosition = new Vector3(Random.Range(-0.3f, 0.3f), Random.Range(0.08f, 0.3f), Random.Range(-0.18f, 0.15f)); } fish.transform.localScale = new Vector3(1f, 1f, 1f); fish.transform.Rotate(fish.transform.up * Random.Range(20f, 200f)); //Texture2D tex2D = new Texture2D(renderTextureCamera.GetRenderTexture().width, renderTextureCamera.GetRenderTexture().height); //tex2D.ReadPixels(RenderTextureCamera.ARCamera_Camera.rect, 0, 0); //tex2D.Apply(); fish.GetComponentInChildren <GetTexture>().enabled = false; Texture2D FrameTexture = new Texture2D(renderTextureCamera.GetRenderTexture().width, renderTextureCamera.GetRenderTexture().height, TextureFormat.RGB24, false); RenderTexture.active = renderTextureCamera.GetRenderTexture(); FrameTexture.ReadPixels(new Rect(0, 0, renderTextureCamera.GetRenderTexture().width, renderTextureCamera.GetRenderTexture().height), 0, 0); RenderTexture.active = null; FrameTexture.Apply(); Material newMat = Resources.Load("FishMat", typeof(Material)) as Material; newMat.EnableKeyword("_MainTex"); newMat.SetTexture("_MainTex", FrameTexture); fish.GetComponentInChildren <SkinnedMeshRenderer>().material = newMat; //GetComponentInChildren<SkinnedMeshRenderer>().material.SetTexture("_MainTex", FrameTexture); FishMovement fishMovement = fish.AddComponent <FishMovement>(); fishMovement.aquariumBehavior = aquariumBehavior; fishMovement.SetPassPoints(passPoints); //fishMovement.movementType = (FishMovement.MovementType)Random.Range(0, 2); }
protected override void OnDestroyOverride() { base.OnDestroyOverride(); if (m_editor != null) { m_editor.BeforeSceneSave -= OnBeforeSceneSave; m_editor.SceneSaved -= OnSceneSaved; } GameViewCamera._Awaked -= OnCameraAwaked; GameViewCamera._Destroyed -= OnCameraDestroyed; GameViewCamera._Enabled -= OnCameraEnabled; GameViewCamera._Disabled -= OnCameraDisabled; GameViewCamera._CameraEnabled -= OnCameraComponentEnabled; GameViewCamera._CameraDisabled -= OnCameraComponentDisabled; if (m_gameView == this) { for (int i = 0; i < m_gameCameras.Count; ++i) { GameViewCamera gameCamera = m_gameCameras[i]; if (gameCamera != null) { gameCamera.Camera.depth = gameCamera.Depth; gameCamera.Camera.rect = gameCamera.Rect; if (Editor == null || !Editor.IsOpened) { gameCamera.Camera.enabled = gameCamera.IsCameraEnabled; } } } m_gameView = null; if (m_renderTextureCameras != null) { for (int i = 0; i < m_renderTextureCameras.Count; ++i) { RenderTextureCamera renderTextureCamera = m_renderTextureCameras[i]; if (renderTextureCamera != null) { Destroy(renderTextureCamera); } } } } }
public void UpdateCamera() { if (cam == null) { cam = GetComponent <Camera>(); } if (mainCam == null) { mainCam = GetComponentInParent <Camera>(); } if (compositor == null) { compositor = FindObjectOfType <RenderTextureCompositor>(); } if (renderTextureCamera == null) { renderTextureCamera = FindObjectOfType <RenderTextureCamera>(); } if (cam == null || mainCam == null || compositor == null || renderTextureCamera == null) { return; } targetWidth = renderTextureCamera.GetCurrentTargetWidth(); if (targetWidth == 0) { targetWidth = 411; } if (rt == null || rt.width != targetWidth) { rt = new RenderTexture(targetWidth, targetWidth, 1, RenderTextureFormat.ARGB32); rt.filterMode = FilterMode.Point; rt.useMipMap = false; rt.wrapMode = TextureWrapMode.Clamp; } cam.targetTexture = rt; cam.orthographicSize = (targetWidth / 48f); compositor.SetUIRenderTexture(rt); }
protected override void OnEditorExist() { base.OnEditorExist(); if (RenderPipelineInfo.Type != RPType.URP) { return; } m_instance = Instantiate(m_prefab, transform, false); m_instance.name = m_prefab.name; IRTE rte = IOC.Resolve <IRTE>(); Canvas foregroundCanvas = IOC.Resolve <IRTEAppearance>().UIForegroundScaler.GetComponent <Canvas>(); Camera foregroundCamera = foregroundCanvas.worldCamera; if (foregroundCamera != null) { GameObject foregroundLayer = new GameObject("ForegroundLayer"); foregroundLayer.transform.SetParent(rte.Root, false); foregroundCanvas = foregroundLayer.AddComponent <Canvas>(); foregroundCanvas.renderMode = RenderMode.ScreenSpaceOverlay; foregroundCamera.gameObject.SetActive(false); foregroundCamera.backgroundColor = new Color(0, 0, 0, 0); m_foregroundOutput = new GameObject("Output"); m_foregroundOutput.transform.SetParent(foregroundCanvas.transform, false); m_foregroundOutput.AddComponent <RectTransform>().Stretch(); RenderTextureCamera renderTextureCamera = foregroundCamera.gameObject.AddComponent <RenderTextureCamera>(); renderTextureCamera.OutputRoot = foregroundCanvas.gameObject.GetComponent <RectTransform>(); renderTextureCamera.Output = m_foregroundOutput.AddComponent <RawImage>(); renderTextureCamera.OverlayMaterial = new Material(Shader.Find("Battlehub/URP/RTEditor/UIForeground")); foregroundCamera.gameObject.SetActive(true); foregroundCanvas.sortingOrder = -1; } }
protected override void AwakeOverride() { base.AwakeOverride(); RuntimeHandlesComponent.InitializeIfRequired(ref Appearance); if (Pivot == null) { Pivot = transform; } m_collidersGO = new GameObject(); m_collidersGO.transform.SetParent(transform, false); m_collidersGO.transform.position = GetGizmoPosition(); m_collidersGO.transform.rotation = Quaternion.identity; m_collidersGO.name = "Colliders"; m_colliderProj = m_collidersGO.AddComponent <BoxCollider>(); m_colliderUp = m_collidersGO.AddComponent <BoxCollider>(); m_colliderDown = m_collidersGO.AddComponent <BoxCollider>(); m_colliderLeft = m_collidersGO.AddComponent <BoxCollider>(); m_colliderRight = m_collidersGO.AddComponent <BoxCollider>(); m_colliderForward = m_collidersGO.AddComponent <BoxCollider>(); m_colliderBackward = m_collidersGO.AddComponent <BoxCollider>(); m_colliders = new[] { m_colliderProj, m_colliderUp, m_colliderDown, m_colliderRight, m_colliderLeft, m_colliderForward, m_colliderBackward }; DisableColliders(); m_camera = GetComponent <Camera>(); m_renderTextureCamera = GetComponent <RenderTextureCamera>(); if (m_renderTextureCamera == null) { m_camera.clearFlags = CameraClearFlags.Depth; m_camera.renderingPath = RenderingPath.Forward; m_camera.allowMSAA = false; m_camera.allowHDR = false; if (BtnProjection != null) { m_canvas = BtnProjection.GetComponentInParent <Canvas>(); } } else { if (RenderPipelineInfo.Type != RPType.Standard) { m_camera.allowMSAA = false; m_camera.allowHDR = false; } m_camera.clearFlags = CameraClearFlags.SolidColor; m_camera.backgroundColor = new Color(0, 0, 0, 0); if (m_output != null) { Vector2 size = Size; m_output.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, size.x); m_output.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, size.y); m_canvasScaler = m_output.GetComponentInParent <CanvasScaler>(); m_canvas = m_output.GetComponentInParent <Canvas>(); } } m_camera.cullingMask = 0; m_camera.orthographic = Window.Camera.orthographic; m_screenHeight = Screen.height; m_screenWidth = Screen.width; UpdateLayout(); InitColliders(); UpdateAlpha(ref m_xAlpha, Vector3.right, 1); UpdateAlpha(ref m_yAlpha, Vector3.up, 1); UpdateAlpha(ref m_zAlpha, Vector3.forward, 1); if (Run.Instance == null) { GameObject runGO = new GameObject(); runGO.name = "Run"; runGO.AddComponent <Run>(); } if (BtnProjection != null) { BtnProjection.onClick.AddListener(OnBtnModeClick); SetTextColor(); } if (!GetComponent <SceneGizmoInput>()) { gameObject.AddComponent <SceneGizmoInput>(); } #if UNITY_2019_1_OR_NEWER RenderPipelineManager.endCameraRendering += OnEndCameraRendering; #endif }
protected override void Awake() { base.Awake(); if (!Application.isPlaying) { return; } if (m_textPanel == null) { m_textPanel = GetComponentInChildren <TimelineTextPanel>(true); } if (m_pointer == null) { m_pointer = GetComponentInChildren <TimelinePointer>(true); } m_scrollRect = GetComponentInChildren <ScrollRect>(true); m_scrollRect.scrollSensitivity = 0; m_scrollRect.onValueChanged.AddListener(OnInitScrollRectValueChanged); m_hScrollbarListener = m_scrollRect.horizontalScrollbar.GetComponentInChildren <DragAndDropListener>(true); m_vScrollbarListener = m_scrollRect.verticalScrollbar.GetComponentInChildren <DragAndDropListener>(true); m_hScrollbarListener.Drop += OnHorizontalScrollbarDrop; m_hScrollbarListener.EndDrag += OnHorizontalScrollbarDrop; m_vScrollbarListener.Drop += OnVerticalScrolbarDrop; m_vScrollbarListener.EndDrag += OnVerticalScrolbarDrop; if (FixedHeight > -1) { ScrollbarResizer[] resizers = m_scrollRect.verticalScrollbar.GetComponentsInChildren <ScrollbarResizer>(true); for (int i = 0; i < resizers.Length; ++i) { resizers[i].gameObject.SetActive(false); } } m_rtListener = m_scrollRect.gameObject.AddComponent <RectTransformChangeListener>(); m_rtListener.RectTransformChanged += OnRectTransformChanged; if (m_output == null) { m_output = m_scrollRect.content.GetComponentInChildren <RawImage>(true); } GameObject cameraGo = RenderCameraPrefab != null?Instantiate(RenderCameraPrefab) : new GameObject(); cameraGo.name = "TimelineGraphicsCamera"; cameraGo.SetActive(false); #if USE_RTE IRTE editor = IOC.Resolve <IRTE>(); cameraGo.transform.SetParent(editor.Root, false); #endif m_camera = cameraGo.GetComponent <Camera>(); if (m_camera == null) { m_camera = cameraGo.AddComponent <Camera>(); } m_camera.enabled = false; m_camera.orthographic = true; m_camera.orthographicSize = 0.5f; m_camera.clearFlags = CameraClearFlags.SolidColor; m_camera.backgroundColor = m_backgroundColor; m_camera.cullingMask = 0; m_rtCamera = cameraGo.AddComponent <RenderTextureCamera>(); m_rtCamera.Fullscreen = false; m_rtCamera.Output = m_output; cameraGo.SetActive(true); m_rtCamera.enabled = false; if (m_timelineGridParams == null) { CreateDefaultTimelineGridParams(); m_timelineGridParams.HorLines = 1; m_timelineGridParams.HorLinesSecondary = 2; } m_timelineGrid = m_output.GetComponent <TimelineGrid>(); if (m_timelineGrid == null) { m_timelineGrid = m_output.gameObject.AddComponent <TimelineGrid>(); } m_timelineGrid.Init(m_camera); m_dopesheet = m_output.gameObject.GetComponent <Dopesheet>(); if (m_dopesheet == null) { m_dopesheet = m_output.gameObject.AddComponent <Dopesheet>(); } m_dopesheet.Init(m_camera); SetTimelineGridParameters(); Clip = new Dopesheet.DsAnimationClip(); m_pointer.SampleChanged += OnTimelineSampleChanged; m_pointer.PointerDown += OnTimlineClick; m_pointer.BeginDrag += OnTimelineBeginDrag; m_pointer.Drag += OnTimelineDrag; m_pointer.Drop += OnTimelineDrop; if (m_boxSelection == null) { m_boxSelection = GetComponentInChildren <TimelineBoxSelection>(); } if (m_boxSelection != null) { m_boxSelection.BeginSelection += OnBeginBoxSelection; m_boxSelection.Selection += OnBoxSelection; } RenderGraphics(); }