public void Render()
        {
            var now       = DateTime.Now;
            var timeDiff  = now - _lastRenderTime;
            var deltaTime = (float)timeDiff.TotalMilliseconds / 1000;

            var rect = GUILayoutUtility.GetRect(Width, Height);

            if (Event.current.type != EventType.Repaint)
            {
                return;
            }
            _cachedRect = rect;

            PreviewRenderUtility.BeginPreview(_cachedRect, _backgroundStyle);
            var cam = PreviewRenderUtility.camera;

            if (RenderTarget != null)
            {
                if (RotateSpeed != 0 && AutoRotate)
                {
                    Rotation += deltaTime * RotateSpeed;
                }


                var rot = _renderTarget.transform.localEulerAngles;
                rot.y = Rotation * Mathf.Rad2Deg;
                _renderTarget.transform.localEulerAngles = rot;

                if (EditorWindow.focusedWindow != null)
                {
                    EditorWindow.focusedWindow.Repaint();
                }
            }

            cam.transform.localPosition = new Vector3(
                0,
                Mathf.Sin(_cameraAngle) * _cameraDistance,
                Mathf.Cos(_cameraAngle) * _cameraDistance
                );

            if (CameraLookAt)
            {
                cam.transform.LookAt(Vector3.zero);
            }

            cam.Render();
            PreviewRenderUtility.EndAndDrawPreview(rect);
            _lastRenderTime = now;
            Rendered?.Invoke(this);
        }
Example #2
0
    public override void OnPreviewGUI(Rect r, GUIStyle background)
    {
        this.Init();

        previewDir = PreviewGUI.Drag2D(previewDir, r);
        if (Event.current.type != EventType.Repaint)
        {
            return;
        }

        m_PreviewUtility.BeginPreview(r, background);
        DoRenderPreview();
        m_PreviewUtility.EndAndDrawPreview(r);
    }
        public void Draw(Rect rect, Action <PreviewRenderUtility> draw)
        {
            if (_renderer == null)
            {
                InitRenderer();
            }

            _renderer.BeginPreview(rect, GUIStyle.none);

            draw?.Invoke(_renderer);

            _renderer.camera.Render();
            _renderer.EndAndDrawPreview(rect);
        }
    public override void OnMaterialInteractivePreviewGUI(MaterialEditor materialEditor, Rect r, GUIStyle background)
    {
        if (Event.current.type == EventType.DragExited)
        {
            if (DragAndDrop.objectReferences.Length > 0)
            {
                GameObject dropped = DragAndDrop.objectReferences[0] as GameObject;
                if (dropped != null)
                {
                    m_targetMesh = AssetDatabase.LoadAssetAtPath <Mesh>(AssetDatabase.GetAssetPath(dropped));
                    EditorPrefs.SetString(PreviewModelPref, AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(m_targetMesh)));
                }
            }
        }

        if (m_targetMesh == null)
        {
            base.OnMaterialInteractivePreviewGUI(materialEditor, r, background);
            return;
        }

        Material mat = materialEditor.target as Material;

        if (m_previewRenderUtility == null)
        {
            m_previewRenderUtility = new PreviewRenderUtility();
            m_previewRenderUtility.cameraFieldOfView = 30f;
        }

        if (m_previewGUIType == null)
        {
            m_previewGUIType = Type.GetType("PreviewGUI, UnityEditor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null");
            m_dragMethod     = m_previewGUIType.GetMethod("Drag2D", BindingFlags.Static | BindingFlags.Public);
        }

        if (m_modelInspectorType == null)
        {
            m_modelInspectorType = Type.GetType("UnityEditor.ModelInspector, UnityEditor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null");
            m_renderMeshMethod   = m_modelInspectorType.GetMethod("RenderMeshPreview", BindingFlags.Static | BindingFlags.NonPublic);
        }

        m_previewDir = (Vector2)m_dragMethod.Invoke(m_previewGUIType, new object[] { m_previewDir, r });

        if (Event.current.type == EventType.Repaint)
        {
            m_previewRenderUtility.BeginPreview(r, background);
            m_renderMeshMethod.Invoke(m_modelInspectorType, new object[] { m_targetMesh, m_previewRenderUtility, mat, null, m_previewDir, -1 });
            m_previewRenderUtility.EndAndDrawPreview(r);
        }
    }
