GetHandleSize() public static method

Get world space size of a manipulator handle at given position.

public static GetHandleSize ( Vector3 position ) : float
position Vector3 The position of the handle in 3d space.
return float
        private void CollisionPlanesSceneGUI()
        {
            if (m_ScenePlanes.Count == 0)
            {
                return;
            }

            Event evt = Event.current;

            Color origCol = Handles.color;
            Color col     = new Color(1, 1, 1, 0.5F);

            for (int i = 0; i < m_ScenePlanes.Count; ++i)
            {
                if (m_ScenePlanes[i] == null)
                {
                    continue;
                }

                Transform  transform          = m_ScenePlanes[i];
                Vector3    position           = transform.position;
                Quaternion rotation           = transform.rotation;
                Vector3    right              = rotation * Vector3.right;
                Vector3    up                 = rotation * Vector3.up;
                Vector3    forward            = rotation * Vector3.forward;
                bool       isPlayingAndStatic = EditorApplication.isPlaying && transform.gameObject.isStatic;
                if (editingPlanes)
                {
                    if (Object.ReferenceEquals(s_SelectedTransform, transform))
                    {
                        EditorGUI.BeginChangeCheck();
                        var newPosition = transform.position;
                        var newRotation = transform.rotation;

                        using (new EditorGUI.DisabledScope(isPlayingAndStatic))
                        {
                            if (isPlayingAndStatic)
                            {
                                Handles.ShowStaticLabel(position);
                            }
                            if (EditMode.editMode == EditMode.SceneViewEditMode.ParticleSystemCollisionModulePlanesMove)
                            {
                                newPosition = Handles.PositionHandle(position, rotation);
                            }
                            else if (EditMode.editMode == EditMode.SceneViewEditMode.ParticleSystemCollisionModulePlanesRotate)
                            {
                                newRotation = Handles.RotationHandle(rotation, position);
                            }
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            Undo.RecordObject(transform, "Modified Collision Plane Transform");
                            transform.position = newPosition;
                            transform.rotation = newRotation;
                            ParticleSystemEditorUtils.PerformCompleteResimulation();
                        }
                    }
                    else
                    {
                        float handleSize = HandleUtility.GetHandleSize(position) * 0.6f;

                        EventType oldEventType = evt.type;

                        // we want ignored mouse up events to check for dragging off of scene view
                        if (evt.type == EventType.Ignore && evt.rawType == EventType.MouseUp)
                        {
                            oldEventType = evt.rawType;
                        }

                        Handles.FreeMoveHandle(position, Quaternion.identity, handleSize, Vector3.zero, Handles.RectangleHandleCap);

                        // Detect selected plane (similar to TreeEditor)
                        if (oldEventType == EventType.MouseDown && evt.type == EventType.Used)
                        {
                            s_SelectedTransform   = transform;
                            oldEventType          = EventType.Used;
                            GUIUtility.hotControl = 0; // Reset hot control or the FreeMoveHandle will prevent input to the new Handles. (case 873514)
                        }
                    }
                }

                Handles.color = col;
                Color color = Handles.s_ColliderHandleColor * 0.9f;
                if (isPlayingAndStatic)
                {
                    color.a *= 0.2f;
                }

                if (m_PlaneVisualizationType == PlaneVizType.Grid)
                {
                    DrawGrid(position, right, forward, up, color);
                }
                else
                {
                    DrawSolidPlane(position, rotation, color, Color.yellow);
                }
            }

            Handles.color = origCol;
        }
示例#2
0
        internal void OnGUI(SceneView view)
        {
            float num = Mathf.Min(view.position.width, view.position.height);

            if (num >= 100f)
            {
                if (Event.current.type == EventType.Repaint)
                {
                    Profiler.BeginSample("SceneView.AxisSelector");
                }
                this.HandleContextClick(view);
                Camera camera = view.camera;
                HandleUtility.PushCamera(camera);
                if (camera.orthographic)
                {
                    camera.orthographicSize = 0.5f;
                }
                camera.cullingMask        = 0;
                camera.transform.position = camera.transform.rotation * new Vector3(0f, 0f, -5f);
                camera.clearFlags         = CameraClearFlags.Nothing;
                camera.nearClipPlane      = 0.1f;
                camera.farClipPlane       = 10f;
                camera.fieldOfView        = view.m_Ortho.Fade(70f, 0f);
                SceneView.AddCursorRect(new Rect(view.position.width - 100f + 22f, 22f, 56f, 102f), MouseCursor.Arrow);
                Handles.SetCamera(new Rect(view.position.width - 100f, 0f, 100f, 100f), camera);
                Handles.BeginGUI();
                this.DrawRotationLock(view);
                this.DrawLabels(view);
                Handles.EndGUI();
                for (int i = 0; i < 3; i++)
                {
                    Vector3 rhs = SceneViewRotation.kDirectionRotations[i] * Vector3.forward;
                    this.dirVisible[i].target = (Mathf.Abs(Vector3.Dot(camera.transform.forward, rhs)) < 0.9f);
                }
                float num2 = HandleUtility.GetHandleSize(Vector3.zero) * 0.2f;
                this.AxisSelectors(view, camera, num2, -1f, SceneViewRotation.styles.viewAxisLabelStyle);
                Color color = Handles.centerColor;
                color    = Color.Lerp(color, Color.gray, this.faded2Dgray);
                color.a *= this.fadedVisibility;
                if (color.a <= 0.1f || view.isRotationLocked)
                {
                    GUI.enabled = false;
                }
                Handles.color = color;
                int        arg_27C_0 = this.m_CenterButtonControlID;
                Vector3    arg_27C_1 = Vector3.zero;
                Quaternion arg_27C_2 = Quaternion.identity;
                float      arg_27C_3 = num2 * 0.8f;
                float      arg_27C_4 = num2;
                if (SceneViewRotation.< > f__mg$cache2 == null)
                {
                    SceneViewRotation.< > f__mg$cache2 = new Handles.CapFunction(Handles.CubeHandleCap);
                }
                if (Handles.Button(arg_27C_0, arg_27C_1, arg_27C_2, arg_27C_3, arg_27C_4, SceneViewRotation.< > f__mg$cache2) && !view.in2DMode && !view.isRotationLocked)
                {
                    if (Event.current.clickCount == 2)
                    {
                        view.FrameSelected();
                    }
                    else if (Event.current.shift || Event.current.button == 2)
                    {
                        this.ViewFromNiceAngle(view, true);
                    }
                    else
                    {
                        this.ViewSetOrtho(view, !view.orthographic);
                    }
                }
                this.AxisSelectors(view, camera, num2, 1f, SceneViewRotation.styles.viewAxisLabelStyle);
                GUI.enabled = true;
                if (!view.in2DMode && !view.isRotationLocked)
                {
                    if (Event.current.type == EditorGUIUtility.swipeGestureEventType)
                    {
                        Event   current = Event.current;
                        Vector3 a;
                        if (current.delta.y > 0f)
                        {
                            a = Vector3.up;
                        }
                        else if (current.delta.y < 0f)
                        {
                            a = -Vector3.up;
                        }
                        else if (current.delta.x < 0f)
                        {
                            a = Vector3.right;
                        }
                        else
                        {
                            a = -Vector3.right;
                        }
                        Vector3 vector = -a - Vector3.forward * 0.9f;
                        vector = view.camera.transform.TransformDirection(vector);
                        float num3 = 0f;
                        int   dir  = 0;
                        for (int j = 0; j < 6; j++)
                        {
                            float num4 = Vector3.Dot(SceneViewRotation.kDirectionRotations[j] * -Vector3.forward, vector);
                            if (num4 > num3)
                            {
                                num3 = num4;
                                dir  = j;
                            }
                        }
                        this.ViewAxisDirection(view, dir);
                        Event.current.Use();
                    }
                }
                HandleUtility.PopCamera(camera);
                Handles.SetCamera(camera);
                if (Event.current.type == EventType.Repaint)
                {
                    Profiler.EndSample();
                }
            }
        }
示例#3
0
        public override void OnSceneGUI(ParticleSystem s, InitialModuleUI initial)
        {
            Event     current = Event.current;
            EventType rawType = current.type;

            if ((current.type == EventType.Ignore) && (current.rawType == EventType.MouseUp))
            {
                rawType = current.rawType;
            }
            Color color  = Handles.color;
            Color color2 = new Color(1f, 1f, 1f, 0.5f);

            Handles.color = color2;
            if (this.m_Type.intValue == 0)
            {
                for (int i = 0; i < this.m_ShownPlanes.Length; i++)
                {
                    UnityEngine.Object objectReferenceValue = this.m_ShownPlanes[i].objectReferenceValue;
                    if (objectReferenceValue != null)
                    {
                        Transform objB = objectReferenceValue as Transform;
                        if (objB != null)
                        {
                            Vector3    position = objB.position;
                            Quaternion rotation = objB.rotation;
                            Vector3    vector2  = (Vector3)(rotation * Vector3.right);
                            Vector3    normal   = (Vector3)(rotation * Vector3.up);
                            Vector3    vector4  = (Vector3)(rotation * Vector3.forward);
                            if (object.ReferenceEquals(m_SelectedTransform, objB))
                            {
                                Tools.s_Hidden = true;
                                EditorGUI.BeginChangeCheck();
                                if (Tools.current == Tool.Move)
                                {
                                    objB.position = Handles.PositionHandle(position, rotation);
                                }
                                else if (Tools.current == Tool.Rotate)
                                {
                                    objB.rotation = Handles.RotationHandle(rotation, position);
                                }
                                if (EditorGUI.EndChangeCheck())
                                {
                                    if (this.m_PlaneVisualizationType == PlaneVizType.Solid)
                                    {
                                        GameObject plane = ParticleEffectUtils.GetPlane(i);
                                        plane.transform.position   = position;
                                        plane.transform.rotation   = rotation;
                                        plane.transform.localScale = new Vector3(this.m_ScaleGrid, this.m_ScaleGrid, this.m_ScaleGrid);
                                    }
                                    ParticleSystemEditorUtils.PerformCompleteResimulation();
                                }
                            }
                            else
                            {
                                int   keyboardControl = GUIUtility.keyboardControl;
                                float size            = HandleUtility.GetHandleSize(position) * 0.06f;
                                Handles.FreeMoveHandle(position, Quaternion.identity, size, Vector3.zero, new Handles.DrawCapFunction(Handles.RectangleCap));
                                if (((rawType == EventType.MouseDown) && (current.type == EventType.Used)) && (keyboardControl != GUIUtility.keyboardControl))
                                {
                                    m_SelectedTransform = objB;
                                    rawType             = EventType.Used;
                                }
                            }
                            if (this.m_PlaneVisualizationType == PlaneVizType.Grid)
                            {
                                Color color3 = (Color)(Handles.s_ColliderHandleColor * 0.9f);
                                if (!base.enabled)
                                {
                                    color3 = new Color(0.7f, 0.7f, 0.7f, 0.7f);
                                }
                                this.DrawGrid(position, vector2, vector4, normal, color3, i);
                            }
                            else
                            {
                                this.DrawSolidPlane(position, rotation, i);
                            }
                        }
                        else
                        {
                            Debug.LogError("Not a transform: " + objectReferenceValue.GetType());
                        }
                    }
                }
            }
            Handles.color = color;
        }
