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

            UnityEngine.Object            objectReferenceValue = listener.FindPropertyRelative("m_Target").objectReferenceValue;
            string                        stringValue          = listener.FindPropertyRelative("m_MethodName").stringValue;
            TestityPersistentListenerMode mode2 = TesityEventDrawer.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}", TesityEventDrawer.GetTypeName(parameterInfo.ParameterType)));
                if (i < num - 1)
                {
                    stringBuilder.Append(", ");
                }
            }
            bool flag = objectReferenceValue == method.target && stringValue == method.methodInfo.Name && mode == mode2;

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

            menu.AddItem(new GUIContent(formattedMethodName), flag, new GenericMenu.MenuFunction2(TesityEventDrawer.SetEventFunction), new TesityEventDrawer.UnityEventFunction(listener, method.target, method.methodInfo, mode));
        }
Exemple #2
0
        private static void GetMethodsForTargetAndMode(UnityEngine.Object target, Type[] delegateArgumentsTypes, List <TesityEventDrawer.ValidMethodMap> methods, TestityPersistentListenerMode mode)
        {
            IEnumerable <TesityEventDrawer.ValidMethodMap> enumerable = TesityEventDrawer.CalculateMethodMap(target, delegateArgumentsTypes, mode == TestityPersistentListenerMode.Object);

            foreach (TesityEventDrawer.ValidMethodMap current in enumerable)
            {
                TesityEventDrawer.ValidMethodMap item = current;
                item.mode = mode;
                methods.Add(item);
            }
        }
Exemple #3
0
        private static void AddMethodsToMenu(GenericMenu menu, SerializedProperty listener, List <TesityEventDrawer.ValidMethodMap> methods, string targetName)
        {
            IEnumerable <TesityEventDrawer.ValidMethodMap> enumerable =
                from e in methods
                orderby(!e.methodInfo.Name.StartsWith("set_")) ? 1 : 0, e.methodInfo.Name
            select e;

            foreach (TesityEventDrawer.ValidMethodMap current in enumerable)
            {
                TesityEventDrawer.AddFunctionsForScript(menu, listener, current, targetName);
            }
        }
Exemple #4
0
        private static void GeneratePopUpForType(GenericMenu menu, UnityEngine.Object target, bool useFullTargetName, SerializedProperty listener, Type[] delegateArgumentsTypes)
        {
            List <TesityEventDrawer.ValidMethodMap> list = new List <TesityEventDrawer.ValidMethodMap>();
            string text = (!useFullTargetName) ? target.GetType().Name : target.GetType().FullName;
            bool   flag = false;

            if (delegateArgumentsTypes.Length != 0)
            {
                TesityEventDrawer.GetMethodsForTargetAndMode(target, delegateArgumentsTypes, list, TestityPersistentListenerMode.EventDefined);
                if (list.Count > 0)
                {
                    menu.AddDisabledItem(new GUIContent(text + "/Dynamic " + string.Join(", ", (
                                                                                             from e in delegateArgumentsTypes
                                                                                             select TesityEventDrawer.GetTypeName(e)).ToArray <string>())));
                    TesityEventDrawer.AddMethodsToMenu(menu, listener, list, text);
                    flag = true;
                }
            }
            list.Clear();
            TesityEventDrawer.GetMethodsForTargetAndMode(target, new Type[]
            {
                typeof(float)
            }, list, TestityPersistentListenerMode.Float);
            TesityEventDrawer.GetMethodsForTargetAndMode(target, new Type[]
            {
                typeof(int)
            }, list, TestityPersistentListenerMode.Int);
            TesityEventDrawer.GetMethodsForTargetAndMode(target, new Type[]
            {
                typeof(string)
            }, list, TestityPersistentListenerMode.String);
            TesityEventDrawer.GetMethodsForTargetAndMode(target, new Type[]
            {
                typeof(bool)
            }, list, TestityPersistentListenerMode.Bool);
            TesityEventDrawer.GetMethodsForTargetAndMode(target, new Type[]
            {
                typeof(UnityEngine.Object)
            }, list, TestityPersistentListenerMode.Object);
            TesityEventDrawer.GetMethodsForTargetAndMode(target, new Type[0], list, TestityPersistentListenerMode.Void);
            if (list.Count > 0)
            {
                if (flag)
                {
                    menu.AddItem(new GUIContent(text + "/ "), false, null);
                }
                if (delegateArgumentsTypes.Length != 0)
                {
                    menu.AddDisabledItem(new GUIContent(text + "/Static Parameters"));
                }
                TesityEventDrawer.AddMethodsToMenu(menu, listener, list, text);
            }
        }
Exemple #5
0
        private static GenericMenu BuildPopupList(UnityEngine.Object target, TestityEventBase dummyEvent, SerializedProperty listener)
        {
            UnityEngine.Object @object = target;
            if (@object is Component)
            {
                @object = (target as Component).gameObject;
            }
            SerializedProperty serializedProperty = listener.FindPropertyRelative("m_MethodName");
            GenericMenu        genericMenu        = new GenericMenu();

            genericMenu.AddItem(new GUIContent("No Function"), string.IsNullOrEmpty(serializedProperty.stringValue), new GenericMenu.MenuFunction2(TesityEventDrawer.ClearEventFunction), new TesityEventDrawer.UnityEventFunction(listener, null, null, TestityPersistentListenerMode.EventDefined));
            if (@object == null)
            {
                return(genericMenu);
            }
            genericMenu.AddSeparator(string.Empty);
            Type       type   = dummyEvent.GetType();
            MethodInfo method = type.GetMethod("Invoke");

            Type[] delegateArgumentsTypes = (
                from x in method.GetParameters()
                select x.ParameterType).ToArray <Type>();
            TesityEventDrawer.GeneratePopUpForType(genericMenu, @object, false, listener, delegateArgumentsTypes);
            if (@object is GameObject)
            {
                Component[]   components = (@object as GameObject).GetComponents <Component>();
                List <string> list       = (
                    from c in components
                    where c != null
                    select c.GetType().Name into x
                    group x by x into g
                    where g.Count <string>() > 1
                    select g.Key).ToList <string>();
                Component[] array = components;
                for (int i = 0; i < array.Length; i++)
                {
                    Component component = array[i];
                    if (!(component == null))
                    {
                        TesityEventDrawer.GeneratePopUpForType(genericMenu, component, list.Contains(component.GetType().Name), listener, delegateArgumentsTypes);
                    }
                }
            }
            return(genericMenu);
        }
