private void OnBeginFrameRendering(ScriptableRenderContext arg1, Camera[] arg2)
 {
     RenderPipelineManager.beginFrameRendering -= OnBeginFrameRendering;
     if (m_window.RenderTextureUsage == RenderTextureUsage.Off || m_window.RenderTextureUsage == RenderTextureUsage.UsePipelineSettings && !RenderPipelineInfo.UseRenderTextures)
     {
         //Stack camera
         IRenderPipelineCameraUtility cameraUtility = IOC.Resolve <IRenderPipelineCameraUtility>();
         if (cameraUtility != null)
         {
             cameraUtility.Stack(Window.Camera, m_camera);
         }
     }
 }
예제 #2
0
        protected override void Awake()
        {
            base.Awake();

            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_rteGizmoCamera       = m_camera.gameObject.AddComponent <RTECamera>();
            m_rteGizmoCamera.Event = CameraEvent.BeforeImageEffects;
            m_rteGizmoCamera.CommandBufferRefresh += OnCommandBufferRefresh;

            m_propertyBlocks = new[] { new MaterialPropertyBlock(), new MaterialPropertyBlock(), new MaterialPropertyBlock() };

            m_cameraUtility = IOC.Resolve <IRenderPipelineCameraUtility>();
            if (m_cameraUtility != null)
            {
                m_cameraUtility.SetBackgroundColor(m_camera, new Color(0, 0, 0, 0));
                m_cameraUtility.EnablePostProcessing(m_camera, false);
                m_cameraUtility.PostProcessingEnabled += OnPostProcessingEnabled;
            }

            m_material = new Material(Shader.Find("Battlehub/RTHandles/RawImage"));

            m_output = new GameObject("SceneGizmoOutput");
            m_output.gameObject.SetActive(false);
            m_output.transform.SetParent(Window.Camera.transform, false);
            m_output.transform.localPosition = Vector3.forward * m_camera.nearClipPlane;
            m_output.AddComponent <MeshFilter>().sharedMesh       = Appearance.CreateRawImageMesh();
            m_output.AddComponent <MeshRenderer>().sharedMaterial = m_material;

            m_graphics = IOC.Resolve <IRTEGraphics>();

            m_camera.clearFlags      = CameraClearFlags.SolidColor;
            m_camera.backgroundColor = new Color(0, 0, 0, 0);
            m_camera.cullingMask     = 0;
            m_camera.orthographic    = Window.Camera.orthographic;
            m_camera.rect            = new Rect(0, 0, 1, 1);
            m_camera.stereoTargetEye = StereoTargetEyeMask.None;

            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>();
            }
        }
        private static Texture2D Render(
            Camera camera,
            Shader shader,
            Renderer[] renderers,
            int width  = -1,
            int height = -1)
        {
            bool autoSize = width < 0 || height < 0;

            int _width  = autoSize ? (int)camera.pixelRect.width : width;
            int _height = autoSize ? (int)camera.pixelRect.height : height;

            GameObject go        = new GameObject();
            Camera     renderCam = go.AddComponent <Camera>();

            renderCam.CopyFrom(camera);

            renderCam.renderingPath   = RenderingPath.Forward;
            renderCam.enabled         = false;
            renderCam.clearFlags      = CameraClearFlags.SolidColor;
            renderCam.backgroundColor = Color.white;
            renderCam.cullingMask     = 0;

            IRenderPipelineCameraUtility cameraUtility = IOC.Resolve <IRenderPipelineCameraUtility>();

            if (cameraUtility != null)
            {
                cameraUtility.EnablePostProcessing(renderCam, false);
                cameraUtility.SetBackgroundColor(renderCam, Color.white);
            }

            renderCam.allowHDR  = false;
            renderCam.allowMSAA = false;
            renderCam.forceIntoRenderTexture = true;

            float aspect = renderCam.aspect;

            renderCam.rect   = new Rect(Vector2.zero, Vector2.one);
            renderCam.aspect = aspect;

            RenderTextureDescriptor descriptor = new RenderTextureDescriptor()
            {
                width             = _width,
                height            = _height,
                colorFormat       = RenderTextureFormat,
                autoGenerateMips  = false,
                depthBufferBits   = 16,
                dimension         = TextureDimension.Tex2D,
                enableRandomWrite = false,
                memoryless        = RenderTextureMemoryless.None,
                sRGB        = true,
                useMipMap   = false,
                volumeDepth = 1,
                msaaSamples = 1
            };
            RenderTexture rt = RenderTexture.GetTemporary(descriptor);

            RenderTexture prev = RenderTexture.active;

            renderCam.targetTexture = rt;
            RenderTexture.active    = rt;

            Material replacementMaterial = new Material(shader);

            IRTEGraphics graphics  = IOC.Resolve <IRTEGraphics>();
            IRTECamera   rteCamera = graphics.CreateCamera(renderCam, CameraEvent.AfterForwardAlpha, false, true);

            rteCamera.RenderersCache.MaterialOverride = replacementMaterial;
            rteCamera.Camera.name = "BoxSelectionCamera";
            foreach (Renderer renderer in renderers)
            {
                Material[] materials = renderer.sharedMaterials;
                for (int i = 0; i < materials.Length; ++i)
                {
                    if (materials[i] != null)
                    {
                        rteCamera.RenderersCache.Add(renderer);
                    }
                }
            }
            rteCamera.RefreshCommandBuffer();

            if (RenderPipelineInfo.Type != RPType.Standard)
            {
                bool invertCulling = GL.invertCulling;
                GL.invertCulling            = true;
                renderCam.projectionMatrix *= Matrix4x4.Scale(new Vector3(1, -1, 1));
                renderCam.Render();
                GL.invertCulling = invertCulling;
            }
            else
            {
                renderCam.Render();
            }

            Texture2D img = new Texture2D(_width, _height, TextureFormat, false, false);

            img.ReadPixels(new Rect(0, 0, _width, _height), 0, 0);
            img.Apply();

            RenderTexture.active = prev;
            RenderTexture.ReleaseTemporary(rt);

            UnityObject.DestroyImmediate(go);
            UnityObject.Destroy(replacementMaterial);

            rteCamera.Destroy();
            //System.IO.File.WriteAllBytes("Assets/box_selection.png", img.EncodeToPNG());

            return(img);
        }