Example #5
0
        public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            m_previewRenderUtility.BeginPreview(r, background);
            var target = m_target.Head.Transform;

            if (target != null)
            {
                SetPreviewCamera(m_previewRenderUtility.m_Camera,
                                 target.position + new Vector3(0, 0.1f, 0),
                                 target.forward
                                 );
            }
            m_previewRenderUtility.EndAndDrawPreview(r);
        }
    public override void OnMaterialInteractivePreviewGUI(MaterialEditor materialEditor, Rect r, GUIStyle background)
    {
        UnityEngine.Object[] targetMats = materialEditor.targets;

        //verify that there is at least one material in this list.
        if (targetMats == null || targetMats.Length < 1)
        {
            return;
        }

        Material firstMat = (Material)targetMats[0];

        if (m_previewMesh == null)
        {
            m_previewMesh = AssetDatabase.LoadAssetAtPath <Mesh>(kPreviewSpherePath);
        }

        m_scroll = HandleInput(m_scroll, r);

        m_previewUtility.BeginPreview(r, background);
        DREditorUtility.DrawPreview(m_previewUtility, firstMat, m_previewMesh, DREditorUtility.PreviewType.kInteractive, m_scroll, ref m_rot);
        m_previewUtility.EndAndDrawPreview(r);
    }
    private void DrawMeshPreview(Rect r, GUIStyle background)
    {
        if (targetMesh == null)
        {
            EditorGUI.DropShadowLabel(r, "Mesh Required");
        }
        else
        {
            // applying camera movement
            meshPreviewUtility.m_Camera.transform.RotateAround(Vector3.zero, Vector3.up, drag.x);
            meshPreviewUtility.m_Camera.transform.RotateAround(Vector3.zero, meshPreviewUtility.m_Camera.transform.right, drag.y);
            meshPreviewUtility.m_Camera.transform.position +=
                meshPreviewUtility.m_Camera.transform.forward * -zoom * meshMaxSize * ZOOM_SPEED +
                meshPreviewUtility.m_Camera.transform.right * -pan.x * meshMaxSize * PAN_SPEED +
                meshPreviewUtility.m_Camera.transform.up * -pan.y * meshMaxSize * PAN_SPEED;

            meshPreviewUtility.BeginPreview(r, background);

            // setting up the lights
            meshPreviewUtility.m_Light[0].intensity          = 1.4f;
            meshPreviewUtility.m_Light[0].transform.rotation = Quaternion.Euler(60f, 0f, 60f);
            meshPreviewUtility.m_Light[0].type    = LightType.Directional;
            meshPreviewUtility.m_Light[0].shadows = LightShadows.Hard;
            InternalEditorUtility.SetCustomLighting(meshPreviewUtility.m_Light, new Color(0.1f, 0.1f, 0.1f, 0f));

            // drawing the inspected mesh
            for (int i = 0; i < targetMesh.subMeshCount; i++)
            {
                Material mat;
                if (targetMeshRenderer.sharedMaterials.Length <= i)
                {
                    mat = defaultMaterial;
                }
                else
                {
                    mat = targetMeshRenderer.sharedMaterials[i];
                    if (mat == null)
                    {
                        mat = defaultMaterial;
                    }
                }

                meshPreviewUtility.DrawMesh(targetMesh, Matrix4x4.identity, mat, i);
            }

            meshPreviewUtility.m_Camera.Render();
            InternalEditorUtility.RemoveCustomLighting();
            meshPreviewUtility.EndAndDrawPreview(r);
        }
    }
    public override void OnPreviewGUI(Rect r, GUIStyle background)
    {
        previewRenderUtility.BeginPreview(r, background);

        var previewCamera = previewRenderUtility.m_Camera;

        previewCamera.transform.position =
            previewObject.transform.position + new Vector3(0, 2.5f, -5);

        previewCamera.transform.LookAt(previewObject.transform);

        previewCamera.Render();

        previewRenderUtility.EndAndDrawPreview(r);
    }
        public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            if (!ShaderUtil.hardwareSupportsRectRenderTexture || !SystemInfo.supports3DTextures)
            {
                if (Event.current.type == EventType.Repaint)
                {
                    EditorGUI.DropShadowLabel(new Rect(r.x, r.y, r.width, 40), "3D texture preview not supported");
                }
                return;
            }

            m_PreviewDir = Drag2D(m_PreviewDir, r);

            Event e = Event.current;

            if (e.type == EventType.ScrollWheel)
            {
                zoom = Mathf.Clamp(zoom + e.delta.y * 0.1f, 0.05f, 5f);
                m_PreviewUtility.camera.nearClipPlane = Mathf.Lerp(0.05f, 2, Mathf.InverseLerp(0.05f, 3f, zoom));
                e.Use();
                Repaint();
            }

            if (e.type != EventType.Repaint)
            {
                return;
            }

            InitPreview();
            material.mainTexture = target as Texture;

            m_PreviewUtility.BeginPreview(r, background);
            bool oldFog = RenderSettings.fog;

            Unsupported.SetRenderSettingsUseFogNoDirty(false);

            m_PreviewUtility.camera.transform.position = -Vector3.forward * zoom;

            m_PreviewUtility.camera.transform.rotation = Quaternion.identity;
            Quaternion rot = Quaternion.Euler(m_PreviewDir.y, 0, 0) * Quaternion.Euler(0, m_PreviewDir.x, 0);

            m_PreviewUtility.DrawMesh(mesh, Vector3.zero, rot, material, 0);
            m_PreviewUtility.Render();

            Unsupported.SetRenderSettingsUseFogNoDirty(oldFog);
            m_PreviewUtility.EndAndDrawPreview(r);
            Repaint();
        }
Example #10
0
        public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            if (bPrefab || previewRenderUtility == null)
            {
                return;
            }

            if (!(r.width > 0 && r.height > 0))
            {
                return;
            }

            previewRenderUtility.BeginPreview(r, background);
            var drag = Vector2.zero;

            //드래그 할 때의 마우스 이동량을 얻어옵니다
            if (Event.current.type == EventType.MouseDrag &&
                r.Contains(Event.current.mousePosition))
            {
                drag = Event.current.delta;
            }
            var previewCamera = PreviewCam;

            if (drag != Vector2.zero)
            {
                drag *= 0.02f;
                previewCamera.transform.Translate(-drag.x, drag.y, 0f);
            }

            if (IsEditorMode && previewObject != null)
            {
                previewObject.gameObject.SetActive(true);
                previewCamera.Render();
                previewObject.gameObject.SetActive(false);
            }
            else
            {
                previewCamera.Render();
            }

            previewRenderUtility.EndAndDrawPreview(r);

            if (drag != Vector2.zero)
            {
                Repaint();
            }
        }
Example #11
0
 virtual public void Draw(Rect rect)
 {
     if (!m_Inited)
     {
         return;
     }
     //更新控制操作
     UF_OnUpdateControl(rect);
     m_Preview.BeginPreview(rect, GUIStyle.none);
     //更新摄像机位置
     UF_OnUpdateCamera();
     //绘制地板
     OnDrawFloor();
     //绘制模型
     OnDrawModel();
     m_Preview.EndAndDrawPreview(rect);
 }
Example #12
0
    //previewの描画
    public override void OnInteractivePreviewGUI(Rect r, GUIStyle background)
    {
        if (previewRenderUtility == null)
        {
            previewSetup();
        }
        previewRenderUtility.BeginPreview(r, background);
        previewObject.SetActive(true);

        previewRenderUtility.camera.Render();

        previewObject.SetActive(false);

        previewRenderUtility.EndAndDrawPreview(r);

        //Debug.Log(previewObject);
    }
Example #13
0
 public override void OnPreviewGUI(Rect r, GUIStyle background)
 {
     if (EditorApplication.isPlaying || EditorApplication.isPlayingOrWillChangePlaymode)
     {
         return;
     }
     InitPreview();
     if (m_PreviewUtility == null || _previewUnityArmatureComp == null || Event.current.type != EventType.Repaint)
     {
         return;
     }
     SetEnabledRecursive(_previewUnityArmatureComp.gameObject, true);
     m_PreviewUtility.BeginPreview(r, background);
     PreviewUtilityCamera.Render();
     m_PreviewUtility.EndAndDrawPreview(r);
     SetEnabledRecursive(_previewUnityArmatureComp.gameObject, false);
 }
Example #14
0
        public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }

            Mesh mesh = GetMesh();

            if (mesh == null)
            {
                return;
            }

            m_PreviewUtility.BeginPreview(r, background);
            Graphics.DrawMeshNow(mesh, r.size, Quaternion.identity);
            m_PreviewUtility.EndAndDrawPreview(r);
        }
Example #15
0
        public void Render(Rect rect)
        {
            preview.BeginPreview(rect, GUIStyle.none);

            foreach (var obj in renderObjects)
            {
                obj.SetActive(true);
            }

            cam.Render();

            foreach (var obj in renderObjects)
            {
                obj.SetActive(false);
            }

            preview.EndAndDrawPreview(rect);
        }