Exemple #6
0
 public void OnGUI(Rect position)
 {
     if (this.m_ListenersArray == null || !this.m_ListenersArray.isArray)
     {
         return;
     }
     this.m_DummyEvent = TesityEventDrawer.GetDummyEvent(this.m_Prop);
     if (this.m_DummyEvent == null)
     {
         return;
     }
     if (this.m_Styles == null)
     {
         this.m_Styles = new TesityEventDrawer.Styles();
     }
     if (this.m_ReorderableList != null)
     {
         int indentLevel = EditorGUI.indentLevel;
         EditorGUI.indentLevel = 0;
         this.m_ReorderableList.DoList(position);
         EditorGUI.indentLevel = indentLevel;
     }
 }
		private static void AddFunctionsForScript(GenericMenu menu, SerializedProperty listener, TesityEventDrawer.ValidMethodMap method, string targetName)
		{
			TestityPersistentListenerMode mode = method.mode;
			UnityEngine.Object objectReferenceValue = listener.FindPropertyRelative("m_Target").objectReferenceValue;
			string stringValue = listener.FindPropertyRelative("m_MethodName").stringValue;
			TestityPersistentListenerMode mode2 = TesityEventDrawer.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}", TesityEventDrawer.GetTypeName(parameterInfo.ParameterType)));
				if (i < num - 1)
				{
					stringBuilder.Append(", ");
				}
			}
			bool flag = objectReferenceValue == method.target && stringValue == method.methodInfo.Name && mode == mode2;
			if (flag && mode == TestityPersistentListenerMode.Object && method.methodInfo.GetParameters().Length == 1)
			{
				flag &= (method.methodInfo.GetParameters()[0].ParameterType.AssemblyQualifiedName == serializedProperty.stringValue);
			}
			string formattedMethodName = TesityEventDrawer.GetFormattedMethodName(targetName, method.methodInfo.Name, stringBuilder.ToString(), mode == TestityPersistentListenerMode.EventDefined);
			menu.AddItem(new GUIContent(formattedMethodName), flag, new GenericMenu.MenuFunction2(TesityEventDrawer.SetEventFunction), new TesityEventDrawer.UnityEventFunction(listener, method.target, method.methodInfo, mode));
		}
Exemple #8
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;
            }
            TestityPersistentListenerMode mode2 = TesityEventDrawer.GetMode(mode);
            SerializedProperty            serializedProperty4;

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

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

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

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

            case TestityPersistentListenerMode.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 (mode2 == TestityPersistentListenerMode.Object)
            {
                EditorGUI.BeginChangeCheck();
                UnityEngine.Object objectReferenceValue = EditorGUI.ObjectField(position3, GUIContent.none, serializedProperty4.objectReferenceValue, type, true);
                if (EditorGUI.EndChangeCheck())
                {
                    serializedProperty4.objectReferenceValue = objectReferenceValue;
                }
            }
            else
            {
                if (mode2 != TestityPersistentListenerMode.Void && mode2 != TestityPersistentListenerMode.EventDefined)
                {
                    EditorGUI.PropertyField(position3, serializedProperty4, GUIContent.none);
                }
            }
            EditorGUI.BeginDisabledGroup(serializedProperty2.objectReferenceValue == null);
            EditorGUI.BeginProperty(rect2, GUIContent.none, serializedProperty3);
            GUIContent content;

            if (EditorGUI.showMixedValue)
            {
                content = new GUIContent("Temp");                //MODIFIED: EditorGUI.mixedValueContent;
            }
            else
            {
                StringBuilder stringBuilder = new StringBuilder();
                if (serializedProperty2.objectReferenceValue == null || string.IsNullOrEmpty(serializedProperty3.stringValue))
                {
                    stringBuilder.Append("No Function");
                }
                else
                {
                    if (!TesityEventDrawer.IsPersistantListenerValid(this.m_DummyEvent, serializedProperty3.stringValue, serializedProperty2.objectReferenceValue, TesityEventDrawer.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 = new GUIContent("Temp");                //MODIFIED: GUIContent.Temp(stringBuilder.ToString());
            }
            if (GUI.Button(rect2, content, EditorStyles.popup))
            {
                TesityEventDrawer.BuildPopupList(serializedProperty2.objectReferenceValue, this.m_DummyEvent, arrayElementAtIndex).DropDown(rect2);
            }
            EditorGUI.EndProperty();
            EditorGUI.EndDisabledGroup();
            GUI.backgroundColor = backgroundColor;
        }
Exemple #9
0
        protected virtual void DrawEventHeader(Rect headerRect)
        {
            headerRect.height = 16f;
            string text = ((!string.IsNullOrEmpty(this.m_Text)) ? this.m_Text : "Event") + TesityEventDrawer.GetEventParams(this.m_DummyEvent);

            GUI.Label(headerRect, text);
        }