Esempio n. 1
0
        public void OnGUI()
        {
            AnimationEvent[] array = null;
            if (this.m_Clip != null)
            {
                array = AnimationUtility.GetAnimationEvents(this.m_Clip);
            }
            else if (this.m_ClipInfo != null)
            {
                array = this.m_ClipInfo.GetEvents();
            }
            if (array == null || this.eventIndex < 0 || this.eventIndex >= array.Length)
            {
                return;
            }
            GUI.changed = false;
            AnimationEvent animationEvent = array[this.eventIndex];

            if (this.m_Root)
            {
                List <string> list;
                List <Type>   list2;
                AnimationEventPopup.CollectSupportedMethods(this.m_Root, out list, out list2);
                List <string> list3 = new List <string>(list.Count);
                for (int i = 0; i < list.Count; i++)
                {
                    string str = " ( )";
                    if (list2[i] != null)
                    {
                        if (list2[i] == typeof(float))
                        {
                            str = " ( float )";
                        }
                        else if (list2[i] == typeof(int))
                        {
                            str = " ( int )";
                        }
                        else
                        {
                            str = string.Format(" ( {0} )", list2[i].Name);
                        }
                    }
                    list3.Add(list[i] + str);
                }
                int count = list.Count;
                int num   = list.IndexOf(animationEvent.functionName);
                if (num == -1)
                {
                    num = list.Count;
                    list.Add(animationEvent.functionName);
                    if (string.IsNullOrEmpty(animationEvent.functionName))
                    {
                        list3.Add("(No Function Selected)");
                    }
                    else
                    {
                        list3.Add(animationEvent.functionName + " (Function Not Supported)");
                    }
                    list2.Add(null);
                }
                EditorGUIUtility.labelWidth = 130f;
                int num2 = num;
                num = EditorGUILayout.Popup("Function: ", num, list3.ToArray(), new GUILayoutOption[0]);
                if (num2 != num && num != -1 && num != count)
                {
                    animationEvent.functionName    = list[num];
                    animationEvent.stringParameter = string.Empty;
                }
                Type type = list2[num];
                if (type != null)
                {
                    EditorGUILayout.Space();
                    if (type == typeof(AnimationEvent))
                    {
                        EditorGUILayout.PrefixLabel("Event Data");
                    }
                    else
                    {
                        EditorGUILayout.PrefixLabel("Parameters");
                    }
                    AnimationEventPopup.DoEditRegularParameters(animationEvent, type);
                }
            }
            else
            {
                animationEvent.functionName = EditorGUILayout.TextField(new GUIContent("Function"), animationEvent.functionName, new GUILayoutOption[0]);
                AnimationEventPopup.DoEditRegularParameters(animationEvent, typeof(AnimationEvent));
            }
            if (GUI.changed)
            {
                if (this.m_Clip != null)
                {
                    Undo.RegisterCompleteObjectUndo(this.m_Clip, "Animation Event Change");
                    AnimationUtility.SetAnimationEvents(this.m_Clip, array);
                }
                else if (this.m_ClipInfo != null)
                {
                    this.m_ClipInfo.SetEvent(this.m_EventIndex, animationEvent);
                }
            }
        }
        public void OnGUI()
        {
            AnimationEvent[] events = (AnimationEvent[])null;
            if ((UnityEngine.Object) this.m_Clip != (UnityEngine.Object)null)
            {
                events = AnimationUtility.GetAnimationEvents(this.m_Clip);
            }
            else if (this.m_ClipInfo != null)
            {
                events = this.m_ClipInfo.GetEvents();
            }
            if (events == null || this.eventIndex < 0 || this.eventIndex >= events.Length)
            {
                return;
            }
            GUI.changed = false;
            AnimationEvent animationEvent = events[this.eventIndex];

            if ((bool)((UnityEngine.Object) this.m_Root))
            {
                List <string>      supportedMethods;
                List <System.Type> supportedMethodsParameter;
                AnimationEventPopup.CollectSupportedMethods(this.m_Root, out supportedMethods, out supportedMethodsParameter);
                List <string> stringList = new List <string>(supportedMethods.Count);
                for (int index = 0; index < supportedMethods.Count; ++index)
                {
                    string str = " ( )";
                    if (supportedMethodsParameter[index] != null)
                    {
                        str = supportedMethodsParameter[index] != typeof(float) ? (supportedMethodsParameter[index] != typeof(int) ? string.Format(" ( {0} )", (object)supportedMethodsParameter[index].Name) : " ( int )") : " ( float )";
                    }
                    stringList.Add(supportedMethods[index] + str);
                }
                int count         = supportedMethods.Count;
                int selectedIndex = supportedMethods.IndexOf(animationEvent.functionName);
                if (selectedIndex == -1)
                {
                    selectedIndex = supportedMethods.Count;
                    supportedMethods.Add(animationEvent.functionName);
                    if (string.IsNullOrEmpty(animationEvent.functionName))
                    {
                        stringList.Add("(No Function Selected)");
                    }
                    else
                    {
                        stringList.Add(animationEvent.functionName + " (Function Not Supported)");
                    }
                    supportedMethodsParameter.Add((System.Type)null);
                }
                EditorGUIUtility.labelWidth = 130f;
                int num    = selectedIndex;
                int index1 = EditorGUILayout.Popup("Function: ", selectedIndex, stringList.ToArray(), new GUILayoutOption[0]);
                if (num != index1 && index1 != -1 && index1 != count)
                {
                    animationEvent.functionName    = supportedMethods[index1];
                    animationEvent.stringParameter = string.Empty;
                }
                System.Type selectedParameter = supportedMethodsParameter[index1];
                if (selectedParameter != null)
                {
                    EditorGUILayout.Space();
                    if (selectedParameter == typeof(AnimationEvent))
                    {
                        EditorGUILayout.PrefixLabel("Event Data");
                    }
                    else
                    {
                        EditorGUILayout.PrefixLabel("Parameters");
                    }
                    AnimationEventPopup.DoEditRegularParameters(animationEvent, selectedParameter);
                }
            }
            else
            {
                animationEvent.functionName = EditorGUILayout.TextField(new GUIContent("Function"), animationEvent.functionName, new GUILayoutOption[0]);
                AnimationEventPopup.DoEditRegularParameters(animationEvent, typeof(AnimationEvent));
            }
            if (!GUI.changed)
            {
                return;
            }
            if ((UnityEngine.Object) this.m_Clip != (UnityEngine.Object)null)
            {
                Undo.RegisterCompleteObjectUndo((UnityEngine.Object) this.m_Clip, "Animation Event Change");
                AnimationUtility.SetAnimationEvents(this.m_Clip, events);
            }
            else
            {
                if (this.m_ClipInfo == null)
                {
                    return;
                }
                this.m_ClipInfo.SetEvent(this.m_EventIndex, animationEvent);
            }
        }