コード例 #1
0
 public static void OnEditAnimationEvent(AnimationWindowEvent awe)
 {
     AnimationWindowEventInspector.OnEditAnimationEvents(new AnimationWindowEvent[]
     {
         awe
     });
 }
コード例 #2
0
 private static void DoEditRegularParameters(AnimationEvent evt, Type selectedParameter)
 {
     if (selectedParameter == typeof(AnimationEvent) || selectedParameter == typeof(float))
     {
         evt.floatParameter = EditorGUILayout.FloatField("Float", evt.floatParameter, new GUILayoutOption[0]);
     }
     if (selectedParameter.IsEnum)
     {
         evt.intParameter = AnimationWindowEventInspector.EnumPopup("Enum", selectedParameter, evt.intParameter);
     }
     else if (selectedParameter == typeof(AnimationEvent) || selectedParameter == typeof(int))
     {
         evt.intParameter = EditorGUILayout.IntField("Int", evt.intParameter, new GUILayoutOption[0]);
     }
     if (selectedParameter == typeof(AnimationEvent) || selectedParameter == typeof(string))
     {
         evt.stringParameter = EditorGUILayout.TextField("String", evt.stringParameter, new GUILayoutOption[0]);
     }
     if (selectedParameter == typeof(AnimationEvent) || selectedParameter.IsSubclassOf(typeof(UnityEngine.Object)) || selectedParameter == typeof(UnityEngine.Object))
     {
         Type type = typeof(UnityEngine.Object);
         if (selectedParameter != typeof(AnimationEvent))
         {
             type = selectedParameter;
         }
         bool allowSceneObjects = false;
         evt.objectReferenceParameter = EditorGUILayout.ObjectField(ObjectNames.NicifyVariableName(type.Name), evt.objectReferenceParameter, type, allowSceneObjects, new GUILayoutOption[0]);
     }
 }
コード例 #3
0
        public static void OnDisabledAnimationEvent()
        {
            AnimationEvent animationEvent = new AnimationEvent();

            using (new EditorGUI.DisabledScope(true))
            {
                animationEvent.functionName = EditorGUILayout.TextField(new GUIContent("Function"), animationEvent.functionName, new GUILayoutOption[0]);
                AnimationWindowEventInspector.DoEditRegularParameters(animationEvent, typeof(AnimationEvent));
            }
        }
