Esempio n. 1
0
 // Reset pose
 public static void ResetPose()
 {
     if (ms_rSprite != null)
     {
         if (ms_rSprite.IsInPosingMode == false)
         {
                             #if BEFORE_UNITY_4_3
             Undo.RegisterSceneUndo("Reset Pose : " + ms_rSprite);
                             #else
             Uni2DUndo.RegisterFullObjectHierarchyUndo(ms_rSprite.gameObject, "Reset Pose : " + ms_rSprite);
                             #endif
         }
         ms_rSprite.RestoreSkeletonPosePosition();
     }
 }
Esempio n. 2
0
    private void UpdatePoseEditGUI(Event a_rEvent)
    {
        //Transform rRootTransform = Selection.activeTransform;
        Vector2 f2MouseGUIPos = a_rEvent.mousePosition;

        if (a_rEvent.isMouse)
        {
            int iMouseButton = a_rEvent.button;

            switch (a_rEvent.type)
            {
            case EventType.MouseMove:
            {
                // Reset state
                m_bIsDragging = false;

                // Something selected, edit tool used => move bone
                if (Uni2DEditorSmoothBindingGUI.activeBone != null && ms_eEditorTool != BoneEditorTool.Select)
                {
                    Uni2DEditorSmoothBindingGUI.activeBone.MoveBoneAlongSpritePlane(f2MouseGUIPos - m_f2MouseGUIOffset, a_rEvent.alt);
                }

                // Consume event
                a_rEvent.Use( );
            }
            break;                      // End MouseMove

            case EventType.MouseDown:
            {
                // Left click
                if (iMouseButton == 0)
                {
                    // Reset drag state
                    m_bIsDragging = false;


                    // Selection
                    if (ms_eEditorTool == BoneEditorTool.Select)
                    {
                        // Pick bones in scene
                        BoneHandle             ePickedHandle;
                        Uni2DSmoothBindingBone rNearestBone = Uni2DEditorSmoothBindingUtils.PickNearestBoneInPosingMode(ms_rSprite, f2MouseGUIPos, out ePickedHandle, null);

                        // Outer disc => move
                        if (ePickedHandle == BoneHandle.OuterDisc || ePickedHandle == BoneHandle.Link)
                        {
                            if (rNearestBone != null)
                            {
                                // Change selection and editor tool
                                Uni2DEditorSmoothBindingGUI.activeBone = rNearestBone;
                                ms_eEditorTool = BoneEditorTool.Move;

                                m_f2MouseGUIOffset = f2MouseGUIPos - HandleUtility.WorldToGUIPoint(rNearestBone.transform.position);
                            }
                        }
                        else                                 // Bone picked via inner disc or no bone picked
                        {
                            // A bone has been picked (via inner disc)
                            // Set selection to this bone
                            if (rNearestBone != null)
                            {
                                Uni2DEditorSmoothBindingGUI.activeBone = rNearestBone;
                            }
                            else                                     // No bone picked
                            {
                                // Get rid of selection if any
                                if (Uni2DEditorSmoothBindingGUI.activeBone != null)
                                {
                                    Uni2DEditorSmoothBindingGUI.activeBone = null;
                                }
                                else                                         // no selection, no bone picked => create a new bone chain
                                {
                                    m_rLastAddedBone = null;

                                    // Create a new root and set it as current active bone
                                    Uni2DEditorSmoothBindingGUI.activeBone = Uni2DEditorSmoothBindingUtils.AddBoneToSprite(ms_rSprite, f2MouseGUIPos, null);
                                    m_rBoneChainOrigin = Uni2DEditorSmoothBindingGUI.activeBone;

                                    // The bone is not a child of a newly created root
                                    //m_bStartFromExistingBone = false;

                                    // Change editor tool
                                    ms_eEditorTool = BoneEditorTool.Create;
                                }
                            }
                        }
                    }                                   // end if( editor tool == select )
                }

                // Consume mouse event
                a_rEvent.Use( );
            }
            break;                      // end MouseDown

            case EventType.MouseDrag:
            {
                if (iMouseButton == 0)
                {
                    switch (ms_eEditorTool)
                    {
                    case BoneEditorTool.Move:
                    {
                        // Something dragged? MOVE IT
                        if (Uni2DEditorSmoothBindingGUI.activeBone != null)
                        {
                            // We're moving an existing bone => register undo at first drag event
                            if (m_bIsDragging == false)
                            {
                                                                                #if BEFORE_UNITY_4_3
                                Undo.SetSnapshotTarget(Uni2DEditorSmoothBindingGUI.activeBone, "Move Uni2D Bone");
                                Undo.CreateSnapshot( );
                                Undo.RegisterSnapshot( );
                                                                                #else
                                Uni2DUndo.RegisterFullObjectHierarchyUndo(ms_rSprite.gameObject, "Move Uni2D Bone");
                                                                                #endif
                            }

                            // Move/drag along sprite plane;
                            Uni2DEditorSmoothBindingGUI.activeBone.MoveBoneAlongSpritePlane(f2MouseGUIPos - m_f2MouseGUIOffset, a_rEvent.alt);
                        }
                        m_bIsDragging = true;
                    }
                    break;

                    case BoneEditorTool.Select:
                    {
                        // Dragging a bone in select mode == dragging on inner disc => add a child to active bone
                        if (Uni2DEditorSmoothBindingGUI.activeBone != null && m_bIsDragging == false)
                        {
                            m_rBoneChainOrigin = Uni2DEditorSmoothBindingGUI.activeBone;
                            m_rLastAddedBone   = null;
                            Uni2DEditorSmoothBindingGUI.activeBone = Uni2DEditorSmoothBindingUtils.AddBoneToSprite(ms_rSprite, f2MouseGUIPos, Uni2DEditorSmoothBindingGUI.activeBone);
                            //m_bStartFromExistingBone = true;
                            ms_eEditorTool = BoneEditorTool.Create;
                        }
                        m_bIsDragging = true;
                    }
                    break;

                    case BoneEditorTool.Create:
                    {
                        if (Uni2DEditorSmoothBindingGUI.activeBone != null)
                        {
                            Uni2DEditorSmoothBindingGUI.activeBone.MoveBoneAlongSpritePlane(f2MouseGUIPos);
                        }
                        m_bIsDragging = true;
                    }
                    break;
                    }
                }

                // Consume event
                a_rEvent.Use( );
            }
            break;                      // End MouseDrag

            case EventType.MouseUp:
            {
                if (iMouseButton == 0)
                {
                    switch (ms_eEditorTool)
                    {
                    // Creation
                    case BoneEditorTool.Create:
                    {
                        BoneHandle             ePickedHandle;
                        Uni2DSmoothBindingBone rNearestBone = Uni2DEditorSmoothBindingUtils.PickNearestBoneInPosingMode(ms_rSprite, f2MouseGUIPos, out ePickedHandle, Uni2DEditorSmoothBindingGUI.activeBone);

                        // Mouse up near the last added bone => close bone chain
                        if (ePickedHandle == BoneHandle.InnerDisc && rNearestBone == m_rLastAddedBone)
                        {
                            Uni2DEditorSmoothBindingUtils.DeleteBone(ms_rSprite, Uni2DEditorSmoothBindingGUI.activeBone);

                            m_rLastAddedBone = null;
                            Uni2DEditorSmoothBindingGUI.activeBone = null;
                            ms_eEditorTool = BoneEditorTool.Select;
                        }
                        else
                        {
                            m_rLastAddedBone = Uni2DEditorSmoothBindingGUI.activeBone;
                            Undo.RegisterCreatedObjectUndo(m_rLastAddedBone.gameObject, "Add Uni2D Bone");

                            // Creating => validate bone and create another one
                            Uni2DEditorSmoothBindingGUI.activeBone = Uni2DEditorSmoothBindingUtils.AddBoneToSprite(ms_rSprite, f2MouseGUIPos, m_rLastAddedBone);
                        }
                    }
                    break;

                    // Move
                    case BoneEditorTool.Move:
                    {
                                                                #if BEFORE_UNITY_4_3
                        Undo.ClearSnapshotTarget( );
                        Undo.RegisterSnapshot( );
                                                                #endif
                        ms_eEditorTool = BoneEditorTool.Select;
                    }
                    break;
                    }

                    // Reset dragging state
                    m_bIsDragging      = false;
                    m_f2MouseGUIOffset = Vector2.zero;
                }                               // end if( left button )
                else if (iMouseButton == 1)     // Delete / stop bone creation
                {
                    switch (ms_eEditorTool)
                    {
                    case BoneEditorTool.Select:
                    {
                        BoneHandle             eBoneHandle;
                        Uni2DSmoothBindingBone rNearestBone = Uni2DEditorSmoothBindingUtils.PickNearestBoneInPosingMode(ms_rSprite, f2MouseGUIPos, out eBoneHandle, null);

                        if (rNearestBone != null)
                        {
                            if (eBoneHandle == BoneHandle.Link)
                            {
                                //Undo.RegisterSetTransformParentUndo( rNearestBone.transform, rRootTransform, "Break Uni2D Bone" );
                                rNearestBone.Break( );
                            }
                            else
                            {
                                                                                #if BEFORE_UNITY_4_3
                                Undo.RegisterSceneUndo("Delete Uni2D Bone");
                                                                                #else
                                Uni2DUndo.RegisterFullObjectHierarchyUndo(ms_rSprite.gameObject, "Delete Uni2D Bone");
                                                                                #endif
                                Uni2DEditorSmoothBindingUtils.DeleteBone(ms_rSprite, rNearestBone);
                            }
                        }
                    }
                    break;

                    case BoneEditorTool.Create:
                    {
                        // Close bone chain
                        Uni2DEditorSmoothBindingUtils.DeleteBone(ms_rSprite, Uni2DEditorSmoothBindingGUI.activeBone);
                        ms_eEditorTool = BoneEditorTool.Select;
                    }
                    break;

                    case BoneEditorTool.Move:
                    {
                        ms_eEditorTool = BoneEditorTool.Select;
                    }
                    break;
                    }
                }                               // End if( right button )

                // Consume event
                a_rEvent.Use( );
            }
            break;      // End MouseUp
            }           // End switch( event.type )
        }               // end if( mouse events )
        else if (a_rEvent.isKey && a_rEvent.type == EventType.keyDown)
        {
            switch (a_rEvent.keyCode)
            {
            case KeyCode.Escape:
            {
                switch (ms_eEditorTool)
                {
                case BoneEditorTool.Select:
                {
                    if (Uni2DEditorSmoothBindingGUI.activeBone != null)
                    {
                        Uni2DEditorSmoothBindingGUI.activeBone = null;
                    }
                    else
                    {
                        Uni2DEditorSmoothBindingGUI.CurrentBoneEditMode = BoneEditMode.None;
                    }
                }
                break;

                case BoneEditorTool.Move:
                {
                                                        #if BEFORE_UNITY_4_3
                    Undo.RestoreSnapshot( );
                                                        #endif
                    ms_eEditorTool = BoneEditorTool.Select;
                }
                break;

                case BoneEditorTool.Create:
                {
                    Uni2DEditorSmoothBindingUtils.DeleteBone(ms_rSprite, Uni2DEditorSmoothBindingGUI.activeBone);
                    ms_eEditorTool = BoneEditorTool.Select;
                }
                break;
                }
                a_rEvent.Use( );
            }
            break;                      // End Escape

            // Delete last created bone (if any)
            case KeyCode.Backspace:
            {
                if (ms_eEditorTool == BoneEditorTool.Create)
                {
                    if (m_rLastAddedBone != null && m_rLastAddedBone != m_rBoneChainOrigin)
                    {
                                                        #if BEFORE_UNITY_4_3
                        Undo.RegisterSceneUndo("Delete Uni2D Bone");
                                                        #else
                        Uni2DUndo.RegisterFullObjectHierarchyUndo(ms_rSprite.gameObject, "Delete Uni2D Bone");
                                                        #endif
                        Uni2DEditorSmoothBindingUtils.DeleteBone(ms_rSprite, Uni2DEditorSmoothBindingGUI.activeBone);

                        Uni2DEditorSmoothBindingGUI.activeBone = Uni2DEditorSmoothBindingUtils.AddBoneToSprite(ms_rSprite, f2MouseGUIPos, m_rLastAddedBone.Parent);
                        Uni2DEditorSmoothBindingUtils.DeleteBone(ms_rSprite, m_rLastAddedBone);

                        Uni2DSmoothBindingBone rParentActiveBone = Uni2DEditorSmoothBindingGUI.activeBone.Parent;
                        if (rParentActiveBone != null && rParentActiveBone.IsFakeRootBone)
                        {
                            m_rLastAddedBone = rParentActiveBone.Parent;                                        // Grand-pa'
                        }
                        else
                        {
                            m_rLastAddedBone = rParentActiveBone;
                        }
                    }
                }
                a_rEvent.Use( );
            }
            break;                      // End Escape

            case KeyCode.Return:
            case KeyCode.KeypadEnter:
            {
                ms_eEditorTool = BoneEditorTool.Select;
                a_rEvent.Use( );
            }
            break;      // End Return / KeypadEnter
            }           // end switch( event.type )
        }               // end if( key down events )
        else
        {
            switch (a_rEvent.type)
            {
            case EventType.ValidateCommand:
            {
                if (a_rEvent.commandName == "Delete" || a_rEvent.commandName == "UndoRedoPerformed")
                {
                    a_rEvent.Use( );
                }
            }
            break;                      // end ValidateCommand

            case EventType.ExecuteCommand:
            {
                if (a_rEvent.commandName == "Delete")
                {
                    if (Uni2DEditorSmoothBindingGUI.activeBone != null && ms_eEditorTool != BoneEditorTool.Create)
                    {
                                                        #if BEFORE_UNITY_4_3
                        Undo.RegisterSceneUndo("Delete Uni2D Bone");
                                                        #else
                        Uni2DUndo.RegisterFullObjectHierarchyUndo(ms_rSprite.gameObject, "Delete Uni2D Bone");
                                                        #endif
                        Uni2DEditorSmoothBindingUtils.DeleteBone(ms_rSprite, Uni2DEditorSmoothBindingGUI.activeBone);
                        ms_eEditorTool = BoneEditorTool.Select;
                    }
                    a_rEvent.Use( );
                }
                else if (a_rEvent.commandName == "UndoRedoPerformed")
                {
                    if (ms_eEditorTool == BoneEditorTool.Create && Uni2DEditorSmoothBindingGUI.activeBone != null)
                    {
                        Uni2DEditorSmoothBindingUtils.DeleteBone(ms_rSprite, Uni2DEditorSmoothBindingGUI.activeBone);
                    }
                    m_rLastAddedBone = null;
                    Uni2DEditorSmoothBindingGUI.activeBone = null;
                    ms_eEditorTool = BoneEditorTool.Select;
                    //Uni2DEditorSmoothBindingGUI.CurrentBoneEditMode = BoneEditMode.None;

                    a_rEvent.Use( );
                }
            }
            break;      // end ExecuteCommand
            }           // end switch( event.type )
        }               // end else
    }