示例#4
0
        internal void OnGUI(SceneView view)
        {
            if ((double)Mathf.Min(view.position.width, view.position.height) < 100.0)
            {
                return;
            }
            if (Event.current.type == EventType.Repaint)
            {
                Profiler.BeginSample("SceneView.AxisSelector");
            }
            this.HandleContextClick(view);
            Camera camera = view.camera;

            HandleUtility.PushCamera(camera);
            if (camera.orthographic)
            {
                camera.orthographicSize = 0.5f;
            }
            camera.cullingMask        = 0;
            camera.transform.position = camera.transform.rotation * new Vector3(0.0f, 0.0f, -5f);
            camera.clearFlags         = CameraClearFlags.Nothing;
            camera.nearClipPlane      = 0.1f;
            camera.farClipPlane       = 10f;
            camera.fieldOfView        = view.m_Ortho.Fade(70f, 0.0f);
            SceneView.AddCursorRect(new Rect((float)((double)view.position.width - 100.0 + 22.0), 22f, 56f, 102f), MouseCursor.Arrow);
            Handles.SetCamera(new Rect(view.position.width - 100f, 0.0f, 100f, 100f), camera);
            Handles.BeginGUI();
            this.DrawLabels(view);
            Handles.EndGUI();
            for (int index = 0; index < 3; ++index)
            {
                Vector3 rhs = SceneViewRotation.kDirectionRotations[index] * Vector3.forward;
                this.dirVisible[index].target = (double)Mathf.Abs(Vector3.Dot(camera.transform.forward, rhs)) < 0.899999976158142;
            }
            float num1 = HandleUtility.GetHandleSize(Vector3.zero) * 0.2f;

            this.AxisSelectors(view, camera, num1, -1f, SceneViewRotation.styles.viewAxisLabelStyle);
            Color color = Color.Lerp(Handles.centerColor, Color.gray, this.faded2Dgray);

            color.a *= this.m_Visible.faded;
            if ((double)color.a <= 0.100000001490116)
            {
                GUI.enabled = false;
            }
            Handles.color = color;
            if (Handles.Button(this.m_CenterButtonControlID, Vector3.zero, Quaternion.identity, num1 * 0.8f, num1, new Handles.DrawCapFunction(Handles.CubeCap)) && !view.in2DMode)
            {
                if (Event.current.clickCount == 2)
                {
                    view.FrameSelected();
                }
                else if (Event.current.shift || Event.current.button == 2)
                {
                    this.ViewFromNiceAngle(view, true);
                }
                else
                {
                    this.ViewSetOrtho(view, !view.orthographic);
                }
            }
            this.AxisSelectors(view, camera, num1, 1f, SceneViewRotation.styles.viewAxisLabelStyle);
            GUI.enabled = true;
            if (!view.in2DMode && Event.current.type == EditorGUIUtility.swipeGestureEventType)
            {
                Event   current   = Event.current;
                Vector3 direction = -((double)current.delta.y <= 0.0 ? ((double)current.delta.y >= 0.0 ? ((double)current.delta.x >= 0.0 ? -Vector3.right : Vector3.right) : -Vector3.up) : Vector3.up) - Vector3.forward * 0.9f;
                Vector3 rhs       = view.camera.transform.TransformDirection(direction);
                float   num2      = 0.0f;
                int     dir       = 0;
                for (int index = 0; index < 6; ++index)
                {
                    float num3 = Vector3.Dot(SceneViewRotation.kDirectionRotations[index] * -Vector3.forward, rhs);
                    if ((double)num3 > (double)num2)
                    {
                        num2 = num3;
                        dir  = index;
                    }
                }
                this.ViewAxisDirection(view, dir);
                Event.current.Use();
            }
            HandleUtility.PopCamera(camera);
            Handles.SetCamera(camera);
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }
            Profiler.EndSample();
        }
示例#5
0
        public override void ToolGUI(SceneView view, Vector3 handlePosition, bool isStatic)
        {
            Rect       handleRect         = Tools.handleRect;
            Quaternion handleRectRotation = Tools.handleRectRotation;

            Vector3[] array = new Vector3[4];
            for (int i = 0; i < 4; i++)
            {
                Vector3 point = RectTool.GetLocalRectPoint(handleRect, i);
                array[i] = handleRectRotation * point + handlePosition;
            }
            RectHandles.RenderRectWithShadow(false, array);
            Color color = GUI.color;

            if (Camera.current)
            {
                Vector3 planeNormal = (!Camera.current.orthographic) ? (handlePosition + handleRectRotation * handleRect.center - Camera.current.transform.position) : Camera.current.transform.forward;
                Vector3 vector      = handleRectRotation * Vector3.right * handleRect.width;
                Vector3 vector2     = handleRectRotation * Vector3.up * handleRect.height;
                float   num         = Mathf.Sqrt(Vector3.Cross(Vector3.ProjectOnPlane(vector, planeNormal), Vector3.ProjectOnPlane(vector2, planeNormal)).magnitude);
                num /= HandleUtility.GetHandleSize(handlePosition);
                float num2   = Mathf.Clamp01((num - 0.2f) / 0.2f * 2f);
                Color color2 = color;
                color2.a *= num2;
                GUI.color = color2;
            }
            Vector3 handlePosition2 = Tools.GetHandlePosition();

            if (!Tools.vertexDragging)
            {
                RectTransform component = Selection.activeTransform.GetComponent <RectTransform>();
                bool          flag      = Selection.transforms.Length > 1;
                bool          flag2     = !flag && Tools.pivotMode == PivotMode.Pivot && component != null;
                using (new EditorGUI.DisabledScope(!flag && !flag2))
                {
                    EditorGUI.BeginChangeCheck();
                    Vector3 a = RectTool.PivotHandleGUI(handleRect, handlePosition2, handleRectRotation);
                    if (EditorGUI.EndChangeCheck() && !isStatic)
                    {
                        if (flag)
                        {
                            Tools.localHandleOffset += Quaternion.Inverse(Tools.handleRotation) * (a - handlePosition2);
                        }
                        else if (flag2)
                        {
                            Transform activeTransform = Selection.activeTransform;
                            Undo.RecordObject(component, "Move Rectangle Pivot");
                            Transform transform = (!Tools.rectBlueprintMode || !InternalEditorUtility.SupportsRectLayout(activeTransform)) ? activeTransform : activeTransform.parent;
                            Vector2   b         = transform.InverseTransformVector(a - handlePosition2);
                            b.x /= component.rect.width;
                            b.y /= component.rect.height;
                            Vector2 vector3 = component.pivot + b;
                            RectTransformEditor.SetPivotSmart(component, vector3.x, 0, true, transform != component.transform);
                            RectTransformEditor.SetPivotSmart(component, vector3.y, 1, true, transform != component.transform);
                        }
                    }
                }
            }
            TransformManipulator.BeginManipulationHandling(true);
            if (!Tools.vertexDragging)
            {
                EditorGUI.BeginChangeCheck();
                Vector3 pivotPosition = handlePosition;
                Vector3 scaleDelta    = RectTool.ResizeHandlesGUI(handleRect, handlePosition, handleRectRotation, out pivotPosition);
                if (EditorGUI.EndChangeCheck() && !isStatic)
                {
                    TransformManipulator.SetResizeDelta(scaleDelta, pivotPosition, handleRectRotation);
                }
                bool flag3 = true;
                if (Tools.rectBlueprintMode)
                {
                    Transform[] transforms = Selection.transforms;
                    for (int j = 0; j < transforms.Length; j++)
                    {
                        Transform transform2 = transforms[j];
                        if (transform2.GetComponent <RectTransform>() != null)
                        {
                            flag3 = false;
                        }
                    }
                }
                if (flag3)
                {
                    EditorGUI.BeginChangeCheck();
                    Quaternion rhs = RectTool.RotationHandlesGUI(handleRect, handlePosition, handleRectRotation);
                    if (EditorGUI.EndChangeCheck() && !isStatic)
                    {
                        float   angle;
                        Vector3 vector4;
                        (Quaternion.Inverse(handleRectRotation) * rhs).ToAngleAxis(out angle, out vector4);
                        vector4 = handleRectRotation * vector4;
                        Undo.RecordObjects(Selection.transforms, "Rotate");
                        Transform[] transforms2 = Selection.transforms;
                        for (int k = 0; k < transforms2.Length; k++)
                        {
                            Transform transform3 = transforms2[k];
                            transform3.RotateAround(handlePosition, vector4, angle);
                            transform3.SetLocalEulerHint(transform3.GetLocalEulerAngles(transform3.rotationOrder));
                            if (transform3.parent != null)
                            {
                                transform3.SendTransformChangedScale();
                            }
                        }
                        Tools.handleRotation = Quaternion.AngleAxis(angle, vector4) * Tools.handleRotation;
                    }
                }
            }
            TransformManipulator.EndManipulationHandling();
            TransformManipulator.BeginManipulationHandling(false);
            EditorGUI.BeginChangeCheck();
            Vector3 a2 = RectTool.MoveHandlesGUI(handleRect, handlePosition, handleRectRotation);

            if (EditorGUI.EndChangeCheck() && !isStatic)
            {
                Vector3 positionDelta = a2 - TransformManipulator.mouseDownHandlePosition;
                TransformManipulator.SetPositionDelta(positionDelta);
            }
            TransformManipulator.EndManipulationHandling();
            GUI.color = color;
        }
