internal static void DoBuiltinToolSettings(Rect rect, GUIStyle buttonLeftStyle, GUIStyle buttonRightStyle)
        {
            GUI.SetNextControlName("ToolbarToolPivotPositionButton");
            Tools.pivotMode = (PivotMode)EditorGUI.CycleButton(new Rect(rect.x, rect.y, rect.width / 2, rect.height), (int)Tools.pivotMode, s_PivotIcons, buttonLeftStyle);
            if (Tools.current == Tool.Scale && Selection.transforms.Length < 2)
            {
                GUI.enabled = false;
            }
            GUI.SetNextControlName("ToolbarToolPivotOrientationButton");
            PivotRotation tempPivot = (PivotRotation)EditorGUI.CycleButton(new Rect(rect.x + rect.width / 2, rect.y, rect.width / 2, rect.height), (int)Tools.pivotRotation, s_PivotRotation, buttonRightStyle);

            if (Tools.pivotRotation != tempPivot)
            {
                Tools.pivotRotation = tempPivot;
                if (tempPivot == PivotRotation.Global)
                {
                    Tools.ResetGlobalHandleRotation();
                }
            }

            if (Tools.current == Tool.Scale)
            {
                GUI.enabled = true;
            }

            if (GUI.changed)
            {
                Tools.RepaintAllToolViews();
            }
        }
示例#2
0
        private void DoPivotButtons(Rect rect)
        {
            Tools.pivotMode = (PivotMode)EditorGUI.CycleButton(new Rect(rect.x, rect.y, rect.width / 2f, rect.height), (int)Tools.pivotMode, Toolbar.s_PivotIcons, "ButtonLeft");
            if (Tools.current == Tool.Scale && Selection.transforms.Length < 2)
            {
                GUI.enabled = false;
            }
            PivotRotation pivotRotation = (PivotRotation)EditorGUI.CycleButton(new Rect(rect.x + rect.width / 2f, rect.y, rect.width / 2f, rect.height), (int)Tools.pivotRotation, Toolbar.s_PivotRotation, "ButtonRight");

            if (Tools.pivotRotation != pivotRotation)
            {
                Tools.pivotRotation = pivotRotation;
                if (pivotRotation == PivotRotation.Global)
                {
                    Tools.ResetGlobalHandleRotation();
                }
            }
            if (Tools.current == Tool.Scale)
            {
                GUI.enabled = true;
            }
            if (GUI.changed)
            {
                Tools.RepaintAllToolViews();
            }
        }
        void DoToolButtons(Rect rect)
        {
            const int builtinIconsLength = 6;

            // Handle temporary override with ALT
            GUI.changed = false;

            int displayTool = Tools.viewToolActive ? 0 : (int)Tools.current;

            for (int i = 1; i < builtinIconsLength; i++)
            {
                s_ShownToolIcons[i]         = s_ToolIcons[i - 1 + (i == displayTool ? s_ShownToolIcons.Length - 1 : 0)];
                s_ShownToolIcons[i].tooltip = s_ToolIcons[i - 1].tooltip;
            }

            var lastCustomTool = EditorToolContext.GetLastCustomTool();

            if (lastCustomTool != null)
            {
                s_ShownToolIcons[builtinIconsLength] = lastCustomTool.toolbarIcon ?? s_CustomToolIcon;
            }
            else
            {
                s_ShownToolIcons[builtinIconsLength] = s_CustomToolIcon;
            }

            s_ShownToolIcons[0] = s_ViewToolIcons[(int)Tools.viewTool + (displayTool == 0 ? s_ViewToolOnOffset : 0)];

            displayTool = GUI.Toolbar(rect, displayTool, s_ShownToolIcons, s_ToolControlNames, Styles.command, GUI.ToolbarButtonSize.FitToContents);

            if (GUI.changed)
            {
                var evt = Event.current;

                if (displayTool == (int)Tool.Custom &&
                    (
                        EditorToolContext.GetLastCustomTool() == null ||
                        evt.button == 1 ||
                        (evt.button == 0 && evt.modifiers == EventModifiers.Alt))
                    )
                {
                    EditorToolGUI.DoToolContextMenu();
                }
                else
                {
                    Tools.current = (Tool)displayTool;
                    Tools.ResetGlobalHandleRotation();
                }
            }
        }