Example #16
0
 public override void OnPreviewGUI(Rect r, GUIStyle background)
 {
     if (Event.current.type == EventType.Repaint)
     {
         if (isTargetValidForPreview)
         {
             _previewUtils.BeginPreview(r, background);
             {
                 _matPropBlock.SetTexture(
                     "_MainTex",
                     targetAtlas ? targetAtlas : Texture2D.whiteTexture);
                 if (targetAtlasA)
                 {
                     _matPropBlock.SetTexture("_AlphaTex", targetAtlasA);
                     _matPropBlock.SetFloat("_ExternalAlpha", 1.0f);
                 }
                 else
                 {
                     _matPropBlock.SetTexture("_AlphaTex", Texture2D.whiteTexture);
                     _matPropBlock.SetFloat("_ExternalAlpha", 0.0f);
                 }
                 var camera = GetCameraFromPreviewUtils(_previewUtils);
                 if (camera)
                 {
                     ConfigureCameraForSequence(camera, targetSequence);
                     var frame = targetFrame;
                     for (var i = 0; i < frame.Materials.Length; ++i)
                     {
                         _previewUtils.DrawMesh(
                             frame.CachedMesh,
                             Matrix4x4.identity,
                             frame.Materials[i],
                             i,
                             _matPropBlock);
                     }
                     camera.Render();
                 }
             }
             _previewUtils.EndAndDrawPreview(r);
         }
     }
 }
Example #17
0
        public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            BulletStormEditorUtil.ReceiveInput(r, ref cameraDistance, ref viewPos);
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }

            previewRenderUtility.BeginPreview(r, background);

            // move camera
            var transform = previewRenderUtility.camera.transform;

            transform.rotation = Quaternion.Euler(-viewPos.y, -viewPos.x, 0);
            transform.position = transform.forward * -cameraDistance;

            BulletStormEditorUtil.DrawShapePreview(shapeContainer.GetShape(), previewRenderUtility.camera,
                                                   labelContent);

            previewRenderUtility.EndAndDrawPreview(r);
        }
Example #18
0
        public void Draw(Rect r, GUIStyle background, int tileIndex)
        {
            previewRenderUtility.BeginPreview(r, background);

            DrawPrefab(brush.tiles[tileIndex].prefabs[0].prefab, Vector3.zero, brush.tiles[tileIndex].rotation);

            for (int i = 0; i < brush.tiles[tileIndex].rule.Length; i++)
            {
                int gridIndex = i > 3 ? i + 1 : i;
                int x         = gridIndex % 3;
                int y         = gridIndex / 3;

                Matrix4x4 trs  = Matrix4x4.TRS(new Vector3((x - 1) * brush.size, 0, (y - 1) * brush.size), Quaternion.identity, Vector3.one * brush.size);
                Mesh      mesh = null;

                switch (brush.tiles[tileIndex].rule[i])
                {
                case Brush.NeighborState.Empty:
                    mesh = emptyMesh;
                    break;

                case Brush.NeighborState.Filled:
                    mesh = fillMesh;
                    break;

                case Brush.NeighborState.Undefined:
                    mesh = undefMesh;
                    break;
                }

                previewRenderUtility.DrawMesh(mesh, trs, mat, 0);
            }

            previewRenderUtility.camera.transform.position = Vector3.zero;
            previewRenderUtility.camera.transform.rotation = Quaternion.Euler(new Vector3(-drag.y, -drag.x, 0));
            previewRenderUtility.camera.transform.position = previewRenderUtility.camera.transform.forward * -cameraDistance;
            previewRenderUtility.camera.Render();

            previewRenderUtility.EndAndDrawPreview(r);
        }
Example #19
0
        public override void OnInteractivePreviewGUI(Rect r, GUIStyle background)
        {
            var drag = Vector2.zero;

            //Get drag value
            if (Event.current.type == EventType.MouseDrag)
            {
                drag = Event.current.delta;
            }

            previewRenderUtility.BeginPreview(r, background);

            //Set each mesh to be rendered in the preview window
            if (myTarget.meshList != null)
            {
                foreach (MeshDistortData data in myTarget.meshList)
                {
                    if (data.meshTransform == null)
                    {
                        continue;
                    }
                    Matrix4x4 matrix = Matrix4x4.TRS(data.meshTransform.position - myTarget.transform.position, data.meshTransform.rotation, data.meshTransform.lossyScale);
                    previewRenderUtility.DrawMesh(data.mesh, matrix, data.originalMaterial, 0);
                }
            }
            var previewCamera = previewRenderUtility.camera;

            //Rotate camera by the drag
            previewCamera.transform.RotateAround(Vector3.zero, Vector3.up, -drag.x);
            previewCamera.transform.RotateAround(Vector3.zero, Vector3.right, -drag.y);

            previewCamera.Render();

            previewRenderUtility.EndAndDrawPreview(r);

            if (drag != Vector2.zero)
            {
                Repaint();
            }
        }
Example #20
0
        public override void OnPreviewGUI(Rect previewRectangle, GUIStyle previewBackground)
        {
            if (previewRenderUtility == null)
            {
                CreatePreview();
            }

            if (Event.current.type != EventType.Repaint)
            {
                return;
            }

            previewRenderUtility.BeginPreview(previewRectangle, previewBackground);
            previewRenderUtility.camera.orthographicSize = 2;

            if (previewRectangle.height > previewRectangle.width)
            {
                previewRenderUtility.camera.orthographicSize *= previewRectangle.height / previewRectangle.width;
            }

            previewRenderUtility.camera.Render();
            previewRenderUtility.EndAndDrawPreview(previewRectangle);
        }
