Exemple #1
0
        private static void AddFunctionsForScript(GenericMenu menu, SerializedProperty listener, UnityEventDrawer.ValidMethodMap method, string targetName)
        {
            PersistentListenerMode mode1 = method.mode;

            UnityEngine.Object     objectReferenceValue = listener.FindPropertyRelative("m_Target").objectReferenceValue;
            string                 stringValue          = listener.FindPropertyRelative("m_MethodName").stringValue;
            PersistentListenerMode mode2            = UnityEventDrawer.GetMode(listener.FindPropertyRelative("m_Mode"));
            SerializedProperty     propertyRelative = listener.FindPropertyRelative("m_Arguments").FindPropertyRelative("m_ObjectArgumentAssemblyTypeName");
            StringBuilder          stringBuilder    = new StringBuilder();
            int length = method.methodInfo.GetParameters().Length;

            for (int index = 0; index < length; ++index)
            {
                System.Reflection.ParameterInfo parameter = method.methodInfo.GetParameters()[index];
                stringBuilder.Append(string.Format("{0}", (object)UnityEventDrawer.GetTypeName(parameter.ParameterType)));
                if (index < length - 1)
                {
                    stringBuilder.Append(", ");
                }
            }
            bool on = objectReferenceValue == method.target && stringValue == method.methodInfo.Name && mode1 == mode2;

            if (on && mode1 == PersistentListenerMode.Object && method.methodInfo.GetParameters().Length == 1)
            {
                on &= method.methodInfo.GetParameters()[0].ParameterType.AssemblyQualifiedName == propertyRelative.stringValue;
            }
            string formattedMethodName = UnityEventDrawer.GetFormattedMethodName(targetName, method.methodInfo.Name, stringBuilder.ToString(), mode1 == PersistentListenerMode.EventDefined);

            menu.AddItem(new GUIContent(formattedMethodName), on, new GenericMenu.MenuFunction2(UnityEventDrawer.SetEventFunction), (object)new UnityEventDrawer.UnityEventFunction(listener, method.target, method.methodInfo, mode1));
        }
        private static void AddFunctionsForScript(GenericMenu menu, SerializedProperty listener, UnityEventDrawer.ValidMethodMap method, string targetName)
        {
            PersistentListenerMode mode = method.mode;

            UnityEngine.Object     objectReferenceValue = listener.FindPropertyRelative("m_Target").objectReferenceValue;
            string                 stringValue          = listener.FindPropertyRelative("m_MethodName").stringValue;
            PersistentListenerMode mode2 = UnityEventDrawer.GetMode(listener.FindPropertyRelative("m_Mode"));
            SerializedProperty     serializedProperty = listener.FindPropertyRelative("m_Arguments").FindPropertyRelative("m_ObjectArgumentAssemblyTypeName");
            StringBuilder          stringBuilder      = new StringBuilder();
            int num = method.methodInfo.GetParameters().Length;

            for (int i = 0; i < num; i++)
            {
                ParameterInfo parameterInfo = method.methodInfo.GetParameters()[i];
                stringBuilder.Append(string.Format("{0}", UnityEventDrawer.GetTypeName(parameterInfo.ParameterType)));
                if (i < num - 1)
                {
                    stringBuilder.Append(", ");
                }
            }
            bool flag = objectReferenceValue == method.target && stringValue == method.methodInfo.Name && mode == mode2;

            if (flag && mode == PersistentListenerMode.Object && method.methodInfo.GetParameters().Length == 1)
            {
                flag &= (method.methodInfo.GetParameters()[0].ParameterType.AssemblyQualifiedName == serializedProperty.stringValue);
            }
            string formattedMethodName = UnityEventDrawer.GetFormattedMethodName(targetName, method.methodInfo.Name, stringBuilder.ToString(), mode == PersistentListenerMode.EventDefined);

            menu.AddItem(new GUIContent(formattedMethodName), flag, new GenericMenu.MenuFunction2(UnityEventDrawer.SetEventFunction), new UnityEventDrawer.UnityEventFunction(listener, method.target, method.methodInfo, mode));
        }