示例#4
0
        protected override void ToolGUI(SceneView view, Vector3 handlePosition, bool isStatic)
        {
            if (Tools.pivotRotation == PivotRotation.Global && Event.current.GetTypeForControl(GUIUtility.hotControl) == EventType.MouseUp)
            {
                Tools.ResetGlobalHandleRotation();
            }

            Quaternion before = Tools.handleRotation;

            EditorGUI.BeginChangeCheck();
            Quaternion after = Handles.RotationHandle(before, handlePosition);

            if (EditorGUI.EndChangeCheck() && !isStatic)
            {
                Quaternion delta = Quaternion.Inverse(before) * after;
                float      angle;
                Vector3    axis;
                delta.ToAngleAxis(out angle, out axis);

                Undo.RecordObjects(Selection.transforms, "Rotate");
                foreach (Transform t in Selection.transforms)
                {
                    // Rotate around handlePosition (Global or Local axis).
                    if (Tools.pivotMode == PivotMode.Center)
                    {
                        t.RotateAround(handlePosition, before * axis, angle);
                    }
                    // Local rotation (Pivot mode with Local axis).
                    else if (TransformManipulator.individualSpace)
                    {
                        t.Rotate(t.rotation * axis, angle, Space.World);
                    }
                    // Pivot mode with Global axis.
                    else
                    {
                        t.Rotate(before * axis, angle, Space.World);
                    }

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

                    if (t.parent != null)
                    {
                        t.SendTransformChangedScale(); // force scale update, needed if tr has non-uniformly scaled parent.
                    }
                }
                Tools.handleRotation = after;
            }
        }
示例#5
0
        private void DoToolButtons(Rect rect)
        {
            GUI.changed = false;
            int num = (int)((!Tools.viewToolActive) ? Tools.current : Tool.View);

            for (int i = 1; i < 5; i++)
            {
                Toolbar.s_ShownToolIcons[i]         = Toolbar.s_ToolIcons[i - 1 + ((i != num) ? 0 : 4)];
                Toolbar.s_ShownToolIcons[i].tooltip = Toolbar.s_ToolIcons[i - 1].tooltip;
            }
            Toolbar.s_ShownToolIcons[0] = Toolbar.s_ViewToolIcons[(int)(Tools.viewTool + ((num != 0) ? 0 : 4))];
            num = GUI.Toolbar(rect, num, Toolbar.s_ShownToolIcons, "Command");
            if (GUI.changed)
            {
                Tools.current = (Tool)num;
                Tools.ResetGlobalHandleRotation();
            }
        }
示例#6
0
        private void DoToolButtons()
        {
            GUI.changed = false;
            int num = (int)((!Tools.viewToolActive) ? Tools.current : Tool.View);

            for (int i = 1; i < 5; i++)
            {
                Toolbar.s_ShownToolIcons[i]         = Toolbar.s_ToolIcons[i - 1 + ((i != num) ? 0 : 4)];
                Toolbar.s_ShownToolIcons[i].tooltip = Toolbar.s_ToolIcons[i - 1].tooltip;
            }
            Toolbar.s_ShownToolIcons[0] = Toolbar.s_ViewToolIcons[(int)(Tools.viewTool + ((num != 0) ? 0 : 4))];
            num = GUI.Toolbar(new Rect(10f, 5f, 160f, 24f), num, Toolbar.s_ShownToolIcons, "Command");
            if (GUI.changed)
            {
                Tools.current = (Tool)num;
            }
            Tools.pivotMode = (PivotMode)EditorGUI.CycleButton(new Rect(190f, 8f, 64f, 18f), (int)Tools.pivotMode, Toolbar.s_PivotIcons, "ButtonLeft");
            if (Tools.current == Tool.Scale && Selection.transforms.Length < 2)
            {
                GUI.enabled = false;
            }
            PivotRotation pivotRotation = (PivotRotation)EditorGUI.CycleButton(new Rect(254f, 8f, 64f, 18f), (int)Tools.pivotRotation, Toolbar.s_PivotRotation, "ButtonRight");

            if (Tools.pivotRotation != pivotRotation)
            {
                Tools.pivotRotation = pivotRotation;
                if (pivotRotation == PivotRotation.Global)
                {
                    Tools.ResetGlobalHandleRotation();
                }
            }
            if (Tools.current == Tool.Scale)
            {
                GUI.enabled = true;
            }
            if (GUI.changed)
            {
                Tools.RepaintAllToolViews();
            }
        }
