Пример #1
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;
        }
Пример #2
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;
        }