Example #21
0
        private void DrawRenderPreview(Rect previewRect)
        {
            Quaternion rotation = Quaternion.Euler(previewRotationX, previewRotationY, 0);
            Matrix4x4  matrix   = Matrix4x4.identity;

            matrix.SetTRS(Vector3.zero, rotation, Vector3.one);
            Vector3 position = -matrix.MultiplyPoint(previewMesh.bounds.center);

            float dist = previewMesh.bounds.extents.magnitude * 2;

            preview.camera.transform.position = new Vector3(0, 0, -dist);
            preview.camera.transform.LookAt(Vector3.zero);
            preview.camera.clearFlags      = CameraClearFlags.Color;
            preview.camera.backgroundColor = Color.gray;
            preview.camera.fieldOfView     = 60;
            preview.camera.nearClipPlane   = .3f;
            preview.camera.farClipPlane    = 10000f;

            preview.BeginPreview(previewRect, GUIStyle.none);
            preview.DrawMesh(previewMesh, position, rotation, previewMaterial, 0);
            preview.Render();
            preview.EndAndDrawPreview(previewRect);
        }
        public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            if (m_ReflectiveMaterial != null)
            {
                m_ReflectiveMaterial.SetFloat("_Exposure", previewExposure);
                m_ReflectiveMaterial.SetFloat("_MipLevel", mipLevelPreview);
            }

            if (m_PreviewUtility == null)
                InitPreview();

            UpdateCamera();

            m_PreviewUtility.BeginPreview(r, GUIStyle.none);
            m_PreviewUtility.DrawMesh(sphereMesh, Matrix4x4.identity, m_ReflectiveMaterial, 0);
            m_PreviewUtility.camera.Render();
            m_PreviewUtility.EndAndDrawPreview(r);

            if (Event.current.type != EventType.Repaint)
            {
                if (HandleMouse(r))
                    Repaint();
            }
        }
        public void DrawMeshGUI(Rect previewRect)
        {
            if (previewRect == default(Rect))
            {
                previewRect = this.previewRect;
            }

            if (previewRect.width > 1)
            {
                this.previewRect = previewRect;
            }

            if (Event.current.rawType == EventType.MouseUp)
            {
                if (Event.current.button == 0)
                {
                    StopDragLMB();
                }
                else if (Event.current.button == 1)
                {
                    StopDragRMB();
                }
            }

            if (Event.current.type == EventType.MouseDown && MouseOverPreview())
            {
                if (Event.current.button == 0)
                {
                    StartDragLMB();
                }
                else if (Event.current.button == 1)
                {
                    StartDragRMB();
                }
            }

            if (isDraggingLMB)
            {
                UpdateDragLMB();
            }
            if (isDraggingRMB)
            {
                UpdateDragRMB();
            }


            if (mesh == null || InternalMaterial == null || Event.current.type != EventType.Repaint)
            {
                return;
            }

            if (previewStyle == null)
            {
                previewStyle = new GUIStyle(EditorStyles.textField);
            }
            previewStyle.normal.background = backgroundTexture;

            editor.Repaint();

            previewRenderUtility.BeginPreview(previewRect, GUIStyle.none);
            DrawMesh();
            previewRenderUtility.EndAndDrawPreview(previewRect);
        }
    public override void OnInteractivePreviewGUI(Rect r, GUIStyle background)
    {
        if (m_VisualEffectGO == null)
        {
            OnEnable();
        }

        bool isRepaint = (Event.current.type == EventType.Repaint);

        m_Angles = VFXPreviewGUI.Drag2D(m_Angles, r);
        Renderer renderer = m_VisualEffectGO.GetComponent <Renderer>();

        if (renderer == null)
        {
            return;
        }

        if (renderer.bounds.size != Vector3.zero)
        {
            m_CurrentBounds = renderer.bounds;

            //make sure that none of the bounds values are 0
            if (m_CurrentBounds.size.x == 0)
            {
                Vector3 size = m_CurrentBounds.size;
                size.x = (m_CurrentBounds.size.y + m_CurrentBounds.size.z) * 0.1f;
                m_CurrentBounds.size = size;
            }
            if (m_CurrentBounds.size.y == 0)
            {
                Vector3 size = m_CurrentBounds.size;
                size.y = (m_CurrentBounds.size.x + m_CurrentBounds.size.z) * 0.1f;
                m_CurrentBounds.size = size;
            }
            if (m_CurrentBounds.size.z == 0)
            {
                Vector3 size = m_CurrentBounds.size;
                size.z = (m_CurrentBounds.size.x + m_CurrentBounds.size.y) * 0.1f;
                m_CurrentBounds.size = size;
            }
        }

        if (m_FrameCount == kSafeFrame) // wait to frame before asking the renderer bounds as it is a computed value.
        {
            float maxBounds = Mathf.Sqrt(m_CurrentBounds.size.x * m_CurrentBounds.size.x + m_CurrentBounds.size.y * m_CurrentBounds.size.y + m_CurrentBounds.size.z * m_CurrentBounds.size.z);
            m_Distance = Mathf.Max(0.01f, maxBounds * 1.25f);
            ComputeFarNear();
        }
        else
        {
            ComputeFarNear();
        }
        m_FrameCount++;
        if (Event.current.isScrollWheel)
        {
            m_Distance *= 1 + (Event.current.delta.y * .015f);
        }

        if (m_Mat == null)
        {
            m_Mat = (Material)EditorGUIUtility.LoadRequired("SceneView/HandleLines.mat");
        }

        if (isRepaint)
        {
            m_PreviewUtility.BeginPreview(r, background);

            Quaternion rot = Quaternion.Euler(0, m_Angles.x, 0) * Quaternion.Euler(m_Angles.y, 0, 0);
            m_PreviewUtility.camera.transform.position      = m_CurrentBounds.center + rot * new Vector3(0, 0, -m_Distance);
            m_PreviewUtility.camera.transform.localRotation = rot;
            m_PreviewUtility.DrawMesh(s_CubeWireFrame, Matrix4x4.TRS(m_CurrentBounds.center, Quaternion.identity, m_CurrentBounds.size), m_Mat, 0);
            m_PreviewUtility.Render(true);
            m_PreviewUtility.EndAndDrawPreview(r);

            // Ask for repaint so the effect is animated.
            Repaint();
        }
    }