示例#6
0
 private static float DefaultMidpointGetSizeFunc(Vector3 localPos)
 {
     return(HandleUtility.GetHandleSize(localPos) * 0.03f);
 }
示例#7
0
        protected virtual void OnSceneGUI()
        {
            Light t = target as Light;

            Color temp = Handles.color;

            if (t.enabled)
            {
                Handles.color = kGizmoLight;
            }
            else
            {
                Handles.color = kGizmoDisabledLight;
            }

            float thisRange = t.range;

            switch (t.type)
            {
            case LightType.Directional:
                Vector3 lightPos = t.transform.position;
                float   lightSize;
                using (new Handles.DrawingScope(Matrix4x4.identity))        //be sure no matrix affect the size computation
                {
                    lightSize = HandleUtility.GetHandleSize(lightPos);
                }
                float radius = lightSize * 0.2f;
                using (new Handles.DrawingScope(Matrix4x4.TRS(lightPos, t.transform.rotation, Vector3.one)))
                {
                    Handles.DrawWireDisc(Vector3.zero, Vector3.forward, radius);
                    foreach (Vector3 normalizedPos in directionalLightHandlesRayPositions)
                    {
                        Vector3 pos = normalizedPos * radius;
                        Handles.DrawLine(pos, pos + new Vector3(0, 0, lightSize));
                    }
                }
                break;

            case LightType.Point:
                thisRange = Handles.RadiusHandle(Quaternion.identity, t.transform.position, thisRange);
                if (GUI.changed)
                {
                    Undo.RecordObject(t, "Adjust Point Light");
                    t.range = thisRange;
                }
                break;

            case LightType.Spot:
                Transform tr            = t.transform;
                Vector3   circleCenter  = tr.position;
                Vector3   arrivalCenter = circleCenter + tr.forward * t.range;
                float     lightDisc     = t.range * Mathf.Tan(Mathf.Deg2Rad * t.spotAngle / 2.0f);
                Handles.DrawLine(circleCenter, arrivalCenter + tr.up * lightDisc);
                Handles.DrawLine(circleCenter, arrivalCenter - tr.up * lightDisc);
                Handles.DrawLine(circleCenter, arrivalCenter + tr.right * lightDisc);
                Handles.DrawLine(circleCenter, arrivalCenter - tr.right * lightDisc);
                Handles.DrawWireDisc(arrivalCenter, tr.forward, lightDisc);
                Handles.color = GetLightHandleColor(Handles.color);
                Vector2 angleAndRange = new Vector2(t.spotAngle, t.range);
                angleAndRange = Handles.ConeHandle(t.transform.rotation, t.transform.position, angleAndRange, 1.0f, 1.0f, true);
                if (GUI.changed)
                {
                    Undo.RecordObject(t, "Adjust Spot Light");
                    t.spotAngle = angleAndRange.x;
                    t.range     = Mathf.Max(angleAndRange.y, 0.01F);
                }
                break;

            case LightType.Rectangle:
                EditorGUI.BeginChangeCheck();
                Vector2 size = Handles.DoRectHandles(t.transform.rotation, t.transform.position, t.areaSize, false);
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(t, "Adjust Rect Light");
                    t.areaSize = size;
                }
                // Draw the area light's normal only if it will not overlap with the current tool
                if (!((Tools.current == Tool.Move || Tools.current == Tool.Scale) && Tools.pivotRotation == PivotRotation.Local))
                {
                    Handles.DrawLine(t.transform.position, t.transform.position + t.transform.forward);
                }
                break;

            case LightType.Disc:
                m_BoundsHandle.radius         = t.areaSize.x;
                m_BoundsHandle.axes           = IMGUI.Controls.PrimitiveBoundsHandle.Axes.X | IMGUI.Controls.PrimitiveBoundsHandle.Axes.Y;
                m_BoundsHandle.center         = Vector3.zero;
                m_BoundsHandle.wireframeColor = Handles.color;
                m_BoundsHandle.handleColor    = GetLightHandleColor(Handles.color);
                Matrix4x4 mat = new Matrix4x4();
                mat.SetTRS(t.transform.position, t.transform.rotation, new Vector3(1, 1, 1));
                EditorGUI.BeginChangeCheck();
                using (new Handles.DrawingScope(Color.white, mat))
                    m_BoundsHandle.DrawHandle();
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(t, "Adjust Disc Light");
                    t.areaSize = new Vector2(m_BoundsHandle.radius, t.areaSize.y);
                }
                break;
            }
            Handles.color = temp;
        }
示例#8
0
        private static Vector3 MoveHandlesGUI(Rect rect, Vector3 pivot, Quaternion rotation)
        {
            int     controlID = GUIUtility.GetControlID(RectTool.s_MoveHandleHash, FocusType.Passive);
            Vector3 vector    = pivot;
            float   num       = HandleUtility.GetHandleSize(pivot) * 0.2f;
            float   num2      = 1f - GUI.color.a;

            Vector3[] array = new Vector3[]
            {
                rotation *new Vector2(rect.x, rect.y) + pivot,
                rotation *new Vector2(rect.xMax, rect.y) + pivot,
                rotation *new Vector2(rect.xMax, rect.yMax) + pivot,
                rotation *new Vector2(rect.x, rect.yMax) + pivot
            };
            VertexSnapping.HandleKeyAndMouseMove(controlID);
            bool      flag           = Selection.transforms.Length == 1 && InternalEditorUtility.SupportsRectLayout(Selection.activeTransform) && Selection.activeTransform.parent.rotation == rotation;
            Event     current        = Event.current;
            EventType typeForControl = current.GetTypeForControl(controlID);
            Plane     plane          = new Plane(array[0], array[1], array[2]);

            switch (typeForControl)
            {
            case EventType.MouseDown:
            {
                bool flag2 = Tools.vertexDragging || (current.button == 0 && current.modifiers == EventModifiers.None && RectHandles.RaycastGUIPointToWorldHit(current.mousePosition, plane, out RectTool.s_StartMouseWorldPos) && (RectTool.SceneViewDistanceToRectangle(array, current.mousePosition) == 0f || (num2 > 0f && RectTool.SceneViewDistanceToDisc(pivot, rotation * Vector3.forward, num, current.mousePosition) == 0f)));
                if (flag2)
                {
                    RectTool.s_StartPosition = pivot;
                    RectTool.s_StartMousePos = (RectTool.s_CurrentMousePos = current.mousePosition);
                    RectTool.s_Moving        = false;
                    RectTool.s_LockAxis      = -1;
                    int num3 = controlID;
                    GUIUtility.keyboardControl = num3;
                    GUIUtility.hotControl      = num3;
                    EditorGUIUtility.SetWantsMouseJumping(1);
                    HandleUtility.ignoreRaySnapObjects = null;
                    current.Use();
                    if (flag)
                    {
                        Transform     activeTransform = Selection.activeTransform;
                        RectTransform component       = activeTransform.GetComponent <RectTransform>();
                        Transform     parent          = activeTransform.parent;
                        RectTransform component2      = parent.GetComponent <RectTransform>();
                        RectTool.s_StartRectPosition = component.anchoredPosition;
                        RectTransformSnapping.CalculatePositionSnapValues(parent, activeTransform, component2, component);
                    }
                }
                break;
            }

            case EventType.MouseUp:
                if (GUIUtility.hotControl == controlID)
                {
                    if (!RectTool.s_Moving)
                    {
                        Selection.activeGameObject = SceneViewPicking.PickGameObject(current.mousePosition);
                    }
                    GUIUtility.hotControl = 0;
                    EditorGUIUtility.SetWantsMouseJumping(0);
                    HandleUtility.ignoreRaySnapObjects = null;
                    current.Use();
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == controlID)
                {
                    RectTool.s_CurrentMousePos += current.delta;
                    if (!RectTool.s_Moving && (RectTool.s_CurrentMousePos - RectTool.s_StartMousePos).magnitude > 3f)
                    {
                        RectTool.s_Moving = true;
                        RectHandles.RaycastGUIPointToWorldHit(RectTool.s_CurrentMousePos, plane, out RectTool.s_StartMouseWorldPos);
                    }
                    if (RectTool.s_Moving)
                    {
                        if (Tools.vertexDragging)
                        {
                            if (HandleUtility.ignoreRaySnapObjects == null)
                            {
                                Handles.SetupIgnoreRaySnapObjects();
                            }
                            Vector3 vector2;
                            if (HandleUtility.FindNearestVertex(RectTool.s_CurrentMousePos, null, out vector2))
                            {
                                vector      = vector2;
                                GUI.changed = true;
                            }
                            ManipulationToolUtility.minDragDifference = Vector2.zero;
                        }
                        else
                        {
                            ManipulationToolUtility.SetMinDragDifferenceForPos(pivot);
                            Vector3 a;
                            if (RectHandles.RaycastGUIPointToWorldHit(RectTool.s_CurrentMousePos, plane, out a))
                            {
                                Vector3 vector3 = a - RectTool.s_StartMouseWorldPos;
                                if (current.shift)
                                {
                                    vector3 = Quaternion.Inverse(rotation) * vector3;
                                    if (RectTool.s_LockAxis == -1)
                                    {
                                        RectTool.s_LockAxis = ((Mathf.Abs(vector3.x) <= Mathf.Abs(vector3.y)) ? 1 : 0);
                                    }
                                    vector3[1 - RectTool.s_LockAxis] = 0f;
                                    vector3 = rotation * vector3;
                                }
                                else
                                {
                                    RectTool.s_LockAxis = -1;
                                }
                                if (flag)
                                {
                                    Transform parent2 = Selection.activeTransform.parent;
                                    Vector3   vector4 = RectTool.s_StartRectPosition + parent2.InverseTransformVector(vector3);
                                    vector4.z = 0f;
                                    Quaternion rotation2    = Quaternion.Inverse(rotation);
                                    Vector2    snapDistance = Vector2.one * HandleUtility.GetHandleSize(vector) * 0.05f;
                                    snapDistance.x /= (rotation2 * parent2.TransformVector(Vector3.right)).x;
                                    snapDistance.y /= (rotation2 * parent2.TransformVector(Vector3.up)).y;
                                    Vector3 vector5 = RectTransformSnapping.SnapToGuides(vector4, snapDistance);
                                    ManipulationToolUtility.DisableMinDragDifferenceBasedOnSnapping(vector4, vector5);
                                    vector3 = parent2.TransformVector(vector5 - RectTool.s_StartRectPosition);
                                }
                                vector      = RectTool.s_StartPosition + vector3;
                                GUI.changed = true;
                            }
                        }
                    }
                    current.Use();
                }
                break;

            case EventType.Repaint:
                if (Tools.vertexDragging)
                {
                    RectHandles.RectScalingCap(controlID, pivot, rotation, 1f);
                }
                else
                {
                    Handles.color = Handles.secondaryColor * new Color(1f, 1f, 1f, 1.5f * num2);
                    Handles.CircleCap(controlID, pivot, rotation, num);
                    Handles.color = Handles.secondaryColor * new Color(1f, 1f, 1f, 0.3f * num2);
                    Handles.DrawSolidDisc(pivot, rotation * Vector3.forward, num);
                }
                break;
            }
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingPosX", typeForControl);
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingLeft", typeForControl);
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingRight", typeForControl);
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingPosY", typeForControl);
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingTop", typeForControl);
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingBottom", typeForControl);
            return(vector);
        }
