UnityEditor.RectHandles.RenderRectWithShadow C# (CSharp) Method

RenderRectWithShadow() public static method

public static RenderRectWithShadow ( bool active ) : void
active bool
return void
        public static void RenderRectWithShadow(bool active, params Vector3[] corners)
        {
            Vector3[] points = new Vector3[] { corners[0], corners[1], corners[2], corners[3], corners[0] };
            Color color = Handles.color;
            Handles.color = new Color(1f, 1f, 1f, !active ? 0.5f : 1f);
            DrawPolyLineWithShadow(new Color(0f, 0f, 0f, !active ? 0.5f : 1f), new Vector2(1f, -1f), points);
            Handles.color = color;
        }

Usage Example

示例#1
0
        protected override void ToolGUI(SceneView view, Vector3 handlePosition, bool isStatic)
        {
            Rect       rect         = Tools.handleRect;
            Quaternion rectRotation = Tools.handleRectRotation;

            // Draw rect
            Vector3[] verts = new Vector3[4];
            for (int i = 0; i < 4; i++)
            {
                Vector3 pos = GetLocalRectPoint(rect, i);
                verts[i] = rectRotation * pos + handlePosition;
            }
            RectHandles.RenderRectWithShadow(false, verts);

            // Handle fading
            Color oldColor = GUI.color;
            float faded    = 1;

            if (Camera.current)
            {
                Vector3 viewDir = Camera.current.orthographic ?
                                  Camera.current.transform.forward :
                                  (handlePosition + rectRotation * rect.center - Camera.current.transform.position);
                Vector3 rectRight   = rectRotation * Vector3.right * rect.width;
                Vector3 rectUp      = rectRotation * Vector3.up * rect.height;
                float   visibleSize = Mathf.Sqrt(Vector3.Cross(Vector3.ProjectOnPlane(rectRight, viewDir), Vector3.ProjectOnPlane(rectUp, viewDir)).magnitude);
                visibleSize /= HandleUtility.GetHandleSize(handlePosition);
                faded        = Mathf.Clamp01((visibleSize - kMinVisibleSize) / kMinVisibleSize * 2);
                Color fadedColor = oldColor;
                fadedColor.a *= faded;
                GUI.color     = fadedColor;
            }

            Vector3 oldPivot = Tools.cachedHandlePosition;

            // Pivot handle
            if (!Tools.vertexDragging)
            {
                RectTransform rectTransform      = Selection.activeTransform.GetComponent <RectTransform>();
                bool          groupPivot         = Selection.transforms.Length > 1;
                bool          rectTransformPivot = !groupPivot && Tools.pivotMode == PivotMode.Pivot && rectTransform != null;
                using (new EditorGUI.DisabledScope(!groupPivot && !rectTransformPivot))
                {
                    EditorGUI.BeginChangeCheck();
                    Vector3 newPivot = PivotHandleGUI(rect, oldPivot, rectRotation);
                    if (EditorGUI.EndChangeCheck() && !isStatic)
                    {
                        if (groupPivot)
                        {
                            Tools.localHandleOffset += Quaternion.Inverse(Tools.handleRotation) * (newPivot - oldPivot);
                        }
                        else if (rectTransformPivot)
                        {
                            Transform tr = Selection.activeTransform;
                            Undo.RecordObject(rectTransform, "Move Rectangle Pivot");
                            Transform space  = Tools.rectBlueprintMode && UnityEditorInternal.InternalEditorUtility.SupportsRectLayout(tr) ? tr.parent : tr;
                            Vector2   offset = space.InverseTransformVector(newPivot - oldPivot);
                            offset.x /= rectTransform.rect.width;
                            offset.y /= rectTransform.rect.height;
                            Vector2 pivot = rectTransform.pivot + offset;

                            RectTransformEditor.SetPivotSmart(rectTransform, pivot.x, 0, true, space != rectTransform.transform);
                            RectTransformEditor.SetPivotSmart(rectTransform, pivot.y, 1, true, space != rectTransform.transform);
                        }
                    }
                }
            }

            TransformManipulator.BeginManipulationHandling(true);
            if (!Tools.vertexDragging)
            {
                // Resize handles
                EditorGUI.BeginChangeCheck();
                Vector3 scalePivot = handlePosition;
                Vector3 scale      = ResizeHandlesGUI(rect, handlePosition, rectRotation, out scalePivot);
                if (EditorGUI.EndChangeCheck() && !isStatic)
                {
                    TransformManipulator.SetResizeDelta(scale, scalePivot, rectRotation);
                }

                bool enableRotation = true;
                if (Tools.rectBlueprintMode)
                {
                    foreach (Transform t in Selection.transforms)
                    {
                        if (t.GetComponent <RectTransform>() != null)
                        {
                            enableRotation = false;
                        }
                    }
                }

                if (enableRotation)
                {
                    // Rotation handles
                    EditorGUI.BeginChangeCheck();
                    Quaternion after = RotationHandlesGUI(rect, handlePosition, rectRotation);
                    if (EditorGUI.EndChangeCheck() && !isStatic)
                    {
                        Quaternion delta = Quaternion.Inverse(rectRotation) * after;
                        float      angle;
                        Vector3    axis;
                        delta.ToAngleAxis(out angle, out axis);
                        axis = rectRotation * axis;

                        Undo.RecordObjects(Selection.transforms, "Rotate");
                        foreach (Transform t in Selection.transforms)
                        {
                            t.RotateAround(handlePosition, axis, angle);

                            // sync euler hints after a rotate tool update tyo fake continuous rotation
                            t.SetLocalEulerHint(t.GetLocalEulerAngles(t.rotationOrder));

                            if (t.parent != null)
                            {
                                t.SendTransformChangedScale(); // force scale update, needed if transform has non-uniformly scaled parent.
                            }
                        }
                        Tools.handleRotation = Quaternion.AngleAxis(angle, axis) * Tools.handleRotation;
                    }
                }
            }
            TransformManipulator.EndManipulationHandling();

            TransformManipulator.BeginManipulationHandling(false);
            // Move handle
            EditorGUI.BeginChangeCheck();
            Vector3 newPos = MoveHandlesGUI(rect, handlePosition, rectRotation);

            if (EditorGUI.EndChangeCheck() && !isStatic)
            {
                if (GridSnapping.active)
                {
                    newPos = GridSnapping.Snap(newPos);
                }

                if (TransformManipulator.HandleHasMoved(newPos))
                {
                    TransformManipulator.SetPositionDelta(newPos, TransformManipulator.mouseDownHandlePosition);
                }
            }
            TransformManipulator.EndManipulationHandling();

            GUI.color = oldColor;
        }
All Usage Examples Of UnityEditor.RectHandles::RenderRectWithShadow