Esempio n. 1
0
 private static void SetData(AnimationWindowEvent[] awEvents, AnimationWindowEventInspector.AnimationWindowEventData data)
 {
     if (data.events != null)
     {
         if (data.clip != null)
         {
             Undo.RegisterCompleteObjectUndo(data.clip, "Animation Event Change");
             AnimationUtility.SetAnimationEvents(data.clip, data.events);
         }
         else if (data.clipInfo != null)
         {
             for (int i = 0; i < awEvents.Length; i++)
             {
                 AnimationWindowEvent animationWindowEvent = awEvents[i];
                 if (animationWindowEvent.eventIndex >= 0 && animationWindowEvent.eventIndex < data.events.Length)
                 {
                     data.clipInfo.SetEvent(animationWindowEvent.eventIndex, data.events[animationWindowEvent.eventIndex]);
                 }
             }
         }
     }
 }
Esempio n. 2
0
 private static AnimationWindowEventInspector.AnimationWindowEventData GetData(AnimationWindowEvent[] awEvents)
 {
     AnimationWindowEventInspector.AnimationWindowEventData animationWindowEventData = default(AnimationWindowEventInspector.AnimationWindowEventData);
     AnimationWindowEventInspector.AnimationWindowEventData result;
     if (awEvents.Length == 0)
     {
         result = animationWindowEventData;
     }
     else
     {
         AnimationWindowEvent animationWindowEvent = awEvents[0];
         animationWindowEventData.root     = animationWindowEvent.root;
         animationWindowEventData.clip     = animationWindowEvent.clip;
         animationWindowEventData.clipInfo = animationWindowEvent.clipInfo;
         if (animationWindowEventData.clip != null)
         {
             animationWindowEventData.events = AnimationUtility.GetAnimationEvents(animationWindowEventData.clip);
         }
         else if (animationWindowEventData.clipInfo != null)
         {
             animationWindowEventData.events = animationWindowEventData.clipInfo.GetEvents();
         }
         if (animationWindowEventData.events != null)
         {
             List <AnimationEvent> list = new List <AnimationEvent>();
             for (int i = 0; i < awEvents.Length; i++)
             {
                 AnimationWindowEvent animationWindowEvent2 = awEvents[i];
                 if (animationWindowEvent2.eventIndex >= 0 && animationWindowEvent2.eventIndex < animationWindowEventData.events.Length)
                 {
                     list.Add(animationWindowEventData.events[animationWindowEvent2.eventIndex]);
                 }
             }
             animationWindowEventData.selectedEvents = list.ToArray();
         }
         result = animationWindowEventData;
     }
     return(result);
 }
Esempio n. 3
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);
            }
        }
Esempio n. 4
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);
         }
     }
 }