示例#9
0
        static Vector3 DoPositionHandle_Internal(PositionHandleIds ids, Vector3 position, Quaternion rotation, PositionHandleParam param)
        {
            Color temp = color;

            bool isStatic = (!Tools.s_Hidden && EditorApplication.isPlaying && GameObjectUtility.ContainsStatic(Selection.gameObjects));

            // Calculate the camera view vector in Handle draw space
            // this handle the case where the matrix is skewed
            var handlePosition       = matrix.MultiplyPoint3x4(position);
            var drawToWorldMatrix    = matrix * Matrix4x4.TRS(position, rotation, Vector3.one);
            var invDrawToWorldMatrix = drawToWorldMatrix.inverse;
            var viewVectorDrawSpace  = GetCameraViewFrom(handlePosition, invDrawToWorldMatrix);

            var size = HandleUtility.GetHandleSize(position);

            // Calculate per axis camera lerp
            for (var i = 0; i < 3; ++i)
            {
                s_DoPositionHandle_Internal_CameraViewLerp[i] = ids[i] == GUIUtility.hotControl ? 0 : GetCameraViewLerpForWorldAxis(viewVectorDrawSpace, GetAxisVector(i));
            }
            // Calculate per plane camera lerp (xy, yz, xz)
            for (var i = 0; i < 3; ++i)
            {
                s_DoPositionHandle_Internal_CameraViewLerp[3 + i] = Mathf.Max(s_DoPositionHandle_Internal_CameraViewLerp[i], s_DoPositionHandle_Internal_CameraViewLerp[(i + 1) % 3]);
            }

            var isHot       = ids.Has(GUIUtility.hotControl);
            var axisOffset  = param.axisOffset;
            var planeOffset = param.planeOffset;

            if (isHot)
            {
                axisOffset  = Vector3.zero;
                planeOffset = Vector3.zero;
            }

            // Draw plane handles (xy, yz, xz)
            var planeSize = isHot ? param.planeSize + param.planeOffset : param.planeSize;

            for (var i = 0; i < 3; ++i)
            {
                if (!param.ShouldShow(3 + i) || isHot && ids[3 + i] != GUIUtility.hotControl)
                {
                    continue;
                }

                var cameraLerp = isHot ? 0 : s_DoPositionHandle_Internal_CameraViewLerp[3 + i];
                if (cameraLerp <= kCameraViewThreshold)
                {
                    var offset = planeOffset * size;
                    offset[s_DoPositionHandle_Internal_PrevIndex[i]] = 0;
                    var planarSize = Mathf.Max(planeSize[i], planeSize[s_DoPositionHandle_Internal_NextIndex[i]]);
                    position = DoPlanarHandle(ids[3 + i], i, position, offset, rotation, size * planarSize, cameraLerp, viewVectorDrawSpace, param.planeOrientation);
                }
            }

            // Draw axis sliders
            // Draw last to have priority over the planes
            for (var i = 0; i < 3; ++i)
            {
                if (!param.ShouldShow(i))
                {
                    continue;
                }

                if (!currentlyDragging)
                {
                    switch (param.axesOrientation)
                    {
                    case PositionHandleParam.Orientation.Camera:
                        s_DoPositionHandle_AxisHandlesOctant[i] = viewVectorDrawSpace[i] > 0.01f ? -1 : 1;
                        break;

                    case PositionHandleParam.Orientation.Signed:
                        s_DoPositionHandle_AxisHandlesOctant[i] = 1;
                        break;
                    }
                }

                var isThisAxisHot = isHot && ids[i] == GUIUtility.hotControl;

                var axisColor = GetColorByAxis(i);
                color = isStatic ? Color.Lerp(axisColor, staticColor, staticBlend) : axisColor;
                GUI.SetNextControlName(s_DoPositionHandle_Internal_AxisNames[i]);

                // if we are hot here, the hot handle must be opaque
                var cameraLerp = isThisAxisHot ? 0 : s_DoPositionHandle_Internal_CameraViewLerp[i];

                if (cameraLerp <= kCameraViewThreshold)
                {
                    color = Color.Lerp(color, Color.clear, cameraLerp);
                    var axisVector = GetAxisVector(i);
                    var dir        = rotation * axisVector;
                    var offset     = dir * axisOffset[i] * size;

                    dir    *= s_DoPositionHandle_AxisHandlesOctant[i];
                    offset *= s_DoPositionHandle_AxisHandlesOctant[i];

                    if (isHot && !isThisAxisHot)
                    {
                        color = s_DisabledHandleColor;
                    }

                    // A plane with this axis is hot
                    if (isHot && (ids[s_DoPositionHandle_Internal_PrevPlaneIndex[i]] == GUIUtility.hotControl || ids[i + 3] == GUIUtility.hotControl))
                    {
                        color = selectedColor;
                    }

                    color = ToActiveColorSpace(color);

                    s_DoPositionHandle_ArrowCapConeOffset = isHot
                        ? rotation * Vector3.Scale(Vector3.Scale(axisVector, param.axisOffset), s_DoPositionHandle_AxisHandlesOctant)
                        : Vector3.zero;
                    position = Slider(ids[i], position, offset, dir, size * param.axisSize[i], DoPositionHandle_ArrowCap, GridSnapping.active ? 0f : SnapSettings.move[i]);
                }
            }

            VertexSnapping.HandleMouseMove(ids.xyz);
            if (param.ShouldShow(PositionHandleParam.Handle.XYZ) && (isHot && ids.xyz == GUIUtility.hotControl || !isHot))
            {
                color = ToActiveColorSpace(centerColor);
                GUI.SetNextControlName("FreeMoveAxis");
                position = FreeMoveHandle(ids.xyz, position, rotation, size * kFreeMoveHandleSizeFactor, GridSnapping.active ? Vector3.zero : SnapSettings.move, RectangleHandleCap);
            }

            color = temp;

            if (GridSnapping.active)
            {
                position = GridSnapping.Snap(position);
            }

            return(position);
        }