コード例 #4
0
        public static string FormatEvent(GameObject root, AnimationEvent evt)
        {
            string result;

            if (string.IsNullOrEmpty(evt.functionName))
            {
                result = "(No Function Selected)";
            }
            else if (!AnimationWindowEventInspector.IsSupportedMethodName(evt.functionName))
            {
                result = evt.functionName + " (Function Not Supported)";
            }
            else if (root == null)
            {
                result = evt.functionName + " (Function Not Supported)";
            }
            else
            {
                MonoBehaviour[] components = root.GetComponents <MonoBehaviour>();
                for (int i = 0; i < components.Length; i++)
                {
                    MonoBehaviour monoBehaviour = components[i];
                    if (!(monoBehaviour == null))
                    {
                        Type type = monoBehaviour.GetType();
                        if (type != typeof(MonoBehaviour) && (type.BaseType == null || !(type.BaseType.Name == "GraphBehaviour")))
                        {
                            MethodInfo methodInfo = null;
                            try
                            {
                                methodInfo = type.GetMethod(evt.functionName, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                            }
                            catch (AmbiguousMatchException)
                            {
                            }
                            if (methodInfo != null)
                            {
                                IEnumerable <Type> paramTypes = from p in methodInfo.GetParameters()
                                                                select p.ParameterType;
                                result = evt.functionName + AnimationWindowEventInspector.FormatEventArguments(paramTypes, evt);
                                return(result);
                            }
                        }
                    }
                }
                result = evt.functionName + " (Function Not Supported)";
            }
            return(result);
        }
コード例 #5
0
        private static void ResetValues(MenuCommand command)
        {
            AnimationWindowEvent animationWindowEvent = command.context as AnimationWindowEvent;

            AnimationWindowEvent[] awEvents = new AnimationWindowEvent[]
            {
                animationWindowEvent
            };
            AnimationWindowEventInspector.AnimationWindowEventData data = AnimationWindowEventInspector.GetData(awEvents);
            if (data.events != null && data.selectedEvents != null && data.selectedEvents.Length != 0)
            {
                AnimationEvent[] selectedEvents = data.selectedEvents;
                for (int i = 0; i < selectedEvents.Length; i++)
                {
                    AnimationEvent animationEvent = selectedEvents[i];
                    animationEvent.functionName             = "";
                    animationEvent.stringParameter          = string.Empty;
                    animationEvent.floatParameter           = 0f;
                    animationEvent.intParameter             = 0;
                    animationEvent.objectReferenceParameter = null;
                }
                AnimationWindowEventInspector.SetData(awEvents, data);
            }
        }
コード例 #6
0
 public void Draw(Rect window)
 {
     EditorGUI.indentLevel++;
     if (this.m_Events != null && this.m_Events.Length > 0)
     {
         AnimationWindowEventInspector.OnEditAnimationEvents(this.m_Events);
     }
     else
     {
         AnimationWindowEventInspector.OnDisabledAnimationEvent();
     }
     EditorGUI.indentLevel--;
     if (this.m_InstantTooltipText != null && this.m_InstantTooltipText != "")
     {
         GUIStyle gUIStyle = "AnimationEventTooltip";
         Vector2  vector   = gUIStyle.CalcSize(new GUIContent(this.m_InstantTooltipText));
         Rect     position = new Rect(window.x + this.m_InstantTooltipPoint.x, window.y + this.m_InstantTooltipPoint.y, vector.x, vector.y);
         if (position.xMax > window.width)
         {
             position.x = window.width - position.width;
         }
         GUI.Label(position, this.m_InstantTooltipText, gUIStyle);
     }
 }
コード例 #7
0
        public void EventLineGUI(Rect rect, AnimationWindowState state)
        {
            //  We only display and manipulate animation events from the main
            //  game object in selection.  If we ever want to update to handle
            //  a multiple selection, a single timeline might not be sufficient...
            AnimationClip clip     = state.activeAnimationClip;
            GameObject    animated = state.activeRootGameObject;

            GUI.BeginGroup(rect);
            Color backupCol = GUI.color;

            Rect eventLineRect = new Rect(0, 0, rect.width, rect.height);

            float mousePosTime = Mathf.Max(Mathf.RoundToInt(state.PixelToTime(Event.current.mousePosition.x, rect) * state.frameRate) / state.frameRate, 0.0f);

            // Draw events
            if (clip != null)
            {
                AnimationEvent[] events      = AnimationUtility.GetAnimationEvents(clip);
                Texture          eventMarker = EditorGUIUtility.IconContent("Animation.EventMarker").image;

                // Calculate rects
                Rect[] hitRects   = new Rect[events.Length];
                Rect[] drawRects  = new Rect[events.Length];
                int    shared     = 1;
                int    sharedLeft = 0;
                for (int i = 0; i < events.Length; i++)
                {
                    AnimationEvent evt = events[i];

                    if (sharedLeft == 0)
                    {
                        shared = 1;
                        while (i + shared < events.Length && events[i + shared].time == evt.time)
                        {
                            shared++;
                        }
                        sharedLeft = shared;
                    }
                    sharedLeft--;

                    // Important to take floor of positions of GUI stuff to get pixel correct alignment of
                    // stuff drawn with both GUI and Handles/GL. Otherwise things are off by one pixel half the time.
                    float keypos       = Mathf.Floor(state.FrameToPixel(evt.time * clip.frameRate, rect));
                    int   sharedOffset = 0;
                    if (shared > 1)
                    {
                        float spread = Mathf.Min((shared - 1) * (eventMarker.width - 1), (int)(state.FrameDeltaToPixel(rect) - eventMarker.width * 2));
                        sharedOffset = Mathf.FloorToInt(Mathf.Max(0, spread - (eventMarker.width - 1) * (sharedLeft)));
                    }

                    Rect r = new Rect(
                        keypos + sharedOffset - eventMarker.width / 2,
                        (rect.height - 10) * (float)(sharedLeft - shared + 1) / Mathf.Max(1, shared - 1),
                        eventMarker.width,
                        eventMarker.height);

                    hitRects[i]  = r;
                    drawRects[i] = r;
                }

                // Store tooptip info
                if (m_DirtyTooltip)
                {
                    if (m_HoverEvent >= 0 && m_HoverEvent < hitRects.Length)
                    {
                        m_InstantTooltipText  = AnimationWindowEventInspector.FormatEvent(animated, events[m_HoverEvent]);
                        m_InstantTooltipPoint = new Vector2(hitRects[m_HoverEvent].xMin + (int)(hitRects[m_HoverEvent].width / 2) + rect.x - 30, rect.yMax);
                    }
                    m_DirtyTooltip = false;
                }

                bool[] selectedEvents = new bool[events.Length];

                Object[] selectedObjects = Selection.objects;
                foreach (Object selectedObject in selectedObjects)
                {
                    AnimationWindowEvent awe = selectedObject as AnimationWindowEvent;
                    if (awe != null)
                    {
                        if (awe.eventIndex >= 0 && awe.eventIndex < selectedEvents.Length)
                        {
                            selectedEvents[awe.eventIndex] = true;
                        }
                    }
                }

                Vector2 offset = Vector2.zero;
                int     clickedIndex;
                float   startSelection, endSelection;

                // TODO: GUIStyle.none has hopping margins that need to be fixed
                HighLevelEvent hEvent = EditorGUIExt.MultiSelection(
                    rect,
                    drawRects,
                    new GUIContent(eventMarker),
                    hitRects,
                    ref selectedEvents,
                    null,
                    out clickedIndex,
                    out offset,
                    out startSelection,
                    out endSelection,
                    GUIStyle.none
                    );

                if (hEvent != HighLevelEvent.None)
                {
                    switch (hEvent)
                    {
                    case HighLevelEvent.BeginDrag:
                        m_EventsAtMouseDown = events;
                        m_EventTimes        = new float[events.Length];
                        for (int i = 0; i < events.Length; i++)
                        {
                            m_EventTimes[i] = events[i].time;
                        }
                        break;

                    case HighLevelEvent.SelectionChanged:
                        state.ClearKeySelections();
                        EditEvents(animated, clip, selectedEvents);
                        break;

                    case HighLevelEvent.Delete:
                        DeleteEvents(clip, selectedEvents);
                        break;

                    case HighLevelEvent.DoubleClick:

                        if (clickedIndex != -1)
                        {
                            EditEvents(animated, clip, selectedEvents);
                        }
                        else
                        {
                            EventLineContextMenuAdd(new EventLineContextMenuObject(animated, clip, mousePosTime, -1, selectedEvents));
                        }
                        break;

                    case HighLevelEvent.Drag:
                        for (int i = events.Length - 1; i >= 0; i--)
                        {
                            if (selectedEvents[i])
                            {
                                AnimationEvent evt = m_EventsAtMouseDown[i];
                                evt.time = m_EventTimes[i] + offset.x * state.PixelDeltaToTime(rect);
                                evt.time = Mathf.Max(0.0F, evt.time);
                                evt.time = Mathf.RoundToInt(evt.time * clip.frameRate) / clip.frameRate;
                            }
                        }
                        int[] order = new int[selectedEvents.Length];
                        for (int i = 0; i < order.Length; i++)
                        {
                            order[i] = i;
                        }
                        System.Array.Sort(m_EventsAtMouseDown, order, new EventComparer());
                        bool[]  selectedOld = (bool[])selectedEvents.Clone();
                        float[] timesOld    = (float[])m_EventTimes.Clone();
                        for (int i = 0; i < order.Length; i++)
                        {
                            selectedEvents[i] = selectedOld[order[i]];
                            m_EventTimes[i]   = timesOld[order[i]];
                        }

                        // Update selection to reflect new order.
                        EditEvents(animated, clip, selectedEvents);

                        Undo.RegisterCompleteObjectUndo(clip, "Move Event");
                        AnimationUtility.SetAnimationEvents(clip, m_EventsAtMouseDown);
                        m_DirtyTooltip = true;
                        break;

                    case HighLevelEvent.ContextClick:
                        GenericMenu menu                = new GenericMenu();
                        var         contextData         = new EventLineContextMenuObject(animated, clip, events[clickedIndex].time, clickedIndex, selectedEvents);
                        int         selectedEventsCount = selectedEvents.Count(selected => selected);

                        menu.AddItem(
                            EditorGUIUtility.TrTextContent("Add Animation Event"),
                            false,
                            EventLineContextMenuAdd,
                            contextData);
                        menu.AddItem(
                            new GUIContent(selectedEventsCount > 1 ? "Delete Animation Events" : "Delete Animation Event"),
                            false,
                            EventLineContextMenuDelete,
                            contextData);
                        menu.ShowAsContext();

                        // Mouse may move while context menu is open - make sure instant tooltip is handled
                        m_InstantTooltipText = null;
                        m_DirtyTooltip       = true;
                        state.Repaint();
                        break;
                    }
                }

                CheckRectsOnMouseMove(rect, events, hitRects);

                // Create context menu on context click
                if (Event.current.type == EventType.ContextClick && eventLineRect.Contains(Event.current.mousePosition))
                {
                    Event.current.Use();
                    // Create menu
                    GenericMenu menu                = new GenericMenu();
                    var         contextData         = new EventLineContextMenuObject(animated, clip, mousePosTime, -1, selectedEvents);
                    int         selectedEventsCount = selectedEvents.Count(selected => selected);

                    menu.AddItem(
                        EditorGUIUtility.TrTextContent("Add Animation Event"),
                        false,
                        EventLineContextMenuAdd,
                        contextData);

                    if (selectedEventsCount > 0)
                    {
                        menu.AddItem(
                            new GUIContent(selectedEventsCount > 1 ? "Delete Animation Events" : "Delete Animation Event"),
                            false,
                            EventLineContextMenuDelete,
                            contextData);
                    }

                    menu.ShowAsContext();
                }
            }

            GUI.color = backupCol;
            GUI.EndGroup();
        }
コード例 #8
0
 public static void OnEditAnimationEvents(AnimationWindowEvent[] awEvents)
 {
     AnimationWindowEventInspector.AnimationWindowEventData data = AnimationWindowEventInspector.GetData(awEvents);
     if (data.events != null && data.selectedEvents != null && data.selectedEvents.Length != 0)
     {
         AnimationEvent firstEvent = data.selectedEvents[0];
         bool           flag       = Array.TrueForAll <AnimationEvent>(data.selectedEvents, (AnimationEvent evt) => evt.functionName == firstEvent.functionName);
         GUI.changed = false;
         if (data.root != null)
         {
             List <AnimationWindowEventMethod> list = AnimationWindowEventInspector.CollectSupportedMethods(data.root);
             List <string> list2 = new List <string>(list.Count);
             for (int i = 0; i < list.Count; i++)
             {
                 AnimationWindowEventMethod animationWindowEventMethod = list[i];
                 string str = " ( )";
                 if (animationWindowEventMethod.parameterType != null)
                 {
                     if (animationWindowEventMethod.parameterType == typeof(float))
                     {
                         str = " ( float )";
                     }
                     else if (animationWindowEventMethod.parameterType == typeof(int))
                     {
                         str = " ( int )";
                     }
                     else
                     {
                         str = string.Format(" ( {0} )", animationWindowEventMethod.parameterType.Name);
                     }
                 }
                 list2.Add(animationWindowEventMethod.name + str);
             }
             int count = list.Count;
             int num   = list.FindIndex((AnimationWindowEventMethod method) => method.name == firstEvent.functionName);
             if (num == -1)
             {
                 num = list.Count;
                 list.Add(new AnimationWindowEventMethod
                 {
                     name          = firstEvent.functionName,
                     parameterType = null
                 });
                 if (string.IsNullOrEmpty(firstEvent.functionName))
                 {
                     list2.Add("(No Function Selected)");
                 }
                 else
                 {
                     list2.Add(firstEvent.functionName + " (Function Not Supported)");
                 }
             }
             EditorGUIUtility.labelWidth = 130f;
             EditorGUI.showMixedValue    = !flag;
             int num2 = (!flag) ? -1 : num;
             num = EditorGUILayout.Popup("Function: ", num, list2.ToArray(), new GUILayoutOption[0]);
             if (num2 != num && num != -1 && num != count)
             {
                 AnimationEvent[] selectedEvents = data.selectedEvents;
                 for (int j = 0; j < selectedEvents.Length; j++)
                 {
                     AnimationEvent animationEvent = selectedEvents[j];
                     animationEvent.functionName    = list[num].name;
                     animationEvent.stringParameter = string.Empty;
                 }
             }
             EditorGUI.showMixedValue = false;
             Type parameterType = list[num].parameterType;
             if (flag && parameterType != null)
             {
                 EditorGUILayout.Space();
                 if (parameterType == typeof(AnimationEvent))
                 {
                     EditorGUILayout.PrefixLabel("Event Data");
                 }
                 else
                 {
                     EditorGUILayout.PrefixLabel("Parameters");
                 }
                 AnimationWindowEventInspector.DoEditRegularParameters(data.selectedEvents, parameterType);
             }
         }
         else
         {
             EditorGUI.showMixedValue = !flag;
             string text  = (!flag) ? "" : firstEvent.functionName;
             string text2 = EditorGUILayout.TextField(EditorGUIUtility.TrTextContent("Function", null, null), text, new GUILayoutOption[0]);
             if (text2 != text)
             {
                 AnimationEvent[] selectedEvents2 = data.selectedEvents;
                 for (int k = 0; k < selectedEvents2.Length; k++)
                 {
                     AnimationEvent animationEvent2 = selectedEvents2[k];
                     animationEvent2.functionName    = text2;
                     animationEvent2.stringParameter = string.Empty;
                 }
             }
             EditorGUI.showMixedValue = false;
             if (flag)
             {
                 AnimationWindowEventInspector.DoEditRegularParameters(data.selectedEvents, typeof(AnimationEvent));
             }
             else
             {
                 using (new EditorGUI.DisabledScope(true))
                 {
                     AnimationEvent animationEvent3 = new AnimationEvent();
                     AnimationWindowEventInspector.DoEditRegularParameters(new AnimationEvent[]
                     {
                         animationEvent3
                     }, typeof(AnimationEvent));
                 }
             }
         }
         if (GUI.changed)
         {
             AnimationWindowEventInspector.SetData(awEvents, data);
         }
     }
 }
コード例 #9
0
        private static void DoEditRegularParameters(AnimationEvent[] events, Type selectedParameter)
        {
            AnimationEvent firstEvent = events[0];

            if (selectedParameter == typeof(AnimationEvent) || selectedParameter == typeof(float))
            {
                bool flag = Array.TrueForAll <AnimationEvent>(events, (AnimationEvent evt) => evt.floatParameter == firstEvent.floatParameter);
                EditorGUI.BeginChangeCheck();
                EditorGUI.showMixedValue = !flag;
                float floatParameter = EditorGUILayout.FloatField("Float", firstEvent.floatParameter, new GUILayoutOption[0]);
                EditorGUI.showMixedValue = false;
                if (EditorGUI.EndChangeCheck())
                {
                    for (int i = 0; i < events.Length; i++)
                    {
                        AnimationEvent animationEvent = events[i];
                        animationEvent.floatParameter = floatParameter;
                    }
                }
            }
            if (selectedParameter == typeof(AnimationEvent) || selectedParameter == typeof(int) || selectedParameter.IsEnum)
            {
                bool flag2 = Array.TrueForAll <AnimationEvent>(events, (AnimationEvent evt) => evt.intParameter == firstEvent.intParameter);
                EditorGUI.BeginChangeCheck();
                EditorGUI.showMixedValue = !flag2;
                int intParameter;
                if (selectedParameter.IsEnum)
                {
                    intParameter = AnimationWindowEventInspector.EnumPopup("Enum", selectedParameter, firstEvent.intParameter);
                }
                else
                {
                    intParameter = EditorGUILayout.IntField("Int", firstEvent.intParameter, new GUILayoutOption[0]);
                }
                EditorGUI.showMixedValue = false;
                if (EditorGUI.EndChangeCheck())
                {
                    for (int j = 0; j < events.Length; j++)
                    {
                        AnimationEvent animationEvent2 = events[j];
                        animationEvent2.intParameter = intParameter;
                    }
                }
            }
            if (selectedParameter == typeof(AnimationEvent) || selectedParameter == typeof(string))
            {
                bool flag3 = Array.TrueForAll <AnimationEvent>(events, (AnimationEvent evt) => evt.stringParameter == firstEvent.stringParameter);
                EditorGUI.BeginChangeCheck();
                EditorGUI.showMixedValue = !flag3;
                string stringParameter = EditorGUILayout.TextField("String", firstEvent.stringParameter, new GUILayoutOption[0]);
                EditorGUI.showMixedValue = false;
                if (EditorGUI.EndChangeCheck())
                {
                    for (int k = 0; k < events.Length; k++)
                    {
                        AnimationEvent animationEvent3 = events[k];
                        animationEvent3.stringParameter = stringParameter;
                    }
                }
            }
            if (selectedParameter == typeof(AnimationEvent) || selectedParameter.IsSubclassOf(typeof(UnityEngine.Object)) || selectedParameter == typeof(UnityEngine.Object))
            {
                bool flag4 = Array.TrueForAll <AnimationEvent>(events, (AnimationEvent evt) => evt.objectReferenceParameter == firstEvent.objectReferenceParameter);
                EditorGUI.BeginChangeCheck();
                Type type = typeof(UnityEngine.Object);
                if (selectedParameter != typeof(AnimationEvent))
                {
                    type = selectedParameter;
                }
                EditorGUI.showMixedValue = !flag4;
                bool allowSceneObjects = false;
                UnityEngine.Object objectReferenceParameter = EditorGUILayout.ObjectField(ObjectNames.NicifyVariableName(type.Name), firstEvent.objectReferenceParameter, type, allowSceneObjects, new GUILayoutOption[0]);
                EditorGUI.showMixedValue = false;
                if (EditorGUI.EndChangeCheck())
                {
                    for (int l = 0; l < events.Length; l++)
                    {
                        AnimationEvent animationEvent4 = events[l];
                        animationEvent4.objectReferenceParameter = objectReferenceParameter;
                    }
                }
            }
        }
コード例 #10
0
 public override void OnInspectorGUI()
 {
     AnimationWindowEvent[] awEvents = (from o in base.targets
                                        select o as AnimationWindowEvent).ToArray <AnimationWindowEvent>();
     AnimationWindowEventInspector.OnEditAnimationEvents(awEvents);
 }
コード例 #11
0
        public static List <AnimationWindowEventMethod> CollectSupportedMethods(GameObject gameObject)
        {
            List <AnimationWindowEventMethod> list = new List <AnimationWindowEventMethod>();
            List <AnimationWindowEventMethod> result;

            if (gameObject == null)
            {
                result = list;
            }
            else
            {
                MonoBehaviour[]  components = gameObject.GetComponents <MonoBehaviour>();
                HashSet <string> hashSet    = new HashSet <string>();
                MonoBehaviour[]  array      = components;
                for (int i = 0; i < array.Length; i++)
                {
                    MonoBehaviour monoBehaviour = array[i];
                    if (!(monoBehaviour == null))
                    {
                        Type type = monoBehaviour.GetType();
                        while (type != typeof(MonoBehaviour) && type != null)
                        {
                            MethodInfo[] methods = type.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                            for (int j = 0; j < methods.Length; j++)
                            {
                                MethodInfo methodInfo = methods[j];
                                string     name       = methodInfo.Name;
                                if (AnimationWindowEventInspector.IsSupportedMethodName(name))
                                {
                                    ParameterInfo[] parameters = methodInfo.GetParameters();
                                    if (parameters.Length <= 1)
                                    {
                                        Type type2 = null;
                                        if (parameters.Length == 1)
                                        {
                                            type2 = parameters[0].ParameterType;
                                            if (type2 != typeof(string) && type2 != typeof(float) && type2 != typeof(int) && type2 != typeof(AnimationEvent) && type2 != typeof(UnityEngine.Object) && !type2.IsSubclassOf(typeof(UnityEngine.Object)) && !type2.IsEnum)
                                            {
                                                goto IL_1BD;
                                            }
                                        }
                                        AnimationWindowEventMethod item = default(AnimationWindowEventMethod);
                                        item.name          = methodInfo.Name;
                                        item.parameterType = type2;
                                        int num = list.FindIndex((AnimationWindowEventMethod m) => m.name == name);
                                        if (num != -1)
                                        {
                                            if (list[num].parameterType != type2)
                                            {
                                                hashSet.Add(name);
                                            }
                                        }
                                        list.Add(item);
                                    }
                                }
                                IL_1BD :;
                            }
                            type = type.BaseType;
                        }
                    }
                }
                foreach (string current in hashSet)
                {
                    for (int k = list.Count - 1; k >= 0; k--)
                    {
                        if (list[k].name.Equals(current))
                        {
                            list.RemoveAt(k);
                        }
                    }
                }
                result = list;
            }
            return(result);
        }
コード例 #12
0
 public static void OnEditAnimationEvent(AnimationWindowEvent awevt)
 {
     AnimationEvent[] array = null;
     if (awevt.clip != null)
     {
         array = AnimationUtility.GetAnimationEvents(awevt.clip);
     }
     else if (awevt.clipInfo != null)
     {
         array = awevt.clipInfo.GetEvents();
     }
     if (array != null && awevt.eventIndex >= 0 && awevt.eventIndex < array.Length)
     {
         AnimationEvent evt = array[awevt.eventIndex];
         GUI.changed = false;
         if (awevt.root != null)
         {
             List <AnimationWindowEventMethod> list = AnimationWindowEventInspector.CollectSupportedMethods(awevt);
             List <string> list2 = new List <string>(list.Count);
             for (int i = 0; i < list.Count; i++)
             {
                 AnimationWindowEventMethod animationWindowEventMethod = list[i];
                 string str = " ( )";
                 if (animationWindowEventMethod.parameterType != null)
                 {
                     if (animationWindowEventMethod.parameterType == typeof(float))
                     {
                         str = " ( float )";
                     }
                     else if (animationWindowEventMethod.parameterType == typeof(int))
                     {
                         str = " ( int )";
                     }
                     else
                     {
                         str = string.Format(" ( {0} )", animationWindowEventMethod.parameterType.Name);
                     }
                 }
                 list2.Add(animationWindowEventMethod.name + str);
             }
             int count = list.Count;
             int num   = list.FindIndex((AnimationWindowEventMethod method) => method.name == evt.functionName);
             if (num == -1)
             {
                 num = list.Count;
                 list.Add(new AnimationWindowEventMethod
                 {
                     name          = evt.functionName,
                     parameterType = null
                 });
                 if (string.IsNullOrEmpty(evt.functionName))
                 {
                     list2.Add("(No Function Selected)");
                 }
                 else
                 {
                     list2.Add(evt.functionName + " (Function Not Supported)");
                 }
             }
             EditorGUIUtility.labelWidth = 130f;
             int num2 = num;
             num = EditorGUILayout.Popup("Function: ", num, list2.ToArray(), new GUILayoutOption[0]);
             if (num2 != num && num != -1 && num != count)
             {
                 evt.functionName    = list[num].name;
                 evt.stringParameter = string.Empty;
             }
             Type parameterType = list[num].parameterType;
             if (parameterType != null)
             {
                 EditorGUILayout.Space();
                 if (parameterType == typeof(AnimationEvent))
                 {
                     EditorGUILayout.PrefixLabel("Event Data");
                 }
                 else
                 {
                     EditorGUILayout.PrefixLabel("Parameters");
                 }
                 AnimationWindowEventInspector.DoEditRegularParameters(evt, parameterType);
             }
         }
         else
         {
             evt.functionName = EditorGUILayout.TextField(new GUIContent("Function"), evt.functionName, new GUILayoutOption[0]);
             AnimationWindowEventInspector.DoEditRegularParameters(evt, typeof(AnimationEvent));
         }
         if (GUI.changed)
         {
             if (awevt.clip != null)
             {
                 Undo.RegisterCompleteObjectUndo(awevt.clip, "Animation Event Change");
                 AnimationUtility.SetAnimationEvents(awevt.clip, array);
             }
             else if (awevt.clipInfo != null)
             {
                 awevt.clipInfo.SetEvent(awevt.eventIndex, evt);
             }
         }
     }
 }
コード例 #13
0
 public override void OnInspectorGUI()
 {
     AnimationWindowEventInspector.OnEditAnimationEvent(base.target as AnimationWindowEvent);
 }
コード例 #14
0
        public void EventLineGUI(Rect rect, AnimationWindowState state)
        {
            if (!(state.selectedItem == null))
            {
                AnimationClip animationClip  = state.selectedItem.animationClip;
                GameObject    rootGameObject = state.selectedItem.rootGameObject;
                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 (animationClip != null)
                {
                    AnimationEvent[] animationEvents = AnimationUtility.GetAnimationEvents(animationClip);
                    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 * animationClip.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  = AnimationWindowEventInspector.FormatEvent(rootGameObject, 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;
                    }
                    bool[] array3 = new bool[animationEvents.Length];
                    UnityEngine.Object[] objects = Selection.objects;
                    UnityEngine.Object[] array4  = objects;
                    for (int j = 0; j < array4.Length; j++)
                    {
                        UnityEngine.Object   @object = array4[j];
                        AnimationWindowEvent animationWindowEvent = @object as AnimationWindowEvent;
                        if (animationWindowEvent != null)
                        {
                            if (animationWindowEvent.eventIndex >= 0 && animationWindowEvent.eventIndex < array3.Length)
                            {
                                array3[animationWindowEvent.eventIndex] = true;
                            }
                        }
                    }
                    Vector2        zero = Vector2.zero;
                    int            num6;
                    float          num7;
                    float          num8;
                    HighLevelEvent highLevelEvent = EditorGUIExt.MultiSelection(rect, array2, new GUIContent(image), array, ref array3, null, out num6, out zero, out num7, out num8, GUIStyle.none);
                    if (highLevelEvent != HighLevelEvent.None)
                    {
                        switch (highLevelEvent)
                        {
                        case HighLevelEvent.DoubleClick:
                            if (num6 != -1)
                            {
                                this.EditEvents(rootGameObject, animationClip, array3);
                            }
                            else
                            {
                                this.EventLineContextMenuAdd(new AnimationEventTimeLine.EventLineContextMenuObject(rootGameObject, animationClip, time, -1, array3));
                            }
                            break;

                        case HighLevelEvent.ContextClick:
                        {
                            GenericMenu genericMenu = new GenericMenu();
                            AnimationEventTimeLine.EventLineContextMenuObject userData = new AnimationEventTimeLine.EventLineContextMenuObject(rootGameObject, animationClip, animationEvents[num6].time, num6, array3);
                            int num9 = array3.Count((bool selected) => selected);
                            genericMenu.AddItem(new GUIContent("Add Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuAdd), userData);
                            genericMenu.AddItem(new GUIContent((num9 <= 1) ? "Delete Animation Event" : "Delete Animation Events"), 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 k = 0; k < animationEvents.Length; k++)
                            {
                                this.m_EventTimes[k] = animationEvents[k].time;
                            }
                            break;

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

                        case HighLevelEvent.Delete:
                            this.DeleteEvents(animationClip, array3);
                            break;

                        case HighLevelEvent.SelectionChanged:
                            state.ClearKeySelections();
                            this.EditEvents(rootGameObject, animationClip, array3);
                            break;
                        }
                    }
                    this.CheckRectsOnMouseMove(rect, animationEvents, array);
                    if (Event.current.type == EventType.ContextClick && rect2.Contains(Event.current.mousePosition))
                    {
                        Event.current.Use();
                        GenericMenu genericMenu2 = new GenericMenu();
                        AnimationEventTimeLine.EventLineContextMenuObject userData2 = new AnimationEventTimeLine.EventLineContextMenuObject(rootGameObject, animationClip, time, -1, array3);
                        int num10 = array3.Count((bool selected) => selected);
                        genericMenu2.AddItem(new GUIContent("Add Animation Event"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuAdd), userData2);
                        if (num10 > 0)
                        {
                            genericMenu2.AddItem(new GUIContent((num10 <= 1) ? "Delete Animation Event" : "Delete Animation Events"), false, new GenericMenu.MenuFunction2(this.EventLineContextMenuDelete), userData2);
                        }
                        genericMenu2.ShowAsContext();
                    }
                }
                GUI.color = color;
                GUI.EndGroup();
            }
        }
コード例 #15
0
        public void EventLineGUI(Rect rect, AnimationWindowState state)
        {
            if (state.selectedItem != null)
            {
                AnimationClip animationClip  = state.selectedItem.animationClip;
                GameObject    rootGameObject = state.selectedItem.rootGameObject;
                GUI.BeginGroup(rect);
                Color color = GUI.color;
                Rect  rect2 = new Rect(0f, 0f, rect.width, rect.height);
                float time  = Mathf.Max((float)(((float)Mathf.RoundToInt(state.PixelToTime(Event.current.mousePosition.x, rect) * state.frameRate)) / state.frameRate), (float)0f);
                if (animationClip != null)
                {
                    int              num8;
                    float            num9;
                    float            num10;
                    AnimationEvent[] animationEvents = AnimationUtility.GetAnimationEvents(animationClip);
                    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 * animationClip.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  = AnimationWindowEventInspector.FormatEvent(rootGameObject, 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];
                    }
                    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(rootGameObject, animationClip, time, -1));
                            break;
                        }
                        Selection.activeObject = AnimationWindowEvent.Edit(rootGameObject, animationClip, num8);
                        break;

                    case HighLevelEvent.ContextClick:
                    {
                        GenericMenu menu = new GenericMenu();
                        EventLineContextMenuObject userData = new EventLineContextMenuObject(rootGameObject, animationClip, 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 event6 = this.m_EventsAtMouseDown[k];
                                event6.time = this.m_EventTimes[k] + (zero.x * state.PixelDeltaToTime(rect));
                                event6.time = Mathf.Max(0f, event6.time);
                                event6.time = ((float)Mathf.RoundToInt(event6.time * animationClip.frameRate)) / animationClip.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(animationClip, "Move Event");
                        AnimationUtility.SetAnimationEvents(animationClip, this.m_EventsAtMouseDown);
                        this.m_DirtyTooltip = true;
                        break;
                    }

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

                    case HighLevelEvent.SelectionChanged:
                        state.ClearKeySelections();
                        if (num8 != -1)
                        {
                            Selection.activeObject = AnimationWindowEvent.Edit(rootGameObject, animationClip, num8);
                        }
                        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(rootGameObject, animationClip, time, -1));
                    menu2.ShowAsContext();
                }
                GUI.color = color;
                GUI.EndGroup();
            }
        }