Example #25
0
    // Process the object uv in lightmap to preview.
    private void ProcessPreviewObjectUVInLightmap()
    {
        if (Selection.transforms.Length <= 0)
        {
            return;
        }

        MeshFilter cMf = Selection.transforms[0].gameObject.GetComponent <MeshFilter>();

        if (null == cMf)
        {
            return;
        }

        Mesh cMesh = cMf.sharedMesh;

        if (null == cMesh)
        {
            return;
        }

        Renderer cRenderer = cMf.gameObject.GetComponent <Renderer>();

        if ((null == cRenderer) || (-1 == cRenderer.lightmapIndex) || (cRenderer.lightmapIndex >= LightmapSettings.lightmaps.Length))
        {
            return;
        }

        // Get preview size.
        m_fPreviewSize = (float)m_miPrResizeHandle.Invoke(m_cPreviewResizerInstance, new object[] { position, 100, 250, 17 });
        //Rect rcPreviewRect = new Rect(0.0f, position.height - m_fPreviewSize, position.width, m_fPreviewSize);

        if (m_fPreviewSize <= 0.0f)
        {
            return;
        }

        if (LightmapSettings.lightmaps.Length <= 0)
        {
            return;
        }

        // Get lightmap max size.
        float     fLightmapSize = Mathf.Max(position.width - LIGHTMAP_LEFT_MARGIN - LIGHTMAP_RIGHT_MARGIN, MAX_LIGHTMAP_SIZE);
        Texture2D cLightmap     = LightmapSettings.lightmaps[0].lightmapColor;

        GUILayoutOption[] aLdAreaOptions = new GUILayoutOption[] { GUILayout.MaxWidth(fLightmapSize), GUILayout.MaxHeight(fLightmapSize) };

        // Draw object uv area in lightmap.
        m_vScrollLightmap = EditorGUILayout.BeginScrollView(m_vScrollLightmap, GUILayout.Height(m_fPreviewSize));
        {
            // Draw label uv info.
            Vector4 vObjectLmArea = cRenderer.lightmapScaleOffset;
            EditorGUILayout.LabelField(string.Format("Object: {0}; Tiling XY: ({1}, {2}); Offset XY: ({3}, {4}).", cMf.gameObject.name, vObjectLmArea.x, vObjectLmArea.y, vObjectLmArea.z, vObjectLmArea.w));
            Rect rcLabel = GUILayoutUtility.GetLastRect();
            EditorGUILayout.Space();
            rcLabel.yMax += GUILayoutUtility.GetLastRect().height;

            // Calculate object uv area size in lightmap.
            Rect rcLightmapDraw = GUILayoutUtility.GetAspectRect((float)cLightmap.width / (float)cLightmap.height, aLdAreaOptions);
            rcLightmapDraw.x += LIGHTMAP_LEFT_MARGIN;
            Rect rcDrawPreview = new Rect(rcLightmapDraw.x, rcLabel.height, rcLightmapDraw.width, rcLightmapDraw.height);

            // Perform preview render.
            m_cPreviewUtility.BeginPreview(rcDrawPreview, Styles.background);
            DoRenderObjectInLightmapPreview(cMesh, cRenderer);
            m_cPreviewUtility.EndAndDrawPreview(rcDrawPreview);
        }

        EditorGUILayout.Space();
        EditorGUILayout.EndScrollView();
    }
    public void OnGUI()
    {
        Event guiEvent = Event.current;

        Rect toolRect = EditorGUILayout.BeginVertical();

        EditorGUILayout.Space();
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.Space();
        UpdateToolbar(guiEvent);
        // FIXME - I get jitter in the toolbar when the window resizes even if I give it a constant
        // rectangle here, so just do this as the simplest version.
        selectedTool = GUILayout.Toolbar(selectedTool, toolbar);
        GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.Space();
        EditorGUILayout.EndVertical();

        Rect viewRect = new Rect(0, toolRect.yMax, this.position.width, this.position.height - toolRect.yMax);

        activeViewTool = ViewTool.None;
        if (guiEvent.isScrollWheel)
        {
            activeViewTool = ViewTool.Zoom;
        }
        if (guiEvent.alt)
        {
            if (guiEvent.control)
            {
                activeViewTool = ViewTool.Zoom;
            }
            else
            {
                activeViewTool = ViewTool.Pan;
            }
        }

        MouseCursor activeCursor = MouseCursor.Arrow;

        switch (activeViewTool)
        {
        case ViewTool.Zoom:
            activeCursor = MouseCursor.Zoom;
            break;

        case ViewTool.Pan:
            activeCursor = MouseCursor.Pan;
            break;
        }
        EditorGUIUtility.AddCursorRect(viewRect, activeCursor);

        bool handled = false;

        if (guiEvent.type == EventType.Repaint)
        {
            //GUILayout.BeginArea(toolbarRect);
            //selectedTool = GUILayout.Toolbar(selectedTool, toolbar);
            //GUILayout.BeginHorizontal();
            //GUILayout.Toolbar(0, images, EditorStyles.toolbarButton);
            //GUILayout.EndHorizontal();
            //GUILayout.EndArea();

            renderUtil.BeginPreview(viewRect, GUIStyle.none);
            // renderUtil.camera.backgroundColor is reset in BeginPreview()
            renderUtil.camera.backgroundColor = backgroundColor;

            foreach (VectorShape shape in shapes)
            {
                renderUtil.DrawMesh(shape.ShapeMesh, Matrix4x4.identity, renderMaterial, 0);
            }
            renderUtil.Render();

            Handles.SetCamera(renderUtil.camera);
            VectorShape.handleDrawSize = HandleUtility.GetHandleSize(Vector3.zero) * viewRect.height / viewRect.width;

            foreach (VectorShape selected in selection)
            {
                selected.DrawEditorHandles(true);
            }

            renderUtil.EndAndDrawPreview(viewRect);
        }
        else if (guiEvent.isScrollWheel && (EditorWindow.mouseOverWindow == this))
        {
            float zoomFactor = HandleUtility.niceMouseDeltaZoom;
            renderUtil.camera.orthographicSize *= (1 - zoomFactor * .02f);

            handled = true;
        }
        else if (guiEvent.isMouse)
        {
            Camera camera    = renderUtil.camera;
            float  viewScale = camera.orthographicSize * 2f / viewRect.height;

            if (activeViewTool == ViewTool.Pan)
            {
                camera.transform.position += (Vector3)(guiEvent.delta * new Vector2(-viewScale, viewScale));

                handled = true;
            }
            else if (activeViewTool == ViewTool.Zoom)
            {
                float zoomFactor = HandleUtility.niceMouseDeltaZoom;
                renderUtil.camera.orthographicSize *= (1 + zoomFactor * .005f);

                handled = true;
            }

            if (!handled)
            {
                // Convert the event to shape space for convenience
                Vector2 mousePosition = guiEvent.mousePosition;
                Vector2 delta         = guiEvent.delta;
                Vector2 cameraPos     = camera.transform.position;
                Vector2 viewPos       = mousePosition - viewRect.center;

                guiEvent.mousePosition = new Vector2(
                    viewPos.x * viewScale + cameraPos.x,
                    viewPos.y * -viewScale + cameraPos.y
                    );
                guiEvent.delta = guiEvent.delta * new Vector2(viewScale, -viewScale);

                foreach (VectorShape selected in selection)
                {
                    handled |= selected.HandleEditorEvent(guiEvent, true);
                }

                guiEvent.mousePosition = mousePosition;
                guiEvent.delta         = delta;
            }
        }
        else if (guiEvent.type == EventType.ValidateCommand)
        {
            switch (guiEvent.commandName)
            {
            case Cmd_Delete:
                if (selection.Count > 0)
                {
                    handled = true;
                }
                break;

            case Cmd_SelectAll:
                if (shapes.Count > 0)
                {
                    handled = true;
                }
                break;
            }
        }
        else if (guiEvent.type == EventType.ExecuteCommand)
        {
            switch (guiEvent.commandName)
            {
            case Cmd_Delete:
                foreach (VectorShape selected in selection)
                {
                    shapes.Remove(selected);
                }
                selection.Clear();
                handled = true;
                break;

            case Cmd_SelectAll:
                foreach (VectorShape selected in shapes)
                {
                    selection.Add(selected);
                }
                handled = true;
                break;

            case Cmd_ModifierKeysChanged:
                Repaint();
                handled = true;
                break;
            }
        }

        if (handled)
        {
            guiEvent.Use();
        }
    }