예제 #4
0
        private void Update()
        {
            if (m_terrainBrush != null && m_terrainBrush.IsPainting)
            {
                if (m_editor.Input.GetPointerUp(0))
                {
                    m_terrainBrush.EndPaint();
                }
            }

            if (m_editor.ActiveWindow == null || m_editor.ActiveWindow.WindowType != RuntimeWindowType.Scene || !m_editor.ActiveWindow.IsPointerOver)
            {
                if (m_decal.enabled)
                {
                    m_decal.enabled = false;
                }

                return;
            }

            Camera cam = m_editor.ActiveWindow.Camera;

            if (cam == null)
            {
                return;
            }

            if (!m_decal.enabled)
            {
                m_decal.enabled = true;
            }

            if (m_prevPos != m_editor.ActiveWindow.Pointer.ScreenPoint || m_prevCamPos != cam.transform.position || m_prevCamRot != cam.transform.rotation)
            {
                m_prevPos    = m_editor.ActiveWindow.Pointer.ScreenPoint;
                m_prevCamPos = cam.transform.position;
                m_prevCamRot = cam.transform.rotation;

                m_terrain = null;

                Ray          ray  = m_editor.ActiveWindow.Pointer;
                RaycastHit[] hits = Physics.RaycastAll(ray);
                foreach (RaycastHit hit in hits)
                {
                    if (!(hit.collider is TerrainCollider))
                    {
                        continue;
                    }

                    m_terrain  = hit.collider.GetComponent <Terrain>();
                    m_position = hit.point;
                    if (m_terrain != null)
                    {
                        break;
                    }
                }

                if (m_terrain == null)
                {
                    Vector3 position = m_editor.ActiveWindow.Camera.transform.position;
                    transform.position = new Vector3(position.x - 10000, position.y - 10000, position.z - 10000);
                    return;
                }

                m_position.y      += 200;
                transform.position = m_position;
            }

            if (m_terrain != null && !m_editor.Tools.IsViewing && m_terrainBrush != null)
            {
                if (m_editor.Input.GetPointerDown(0))
                {
                    IRenderPipelineCameraUtility cameraUtility = IOC.Resolve <IRenderPipelineCameraUtility>();
                    if (cameraUtility != null)
                    {
                        cameraUtility.RequiresDepthTexture(m_editor.ActiveWindow.Camera, true);
                    }

                    m_terrainBrush.Terrain = m_terrain;
                    m_terrainBrush.BeginPaint();
                }
                else if (m_editor.Input.GetPointer(0))
                {
                    m_terrainBrush.Terrain = m_terrain;
                    m_terrainBrush.Paint(m_terrain.transform.InverseTransformPoint(m_position), (m_editor.Input.GetKey(KeyCode.LeftShift) ? -Time.deltaTime : Time.deltaTime) * 100.0f, Opacity / 100.0f);
                }
            }
        }
예제 #5
0
        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>();
            }

            IRenderPipelineCameraUtility cameraUtility = IOC.Resolve <IRenderPipelineCameraUtility>();
            if (cameraUtility != null)
            {
                cameraUtility.EnablePostProcessing(m_camera, false);
                cameraUtility.SetBackgroundColor(m_camera, m_backgroundColor);
            }

            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;
            }
        }