示例#10
0
        public static bool MovePoints(IEditablePoint points, Transform cloudTransform, List <int> selection)
        {
            // ISSUE: object of a compiler-generated type is created
            // ISSUE: variable of a compiler-generated type
            PointEditor.\u003CMovePoints\u003Ec__AnonStorey40 pointsCAnonStorey40 = new PointEditor.\u003CMovePoints\u003Ec__AnonStorey40();
            // ISSUE: reference to a compiler-generated field
            pointsCAnonStorey40.points = points;
            if (selection.Count == 0)
            {
                return(false);
            }
            if (Event.current.type == EventType.MouseUp)
            {
                PointEditor.s_EditingScale    = Vector3.one;
                PointEditor.s_EditingRotation = Quaternion.identity;
            }
            if ((bool)((UnityEngine.Object)Camera.current))
            {
                Vector3 zero = Vector3.zero;
                // ISSUE: reference to a compiler-generated method
                // ISSUE: reference to a compiler-generated field
                Vector3 position1 = Tools.pivotMode != PivotMode.Pivot ? selection.Aggregate <int, Vector3>(zero, new Func <Vector3, int, Vector3>(pointsCAnonStorey40.\u003C\u003Em__57)) / (float)selection.Count : pointsCAnonStorey40.points.GetPosition(selection[0]);
                Vector3 position2 = cloudTransform.TransformPoint(position1);
                switch (Tools.current)
                {
                case Tool.Move:
                    Vector3 position3 = Handles.PositionHandle(position2, Tools.pivotRotation != PivotRotation.Local ? Quaternion.identity : cloudTransform.rotation);
                    if (GUI.changed)
                    {
                        Vector3 vector3 = cloudTransform.InverseTransformPoint(position3) - cloudTransform.InverseTransformPoint(position2);
                        using (List <int> .Enumerator enumerator = selection.GetEnumerator())
                        {
                            while (enumerator.MoveNext())
                            {
                                int current = enumerator.Current;
                                // ISSUE: reference to a compiler-generated field
                                // ISSUE: reference to a compiler-generated field
                                pointsCAnonStorey40.points.SetPosition(current, pointsCAnonStorey40.points.GetPosition(current) + vector3);
                            }
                        }
                        return(true);
                    }
                    break;

                case Tool.Rotate:
                    Quaternion quaternion = Handles.RotationHandle(PointEditor.s_EditingRotation, position2);
                    if (GUI.changed)
                    {
                        Vector3 vector3_1 = cloudTransform.InverseTransformPoint(position2);
                        using (List <int> .Enumerator enumerator = selection.GetEnumerator())
                        {
                            while (enumerator.MoveNext())
                            {
                                int current = enumerator.Current;
                                // ISSUE: reference to a compiler-generated field
                                Vector3 vector3_2 = pointsCAnonStorey40.points.GetPosition(current) - vector3_1;
                                Vector3 vector3_3 = Quaternion.Inverse(PointEditor.s_EditingRotation) * vector3_2;
                                Vector3 position4 = quaternion * vector3_3 + vector3_1;
                                // ISSUE: reference to a compiler-generated field
                                pointsCAnonStorey40.points.SetPosition(current, position4);
                            }
                        }
                        PointEditor.s_EditingRotation = quaternion;
                        return(true);
                    }
                    break;

                case Tool.Scale:
                    Vector3 vector3_4 = Handles.ScaleHandle(PointEditor.s_EditingScale, position2, Quaternion.identity, HandleUtility.GetHandleSize(position2));
                    if (GUI.changed)
                    {
                        Vector3 vector3_1 = cloudTransform.InverseTransformPoint(position2);
                        using (List <int> .Enumerator enumerator = selection.GetEnumerator())
                        {
                            while (enumerator.MoveNext())
                            {
                                int current = enumerator.Current;
                                // ISSUE: reference to a compiler-generated field
                                Vector3 position4 = pointsCAnonStorey40.points.GetPosition(current) - vector3_1;
                                position4.x /= PointEditor.s_EditingScale.x;
                                position4.y /= PointEditor.s_EditingScale.y;
                                position4.z /= PointEditor.s_EditingScale.z;
                                position4.x *= vector3_4.x;
                                position4.y *= vector3_4.y;
                                position4.z *= vector3_4.z;
                                position4   += vector3_1;
                                // ISSUE: reference to a compiler-generated field
                                pointsCAnonStorey40.points.SetPosition(current, position4);
                            }
                        }
                        PointEditor.s_EditingScale = vector3_4;
                        return(true);
                    }
                    break;
                }
            }
            return(false);
        }
示例#11
0
        internal static Quaternion DoRotationHandle(RotationHandleIds ids, Quaternion rotation, Vector3 position, RotationHandleParam param)
        {
            var evt        = Event.current;
            var camForward = Handles.inverseMatrix.MultiplyVector(Camera.current != null ? Camera.current.transform.forward : Vector3.forward);

            var size     = HandleUtility.GetHandleSize(position);
            var temp     = color;
            var isStatic = (!Tools.s_Hidden && EditorApplication.isPlaying && GameObjectUtility.ContainsStatic(Selection.gameObjects));

            var isHot = ids.Has(GUIUtility.hotControl);

            // Draw freerotation first to give it the lowest priority
            if (!isStatic &&
                param.ShouldShow(RotationHandleParam.Handle.XYZ) &&
                (isHot && ids.xyz == GUIUtility.hotControl || !isHot))
            {
                color    = centerColor;
                rotation = UnityEditorInternal.FreeRotate.Do(ids.xyz, rotation, position, size * param.xyzSize, param.displayXYZCircle);
            }

            var radiusOfAxesHandles = -1f;

            for (var i = 0; i < 3; ++i)
            {
                if (!param.ShouldShow(i))
                {
                    continue;
                }

                var axisColor = GetColorByAxis(i);
                color = isStatic ? Color.Lerp(axisColor, staticColor, staticBlend) : axisColor;
                color = ToActiveColorSpace(color);
                var axisDir = GetAxisVector(i);

                var radius = size * param.axisSize[i];
                radiusOfAxesHandles = Mathf.Max(radius, radiusOfAxesHandles);

                rotation = UnityEditorInternal.Disc.Do(ids[i], rotation, position, rotation * axisDir, radius, true, EditorSnapSettings.rotate, param.enableRayDrag, true, k_RotationPieColor);
            }

            if (radiusOfAxesHandles > 0 && evt.type == EventType.Repaint)
            {
                Handles.color = new Color(0, 0, 0, 0.2f);
                Handles.DrawWireDisc(position, camForward, radiusOfAxesHandles);
            }

            if (isHot && evt.type == EventType.Repaint)
            {
                color = ToActiveColorSpace(s_DisabledHandleColor);
                Handles.DrawWireDisc(position, camForward, size * param.axisSize[0]);
            }

            if (!isStatic &&
                param.ShouldShow(RotationHandleParam.Handle.CameraAxis) &&
                (isHot && ids.cameraAxis == GUIUtility.hotControl || !isHot))
            {
                color    = ToActiveColorSpace(centerColor);
                rotation = UnityEditorInternal.Disc.Do(ids.cameraAxis, rotation, position, camForward, size * param.cameraAxisSize, false, 0, param.enableRayDrag, true, k_RotationPieColor);
            }

            color = temp;
            return(rotation);
        }
示例#12
0
        public static void DrawDistanceGizmo(Vector3 anchor, Vector3 connectedAnchor, float distance)
        {
            Vector3 vector2    = anchor - connectedAnchor;
            Vector3 normalized = vector2.normalized;
            Vector3 end        = connectedAnchor + ((Vector3)(normalized * distance));
            Vector3 vector4    = (Vector3)(Vector3.Cross(normalized, Vector3.forward) * (HandleUtility.GetHandleSize(connectedAnchor) * 0.16f));

            Handles.color = Color.green;
            DrawAALine(anchor, end);
            DrawAALine(connectedAnchor + vector4, connectedAnchor - vector4);
            DrawAALine(end + vector4, end - vector4);
        }
示例#13
0
        private Vector3 EdgeHandle(Vector3 handlePos, Vector3 handleDir, Vector3 slideDir1, Vector3 slideDir2, Matrix4x4 transform)
        {
            Color color = Handles.color;
            bool  flag  = true;

            if ((bool)((UnityEngine.Object)Camera.current))
            {
                Vector3 vector3    = Handles.matrix.inverse.MultiplyPoint(Camera.current.transform.position);
                Vector3 normalized = (handlePos - vector3).normalized;
                if ((double)Mathf.Acos(Mathf.Abs(Vector3.Dot(Vector3.Cross(slideDir1, slideDir2), normalized))) > 1.51843643188477)
                {
                    flag = false;
                }
            }
            float alphaFactor = !flag ? 0.0f : 1f;

            this.AdjustEdgeHandleColor(handlePos, slideDir1, slideDir2, transform, alphaFactor);
            int controlId = GUIUtility.GetControlID(this.m_ControlIdHint, FocusType.Keyboard);

            if ((double)alphaFactor > 0.0)
            {
                handlePos = Slider2D.Do(controlId, handlePos, handleDir, slideDir1, slideDir2, HandleUtility.GetHandleSize(handlePos) * 0.03f, new Handles.DrawCapFunction(Handles.DotCap), SnapSettings.scale, true);
            }
            Handles.color = color;
            return(handlePos);
        }