Example #27
0
    public void OnGUI()
    {
        Event guiEvent = Event.current;

        if (guiEvent.isScrollWheel)
        {
            overrideAction = ActionType.ViewZoom;
        }
        else if (guiEvent.type == EventType.MouseDown)
        {
            mouseDownPosition = guiEvent.mousePosition;
            mouseDownTime     = Time.time;
            mouseIsDown       = true;
        }
        else if (guiEvent.type == EventType.MouseUp)
        {
            mouseIsDown = false;
        }
        else if (guiEvent.type != EventType.Repaint)
        {
            overrideAction = ActionType.None;
            if (guiEvent.alt)
            {
                if (guiEvent.control)
                {
                    overrideAction = ActionType.ViewZoom;
                }
                else
                {
                    overrideAction = ActionType.ViewPan;
                }
            }
        }

        UpdateMouseToShape();
        Rect toolRect = new Rect(0, 0, this.position.width, toolAreaHeight);

        Rect toolbarRect = new Rect(toolbarPadding * 2, toolbarPadding, toolbarWidth * (toolIcons.Length + 1) + toolbarPadding, toolbarHeight);

        OnToolbarArea(guiEvent, toolbarRect);

        Rect separatorRect = new Rect(toolbarRect.xMax + toolbarPadding, 0, separatorWidth, toolRect.height);

        GUI.DrawTexture(separatorRect, separatorTexture);

        Rect infoRect = new Rect(separatorRect.xMax, 0, toolRect.width - separatorRect.xMax, toolRect.height);

        switch (activeTool)
        {
        case ToolSet.View:
            OnInfoAreaView(guiEvent, infoRect);
            baseAction = ActionType.ViewPan;
            break;

        case ToolSet.Select:
            OnInfoAreaSelect(guiEvent, infoRect);
            baseAction = ActionType.SelectNormal;
            break;

        case ToolSet.Brush:
            OnInfoAreaBrush(guiEvent, infoRect);
            baseAction = ActionType.LineEdit;
            break;

        case ToolSet.Shape:
            OnInfoAreaShape(guiEvent, infoRect);
            baseAction = ActionType.ShapeEdit;
            break;
        }

        Rect viewRect = new Rect(0, toolRect.yMax, this.position.width, this.position.height - toolRect.yMax);

        MouseCursor activeCursor = MouseCursor.Arrow;

        switch (action)
        {
        case ActionType.ViewPan:
            activeCursor = MouseCursor.Pan;
            break;

        case ActionType.ViewZoom:
            activeCursor = MouseCursor.Zoom;
            break;
        }
        EditorGUIUtility.AddCursorRect(viewRect, activeCursor);

        bool handled = false;

        if (guiEvent.type == EventType.Repaint)
        {
            renderUtil.BeginPreview(viewRect, GUIStyle.none);
            renderUtil.camera.backgroundColor = backgroundColor;

            foreach (VectorShape shape in shapes)
            {
                renderUtil.DrawMesh(shape.ShapeMesh, Matrix4x4.identity, renderMaterial, 0);
            }
            renderUtil.Render();

            Handles.SetCamera(renderUtil.camera);
            VectorShape.handleDrawSize = HandleUtility.GetHandleSize(Vector3.zero) * viewRect.height / viewRect.width;

            foreach (VectorShape selected in selection)
            {
                selected.DrawEditorHandles(true, (selected == focusedShape));
            }

            if (selectionRect != Rect.zero)
            {
                Color outlineColor = Handles.color;
                Color fillColor    = new Color(outlineColor.r, outlineColor.g, outlineColor.b, 0.2f);
                Handles.DrawSolidRectangleWithOutline(selectionRect, fillColor, outlineColor);
            }

            renderUtil.EndAndDrawPreview(viewRect);

            Vector2 originLoc = mouseToShapeMatrix.Inverse().MultiplyPoint(Vector2.zero);
            if (viewRect.Contains(originLoc))
            {
                GUIStyle originPivot = "U2D.pivotDot";
                if (originPivot != null)
                {
                    Rect pivotRect = new Rect(0f, 0f, originPivot.fixedWidth, originPivot.fixedHeight);
                    pivotRect.center = originLoc;
                    originPivot.Draw(pivotRect, false, false, false, false);
                }
            }

            if (showSnap)
            {
                Vector2 snapLoc = mouseToShapeMatrix.Inverse().MultiplyPoint(snapPosition);
                if (viewRect.Contains(snapLoc))
                {
                    GUIStyle snapPivot = "U2D.dragDot";
                    if (snapPivot != null)
                    {
                        Rect pivotRect = new Rect(0f, 0f, snapPivot.fixedWidth, snapPivot.fixedHeight);
                        pivotRect.center = snapLoc;
                        snapPivot.Draw(pivotRect, false, false, false, false);
                    }
                }
            }
        }
        else if (guiEvent.isScrollWheel && (EditorWindow.mouseOverWindow == this))
        {
            float zoomFactor       = HandleUtility.niceMouseDeltaZoom;
            float orthographicSize = renderUtil.camera.orthographicSize * (1 - zoomFactor * .02f);
            SetCameraSize(orthographicSize);

            handled = true;
        }
        else if (guiEvent.isMouse)
        {
            // Update mouse position
            mousePosition  = guiEvent.mousePosition;
            mouseInContent = (viewRect.Contains(mousePosition));

            switch (action)
            {
            case ActionType.ViewPan:
            case ActionType.ViewZoom:
                handled = OnViewToolMouse(guiEvent);
                break;

            case ActionType.SelectNormal:
            case ActionType.SelectAdditive:
            case ActionType.SelectSubtractive:
                handled = OnSelectToolMouse(guiEvent);
                break;

            case ActionType.LineEdit:
            case ActionType.CurveEdit:
                handled = OnBrushToolMouse(guiEvent);
                break;

            case ActionType.ShapeEdit:
                handled = OnShapeToolMouse(guiEvent);
                break;

            case ActionType.SetOrigin:
                handled = OnSetOriginMouse(guiEvent);
                break;
                //case ActionType.ChangeScale:
                //handled = OnChangeScaleMouse(guiEvent);
                //break;
            }

            if (!handled)
            {
                Vector2 delta = guiEvent.delta;
                guiEvent.mousePosition = MouseToShapePoint(mousePosition);
                guiEvent.delta         = guiEvent.delta * new Vector2(mouseToShapeScale, -mouseToShapeScale);

                foreach (VectorShape selected in selection)
                {
                    handled |= selected.HandleEditorEvent(guiEvent, true);
                }

                guiEvent.mousePosition = mousePosition;
                guiEvent.delta         = delta;
            }
        }
        else if (guiEvent.type == EventType.ValidateCommand)
        {
            switch (guiEvent.commandName)
            {
            case Cmd_Delete:
                if (selection.Count > 0)
                {
                    handled = true;
                }
                break;

            case Cmd_SelectAll:
                if (shapes.Count > 0)
                {
                    handled = true;
                }
                break;
            }
        }
        else if (guiEvent.type == EventType.ExecuteCommand)
        {
            switch (guiEvent.commandName)
            {
            case Cmd_Delete:
                foreach (VectorShape selected in selection)
                {
                    shapes.Remove(selected);
                }
                selection.Clear();
                handled = true;
                break;

            case Cmd_SelectAll:
                foreach (VectorShape selected in shapes)
                {
                    selection.Add(selected);
                }
                handled = true;
                break;

            case Cmd_ModifierKeysChanged:
                Repaint();
                handled = true;
                break;
            }
        }

        if (action == ActionType.ChangeScale)
        {
            handled = OnChangeScaleGUI(guiEvent);
        }

        if (handled)
        {
            guiEvent.Use();
        }
    }