Exemple #3
0
        private void DrawEventListener(Rect rect, int index, bool isactive, bool isfocused)
        {
            SerializedProperty arrayElementAtIndex = this.m_ListenersArray.GetArrayElementAtIndex(index);

            rect.y += 1f;
            Rect[]             rowRects            = this.GetRowRects(rect);
            Rect               position            = rowRects[0];
            Rect               position2           = rowRects[1];
            Rect               rect2               = rowRects[2];
            Rect               position3           = rowRects[3];
            SerializedProperty property            = arrayElementAtIndex.FindPropertyRelative("m_CallState");
            SerializedProperty mode                = arrayElementAtIndex.FindPropertyRelative("m_Mode");
            SerializedProperty serializedProperty  = arrayElementAtIndex.FindPropertyRelative("m_Arguments");
            SerializedProperty serializedProperty2 = arrayElementAtIndex.FindPropertyRelative("m_Target");
            SerializedProperty serializedProperty3 = arrayElementAtIndex.FindPropertyRelative("m_MethodName");
            Color              backgroundColor     = GUI.backgroundColor;

            GUI.backgroundColor = Color.white;
            EditorGUI.PropertyField(position, property, GUIContent.none);
            EditorGUI.BeginChangeCheck();
            GUI.Box(position2, GUIContent.none);
            EditorGUI.PropertyField(position2, serializedProperty2, GUIContent.none);
            if (EditorGUI.EndChangeCheck())
            {
                serializedProperty3.stringValue = null;
            }
            PersistentListenerMode persistentListenerMode = UnityEventDrawer.GetMode(mode);

            if (serializedProperty2.objectReferenceValue == null || string.IsNullOrEmpty(serializedProperty3.stringValue))
            {
                persistentListenerMode = PersistentListenerMode.Void;
            }
            SerializedProperty serializedProperty4;

            switch (persistentListenerMode)
            {
            case PersistentListenerMode.Object:
                serializedProperty4 = serializedProperty.FindPropertyRelative("m_ObjectArgument");
                break;

            case PersistentListenerMode.Int:
                serializedProperty4 = serializedProperty.FindPropertyRelative("m_IntArgument");
                break;

            case PersistentListenerMode.Float:
                serializedProperty4 = serializedProperty.FindPropertyRelative("m_FloatArgument");
                break;

            case PersistentListenerMode.String:
                serializedProperty4 = serializedProperty.FindPropertyRelative("m_StringArgument");
                break;

            case PersistentListenerMode.Bool:
                serializedProperty4 = serializedProperty.FindPropertyRelative("m_BoolArgument");
                break;

            default:
                serializedProperty4 = serializedProperty.FindPropertyRelative("m_IntArgument");
                break;
            }
            string stringValue = serializedProperty.FindPropertyRelative("m_ObjectArgumentAssemblyTypeName").stringValue;
            Type   type        = typeof(UnityEngine.Object);

            if (!string.IsNullOrEmpty(stringValue))
            {
                type = (Type.GetType(stringValue, false) ?? typeof(UnityEngine.Object));
            }
            if (persistentListenerMode == PersistentListenerMode.Object)
            {
                EditorGUI.BeginChangeCheck();
                UnityEngine.Object objectReferenceValue = EditorGUI.ObjectField(position3, GUIContent.none, serializedProperty4.objectReferenceValue, type, true);
                if (EditorGUI.EndChangeCheck())
                {
                    serializedProperty4.objectReferenceValue = objectReferenceValue;
                }
            }
            else if (persistentListenerMode != PersistentListenerMode.Void && persistentListenerMode != PersistentListenerMode.EventDefined)
            {
                EditorGUI.PropertyField(position3, serializedProperty4, GUIContent.none);
            }
            using (new EditorGUI.DisabledScope(serializedProperty2.objectReferenceValue == null))
            {
                EditorGUI.BeginProperty(rect2, GUIContent.none, serializedProperty3);
                GUIContent content;
                if (EditorGUI.showMixedValue)
                {
                    content = EditorGUI.mixedValueContent;
                }
                else
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    if (serializedProperty2.objectReferenceValue == null || string.IsNullOrEmpty(serializedProperty3.stringValue))
                    {
                        stringBuilder.Append("No Function");
                    }
                    else if (!UnityEventDrawer.IsPersistantListenerValid(this.m_DummyEvent, serializedProperty3.stringValue, serializedProperty2.objectReferenceValue, UnityEventDrawer.GetMode(mode), type))
                    {
                        string             arg = "UnknownComponent";
                        UnityEngine.Object objectReferenceValue2 = serializedProperty2.objectReferenceValue;
                        if (objectReferenceValue2 != null)
                        {
                            arg = objectReferenceValue2.GetType().Name;
                        }
                        stringBuilder.Append(string.Format("<Missing {0}.{1}>", arg, serializedProperty3.stringValue));
                    }
                    else
                    {
                        stringBuilder.Append(serializedProperty2.objectReferenceValue.GetType().Name);
                        if (!string.IsNullOrEmpty(serializedProperty3.stringValue))
                        {
                            stringBuilder.Append(".");
                            if (serializedProperty3.stringValue.StartsWith("set_"))
                            {
                                stringBuilder.Append(serializedProperty3.stringValue.Substring(4));
                            }
                            else
                            {
                                stringBuilder.Append(serializedProperty3.stringValue);
                            }
                        }
                    }
                    content = GUIContent.Temp(stringBuilder.ToString());
                }
                if (GUI.Button(rect2, content, EditorStyles.popup))
                {
                    UnityEventDrawer.BuildPopupList(serializedProperty2.objectReferenceValue, this.m_DummyEvent, arrayElementAtIndex).DropDown(rect2);
                }
                EditorGUI.EndProperty();
            }
            GUI.backgroundColor = backgroundColor;
        }