示例#14
0
        // Ensure all controlIDs used in this OnGUI are permanent controlIDs so this method can be called
        // in different places for handling input early and rendering late.
        internal void OnGUI(SceneView view)
        {
            Rect  cameraGUIRect = view.cameraRect;
            float screenSize    = Mathf.Min(cameraGUIRect.width, cameraGUIRect.height);

            if (screenSize < kRotationSize)
            {
                return;
            }

            if (Event.current.type == EventType.Repaint)
            {
                Profiler.BeginSample("SceneView.AxisSelector");
            }

            HandleContextClick(view);

            // This is a pretty weird way of doing things, but it works, so...
            Camera cam = view.camera;

            HandleUtility.PushCamera(cam);
            if (cam.orthographic)
            {
                cam.orthographicSize = .5f;
            }

            cam.cullingMask        = 0;
            cam.transform.position = cam.transform.rotation * new Vector3(0, 0, -5);
            cam.clearFlags         = CameraClearFlags.Nothing;
            cam.nearClipPlane      = .1f;
            cam.farClipPlane       = 10;
            cam.fieldOfView        = view.m_Ortho.Fade(70, 0);

            SceneView.AddCursorRect(new Rect(cameraGUIRect.width - kRotationSize + kRotationMenuInset, kRotationMenuInset, kRotationSize - 2 * kRotationMenuInset, kRotationSize + 24 - kRotationMenuInset), MouseCursor.Arrow);

            Handles.SetCamera(new Rect(cameraGUIRect.width - kRotationSize, 0, kRotationSize, kRotationSize), cam);

            Handles.BeginGUI();

            DrawRotationLock(view);
            DrawLabels(view);

            Handles.EndGUI();

            // animate visibility of three axis widgets
            for (int i = 0; i < 3; ++i)
            {
                Vector3 direction = kDirectionRotations[i] * Vector3.forward;
                dirVisible[i].target = Mathf.Abs(Vector3.Dot(cam.transform.forward, direction)) < 0.9f;
            }

            float size = HandleUtility.GetHandleSize(Vector3.zero) * .2f;

            // Do axes behind the center one
            AxisSelectors(view, cam, size, -1.0f, styles.viewAxisLabelStyle);

            // Do center handle

            Color centerColor = Handles.centerColor;

            centerColor    = Color.Lerp(centerColor, Color.gray, faded2Dgray);
            centerColor.a *= fadedVisibility;
            if (centerColor.a <= 0.1f || view.isRotationLocked)
            {
                GUI.enabled = false;
            }

            Handles.color = centerColor;
            if (Handles.Button(m_CenterButtonControlID, Vector3.zero, Quaternion.identity, size * 0.8f, size, Handles.CubeHandleCap) && !view.in2DMode && !view.isRotationLocked)
            {
                if (Event.current.clickCount == 2)
                {
                    view.FrameSelected();
                }
                else
                {
                    // If middle-click or shift-click, choose a perspective view from a nice angle,
                    // similar to in Unity 3.5.
                    if (Event.current.shift || Event.current.button == 2)
                    {
                        ViewFromNiceAngle(view, true);
                    }
                    // Else, toggle perspective
                    else
                    {
                        ViewSetOrtho(view, !view.orthographic);
                    }
                }
            }

            // Do axes in front of the center one
            AxisSelectors(view, cam, size, 1.0f, styles.viewAxisLabelStyle);

            GUI.enabled = true;

            if (!view.in2DMode && !view.isRotationLocked)
            {
                // Swipe handling
                if (Event.current.type == EditorGUIUtility.swipeGestureEventType)
                {
                    // Get swipe dir as Vector3
                    Event   evt = Event.current;
                    Vector3 swipeDir;
                    if (evt.delta.y > 0)
                    {
                        swipeDir = Vector3.up;
                    }
                    else if (evt.delta.y < 0)
                    {
                        swipeDir = -Vector3.up;
                    }
                    else if (evt.delta.x < 0) // delta x inverted for some reason
                    {
                        swipeDir = Vector3.right;
                    }
                    else
                    {
                        swipeDir = -Vector3.right;
                    }

                    // Inverse swipe dir, so swiping down will go to top view etc.
                    // This is consistent with how we do orbiting, where moving the mouse down sees the object more from above etc.
                    // Also, make swipe dir point almost 45 degrees in towards the camera.
                    // This means the swipe will pick the closest axis in the swiped direction,
                    // instead of picking the one closest to being 90 degrees away.
                    Vector3 goalVector = -swipeDir - Vector3.forward * 0.9f;

                    // Transform swipe dir by camera transform, so up is camera's local up, etc.
                    goalVector = view.camera.transform.TransformDirection(goalVector);

                    // Get global axis that's closest to the swipe dir vector
                    float bestDotProduct = 0;
                    int   dir            = 0;
                    for (int i = 0; i < 6; i++)
                    {
                        // Note that kDirectionRotations are not the forward direction of each dir;
                        // it's the back direction *towards* the camera.
                        float dotProduct = Vector3.Dot(kDirectionRotations[i] * -Vector3.forward, goalVector);
                        if (dotProduct > bestDotProduct)
                        {
                            bestDotProduct = dotProduct;
                            dir            = i;
                        }
                    }

                    // Look along chosen axis
                    ViewAxisDirection(view, dir);
                    Event.current.Use();
                }
            }

            HandleUtility.PopCamera(cam);
            Handles.SetCamera(cam);

            if (Event.current.type == EventType.Repaint)
            {
                Profiler.EndSample();
            }
        }
        public override void OnSceneGUI(ParticleSystem s, InitialModuleUI initial)
        {
            Event     current   = Event.current;
            EventType eventType = current.type;

            if (current.type == EventType.Ignore && current.rawType == EventType.MouseUp)
            {
                eventType = current.rawType;
            }
            Color color  = Handles.color;
            Color color2 = new Color(1f, 1f, 1f, 0.5f);

            Handles.color = color2;
            if (this.m_Type.intValue == 0)
            {
                for (int i = 0; i < this.m_ShownPlanes.Length; i++)
                {
                    UnityEngine.Object objectReferenceValue = this.m_ShownPlanes[i].objectReferenceValue;
                    if (objectReferenceValue != null)
                    {
                        Transform transform = objectReferenceValue as Transform;
                        if (transform != null)
                        {
                            Vector3    position = transform.position;
                            Quaternion rotation = transform.rotation;
                            Vector3    axis     = rotation * Vector3.right;
                            Vector3    normal   = rotation * Vector3.up;
                            Vector3    axis2    = rotation * Vector3.forward;
                            if (object.ReferenceEquals(CollisionModuleUI.s_SelectedTransform, transform))
                            {
                                Tools.s_Hidden = true;
                                EditorGUI.BeginChangeCheck();
                                if (Tools.current == Tool.Move)
                                {
                                    transform.position = Handles.PositionHandle(position, rotation);
                                }
                                else if (Tools.current == Tool.Rotate)
                                {
                                    transform.rotation = Handles.RotationHandle(rotation, position);
                                }
                                if (EditorGUI.EndChangeCheck())
                                {
                                    if (this.m_PlaneVisualizationType == CollisionModuleUI.PlaneVizType.Solid)
                                    {
                                        GameObject plane = ParticleEffectUtils.GetPlane(i);
                                        plane.transform.position   = position;
                                        plane.transform.rotation   = rotation;
                                        plane.transform.localScale = new Vector3(this.m_ScaleGrid, this.m_ScaleGrid, this.m_ScaleGrid);
                                    }
                                    ParticleSystemEditorUtils.PerformCompleteResimulation();
                                }
                            }
                            else
                            {
                                int        keyboardControl = GUIUtility.keyboardControl;
                                float      num             = HandleUtility.GetHandleSize(position) * 0.06f;
                                Vector3    arg_1EB_0       = position;
                                Quaternion arg_1EB_1       = Quaternion.identity;
                                float      arg_1EB_2       = num;
                                Vector3    arg_1EB_3       = Vector3.zero;
                                if (CollisionModuleUI.< > f__mg$cache0 == null)
                                {
                                    CollisionModuleUI.< > f__mg$cache0 = new Handles.CapFunction(Handles.RectangleHandleCap);
                                }
                                Handles.FreeMoveHandle(arg_1EB_0, arg_1EB_1, arg_1EB_2, arg_1EB_3, CollisionModuleUI.< > f__mg$cache0);
                                if (eventType == EventType.MouseDown && current.type == EventType.Used && keyboardControl != GUIUtility.keyboardControl)
                                {
                                    CollisionModuleUI.s_SelectedTransform = transform;
                                    eventType = EventType.Used;
                                }
                            }
                            if (this.m_PlaneVisualizationType == CollisionModuleUI.PlaneVizType.Grid)
                            {
                                Color color3 = Handles.s_ColliderHandleColor * 0.9f;
                                if (!base.enabled)
                                {
                                    color3 = new Color(0.7f, 0.7f, 0.7f, 0.7f);
                                }
                                this.DrawGrid(position, axis, axis2, normal, color3, i);
                            }
                            else
                            {
                                this.DrawSolidPlane(position, rotation, i);
                            }
                        }
                        else
                        {
                            Debug.LogError("Not a transform: " + objectReferenceValue.GetType());
                        }
                    }
                }
            }
            Handles.color = color;
        }