Example #28
0
        void RendererPreview()
        {
            using (new EditorGUILayout.VerticalScope())
            {
                var rect = GUILayoutUtility.GetRect(512f, 512f);
                previewRender.BeginPreview(rect, GUIStyle.none);
                var previewCam = previewRender.camera;
                if (rect.Contains(Event.current.mousePosition))
                {
                    if (Event.current.type == EventType.MouseDrag && Event.current.button == 1)
                    {
                        ResetRange();
                        var drag = Event.current.delta;
                        if (drag != Vector2.zero)
                        {
                            previewCam.transform.RotateAround(centerPos, previewCam.transform.rotation * Vector3.up, drag.x);
                            previewCam.transform.RotateAround(centerPos, previewCam.transform.rotation * Vector3.right, drag.y);
                            Repaint();
                        }
                    }
                    else if (Event.current.type == EventType.MouseDrag && Event.current.button == 2)
                    {
                        ResetRange();
                        var drag = Event.current.delta;
                        if (drag != Vector2.zero)
                        {
                            drag.x *= -1f;
                            var limit    = Mathf.Max(new float[] { bounds.extents.x, bounds.extents.y, bounds.extents.z });
                            var deltaPos = previewCam.transform.rotation * drag * 0.002f;
                            deltaPos.x = Mathf.Clamp(deltaPos.x + centerPos.x, -limit, limit) - centerPos.x;
                            deltaPos.y = Mathf.Clamp(deltaPos.y + centerPos.y, -limit, limit) - centerPos.y;
                            deltaPos.z = Mathf.Clamp(deltaPos.z + centerPos.z, -limit, limit) - centerPos.z;
                            centerPos += deltaPos;
                            previewCam.transform.position += deltaPos;
                            Repaint();
                        }
                    }
                    else if (Event.current.type == EventType.ScrollWheel)
                    {
                        var scroll = Event.current.delta.y;
                        if (scroll != 0)
                        {
                            var cameraPos = previewCam.transform.position - centerPos;
                            var farLimit  = bounds.size.magnitude * 4f;
                            previewCam.transform.position = centerPos + cameraPos.normalized * Mathf.Clamp(cameraPos.magnitude + scroll * 0.1f, 0.01f, farLimit);
                            Repaint();
                        }
                    }
                    else if (Event.current.type == EventType.MouseDrag && Event.current.button == 0)
                    {
                        dragEndPosition = Event.current.mousePosition;
                        if (dragBeginPosition == Vector2.zero)
                        {
                            dragBeginPosition = dragEndPosition;
                        }
                        Repaint();
                    }
                    else if (Event.current.type == EventType.MouseDown && Event.current.button == 0)
                    {
                        ResetRange();
                        dragBeginPosition = Event.current.mousePosition;
                        dragEndPosition   = dragBeginPosition;
                    }
                    else if (Event.current.type == EventType.MouseUp && Event.current.button == 0)
                    {
                        var endRay       = MouseToRay(Event.current.mousePosition, rect, previewCam);
                        var beginRay     = MouseToRay(dragBeginPosition, rect, previewCam);
                        var physicsScene = PhysicsSceneExtensions.GetPhysicsScene(previewCam.scene);
                        try
                        {
                            Physics.queriesHitBackfaces = true;
                            if (dragBeginPosition == dragEndPosition)
                            {
                                RaycastHit hit;
                                physicsScene.Raycast(endRay.origin, endRay.direction, out hit, 10f);
                                if (hit.collider)
                                {
                                    PushInactiveGO(new HashSet <GameObject>()
                                    {
                                        hit.collider.gameObject
                                    });
                                }
                            }
                            else
                            {
                                var position = (endRay.origin + beginRay.origin) * 0.5f + 5f * endRay.direction;
                                var rotation = Quaternion.LookRotation(endRay.direction, previewCam.transform.up);
                                var size     = previewCam.transform.InverseTransformPoint(endRay.origin) - previewCam.transform.InverseTransformPoint(beginRay.origin);
                                size.x = Math.Abs(size.x * 0.5f);
                                size.y = Math.Abs(size.y * 0.5f);
                                size.z = 10f;
                                var cols = s_OverlapBoxMethodInfo.Invoke(null, new object[] { physicsScene, position, size, rotation, Physics.AllLayers, QueryTriggerInteraction.UseGlobal }) as Collider[];
                                if (cols.Length > 0)
                                {
                                    PushInactiveGO(cols.Select(c => c.gameObject));
                                }
                            }
                        }
                        catch
                        {
                            throw;
                        }
                        finally
                        {
                            Physics.queriesHitBackfaces = false;
                        }
                        Repaint();
                        ResetRange();
                    }
                }
                else if (Event.current.type != EventType.Layout)
                {
                    ResetRange();
                }
                previewCam.nearClipPlane = Mathf.Sqrt(bounds.SqrDistance(previewCam.transform.position)) + 0.001f;
                previewCam.farClipPlane  = bounds.size.magnitude + previewCam.nearClipPlane;
                previewCam.Render();
                previewRender.EndAndDrawPreview(rect);

                EditorGUI.DrawRect(new Rect(dragBeginPosition, dragEndPosition - dragBeginPosition), s_RangeColor);

                using (new EditorGUILayout.HorizontalScope())
                {
                    EditorGUI.BeginChangeCheck();
                    backgroundColor = EditorGUILayout.ColorField("Background Color", backgroundColor);
                    if (EditorGUI.EndChangeCheck())
                    {
                        previewCam.backgroundColor = backgroundColor;
                        Repaint();
                    }

                    GUILayout.FlexibleSpace();

                    using (new EditorGUI.DisabledGroupScope(inactiveGOs.Count == 0))
                    {
                        if (GUILayout.Button("Undo"))
                        {
                            UndoInactiveGO();
                        }
                        if (GUILayout.Button("Reset"))
                        {
                            while (inactiveGOs.Count > 0)
                            {
                                UndoInactiveGO();
                            }
                        }
                    }
                    GUILayout.FlexibleSpace();
                }
            }
        }
