UnityEditor.Tools.GetHandlePosition C# (CSharp) Method

GetHandlePosition() static private method

static private GetHandlePosition ( ) : Vector3
return Vector3
        internal static Vector3 GetHandlePosition()
        {
            Transform activeTransform = Selection.activeTransform;
            if (activeTransform == null)
            {
                return new Vector3(float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity);
            }
            Vector3 vector2 = handleOffset + (handleRotation * localHandleOffset);
            PivotMode pivotMode = get.m_PivotMode;
            if (pivotMode != PivotMode.Center)
            {
                if (pivotMode != PivotMode.Pivot)
                {
                    return new Vector3(float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity);
                }
            }
            else
            {
                if (current == Tool.Rect)
                {
                    return (((Vector3) (handleRotation * InternalEditorUtility.CalculateSelectionBoundsInSpace(Vector3.zero, handleRotation, rectBlueprintMode).center)) + vector2);
                }
                return (InternalEditorUtility.CalculateSelectionBounds(true, false).center + vector2);
            }
            if (((current == Tool.Rect) && rectBlueprintMode) && InternalEditorUtility.SupportsRectLayout(activeTransform))
            {
                return (activeTransform.parent.TransformPoint(new Vector3(activeTransform.localPosition.x, activeTransform.localPosition.y, 0f)) + vector2);
            }
            return (activeTransform.position + vector2);
        }

Usage Example

示例#1
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 vector5 = RectTool.MoveHandlesGUI(handleRect, handlePosition, handleRectRotation);

            if (EditorGUI.EndChangeCheck() && !isStatic)
            {
                if (GridSnapping.active)
                {
                    vector5 = GridSnapping.Snap(vector5);
                }
                if (TransformManipulator.HandleHasMoved(vector5))
                {
                    TransformManipulator.SetPositionDelta(vector5, TransformManipulator.mouseDownHandlePosition);
                }
            }
            TransformManipulator.EndManipulationHandling();
            GUI.color = color;
        }
All Usage Examples Of UnityEditor.Tools::GetHandlePosition