Exemplo n.º 1
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------
    void EventInfoViewField( Rect _rect, exSpriteAnimClip _animClip )
    {
        float maxHeight = _rect.height-3;
        Rect lastRect = new Rect( -100, _rect.y, 7, maxHeight );
        Rect curRect = new Rect( -100, _rect.y, 7, maxHeight );
        exSpriteAnimClip.EventInfo lastClicked = null;

        // NOTE: when editor.playing, the selectedFrameInfos will become invalid, don't know why :(
        bool selectedAreInvalid = true;
        foreach ( exSpriteAnimClip.EventInfo eventInfo in _animClip.eventInfos ) {

            if ( selectedEventInfos.IndexOf(eventInfo) != -1 )
                selectedAreInvalid = false;

            float at = _rect.x + (eventInfo.time / _animClip.length) * totalWidth;
            lastRect = curRect;
            curRect = new Rect( at - 4, _rect.y, 7, maxHeight );
            if ( exIntersection2D.RectRect( lastRect, curRect ) ) {
                curRect.height = Mathf.Max( lastRect.height - 5.0f, 10.0f );
            }
            exSpriteAnimClip.EventInfo clicked_ei = null;

            if ( at >= spriteAnimClipRect.x && at <= spriteAnimClipRect.xMax )
                clicked_ei = EventInfoField ( curRect, eventInfo );
            if ( clicked_ei != null )
                lastClicked = clicked_ei;
        }
        if ( selectedAreInvalid )
            selectedEventInfos.Clear();

        // ========================================================
        Event e = Event.current;
        // ========================================================

        if ( lastClicked != null ) {
            if ( e.command || e.control ) {
                ToggleSelected(lastClicked);
            }
            else {
                inDraggingEventInfoState = true;
                activeEventInfo = lastClicked;
                bool selected = selectedEventInfos.IndexOf(lastClicked) != -1;
                if ( selected == false ) {
                    if ( e.command == false && e.control == false ) {
                        selectedEventInfos.Clear();
                        AddSelected(lastClicked);
                    }
                }
            }

            e.Use();
            Repaint();
        }

        // ========================================================
        //
        // ========================================================

        if ( e.isMouse ) {
            if ( _rect.Contains(e.mousePosition) ) {
                // mouse down
                if ( e.type == EventType.MouseDown
                     && e.button == 0
                     && e.clickCount == 1 )
                {
                    GUIUtility.keyboardControl = -1; // remove any keyboard control
                    selectedFrameInfos.Clear();

                    mouseDownPos = e.mousePosition;
                    inRectSelectEventState = true;
                    UpdateSelectRect (mouseDownPos);
                    ConfirmRectSelectEventInfo();
                    Repaint();

                    e.Use();
                }

                // double click mouse down
                if ( e.type == EventType.MouseDown
                     && e.clickCount == 2
                     && e.command == false )
                {
                    // Undo.RegisterUndo(curEdit, "AddEventInfo"); // DISABLE
                    exSpriteAnimClip.EventInfo eventInfo = new exSpriteAnimClip.EventInfo();
                    eventInfo.time = curEdit.SnapToSeconds( ((e.mousePosition.x - _rect.x) * _animClip.length) / totalWidth );
                    _animClip.AddEvent(eventInfo);
                    EditorUtility.SetDirty(_animClip);
                    e.Use();
                }
            }
        }
    }
Exemplo n.º 2
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    void EventInfoViewField(Rect _rect, exSpriteAnimClip _animClip)
    {
        float maxHeight = _rect.height - 3;
        Rect  lastRect  = new Rect(-100, _rect.y, 7, maxHeight);
        Rect  curRect   = new Rect(-100, _rect.y, 7, maxHeight);

        exSpriteAnimClip.EventInfo lastClicked = null;

        // NOTE: when editor.playing, the selectedFrameInfos will become invalid, don't know why :(
        bool selectedAreInvalid = true;

        foreach (exSpriteAnimClip.EventInfo eventInfo in _animClip.eventInfos)
        {
            if (selectedEventInfos.IndexOf(eventInfo) != -1)
            {
                selectedAreInvalid = false;
            }

            float at = _rect.x + (eventInfo.time / _animClip.length) * totalWidth;
            lastRect = curRect;
            curRect  = new Rect(at - 4, _rect.y, 7, maxHeight);
            if (exIntersection2D.RectRect(lastRect, curRect))
            {
                curRect.height = Mathf.Max(lastRect.height - 5.0f, 10.0f);
            }
            exSpriteAnimClip.EventInfo clicked_ei = null;

            if (at >= spriteAnimClipRect.x && at <= spriteAnimClipRect.xMax)
            {
                clicked_ei = EventInfoField(curRect, eventInfo);
            }
            if (clicked_ei != null)
            {
                lastClicked = clicked_ei;
            }
        }
        if (selectedAreInvalid)
        {
            selectedEventInfos.Clear();
        }

        // ========================================================
        Event e = Event.current;

        // ========================================================

        if (lastClicked != null)
        {
            if (e.command || e.control)
            {
                ToggleSelected(lastClicked);
            }
            else
            {
                inDraggingEventInfoState = true;
                activeEventInfo          = lastClicked;
                bool selected = selectedEventInfos.IndexOf(lastClicked) != -1;
                if (selected == false)
                {
                    if (e.command == false && e.control == false)
                    {
                        selectedEventInfos.Clear();
                        AddSelected(lastClicked);
                    }
                }
            }

            e.Use();
            Repaint();
        }

        // ========================================================
        //
        // ========================================================

        if (e.isMouse)
        {
            if (_rect.Contains(e.mousePosition))
            {
                // mouse down
                if (e.type == EventType.MouseDown &&
                    e.button == 0 &&
                    e.clickCount == 1)
                {
                    GUIUtility.keyboardControl = -1; // remove any keyboard control
                    selectedFrameInfos.Clear();

                    mouseDownPos           = e.mousePosition;
                    inRectSelectEventState = true;
                    UpdateSelectRect(mouseDownPos);
                    ConfirmRectSelectEventInfo();
                    Repaint();

                    e.Use();
                }

                // double click mouse down
                if (e.type == EventType.MouseDown &&
                    e.clickCount == 2 &&
                    e.command == false)
                {
                    // Undo.RegisterUndo(curEdit, "AddEventInfo"); // DISABLE
                    exSpriteAnimClip.EventInfo eventInfo = new exSpriteAnimClip.EventInfo();
                    eventInfo.time = curEdit.SnapToSeconds(((e.mousePosition.x - _rect.x) * _animClip.length) / totalWidth);
                    _animClip.AddEvent(eventInfo);
                    EditorUtility.SetDirty(_animClip);
                    e.Use();
                }
            }
        }
    }