Exemple #4
0
        private void DrawEventListener(Rect rect, int index, bool isactive, bool isfocused)
        {
            SerializedProperty arrayElementAtIndex = this.m_ListenersArray.GetArrayElementAtIndex(index);

            ++rect.y;
            Rect[]             rowRects          = this.GetRowRects(rect);
            Rect               position1         = rowRects[0];
            Rect               position2         = rowRects[1];
            Rect               rect1             = rowRects[2];
            Rect               position3         = rowRects[3];
            SerializedProperty propertyRelative1 = arrayElementAtIndex.FindPropertyRelative("m_CallState");
            SerializedProperty propertyRelative2 = arrayElementAtIndex.FindPropertyRelative("m_Mode");
            SerializedProperty propertyRelative3 = arrayElementAtIndex.FindPropertyRelative("m_Arguments");
            SerializedProperty propertyRelative4 = arrayElementAtIndex.FindPropertyRelative("m_Target");
            SerializedProperty propertyRelative5 = arrayElementAtIndex.FindPropertyRelative("m_MethodName");
            Color              backgroundColor   = GUI.backgroundColor;

            GUI.backgroundColor = Color.white;
            EditorGUI.PropertyField(position1, propertyRelative1, GUIContent.none);
            EditorGUI.BeginChangeCheck();
            GUI.Box(position2, GUIContent.none);
            EditorGUI.PropertyField(position2, propertyRelative4, GUIContent.none);
            if (EditorGUI.EndChangeCheck())
            {
                propertyRelative5.stringValue = (string)null;
            }
            PersistentListenerMode persistentListenerMode = UnityEventDrawer.GetMode(propertyRelative2);

            if (propertyRelative4.objectReferenceValue == (UnityEngine.Object)null || string.IsNullOrEmpty(propertyRelative5.stringValue))
            {
                persistentListenerMode = PersistentListenerMode.Void;
            }
            SerializedProperty propertyRelative6;

            switch (persistentListenerMode)
            {
            case PersistentListenerMode.Object:
                propertyRelative6 = propertyRelative3.FindPropertyRelative("m_ObjectArgument");
                break;

            case PersistentListenerMode.Int:
                propertyRelative6 = propertyRelative3.FindPropertyRelative("m_IntArgument");
                break;

            case PersistentListenerMode.Float:
                propertyRelative6 = propertyRelative3.FindPropertyRelative("m_FloatArgument");
                break;

            case PersistentListenerMode.String:
                propertyRelative6 = propertyRelative3.FindPropertyRelative("m_StringArgument");
                break;

            case PersistentListenerMode.Bool:
                propertyRelative6 = propertyRelative3.FindPropertyRelative("m_BoolArgument");
                break;

            default:
                propertyRelative6 = propertyRelative3.FindPropertyRelative("m_IntArgument");
                break;
            }
            string stringValue = propertyRelative3.FindPropertyRelative("m_ObjectArgumentAssemblyTypeName").stringValue;

            System.Type type = typeof(UnityEngine.Object);
            if (!string.IsNullOrEmpty(stringValue))
            {
                type = System.Type.GetType(stringValue, false) ?? typeof(UnityEngine.Object);
            }
            if (persistentListenerMode == PersistentListenerMode.Object)
            {
                EditorGUI.BeginChangeCheck();
                UnityEngine.Object @object = EditorGUI.ObjectField(position3, GUIContent.none, propertyRelative6.objectReferenceValue, type, true);
                if (EditorGUI.EndChangeCheck())
                {
                    propertyRelative6.objectReferenceValue = @object;
                }
            }
            else if (persistentListenerMode != PersistentListenerMode.Void && persistentListenerMode != PersistentListenerMode.EventDefined)
            {
                EditorGUI.PropertyField(position3, propertyRelative6, GUIContent.none);
            }
            EditorGUI.BeginDisabledGroup(propertyRelative4.objectReferenceValue == (UnityEngine.Object)null);
            EditorGUI.BeginProperty(rect1, GUIContent.none, propertyRelative5);
            GUIContent content;

            if (EditorGUI.showMixedValue)
            {
                content = EditorGUI.mixedValueContent;
            }
            else
            {
                StringBuilder stringBuilder = new StringBuilder();
                if (propertyRelative4.objectReferenceValue == (UnityEngine.Object)null || string.IsNullOrEmpty(propertyRelative5.stringValue))
                {
                    stringBuilder.Append("No Function");
                }
                else if (!UnityEventDrawer.IsPersistantListenerValid(this.m_DummyEvent, propertyRelative5.stringValue, propertyRelative4.objectReferenceValue, UnityEventDrawer.GetMode(propertyRelative2), type))
                {
                    string             str = "UnknownComponent";
                    UnityEngine.Object objectReferenceValue = propertyRelative4.objectReferenceValue;
                    if (objectReferenceValue != (UnityEngine.Object)null)
                    {
                        str = objectReferenceValue.GetType().Name;
                    }
                    stringBuilder.Append(string.Format("<Missing {0}.{1}>", (object)str, (object)propertyRelative5.stringValue));
                }
                else
                {
                    stringBuilder.Append(propertyRelative4.objectReferenceValue.GetType().Name);
                    if (!string.IsNullOrEmpty(propertyRelative5.stringValue))
                    {
                        stringBuilder.Append(".");
                        if (propertyRelative5.stringValue.StartsWith("set_"))
                        {
                            stringBuilder.Append(propertyRelative5.stringValue.Substring(4));
                        }
                        else
                        {
                            stringBuilder.Append(propertyRelative5.stringValue);
                        }
                    }
                }
                content = GUIContent.Temp(stringBuilder.ToString());
            }
            if (GUI.Button(rect1, content, EditorStyles.popup))
            {
                UnityEventDrawer.BuildPopupList(propertyRelative4.objectReferenceValue, this.m_DummyEvent, arrayElementAtIndex).DropDown(rect1);
            }
            EditorGUI.EndProperty();
            EditorGUI.EndDisabledGroup();
            GUI.backgroundColor = backgroundColor;
        }