Esempio n. 3
0
    private void UpdateAnimEditGUI(Event a_rEvent)
    {
        Vector2 f2MouseGUIPos = a_rEvent.mousePosition;

        if (a_rEvent.isMouse)
        {
            int iMouseButton = a_rEvent.button;

            switch (a_rEvent.type)
            {
            case EventType.MouseMove:
            {
                // Reset state
                m_bIsDragging = false;

                // Consume event
                a_rEvent.Use( );
            }
            break;                      // End MouseMove

            case EventType.MouseDown:
            {
                // Left click
                if (iMouseButton == 0)
                {
                    // Reset drag state
                    m_bIsDragging = false;

                    // Pick bones in scene
                    BoneHandle             ePickedHandle;
                    Uni2DSmoothBindingBone rNearestBone = Uni2DEditorSmoothBindingUtils.PickNearestBoneInAnimMode(ms_rSprite, f2MouseGUIPos, out ePickedHandle, null);

                    // Selection
                    if (ms_eEditorTool == BoneEditorTool.Select && rNearestBone != null)
                    {
                        // Change selection and editor tool
                        Uni2DEditorSmoothBindingGUI.activeBone = rNearestBone;

                        m_f2MouseGUIOffset = f2MouseGUIPos - HandleUtility.WorldToGUIPoint(rNearestBone.transform.position);
                    }                                   // end if( editor tool == select )
                }

                // Consume mouse event
                a_rEvent.Use( );
            }
            break;                      // end MouseDown

            case EventType.MouseDrag:
            {
                if (iMouseButton == 0)
                {
                    switch (ms_eEditorTool)
                    {
                    case BoneEditorTool.Move:
                    {
                        // Something dragged? MOVE IT
                        if (Uni2DEditorSmoothBindingGUI.activeBone != null)
                        {
                            // We're moving an existing bone => register undo at first drag event
                            if (m_bIsDragging == false)
                            {
                                                                                #if BEFORE_UNITY_4_3
                                Undo.SetSnapshotTarget(Uni2DEditorSmoothBindingGUI.activeBone, "Move Uni2D Bone");
                                Undo.CreateSnapshot( );
                                Undo.RegisterSnapshot( );
                                                                                #else
                                Uni2DUndo.RegisterFullObjectHierarchyUndo(Uni2DEditorSmoothBindingGUI.activeBone.gameObject, "Move Uni2D Bone");
                                                                                #endif
                            }

                            // Move/drag along sprite plane
                            Uni2DEditorSmoothBindingGUI.activeBone.RotateBoneAlongSpritePlane(f2MouseGUIPos - m_f2MouseGUIOffset);
                        }
                        m_bIsDragging = true;
                    }
                    break;

                    case BoneEditorTool.Select:
                    {
                        // Dragging a bone in select mode == dragging on inner disc => add a child to active bone
                        if (Uni2DEditorSmoothBindingGUI.activeBone != null && m_bIsDragging == false)
                        {
                            ms_eEditorTool     = BoneEditorTool.Move;
                            m_f2MouseGUIOffset = f2MouseGUIPos - HandleUtility.WorldToGUIPoint(Uni2DEditorSmoothBindingGUI.activeBone.transform.position);

                            Uni2DEditorSmoothBindingGUI.activeBone.RotateBoneAlongSpritePlane(f2MouseGUIPos - m_f2MouseGUIOffset);
                        }
                        m_bIsDragging = true;
                    }
                    break;
                    }
                }

                // Consume event
                a_rEvent.Use( );
            }
            break;                      // End MouseDrag

            case EventType.MouseUp:
            {
                if (iMouseButton == 0)
                {
                    if (ms_eEditorTool == BoneEditorTool.Move)
                    {
                                                        #if BEFORE_UNITY_4_3
                        Undo.ClearSnapshotTarget( );
                        Undo.RegisterSnapshot( );
                                                        #endif
                        ms_eEditorTool = BoneEditorTool.Select;
                    }

                    // Reset dragging state
                    m_bIsDragging      = false;
                    m_f2MouseGUIOffset = Vector2.zero;
                }                                                                    // end if( left button )
                else if (iMouseButton == 1 && ms_eEditorTool == BoneEditorTool.Move) // Delete / stop bone creation
                {
                    ms_eEditorTool = BoneEditorTool.Select;
                }                               // End if( right button )

                // Consume event
                a_rEvent.Use( );
            }
            break;      // End MouseUp
            }           // End switch( event.type )
        }               // end if( mouse events )
        else if (a_rEvent.isKey && a_rEvent.type == EventType.keyDown)
        {
            switch (a_rEvent.keyCode)
            {
            case KeyCode.Escape:
            {
                switch (ms_eEditorTool)
                {
                case BoneEditorTool.Select:
                {
                    if (Uni2DEditorSmoothBindingGUI.activeBone != null)
                    {
                        Uni2DEditorSmoothBindingGUI.activeBone = null;
                    }
                    else
                    {
                        Uni2DEditorSmoothBindingGUI.CurrentBoneEditMode = BoneEditMode.None;
                    }
                }
                break;

                case BoneEditorTool.Move:
                {
                                                        #if BEFORE_UNITY_4_3
                    Undo.RestoreSnapshot( );
                                                        #endif
                    ms_eEditorTool = BoneEditorTool.Select;
                }
                break;
                }
                a_rEvent.Use( );
            }
            break;                      // End Escape

            case KeyCode.Return:
            case KeyCode.KeypadEnter:
            {
                ms_eEditorTool = BoneEditorTool.Select;
                a_rEvent.Use( );
            }
            break;      // End Return / KeypadEnter
            }           // end switch( event.type )
        }               // end if( key down events )
        else
        {
            switch (a_rEvent.type)
            {
            case EventType.ValidateCommand:
            {
                if (a_rEvent.commandName == "Delete" || a_rEvent.commandName == "UndoRedoPerformed")
                {
                    a_rEvent.Use( );
                }
            }
            break;                      // end ValidateCommand

            case EventType.ExecuteCommand:
            {
                if (a_rEvent.commandName == "Delete")
                {
                    a_rEvent.Use( );
                }
                else if (a_rEvent.commandName == "UndoRedoPerformed")
                {
                    Uni2DEditorSmoothBindingGUI.activeBone = null;
                    ms_eEditorTool = BoneEditorTool.Select;
                    //Uni2DEditorSmoothBindingGUI.CurrentBoneEditMode = BoneEditMode.None;
                    a_rEvent.Use( );
                }
            }
            break;      // end ExecuteCommand
            }           // end switch( event.type )
        }               // end else
    }