示例#16
0
        private static Vector3 ResizeHandlesGUI(Rect rect, Vector3 pivot, Quaternion rotation, out Vector3 scalePivot)
        {
            if (Event.current.type == EventType.MouseDown)
            {
                RectTool.s_StartRect = rect;
            }
            scalePivot = pivot;
            Vector3    result    = Vector3.one;
            Quaternion rotation2 = Quaternion.Inverse(rotation);

            for (int i = 0; i <= 2; i++)
            {
                for (int j = 0; j <= 2; j++)
                {
                    if (i != 1 || j != 1)
                    {
                        Vector3 rectPointInWorld  = RectTool.GetRectPointInWorld(RectTool.s_StartRect, pivot, rotation, i, j);
                        Vector3 rectPointInWorld2 = RectTool.GetRectPointInWorld(rect, pivot, rotation, i, j);
                        float   num       = 0.05f * HandleUtility.GetHandleSize(rectPointInWorld2);
                        int     controlID = GUIUtility.GetControlID(RectTool.s_ResizeHandlesHash, FocusType.Passive);
                        if (GUI.color.a > 0f || GUIUtility.hotControl == controlID)
                        {
                            EditorGUI.BeginChangeCheck();
                            EventType type = Event.current.type;
                            Vector3   vector;
                            if (i == 1 || j == 1)
                            {
                                Vector3 sideVector = (i != 1) ? (rotation * Vector3.up * rect.height) : (rotation * Vector3.right * rect.width);
                                Vector3 direction  = (i != 1) ? (rotation * Vector3.right) : (rotation * Vector3.up);
                                vector = RectHandles.SideSlider(controlID, rectPointInWorld2, sideVector, direction, num, null, 0f);
                            }
                            else
                            {
                                Vector3 outwardsDir  = rotation * Vector3.right * (float)(i - 1);
                                Vector3 outwardsDir2 = rotation * Vector3.up * (float)(j - 1);
                                vector = RectHandles.CornerSlider(controlID, rectPointInWorld2, rotation * Vector3.forward, outwardsDir, outwardsDir2, num, new Handles.DrawCapFunction(RectHandles.RectScalingCap), Vector2.zero);
                            }
                            bool flag = Selection.transforms.Length == 1 && InternalEditorUtility.SupportsRectLayout(Selection.activeTransform) && Selection.activeTransform.parent.rotation == rotation;
                            if (flag)
                            {
                                Transform     activeTransform = Selection.activeTransform;
                                RectTransform component       = activeTransform.GetComponent <RectTransform>();
                                Transform     parent          = activeTransform.parent;
                                RectTransform component2      = parent.GetComponent <RectTransform>();
                                if (type == EventType.MouseDown && Event.current.type != EventType.MouseDown)
                                {
                                    RectTransformSnapping.CalculateOffsetSnapValues(parent, activeTransform, component2, component, i, j);
                                }
                            }
                            if (EditorGUI.EndChangeCheck())
                            {
                                ManipulationToolUtility.SetMinDragDifferenceForPos(rectPointInWorld2);
                                if (flag)
                                {
                                    Transform     parent2      = Selection.activeTransform.parent;
                                    RectTransform component3   = parent2.GetComponent <RectTransform>();
                                    Vector2       snapDistance = Vector2.one * HandleUtility.GetHandleSize(vector) * 0.05f;
                                    snapDistance.x /= (rotation2 * parent2.TransformVector(Vector3.right)).x;
                                    snapDistance.y /= (rotation2 * parent2.TransformVector(Vector3.up)).y;
                                    Vector3 vector2 = parent2.InverseTransformPoint(vector) - component3.rect.min;
                                    Vector3 vector3 = RectTransformSnapping.SnapToGuides(vector2, snapDistance) + Vector3.forward * vector2.z;
                                    ManipulationToolUtility.DisableMinDragDifferenceBasedOnSnapping(vector2, vector3);
                                    vector = parent2.TransformPoint(vector3 + component3.rect.min);
                                }
                                bool alt       = Event.current.alt;
                                bool actionKey = EditorGUI.actionKey;
                                bool flag2     = Event.current.shift && !actionKey;
                                if (!alt)
                                {
                                    scalePivot = RectTool.GetRectPointInWorld(RectTool.s_StartRect, pivot, rotation, 2 - i, 2 - j);
                                }
                                if (flag2)
                                {
                                    vector = Vector3.Project(vector - scalePivot, rectPointInWorld - scalePivot) + scalePivot;
                                }
                                Vector3 vector4 = rotation2 * (rectPointInWorld - scalePivot);
                                Vector3 vector5 = rotation2 * (vector - scalePivot);
                                if (i != 1)
                                {
                                    result.x = vector5.x / vector4.x;
                                }
                                if (j != 1)
                                {
                                    result.y = vector5.y / vector4.y;
                                }
                                if (flag2)
                                {
                                    float d = (i != 1) ? result.x : result.y;
                                    result = Vector3.one * d;
                                }
                                if (actionKey && i == 1)
                                {
                                    if (Event.current.shift)
                                    {
                                        result.x = (result.z = 1f / Mathf.Sqrt(Mathf.Max(result.y, 0.0001f)));
                                    }
                                    else
                                    {
                                        result.x = 1f / Mathf.Max(result.y, 0.0001f);
                                    }
                                }
                                if (flag2)
                                {
                                    float d2 = (i != 1) ? result.x : result.y;
                                    result = Vector3.one * d2;
                                }
                                if (actionKey && i == 1)
                                {
                                    if (Event.current.shift)
                                    {
                                        result.x = (result.z = 1f / Mathf.Sqrt(Mathf.Max(result.y, 0.0001f)));
                                    }
                                    else
                                    {
                                        result.x = 1f / Mathf.Max(result.y, 0.0001f);
                                    }
                                }
                                if (actionKey && j == 1)
                                {
                                    if (Event.current.shift)
                                    {
                                        result.y = (result.z = 1f / Mathf.Sqrt(Mathf.Max(result.x, 0.0001f)));
                                    }
                                    else
                                    {
                                        result.y = 1f / Mathf.Max(result.x, 0.0001f);
                                    }
                                }
                            }
                            if (i == 0)
                            {
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingLeft", type);
                            }
                            if (i == 2)
                            {
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingRight", type);
                            }
                            if (i != 1)
                            {
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingWidth", type);
                            }
                            if (j == 0)
                            {
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingBottom", type);
                            }
                            if (j == 2)
                            {
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingTop", type);
                            }
                            if (j != 1)
                            {
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingHeight", type);
                            }
                        }
                    }
                }
            }
            return(result);
        }
示例#17
0
            public override void OnToolGUI(EditorWindow window)
            {
                var firstTransform = SyncScenePlanes();

                if (m_ScenePlanes.Count == 0)
                {
                    return;
                }

                // Clear invalid selection (ie when selecting other system)
                if (s_SelectedTransform != null)
                {
                    if (!m_ScenePlanes.Contains(s_SelectedTransform))
                    {
                        s_SelectedTransform = null;
                    }
                }

                // Always try to select first collider if no selection exists
                if (s_SelectedTransform == null)
                {
                    s_SelectedTransform = firstTransform;
                }

                Event evt = Event.current;

                Color origCol   = Handles.color;
                Color col       = new Color(1, 1, 1, 0.5F);
                bool  isPlaying = EditorApplication.isPlaying;

                foreach (var transform in m_ScenePlanes)
                {
                    Vector3    position           = transform.position;
                    Quaternion rotation           = transform.rotation;
                    Vector3    right              = rotation * Vector3.right;
                    Vector3    up                 = rotation * Vector3.up;
                    Vector3    forward            = rotation * Vector3.forward;
                    bool       isPlayingAndStatic = isPlaying && transform.gameObject.isStatic;

                    if (ReferenceEquals(s_SelectedTransform, transform))
                    {
                        EditorGUI.BeginChangeCheck();
                        var newPosition = transform.position;
                        var newRotation = transform.rotation;

                        using (new EditorGUI.DisabledScope(isPlayingAndStatic))
                        {
                            if (isPlayingAndStatic)
                            {
                                Handles.ShowSceneViewLabel(position, Handles.s_StaticLabel);
                            }
                            Handles.TransformHandle(ref newPosition, ref newRotation);
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            Undo.RecordObject(transform, s_UndoCollisionPlaneString);
                            transform.position = newPosition;
                            transform.rotation = newRotation;
                            ParticleSystemEditorUtils.PerformCompleteResimulation();
                        }
                    }
                    else
                    {
                        float handleSize = HandleUtility.GetHandleSize(position) * 0.6f;

                        EventType oldEventType = evt.type;

                        // we want ignored mouse up events to check for dragging off of scene view
                        if (evt.type == EventType.Ignore && evt.rawType == EventType.MouseUp)
                        {
                            oldEventType = evt.rawType;
                        }

                        Handles.FreeMoveHandle(position, handleSize, Vector3.zero, Handles.RectangleHandleCap);

                        // Detect selected plane (similar to TreeEditor)
                        if (oldEventType == EventType.MouseDown && evt.type == EventType.Used)
                        {
                            s_SelectedTransform   = transform;
                            oldEventType          = EventType.Used;
                            GUIUtility.hotControl = 0; // Reset hot control or the FreeMoveHandle will prevent input to the new Handles. (case 873514)
                        }
                    }

                    Handles.color = col;
                    Color color = Handles.s_ColliderHandleColor * 0.9f;
                    if (isPlayingAndStatic)
                    {
                        color.a *= 0.2f;
                    }

                    if (m_PlaneVisualizationType == PlaneVizType.Grid)
                    {
                        DrawGrid(position, right, forward, up, color);
                    }
                    else
                    {
                        DrawSolidPlane(position, rotation, color, Color.yellow);
                    }
                }

                Handles.color = origCol;
            }
示例#18
0
        private static Vector3 PivotHandleGUI(Rect rect, Vector3 pivot, Quaternion rotation)
        {
            int       controlID      = GUIUtility.GetControlID(RectTool.s_PivotHandleHash, FocusType.Passive);
            EventType typeForControl = Event.current.GetTypeForControl(controlID);

            if (GUI.color.a > 0f || GUIUtility.hotControl == controlID)
            {
                EventType eventType = typeForControl;
                EditorGUI.BeginChangeCheck();
                Vector3 a = Handles.Slider2D(controlID, pivot, rotation * Vector3.forward, rotation * Vector3.right, rotation * Vector3.up, HandleUtility.GetHandleSize(pivot) * 0.1f, new Handles.DrawCapFunction(RectHandles.PivotCap), Vector2.zero);
                if (eventType == EventType.MouseDown && GUIUtility.hotControl == controlID)
                {
                    RectTransformSnapping.CalculatePivotSnapValues(rect, pivot, rotation);
                }
                if (EditorGUI.EndChangeCheck())
                {
                    Vector2 vector = Quaternion.Inverse(rotation) * (a - pivot);
                    vector.x /= rect.width;
                    vector.y /= rect.height;
                    Vector2 vector2      = new Vector2(-rect.x / rect.width, -rect.y / rect.height);
                    Vector2 vector3      = vector2 + vector;
                    Vector2 snapDistance = HandleUtility.GetHandleSize(pivot) * 0.05f * new Vector2(1f / rect.width, 1f / rect.height);
                    vector3   = RectTransformSnapping.SnapToGuides(vector3, snapDistance);
                    vector    = vector3 - vector2;
                    vector.x *= rect.width;
                    vector.y *= rect.height;
                    pivot    += rotation * vector;
                }
            }
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingPivot", typeForControl);
            return(pivot);
        }