示例#7
0
        void DoToolButtons(Rect rect)
        {
            // Handle temporary override with ALT
            GUI.changed = false;

            int displayTool = Tools.viewToolActive ? 0 : (int)Tools.current;

            // Change the icon to match the correct view tool
            for (int i = 1; i < s_ShownToolIcons.Length; i++)
            {
                s_ShownToolIcons[i]         = s_ToolIcons[i - 1 + (i == displayTool ? s_ShownToolIcons.Length - 1 : 0)];
                s_ShownToolIcons[i].tooltip = s_ToolIcons[i - 1].tooltip;
            }
            s_ShownToolIcons[0] = s_ViewToolIcons[(int)Tools.viewTool + (displayTool == 0 ? s_ShownToolIcons.Length - 1 : 0)];

            displayTool = GUI.Toolbar(rect, displayTool, s_ShownToolIcons, s_ToolControlNames, "Command", GUI.ToolbarButtonSize.FitToContents);
            if (GUI.changed)
            {
                Tools.current = (Tool)displayTool;
                Tools.ResetGlobalHandleRotation();
            }
        }
示例#8
0
        internal static void ControlsHack()
        {
            Event current = Event.current;

            if (Tools.kViewKey.activated)
            {
                Tools.current = Tool.View;
                Tools.ResetGlobalHandleRotation();
                current.Use();
                if (Toolbar.get)
                {
                    Toolbar.get.Repaint();
                }
                else
                {
                    Debug.LogError("Press Play twice for sceneview keyboard shortcuts to work");
                }
            }
            if (Tools.kMoveKey.activated)
            {
                Tools.current = Tool.Move;
                Tools.ResetGlobalHandleRotation();
                current.Use();
                if (Toolbar.get)
                {
                    Toolbar.get.Repaint();
                }
                else
                {
                    Debug.LogError("Press Play twice for sceneview keyboard shortcuts to work");
                }
            }
            if (Tools.kRotateKey.activated)
            {
                Tools.current = Tool.Rotate;
                Tools.ResetGlobalHandleRotation();
                current.Use();
                if (Toolbar.get)
                {
                    Toolbar.get.Repaint();
                }
                else
                {
                    Debug.LogError("Press Play twice for sceneview keyboard shortcuts to work");
                }
            }
            if (Tools.kScaleKey.activated)
            {
                Tools.current = Tool.Scale;
                Tools.ResetGlobalHandleRotation();
                current.Use();
                if (Toolbar.get)
                {
                    Toolbar.get.Repaint();
                }
                else
                {
                    Debug.LogError("Press Play twice for sceneview keyboard shortcuts to work");
                }
            }
            if (Tools.kRectKey.activated)
            {
                Tools.current = Tool.Rect;
                Tools.ResetGlobalHandleRotation();
                current.Use();
                if (Toolbar.get)
                {
                    Toolbar.get.Repaint();
                }
                else
                {
                    Debug.LogError("Press Play twice for sceneview keyboard shortcuts to work");
                }
            }
            if (Tools.kPivotMode.activated)
            {
                Tools.pivotMode = PivotMode.Pivot - (int)Tools.pivotMode;
                Tools.ResetGlobalHandleRotation();
                current.Use();
                Tools.RepaintAllToolViews();
            }
            if (Tools.kPivotRotation.activated)
            {
                Tools.pivotRotation = PivotRotation.Global - (int)Tools.pivotRotation;
                Tools.ResetGlobalHandleRotation();
                current.Use();
                Tools.RepaintAllToolViews();
            }
        }
示例#9
0
 internal static void OnSelectionChange()
 {
     Tools.ResetGlobalHandleRotation();
     Tools.localHandleOffset = Vector3.zero;
 }