コード例 #1
0
        public void EventLineContextMenuEdit(object obj)
        {
            EventLineContextMenuObject obj2 = (EventLineContextMenuObject)obj;

            AnimationEventPopup.Edit(obj2.m_Animated, obj2.m_Clip, obj2.m_Index, this.m_Owner);
            this.Select(obj2.m_Clip, obj2.m_Index);
        }
コード例 #2
0
        public void EventLineGUI(Rect rect, AnimationWindowState state)
        {
            AnimationClip activeAnimationClip  = state.activeAnimationClip;
            GameObject    activeRootGameObject = state.activeRootGameObject;

            if (activeRootGameObject == null)
            {
                return;
            }
            GUI.BeginGroup(rect);
            Color color = GUI.color;
            Rect  rect2 = new Rect(0f, 0f, rect.width, rect.height);
            float time  = Mathf.Max((float)Mathf.RoundToInt(state.PixelToTime(Event.current.mousePosition.x, rect) * state.frameRate) / state.frameRate, 0f);

            if (activeAnimationClip != null)
            {
                AnimationEvent[] animationEvents = AnimationUtility.GetAnimationEvents(activeAnimationClip);
                Texture          image           = EditorGUIUtility.IconContent("Animation.EventMarker").image;
                Rect[]           array           = new Rect[animationEvents.Length];
                Rect[]           array2          = new Rect[animationEvents.Length];
                int num  = 1;
                int num2 = 0;
                for (int i = 0; i < animationEvents.Length; i++)
                {
                    AnimationEvent animationEvent = animationEvents[i];
                    if (num2 == 0)
                    {
                        num = 1;
                        while (i + num < animationEvents.Length && animationEvents[i + num].time == animationEvent.time)
                        {
                            num++;
                        }
                        num2 = num;
                    }
                    num2--;
                    float num3 = Mathf.Floor(state.FrameToPixel(animationEvent.time * activeAnimationClip.frameRate, rect));
                    int   num4 = 0;
                    if (num > 1)
                    {
                        float num5 = (float)Mathf.Min((num - 1) * (image.width - 1), (int)(state.FrameDeltaToPixel(rect) - (float)(image.width * 2)));
                        num4 = Mathf.FloorToInt(Mathf.Max(0f, num5 - (float)((image.width - 1) * num2)));
                    }
                    Rect rect3 = new Rect(num3 + (float)num4 - (float)(image.width / 2), (rect.height - 10f) * (float)(num2 - num + 1) / (float)Mathf.Max(1, num - 1), (float)image.width, (float)image.height);
                    array[i]  = rect3;
                    array2[i] = rect3;
                }
                if (this.m_DirtyTooltip)
                {
                    if (this.m_HoverEvent >= 0 && this.m_HoverEvent < array.Length)
                    {
                        this.m_InstantTooltipText  = AnimationEventPopup.FormatEvent(activeRootGameObject, animationEvents[this.m_HoverEvent]);
                        this.m_InstantTooltipPoint = new Vector2(array[this.m_HoverEvent].xMin + (float)((int)(array[this.m_HoverEvent].width / 2f)) + rect.x - 30f, rect.yMax);
                    }
                    this.m_DirtyTooltip = false;
                }
                if (this.m_EventsSelected == null || this.m_EventsSelected.Length != animationEvents.Length)
                {
                    this.m_EventsSelected = new bool[animationEvents.Length];
                    AnimationEventPopup.ClosePopup();
                }
                Vector2        zero = Vector2.zero;
                int            num6;
                float          num7;
                float          num8;
                HighLevelEvent highLevelEvent = EditorGUIExt.MultiSelection(rect, array2, new GUIContent(image), array, ref this.m_EventsSelected, null, out num6, out zero, out num7, out num8, GUIStyle.none);
                if (highLevelEvent != HighLevelEvent.None)
                {
                    switch (highLevelEvent)
                    {
                    case HighLevelEvent.DoubleClick:
                        if (num6 != -1)
                        {
                            AnimationEventPopup.Edit(activeRootGameObject, state.activeAnimationClip, num6, this.m_Owner);
                        }
                        else
                        {
                            this.EventLineContextMenuAdd(new AnimationEventTimeLine.EventLineContextMenuObject(activeRootGameObject, activeAnimationClip, time, -1));
                        }
                        break;

                    case HighLevelEvent.ContextClick:
                    {
                        GenericMenu genericMenu = new GenericMenu();
                        AnimationEventTimeLine.EventLineContextMenuObject userData = new AnimationEventTimeLine.EventLineContextMenuObject(activeRootGameObject, activeAnimationClip, animationEvents[num6].time, num6);
                        genericMenu.AddItem(new GUIContent("Edit Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuEdit), userData);
                        genericMenu.AddItem(new GUIContent("Add Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuAdd), userData);
                        genericMenu.AddItem(new GUIContent("Delete Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuDelete), userData);
                        genericMenu.ShowAsContext();
                        this.m_InstantTooltipText = null;
                        this.m_DirtyTooltip       = true;
                        state.Repaint();
                        break;
                    }

                    case HighLevelEvent.BeginDrag:
                        this.m_EventsAtMouseDown = animationEvents;
                        this.m_EventTimes        = new float[animationEvents.Length];
                        for (int j = 0; j < animationEvents.Length; j++)
                        {
                            this.m_EventTimes[j] = animationEvents[j].time;
                        }
                        break;

                    case HighLevelEvent.Drag:
                    {
                        for (int k = animationEvents.Length - 1; k >= 0; k--)
                        {
                            if (this.m_EventsSelected[k])
                            {
                                AnimationEvent animationEvent2 = this.m_EventsAtMouseDown[k];
                                animationEvent2.time = this.m_EventTimes[k] + zero.x * state.PixelDeltaToTime(rect);
                                animationEvent2.time = Mathf.Max(0f, animationEvent2.time);
                                animationEvent2.time = (float)Mathf.RoundToInt(animationEvent2.time * activeAnimationClip.frameRate) / activeAnimationClip.frameRate;
                            }
                        }
                        int[] array3 = new int[this.m_EventsSelected.Length];
                        for (int l = 0; l < array3.Length; l++)
                        {
                            array3[l] = l;
                        }
                        Array.Sort(this.m_EventsAtMouseDown, array3, new AnimationEventTimeLine.EventComparer());
                        bool[]  array4 = (bool[])this.m_EventsSelected.Clone();
                        float[] array5 = (float[])this.m_EventTimes.Clone();
                        for (int m = 0; m < array3.Length; m++)
                        {
                            this.m_EventsSelected[m] = array4[array3[m]];
                            this.m_EventTimes[m]     = array5[array3[m]];
                        }
                        Undo.RegisterCompleteObjectUndo(activeAnimationClip, "Move Event");
                        AnimationUtility.SetAnimationEvents(activeAnimationClip, this.m_EventsAtMouseDown);
                        this.m_DirtyTooltip = true;
                        break;
                    }

                    case HighLevelEvent.Delete:
                        this.DeleteEvents(activeAnimationClip, this.m_EventsSelected);
                        break;

                    case HighLevelEvent.SelectionChanged:
                        state.ClearKeySelections();
                        if (num6 != -1)
                        {
                            AnimationEventPopup.UpdateSelection(activeRootGameObject, state.activeAnimationClip, num6, this.m_Owner);
                        }
                        break;
                    }
                }
                this.CheckRectsOnMouseMove(rect, animationEvents, array);
            }
            if (Event.current.type == EventType.ContextClick && rect2.Contains(Event.current.mousePosition))
            {
                Event.current.Use();
                GenericMenu genericMenu2 = new GenericMenu();
                genericMenu2.AddItem(new GUIContent("Add Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuAdd), new AnimationEventTimeLine.EventLineContextMenuObject(activeRootGameObject, activeAnimationClip, time, -1));
                genericMenu2.ShowAsContext();
            }
            GUI.color = color;
            GUI.EndGroup();
        }
コード例 #3
0
 public void EventLineContextMenuEdit(object obj)
 {
     AnimationEventTimeLine.EventLineContextMenuObject eventLineContextMenuObject = (AnimationEventTimeLine.EventLineContextMenuObject)obj;
     AnimationEventPopup.Edit(eventLineContextMenuObject.m_Animated, eventLineContextMenuObject.m_Clip, eventLineContextMenuObject.m_Index, this.m_Owner);
     this.Select(eventLineContextMenuObject.m_Clip, eventLineContextMenuObject.m_Index);
 }
コード例 #4
0
        public bool HandleEventManipulation(Rect rect, ref AnimationEvent[] events, AnimationClipInfoProperties clipInfo)
        {
            Texture image = EditorGUIUtility.IconContent("Animation.EventMarker").image;
            bool    flag  = false;

            Rect[] rectArray = new Rect[events.Length];
            Rect[] positions = new Rect[events.Length];
            int    num1      = 1;
            int    num2      = 0;

            for (int index = 0; index < events.Length; ++index)
            {
                AnimationEvent animationEvent = events[index];
                if (num2 == 0)
                {
                    num1 = 1;
                    while (index + num1 < events.Length && (double)events[index + num1].time == (double)animationEvent.time)
                    {
                        ++num1;
                    }
                    num2 = num1;
                }
                --num2;
                float num3 = Mathf.Floor(this.m_Timeline.TimeToPixel(animationEvent.time, rect));
                int   num4 = 0;
                if (num1 > 1)
                {
                    num4 = Mathf.FloorToInt(Mathf.Max(0.0f, (float)Mathf.Min((num1 - 1) * (image.width - 1), (int)(1.0 / (double)this.m_Timeline.PixelDeltaToTime(rect) - (double)(image.width * 2))) - (float)((image.width - 1) * num2)));
                }
                Rect rect1 = new Rect(num3 + (float)num4 - (float)(image.width / 2), (rect.height - 10f) * (float)(num2 - num1 + 1) / (float)Mathf.Max(1, num1 - 1), (float)image.width, (float)image.height);
                rectArray[index] = rect1;
                positions[index] = rect1;
            }
            this.m_EventRects = new Rect[rectArray.Length];
            for (int index = 0; index < rectArray.Length; ++index)
            {
                this.m_EventRects[index] = new Rect(rectArray[index].x + rect.x, rectArray[index].y + rect.y, rectArray[index].width, rectArray[index].height);
            }
            if (this.m_EventsSelected == null || this.m_EventsSelected.Length != events.Length || this.m_EventsSelected.Length == 0)
            {
                this.m_EventsSelected = new bool[events.Length];
                AnimationEventPopup.ClosePopup();
            }
            Vector2 offset = Vector2.zero;
            int     clickedIndex;
            float   startSelect;
            float   endSelect;

            switch (EditorGUIExt.MultiSelection(rect, positions, new GUIContent(image), rectArray, ref this.m_EventsSelected, (bool[])null, out clickedIndex, out offset, out startSelect, out endSelect, GUIStyle.none))
            {
            case HighLevelEvent.ContextClick:
                GenericMenu genericMenu = new GenericMenu();
                genericMenu.AddItem(new GUIContent("Add Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuAdd), (object)new EventManipulationHandler.EventModificationContextMenuObjet(clipInfo, events[clickedIndex].time, clickedIndex));
                genericMenu.AddItem(new GUIContent("Delete Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuDelete), (object)new EventManipulationHandler.EventModificationContextMenuObjet(clipInfo, events[clickedIndex].time, clickedIndex));
                genericMenu.ShowAsContext();
                this.m_InstantTooltipText = (string)null;
                break;

            case HighLevelEvent.BeginDrag:
                EventManipulationHandler.m_EventsAtMouseDown = events;
                EventManipulationHandler.m_EventTimes        = new float[events.Length];
                for (int index = 0; index < events.Length; ++index)
                {
                    EventManipulationHandler.m_EventTimes[index] = events[index].time;
                }
                break;

            case HighLevelEvent.Drag:
                for (int index = events.Length - 1; index >= 0; --index)
                {
                    if (this.m_EventsSelected[index])
                    {
                        EventManipulationHandler.m_EventsAtMouseDown[index].time = Mathf.Clamp01(EventManipulationHandler.m_EventTimes[index] + offset.x / rect.width);
                    }
                }
                int[] numArray1 = new int[this.m_EventsSelected.Length];
                for (int index = 0; index < numArray1.Length; ++index)
                {
                    numArray1[index] = index;
                }
                Array.Sort((Array)EventManipulationHandler.m_EventsAtMouseDown, (Array)numArray1, (IComparer) new AnimationEventTimeLine.EventComparer());
                bool[]  flagArray = (bool[])this.m_EventsSelected.Clone();
                float[] numArray2 = (float[])EventManipulationHandler.m_EventTimes.Clone();
                for (int index = 0; index < numArray1.Length; ++index)
                {
                    this.m_EventsSelected[index] = flagArray[numArray1[index]];
                    EventManipulationHandler.m_EventTimes[index] = numArray2[numArray1[index]];
                }
                events = EventManipulationHandler.m_EventsAtMouseDown;
                flag   = true;
                break;

            case HighLevelEvent.Delete:
                flag = this.DeleteEvents(ref events, this.m_EventsSelected);
                break;

            case HighLevelEvent.SelectionChanged:
                if (clickedIndex >= 0)
                {
                    AnimationEventPopup.Edit(clipInfo, clickedIndex);
                    break;
                }
                AnimationEventPopup.ClosePopup();
                break;
            }
            this.CheckRectsOnMouseMove(rect, events, rectArray);
            return(flag);
        }
コード例 #5
0
 public void SelectEvent(AnimationEvent[] events, int index, AnimationClipInfoProperties clipInfo)
 {
     this.m_EventsSelected        = new bool[events.Length];
     this.m_EventsSelected[index] = true;
     AnimationEventPopup.Edit(clipInfo, index);
 }
コード例 #6
0
        public void EventLineGUI(Rect rect, AnimationWindowState state)
        {
            AnimationClip activeAnimationClip  = state.activeAnimationClip;
            GameObject    activeRootGameObject = state.activeRootGameObject;

            GUI.BeginGroup(rect);
            Color color = GUI.color;
            Rect  rect2 = new Rect(0f, 0f, rect.width, rect.height);
            float time  = ((float)Mathf.RoundToInt(state.PixelToTime(Event.current.mousePosition.x, rect) * state.frameRate)) / state.frameRate;

            if (activeAnimationClip != null)
            {
                int              num8;
                float            num9;
                float            num10;
                AnimationEvent[] animationEvents = AnimationUtility.GetAnimationEvents(activeAnimationClip);
                Texture          image           = EditorGUIUtility.IconContent("Animation.EventMarker").image;
                Rect[]           hitPositions    = new Rect[animationEvents.Length];
                Rect[]           positions       = new Rect[animationEvents.Length];
                int              num2            = 1;
                int              num3            = 0;
                for (int i = 0; i < animationEvents.Length; i++)
                {
                    AnimationEvent event2 = animationEvents[i];
                    if (num3 == 0)
                    {
                        num2 = 1;
                        while (((i + num2) < animationEvents.Length) && (animationEvents[i + num2].time == event2.time))
                        {
                            num2++;
                        }
                        num3 = num2;
                    }
                    num3--;
                    float num5 = Mathf.Floor(state.FrameToPixel(event2.time * activeAnimationClip.frameRate, rect));
                    int   num6 = 0;
                    if (num2 > 1)
                    {
                        float num7 = Mathf.Min((int)((num2 - 1) * (image.width - 1)), (int)(((int)state.FrameDeltaToPixel(rect)) - (image.width * 2)));
                        num6 = Mathf.FloorToInt(Mathf.Max((float)0f, (float)(num7 - ((image.width - 1) * num3))));
                    }
                    Rect rect3 = new Rect((num5 + num6) - (image.width / 2), ((rect.height - 10f) * ((num3 - num2) + 1)) / ((float)Mathf.Max(1, num2 - 1)), (float)image.width, (float)image.height);
                    hitPositions[i] = rect3;
                    positions[i]    = rect3;
                }
                if (this.m_DirtyTooltip)
                {
                    if ((this.m_HoverEvent >= 0) && (this.m_HoverEvent < hitPositions.Length))
                    {
                        this.m_InstantTooltipText  = AnimationEventPopup.FormatEvent(activeRootGameObject, animationEvents[this.m_HoverEvent]);
                        this.m_InstantTooltipPoint = new Vector2(((hitPositions[this.m_HoverEvent].xMin + ((int)(hitPositions[this.m_HoverEvent].width / 2f))) + rect.x) - 30f, rect.yMax);
                    }
                    this.m_DirtyTooltip = false;
                }
                if ((this.m_EventsSelected == null) || (this.m_EventsSelected.Length != animationEvents.Length))
                {
                    this.m_EventsSelected = new bool[animationEvents.Length];
                    AnimationEventPopup.ClosePopup();
                }
                Vector2 zero = Vector2.zero;
                switch (EditorGUIExt.MultiSelection(rect, positions, new GUIContent(image), hitPositions, ref this.m_EventsSelected, null, out num8, out zero, out num9, out num10, GUIStyle.none))
                {
                case HighLevelEvent.DoubleClick:
                    if (num8 == -1)
                    {
                        this.EventLineContextMenuAdd(new EventLineContextMenuObject(activeRootGameObject, activeAnimationClip, time, -1));
                        break;
                    }
                    AnimationEventPopup.Edit(activeRootGameObject, state.activeAnimationClip, num8, this.m_Owner);
                    break;

                case HighLevelEvent.ContextClick:
                {
                    GenericMenu menu = new GenericMenu();
                    EventLineContextMenuObject userData = new EventLineContextMenuObject(activeRootGameObject, activeAnimationClip, animationEvents[num8].time, num8);
                    menu.AddItem(new GUIContent("Edit Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuEdit), userData);
                    menu.AddItem(new GUIContent("Add Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuAdd), userData);
                    menu.AddItem(new GUIContent("Delete Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuDelete), userData);
                    menu.ShowAsContext();
                    this.m_InstantTooltipText = null;
                    this.m_DirtyTooltip       = true;
                    state.Repaint();
                    break;
                }

                case HighLevelEvent.BeginDrag:
                    this.m_EventsAtMouseDown = animationEvents;
                    this.m_EventTimes        = new float[animationEvents.Length];
                    for (int j = 0; j < animationEvents.Length; j++)
                    {
                        this.m_EventTimes[j] = animationEvents[j].time;
                    }
                    break;

                case HighLevelEvent.Drag:
                {
                    for (int k = animationEvents.Length - 1; k >= 0; k--)
                    {
                        if (this.m_EventsSelected[k])
                        {
                            AnimationEvent event4 = this.m_EventsAtMouseDown[k];
                            event4.time = this.m_EventTimes[k] + (zero.x * state.PixelDeltaToTime(rect));
                            event4.time = Mathf.Max(0f, event4.time);
                            event4.time = ((float)Mathf.RoundToInt(event4.time * activeAnimationClip.frameRate)) / activeAnimationClip.frameRate;
                        }
                    }
                    int[] items = new int[this.m_EventsSelected.Length];
                    for (int m = 0; m < items.Length; m++)
                    {
                        items[m] = m;
                    }
                    Array.Sort(this.m_EventsAtMouseDown, items, new EventComparer());
                    bool[]  flagArray = (bool[])this.m_EventsSelected.Clone();
                    float[] numArray2 = (float[])this.m_EventTimes.Clone();
                    for (int n = 0; n < items.Length; n++)
                    {
                        this.m_EventsSelected[n] = flagArray[items[n]];
                        this.m_EventTimes[n]     = numArray2[items[n]];
                    }
                    Undo.RegisterCompleteObjectUndo(activeAnimationClip, "Move Event");
                    AnimationUtility.SetAnimationEvents(activeAnimationClip, this.m_EventsAtMouseDown);
                    this.m_DirtyTooltip = true;
                    break;
                }

                case HighLevelEvent.Delete:
                    this.DeleteEvents(activeAnimationClip, this.m_EventsSelected);
                    break;

                case HighLevelEvent.SelectionChanged:
                    state.ClearKeySelections();
                    if (num8 != -1)
                    {
                        AnimationEventPopup.UpdateSelection(activeRootGameObject, state.activeAnimationClip, num8, this.m_Owner);
                    }
                    break;
                }
                this.CheckRectsOnMouseMove(rect, animationEvents, hitPositions);
            }
            if ((Event.current.type == EventType.ContextClick) && rect2.Contains(Event.current.mousePosition))
            {
                Event.current.Use();
                GenericMenu menu2 = new GenericMenu();
                menu2.AddItem(new GUIContent("Add Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuAdd), new EventLineContextMenuObject(activeRootGameObject, activeAnimationClip, time, -1));
                menu2.ShowAsContext();
            }
            GUI.color = color;
            GUI.EndGroup();
        }
コード例 #7
0
        public bool HandleEventManipulation(Rect rect, ref AnimationEvent[] events, AnimationClipInfoProperties clipInfo)
        {
            Texture image  = EditorGUIUtility.IconContent("Animation.EventMarker").image;
            bool    result = false;

            Rect[] array  = new Rect[events.Length];
            Rect[] array2 = new Rect[events.Length];
            int    num    = 1;
            int    num2   = 0;

            for (int i = 0; i < events.Length; i++)
            {
                AnimationEvent animationEvent = events[i];
                if (num2 == 0)
                {
                    num = 1;
                    while (i + num < events.Length && events[i + num].time == animationEvent.time)
                    {
                        num++;
                    }
                    num2 = num;
                }
                num2--;
                float num3 = Mathf.Floor(this.m_Timeline.TimeToPixel(animationEvent.time, rect));
                int   num4 = 0;
                if (num > 1)
                {
                    float num5 = (float)Mathf.Min((num - 1) * (image.width - 1), (int)(1f / this.m_Timeline.PixelDeltaToTime(rect) - (float)(image.width * 2)));
                    num4 = Mathf.FloorToInt(Mathf.Max(0f, num5 - (float)((image.width - 1) * num2)));
                }
                Rect rect2 = new Rect(num3 + (float)num4 - (float)(image.width / 2), (rect.height - 10f) * (float)(num2 - num + 1) / (float)Mathf.Max(1, num - 1), (float)image.width, (float)image.height);
                array[i]  = rect2;
                array2[i] = rect2;
            }
            this.m_EventRects = new Rect[array.Length];
            for (int j = 0; j < array.Length; j++)
            {
                this.m_EventRects[j] = new Rect(array[j].x + rect.x, array[j].y + rect.y, array[j].width, array[j].height);
            }
            if (this.m_EventsSelected == null || this.m_EventsSelected.Length != events.Length || this.m_EventsSelected.Length == 0)
            {
                this.m_EventsSelected = new bool[events.Length];
                AnimationEventPopup.ClosePopup();
            }
            Vector2        zero = Vector2.zero;
            int            num6;
            float          num7;
            float          num8;
            HighLevelEvent highLevelEvent = EditorGUIExt.MultiSelection(rect, array2, new GUIContent(image), array, ref this.m_EventsSelected, null, out num6, out zero, out num7, out num8, GUIStyle.none);

            if (highLevelEvent != HighLevelEvent.None)
            {
                switch (highLevelEvent)
                {
                case HighLevelEvent.ContextClick:
                {
                    GenericMenu genericMenu = new GenericMenu();
                    genericMenu.AddItem(new GUIContent("Add Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuAdd), new EventManipulationHandler.EventModificationContextMenuObjet(clipInfo, events[num6].time, num6));
                    genericMenu.AddItem(new GUIContent("Delete Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuDelete), new EventManipulationHandler.EventModificationContextMenuObjet(clipInfo, events[num6].time, num6));
                    genericMenu.ShowAsContext();
                    this.m_InstantTooltipText = null;
                    break;
                }

                case HighLevelEvent.BeginDrag:
                    EventManipulationHandler.m_EventsAtMouseDown = events;
                    EventManipulationHandler.m_EventTimes        = new float[events.Length];
                    for (int k = 0; k < events.Length; k++)
                    {
                        EventManipulationHandler.m_EventTimes[k] = events[k].time;
                    }
                    break;

                case HighLevelEvent.Drag:
                {
                    for (int l = events.Length - 1; l >= 0; l--)
                    {
                        if (this.m_EventsSelected[l])
                        {
                            AnimationEvent animationEvent2 = EventManipulationHandler.m_EventsAtMouseDown[l];
                            animationEvent2.time = Mathf.Clamp01(EventManipulationHandler.m_EventTimes[l] + zero.x / rect.width);
                        }
                    }
                    int[] array3 = new int[this.m_EventsSelected.Length];
                    for (int m = 0; m < array3.Length; m++)
                    {
                        array3[m] = m;
                    }
                    Array.Sort(EventManipulationHandler.m_EventsAtMouseDown, array3, new AnimationEventTimeLine.EventComparer());
                    bool[]  array4 = (bool[])this.m_EventsSelected.Clone();
                    float[] array5 = (float[])EventManipulationHandler.m_EventTimes.Clone();
                    for (int n = 0; n < array3.Length; n++)
                    {
                        this.m_EventsSelected[n] = array4[array3[n]];
                        EventManipulationHandler.m_EventTimes[n] = array5[array3[n]];
                    }
                    events = EventManipulationHandler.m_EventsAtMouseDown;
                    result = true;
                    break;
                }

                case HighLevelEvent.Delete:
                    result = this.DeleteEvents(ref events, this.m_EventsSelected);
                    break;

                case HighLevelEvent.SelectionChanged:
                    if (num6 >= 0)
                    {
                        AnimationEventPopup.Edit(clipInfo, num6);
                    }
                    else
                    {
                        AnimationEventPopup.ClosePopup();
                    }
                    break;
                }
            }
            this.CheckRectsOnMouseMove(rect, events, array);
            return(result);
        }
コード例 #8
0
        public bool HandleEventManipulation(Rect rect, ref AnimationEvent[] events, AnimationClipInfoProperties clipInfo)
        {
            int     num8;
            float   num9;
            float   num10;
            Texture image = EditorGUIUtility.IconContent("Animation.EventMarker").image;
            bool    flag  = false;

            Rect[] hitPositions = new Rect[events.Length];
            Rect[] positions    = new Rect[events.Length];
            int    num          = 1;
            int    num2         = 0;

            for (int i = 0; i < events.Length; i++)
            {
                AnimationEvent event2 = events[i];
                if (num2 == 0)
                {
                    num = 1;
                    while (((i + num) < events.Length) && (events[i + num].time == event2.time))
                    {
                        num++;
                    }
                    num2 = num;
                }
                num2--;
                float num4 = Mathf.Floor(this.m_Timeline.TimeToPixel(event2.time, rect));
                int   num5 = 0;
                if (num > 1)
                {
                    float num6 = Mathf.Min((int)((num - 1) * (image.width - 1)), (int)(((int)(1f / this.m_Timeline.PixelDeltaToTime(rect))) - (image.width * 2)));
                    num5 = Mathf.FloorToInt(Mathf.Max((float)0f, (float)(num6 - ((image.width - 1) * num2))));
                }
                Rect rect2 = new Rect((num4 + num5) - (image.width / 2), ((rect.height - 10f) * ((num2 - num) + 1)) / ((float)Mathf.Max(1, num - 1)), (float)image.width, (float)image.height);
                hitPositions[i] = rect2;
                positions[i]    = rect2;
            }
            this.m_EventRects = new Rect[hitPositions.Length];
            for (int j = 0; j < hitPositions.Length; j++)
            {
                this.m_EventRects[j] = new Rect(hitPositions[j].x + rect.x, hitPositions[j].y + rect.y, hitPositions[j].width, hitPositions[j].height);
            }
            if (((this.m_EventsSelected == null) || (this.m_EventsSelected.Length != events.Length)) || (this.m_EventsSelected.Length == 0))
            {
                this.m_EventsSelected = new bool[events.Length];
                AnimationEventPopup.ClosePopup();
            }
            Vector2 zero = Vector2.zero;

            switch (EditorGUIExt.MultiSelection(rect, positions, new GUIContent(image), hitPositions, ref this.m_EventsSelected, null, out num8, out zero, out num9, out num10, GUIStyle.none))
            {
            case HighLevelEvent.ContextClick:
            {
                GenericMenu menu = new GenericMenu();
                menu.AddItem(new GUIContent("Add Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuAdd), new EventModificationContextMenuObjet(clipInfo, events[num8].time, num8));
                menu.AddItem(new GUIContent("Delete Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuDelete), new EventModificationContextMenuObjet(clipInfo, events[num8].time, num8));
                menu.ShowAsContext();
                this.m_InstantTooltipText = null;
                break;
            }

            case HighLevelEvent.BeginDrag:
                m_EventsAtMouseDown = events;
                m_EventTimes        = new float[events.Length];
                for (int k = 0; k < events.Length; k++)
                {
                    m_EventTimes[k] = events[k].time;
                }
                break;

            case HighLevelEvent.Drag:
            {
                for (int m = events.Length - 1; m >= 0; m--)
                {
                    if (this.m_EventsSelected[m])
                    {
                        AnimationEvent event4 = m_EventsAtMouseDown[m];
                        event4.time = Mathf.Clamp01(m_EventTimes[m] + (zero.x / rect.width));
                    }
                }
                int[] items = new int[this.m_EventsSelected.Length];
                for (int n = 0; n < items.Length; n++)
                {
                    items[n] = n;
                }
                Array.Sort(m_EventsAtMouseDown, items, new AnimationEventTimeLine.EventComparer());
                bool[]  flagArray = (bool[])this.m_EventsSelected.Clone();
                float[] numArray2 = (float[])m_EventTimes.Clone();
                for (int num14 = 0; num14 < items.Length; num14++)
                {
                    this.m_EventsSelected[num14] = flagArray[items[num14]];
                    m_EventTimes[num14]          = numArray2[items[num14]];
                }
                events = m_EventsAtMouseDown;
                flag   = true;
                break;
            }

            case HighLevelEvent.Delete:
                flag = this.DeleteEvents(ref events, this.m_EventsSelected);
                break;

            case HighLevelEvent.SelectionChanged:
                if (num8 < 0)
                {
                    AnimationEventPopup.ClosePopup();
                    break;
                }
                AnimationEventPopup.Edit(clipInfo, num8);
                break;
            }
            this.CheckRectsOnMouseMove(rect, events, hitPositions);
            return(flag);
        }
コード例 #9
0
        public void EventLineGUI(Rect rect, AnimationWindowState state)
        {
            AnimationClip activeAnimationClip  = state.activeAnimationClip;
            GameObject    activeRootGameObject = state.activeRootGameObject;

            GUI.BeginGroup(rect);
            Color color = GUI.color;
            Rect  rect1 = new Rect(0.0f, 0.0f, rect.width, rect.height);
            float time  = (float)Mathf.RoundToInt(state.PixelToTime(Event.current.mousePosition.x, rect) * state.frameRate) / state.frameRate;

            if ((UnityEngine.Object)activeAnimationClip != (UnityEngine.Object)null)
            {
                AnimationEvent[] animationEvents = AnimationUtility.GetAnimationEvents(activeAnimationClip);
                Texture          image           = EditorGUIUtility.IconContent("Animation.EventMarker").image;
                Rect[]           rectArray       = new Rect[animationEvents.Length];
                Rect[]           positions       = new Rect[animationEvents.Length];
                int num1 = 1;
                int num2 = 0;
                for (int index = 0; index < animationEvents.Length; ++index)
                {
                    AnimationEvent animationEvent = animationEvents[index];
                    if (num2 == 0)
                    {
                        num1 = 1;
                        while (index + num1 < animationEvents.Length && (double)animationEvents[index + num1].time == (double)animationEvent.time)
                        {
                            ++num1;
                        }
                        num2 = num1;
                    }
                    --num2;
                    float num3 = Mathf.Floor(state.FrameToPixel(animationEvent.time * activeAnimationClip.frameRate, rect));
                    int   num4 = 0;
                    if (num1 > 1)
                    {
                        num4 = Mathf.FloorToInt(Mathf.Max(0.0f, (float)Mathf.Min((num1 - 1) * (image.width - 1), (int)((double)state.FrameDeltaToPixel(rect) - (double)(image.width * 2))) - (float)((image.width - 1) * num2)));
                    }
                    Rect rect2 = new Rect(num3 + (float)num4 - (float)(image.width / 2), (rect.height - 10f) * (float)(num2 - num1 + 1) / (float)Mathf.Max(1, num1 - 1), (float)image.width, (float)image.height);
                    rectArray[index] = rect2;
                    positions[index] = rect2;
                }
                if (this.m_DirtyTooltip)
                {
                    if (this.m_HoverEvent >= 0 && this.m_HoverEvent < rectArray.Length)
                    {
                        this.m_InstantTooltipText  = AnimationEventPopup.FormatEvent(activeRootGameObject, animationEvents[this.m_HoverEvent]);
                        this.m_InstantTooltipPoint = new Vector2((float)((double)rectArray[this.m_HoverEvent].xMin + (double)(int)((double)rectArray[this.m_HoverEvent].width / 2.0) + (double)rect.x - 30.0), rect.yMax);
                    }
                    this.m_DirtyTooltip = false;
                }
                if (this.m_EventsSelected == null || this.m_EventsSelected.Length != animationEvents.Length)
                {
                    this.m_EventsSelected = new bool[animationEvents.Length];
                    AnimationEventPopup.ClosePopup();
                }
                Vector2 offset = Vector2.zero;
                int     clickedIndex;
                float   startSelect;
                float   endSelect;
                switch (EditorGUIExt.MultiSelection(rect, positions, new GUIContent(image), rectArray, ref this.m_EventsSelected, (bool[])null, out clickedIndex, out offset, out startSelect, out endSelect, GUIStyle.none))
                {
                case HighLevelEvent.DoubleClick:
                    if (clickedIndex != -1)
                    {
                        AnimationEventPopup.Edit(activeRootGameObject, state.activeAnimationClip, clickedIndex, this.m_Owner);
                        break;
                    }
                    this.EventLineContextMenuAdd((object)new AnimationEventTimeLine.EventLineContextMenuObject(activeRootGameObject, activeAnimationClip, time, -1));
                    break;

                case HighLevelEvent.ContextClick:
                    GenericMenu genericMenu = new GenericMenu();
                    AnimationEventTimeLine.EventLineContextMenuObject contextMenuObject = new AnimationEventTimeLine.EventLineContextMenuObject(activeRootGameObject, activeAnimationClip, animationEvents[clickedIndex].time, clickedIndex);
                    genericMenu.AddItem(new GUIContent("Edit Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuEdit), (object)contextMenuObject);
                    genericMenu.AddItem(new GUIContent("Add Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuAdd), (object)contextMenuObject);
                    genericMenu.AddItem(new GUIContent("Delete Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuDelete), (object)contextMenuObject);
                    genericMenu.ShowAsContext();
                    this.m_InstantTooltipText = (string)null;
                    this.m_DirtyTooltip       = true;
                    state.Repaint();
                    break;

                case HighLevelEvent.BeginDrag:
                    this.m_EventsAtMouseDown = animationEvents;
                    this.m_EventTimes        = new float[animationEvents.Length];
                    for (int index = 0; index < animationEvents.Length; ++index)
                    {
                        this.m_EventTimes[index] = animationEvents[index].time;
                    }
                    break;

                case HighLevelEvent.Drag:
                    for (int index = animationEvents.Length - 1; index >= 0; --index)
                    {
                        if (this.m_EventsSelected[index])
                        {
                            AnimationEvent animationEvent = this.m_EventsAtMouseDown[index];
                            animationEvent.time = this.m_EventTimes[index] + offset.x * state.PixelDeltaToTime(rect);
                            animationEvent.time = Mathf.Max(0.0f, animationEvent.time);
                            animationEvent.time = (float)Mathf.RoundToInt(animationEvent.time * activeAnimationClip.frameRate) / activeAnimationClip.frameRate;
                        }
                    }
                    int[] numArray1 = new int[this.m_EventsSelected.Length];
                    for (int index = 0; index < numArray1.Length; ++index)
                    {
                        numArray1[index] = index;
                    }
                    Array.Sort((Array)this.m_EventsAtMouseDown, (Array)numArray1, (IComparer) new AnimationEventTimeLine.EventComparer());
                    bool[]  flagArray = (bool[])this.m_EventsSelected.Clone();
                    float[] numArray2 = (float[])this.m_EventTimes.Clone();
                    for (int index = 0; index < numArray1.Length; ++index)
                    {
                        this.m_EventsSelected[index] = flagArray[numArray1[index]];
                        this.m_EventTimes[index]     = numArray2[numArray1[index]];
                    }
                    Undo.RegisterCompleteObjectUndo((UnityEngine.Object)activeAnimationClip, "Move Event");
                    AnimationUtility.SetAnimationEvents(activeAnimationClip, this.m_EventsAtMouseDown);
                    this.m_DirtyTooltip = true;
                    break;

                case HighLevelEvent.Delete:
                    this.DeleteEvents(activeAnimationClip, this.m_EventsSelected);
                    break;

                case HighLevelEvent.SelectionChanged:
                    state.ClearKeySelections();
                    if (clickedIndex != -1)
                    {
                        AnimationEventPopup.UpdateSelection(activeRootGameObject, state.activeAnimationClip, clickedIndex, this.m_Owner);
                        break;
                    }
                    break;
                }
                this.CheckRectsOnMouseMove(rect, animationEvents, rectArray);
            }
            if (Event.current.type == EventType.ContextClick && rect1.Contains(Event.current.mousePosition))
            {
                Event.current.Use();
                GenericMenu genericMenu = new GenericMenu();
                genericMenu.AddItem(new GUIContent("Add Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuAdd), (object)new AnimationEventTimeLine.EventLineContextMenuObject(activeRootGameObject, activeAnimationClip, time, -1));
                genericMenu.ShowAsContext();
            }
            GUI.color = color;
            GUI.EndGroup();
        }