Example #29
0
    public void OnGUI()
    {
        Event guiEvent = Event.current;

        activeViewTool = ViewTool.None;
        if (guiEvent.isScrollWheel)
        {
            activeViewTool = ViewTool.Zoom;
        }
        else if ((activeTool == ToolSet.View) || (guiEvent.alt))
        {
            if (guiEvent.control)
            {
                activeViewTool = ViewTool.Zoom;
            }
            else
            {
                activeViewTool = ViewTool.Pan;
            }
        }

        if (guiEvent.type == EventType.MouseDown)
        {
            mouseDownPosition = guiEvent.mousePosition;
            mouseDownTime     = Time.time;
            mouseIsDown       = true;
        }
        else if (guiEvent.type == EventType.MouseUp)
        {
            mouseIsDown = false;
        }

        Rect toolRect = new Rect(0, 0, this.position.width, toolbarHeight + toolbarPadding * 2);

        Rect toolbarRect = new Rect(toolbarPadding * 2, toolbarPadding, toolbarWidth * toolIcons.Length, toolbarHeight);

        OnToolbarArea(guiEvent, toolbarRect);

        Rect separatorRect = new Rect(toolbarRect.xMax + toolbarPadding, 0, separatorWidth, toolRect.height);

        GUI.DrawTexture(separatorRect, separatorTexture);

        Rect infoRect = new Rect(separatorRect.xMax, 0, toolRect.width - separatorRect.xMax, toolRect.height);

        switch (activeTool)
        {
        case ToolSet.View:
            OnInfoAreaView(guiEvent, infoRect);
            break;

        case ToolSet.Select:
            OnInfoAreaSelect(guiEvent, infoRect);
            break;

        case ToolSet.Brush:
            OnInfoAreaBrush(guiEvent, infoRect);
            break;

        case ToolSet.Shape:
            OnInfoAreaShape(guiEvent, infoRect);
            break;
        }

        Rect viewRect = new Rect(0, toolRect.yMax, this.position.width, this.position.height - toolRect.yMax);

        MouseCursor activeCursor = MouseCursor.Arrow;

        switch (activeViewTool)
        {
        case ViewTool.Zoom:
            activeCursor = MouseCursor.Zoom;
            break;

        case ViewTool.Pan:
            activeCursor = MouseCursor.Pan;
            break;
        }
        EditorGUIUtility.AddCursorRect(viewRect, activeCursor);

        bool handled = false;

        if (guiEvent.type == EventType.Repaint)
        {
            renderUtil.BeginPreview(viewRect, GUIStyle.none);
            // renderUtil.camera.backgroundColor is reset in BeginPreview()
            renderUtil.camera.backgroundColor = backgroundColor;

            foreach (VectorShape shape in shapes)
            {
                renderUtil.DrawMesh(shape.ShapeMesh, Matrix4x4.identity, renderMaterial, 0);
                //Debug.Log(shape.ShapeMesh.vertexCount);
            }
            renderUtil.Render();

            Handles.SetCamera(renderUtil.camera);
            VectorShape.handleDrawSize = HandleUtility.GetHandleSize(Vector3.zero) * viewRect.height / viewRect.width;

            foreach (VectorShape selected in selection)
            {
                selected.DrawEditorHandles(true, (selected == focusedShape));
            }

            if (selectionRect != Rect.zero)
            {
                Color outlineColor = Handles.color;
                Color fillColor    = new Color(outlineColor.r, outlineColor.g, outlineColor.b, 0.2f);
                Handles.DrawSolidRectangleWithOutline(selectionRect, fillColor, outlineColor);
            }

            renderUtil.EndAndDrawPreview(viewRect);
        }
        else if (guiEvent.isScrollWheel && (EditorWindow.mouseOverWindow == this))
        {
            float zoomFactor = HandleUtility.niceMouseDeltaZoom;
            renderUtil.camera.orthographicSize *= (1 - zoomFactor * .02f);

            // Update matrix from mouse to shape space
            mouseToShapeScale  = renderUtil.camera.orthographicSize * 2f / viewRect.height;
            mouseToShapeMatrix =
                Matrix2D.Translate(renderUtil.camera.transform.position) *
                Matrix2D.Scale(new Vector2(mouseToShapeScale, -mouseToShapeScale)) *
                Matrix2D.Translate(-viewRect.center);

            handled = true;
        }
        else if (guiEvent.isMouse)
        {
            // Update mouse position and matrix from mouse to shape space
            mouseToShapeScale  = renderUtil.camera.orthographicSize * 2f / viewRect.height;
            mousePosition      = guiEvent.mousePosition;
            mouseToShapeMatrix =
                Matrix2D.Translate(renderUtil.camera.transform.position) *
                Matrix2D.Scale(new Vector2(mouseToShapeScale, -mouseToShapeScale)) *
                Matrix2D.Translate(-viewRect.center);

            mouseInContent = (viewRect.Contains(mousePosition));

            if (activeViewTool != ViewTool.None)
            {
                handled = OnViewToolMouse(guiEvent);
            }
            else
            {
                switch (activeTool)
                {
                case ToolSet.Select:
                    handled = OnSelectToolMouse(guiEvent);
                    break;

                case ToolSet.Brush:
                    handled = OnBrushToolMouse(guiEvent);
                    break;

                case ToolSet.Shape:
                    handled = OnShapeToolMouse(guiEvent);
                    break;
                }
            }

            if (!handled)
            {
                Vector2 delta = guiEvent.delta;
                guiEvent.mousePosition = MouseToShapePoint(mousePosition);
                guiEvent.delta         = guiEvent.delta * new Vector2(mouseToShapeScale, -mouseToShapeScale);

                foreach (VectorShape selected in selection)
                {
                    handled |= selected.HandleEditorEvent(guiEvent, true);
                }

                guiEvent.mousePosition = mousePosition;
                guiEvent.delta         = delta;
            }
        }
        else if (guiEvent.type == EventType.ValidateCommand)
        {
            switch (guiEvent.commandName)
            {
            case Cmd_Delete:
                if (selection.Count > 0)
                {
                    handled = true;
                }
                break;

            case Cmd_SelectAll:
                if (shapes.Count > 0)
                {
                    handled = true;
                }
                break;
            }
        }
        else if (guiEvent.type == EventType.ExecuteCommand)
        {
            switch (guiEvent.commandName)
            {
            case Cmd_Delete:
                foreach (VectorShape selected in selection)
                {
                    shapes.Remove(selected);
                }
                selection.Clear();
                handled = true;
                break;

            case Cmd_SelectAll:
                foreach (VectorShape selected in shapes)
                {
                    selection.Add(selected);
                }
                handled = true;
                break;

            case Cmd_ModifierKeysChanged:
                Repaint();
                handled = true;
                break;
            }
        }

        if (handled)
        {
            guiEvent.Use();
        }
    }