示例#19
0
        internal void OnGUI(SceneView view)
        {
            int num = Mathf.Min(Screen.width, Screen.height);

            if (num < 100)
            {
                return;
            }
            if (Event.current.type == EventType.Repaint)
            {
                Profiler.BeginSample("SceneView.AxisSelector");
            }
            Camera camera = view.camera;

            HandleUtility.PushCamera(camera);
            if (camera.orthographic)
            {
                camera.orthographicSize = 0.5f;
            }
            camera.cullingMask        = 0;
            camera.transform.position = camera.transform.rotation * new Vector3(0f, 0f, -5f);
            camera.clearFlags         = CameraClearFlags.Nothing;
            camera.nearClipPlane      = 0.1f;
            camera.farClipPlane       = 10f;
            camera.fieldOfView        = view.m_Ortho.Fade(70f, 0f);
            SceneView.AddCursorRect(new Rect((float)(Screen.width - 100 + 22), 22f, 56f, 102f), MouseCursor.Arrow);
            Handles.SetCamera(new Rect((float)(Screen.width - 100), 0f, 100f, 100f), camera);
            Handles.BeginGUI();
            Rect rect = new Rect((float)(Screen.width - 100 + 17), 92f, 66f, 16f);

            if (!view.in2DMode && GUI.Button(rect, string.Empty, SceneViewRotation.styles.viewLabelStyleLeftAligned))
            {
                if (Event.current.button == 1)
                {
                    this.DisplayContextMenu(rect, view);
                }
                else
                {
                    this.ViewSetOrtho(view, !view.orthographic);
                }
            }
            int   num2     = 8;
            Rect  position = rect;
            float num3     = 0f;
            float num4     = 0f;

            for (int i = 0; i < SceneViewRotation.kDirNames.Length; i++)
            {
                if (i != num2)
                {
                    num4 += this.dirNameVisible[i].faded;
                    if (this.dirNameVisible[i].faded > 0f)
                    {
                        num3 += SceneViewRotation.styles.viewLabelStyleLeftAligned.CalcSize(EditorGUIUtility.TempContent(SceneViewRotation.kDirNames[i])).x *this.dirNameVisible[i].faded;
                    }
                }
            }
            if (num4 > 0f)
            {
                num3 /= num4;
            }
            position.x += 37f - num3 * 0.5f;
            position.x  = (float)Mathf.RoundToInt(position.x);
            int num5 = 0;

            while (num5 < this.dirNameVisible.Length && num5 < SceneViewRotation.kDirNames.Length)
            {
                if (num5 != num2)
                {
                    Color centerColor = Handles.centerColor;
                    centerColor.a *= this.dirNameVisible[num5].faded;
                    if (centerColor.a > 0f)
                    {
                        GUI.color = centerColor;
                        GUI.Label(position, SceneViewRotation.kDirNames[num5], SceneViewRotation.styles.viewLabelStyleLeftAligned);
                    }
                }
                num5++;
            }
            Color centerColor2 = Handles.centerColor;

            centerColor2.a *= this.faded2Dgray * this.m_Visible.faded;
            if (centerColor2.a > 0f)
            {
                GUI.color = centerColor2;
                GUI.Label(rect, SceneViewRotation.kDirNames[num2], SceneViewRotation.styles.viewLabelStyleCentered);
            }
            if (this.faded2Dgray < 1f)
            {
                this.DrawIsoStatusSymbol(new Vector3(position.x - 8f, position.y + 8.5f, 0f), view, 1f - this.faded2Dgray);
            }
            Handles.EndGUI();
            for (int j = 0; j < 3; j++)
            {
                Vector3 rhs = SceneViewRotation.kDirectionRotations[j] * Vector3.forward;
                this.dirVisible[j].target = (Mathf.Abs(Vector3.Dot(camera.transform.forward, rhs)) < 0.9f);
            }
            float num6 = HandleUtility.GetHandleSize(Vector3.zero) * 0.2f;

            this.AxisSelectors(view, camera, num6, -1f, SceneViewRotation.styles.viewAxisLabelStyle);
            Color color = Handles.centerColor;

            color    = Color.Lerp(color, Color.gray, this.faded2Dgray);
            color.a *= this.m_Visible.faded;
            if (color.a <= 0.1f)
            {
                GUI.enabled = false;
            }
            Handles.color = color;
            if (Handles.Button(Vector3.zero, Quaternion.identity, num6 * 0.8f, num6, new Handles.DrawCapFunction(Handles.CubeCap)) && !view.in2DMode)
            {
                if (Event.current.clickCount == 2)
                {
                    view.FrameSelected();
                }
                else
                {
                    if (Event.current.shift || Event.current.button == 2)
                    {
                        this.ViewFromNiceAngle(view, true);
                    }
                    else
                    {
                        this.ViewSetOrtho(view, !view.orthographic);
                    }
                }
            }
            this.AxisSelectors(view, camera, num6, 1f, SceneViewRotation.styles.viewAxisLabelStyle);
            GUI.enabled = true;
            if (!view.in2DMode && Event.current.type == EditorGUIUtility.swipeGestureEventType)
            {
                Event   current = Event.current;
                Vector3 a;
                if (current.delta.y > 0f)
                {
                    a = Vector3.up;
                }
                else
                {
                    if (current.delta.y < 0f)
                    {
                        a = -Vector3.up;
                    }
                    else
                    {
                        if (current.delta.x < 0f)
                        {
                            a = Vector3.right;
                        }
                        else
                        {
                            a = -Vector3.right;
                        }
                    }
                }
                Vector3 vector = -a - Vector3.forward * 0.9f;
                vector = view.camera.transform.TransformDirection(vector);
                float num7 = 0f;
                int   dir  = 0;
                for (int k = 0; k < 6; k++)
                {
                    float num8 = Vector3.Dot(SceneViewRotation.kDirectionRotations[k] * -Vector3.forward, vector);
                    if (num8 > num7)
                    {
                        num7 = num8;
                        dir  = k;
                    }
                }
                this.ViewAxisDirection(view, dir);
                Event.current.Use();
            }
            HandleUtility.PopCamera(camera);
            Handles.SetCamera(camera);
            if (Event.current.type == EventType.Repaint)
            {
                Profiler.EndSample();
            }
        }
        internal static void TransformHandle(TransformHandleIds ids, ref Vector3 position, ref Quaternion rotation, ref Vector3 scale, TransformHandleParam param)
        {
            var workingRotation = rotation;
            var pParam          = param.position;
            var rParam          = param.rotation;
            var sParam          = param.scale;

            var isHot         = ids.Has(GUIUtility.hotControl);
            var cameraAligned = (isHot && s_IsHotInCameraAlignedMode || !isHot && Event.current.shift);

            if (Tools.vertexDragging)
            {
                pParam = param.vertexSnappingPosition;
                rParam = param.vertexSnappingRotation;
                sParam = param.vertexSnappingScale;
            }
            else if (cameraAligned)
            {
                workingRotation = Camera.current.transform.rotation;

                pParam = param.cameraAlignedPosition;
                rParam = param.cameraAlignedRotation;
                sParam = param.cameraAlignedScale;
            }
            else if (Tools.pivotRotation == PivotRotation.Local)
            {
                pParam = param.localPosition;
                rParam = param.localRotation;
                sParam = param.localScale;
            }

            // Draw only the hot control
            if (ids.Has(GUIUtility.hotControl))
            {
                if (ids.position.Has(GUIUtility.hotControl))
                {
                    position = DoPositionHandle_Internal(ids.position, position, workingRotation, pParam);
                }
                else if (ids.rotation.Has(GUIUtility.hotControl))
                {
                    var endRotation = DoRotationHandle(ids.rotation, workingRotation, position, rParam);

                    if (cameraAligned)
                    {
                        // For camera aligned axis rotation, we need to store the initial rotation to rotate only the delta
                        if (!s_TransformHandle_RotationData.ContainsKey(ids.rotation))
                        {
                            s_TransformHandle_RotationData[ids.rotation] = new RotationHandleData
                            {
                                rotationStarted = true,
                                initialRotation = rotation
                            };
                        }

                        // For freemove rotation, we already have the delta rotation properly
                        var initialRotation = ids.rotation.xyz != GUIUtility.hotControl
                            ? s_TransformHandle_RotationData[ids.rotation].initialRotation
                            : rotation;
                        var     d = endRotation * Quaternion.Inverse(workingRotation);
                        float   angle;
                        Vector3 axis;
                        d.ToAngleAxis(out angle, out axis);
                        rotation = Quaternion.AngleAxis(angle, axis) * initialRotation;
                    }
                    else
                    {
                        rotation = endRotation;
                    }
                }
                else if (ids.scale.Has(GUIUtility.hotControl))
                {
                    scale = DoScaleHandle(ids.scale, scale, position, workingRotation, HandleUtility.GetHandleSize(position), sParam);
                }
            }
            else
            {
                if (s_TransformHandle_RotationData.ContainsKey(ids.rotation))
                {
                    var data = s_TransformHandle_RotationData[ids.rotation];
                    data.rotationStarted = false;
                    s_TransformHandle_RotationData[ids.rotation] = data;
                }

                // Drawing only
                DoRotationHandle(ids.rotation, workingRotation, position, rParam);
                // Draw scale position last so axes have priority
                DoPositionHandle_Internal(ids.position, position, workingRotation, pParam);
                DoScaleHandle(ids.scale, scale, position, workingRotation, HandleUtility.GetHandleSize(position), sParam);
            }

            var nowIsHot = ids.Has(GUIUtility.hotControl);

            if (nowIsHot && !isHot && cameraAligned)
            {
                s_IsHotInCameraAlignedMode = true;
            }
            else if (s_IsHotInCameraAlignedMode && (!isHot || !nowIsHot))
            {
                s_IsHotInCameraAlignedMode = false;
            }
        }
示例#21
0
 protected static Vector3 SnapToPoint(Vector3 position, Vector3 snapPosition, float snapDistance)
 {
     snapDistance = HandleUtility.GetHandleSize(position) * snapDistance;
     return((Vector3.Distance(position, snapPosition) > snapDistance) ? position : snapPosition);
 }