public BaseInvokableCall GetRuntimeCall(UnityEventBase theEvent)
		{
			if (this.m_CallState == UnityEventCallState.RuntimeOnly && !Application.isPlaying)
			{
				return null;
			}
			if (this.m_CallState == UnityEventCallState.Off || theEvent == null)
			{
				return null;
			}
			MethodInfo methodInfo = theEvent.FindMethod(this);
			if (methodInfo == null)
			{
				return null;
			}
			switch (this.m_Mode)
			{
			case PersistentListenerMode.EventDefined:
				return theEvent.GetDelegate(this.target, methodInfo);
			case PersistentListenerMode.Void:
				return new InvokableCall(this.target, methodInfo);
			case PersistentListenerMode.Object:
				return PersistentCall.GetObjectCall(this.target, methodInfo, this.m_Arguments);
			case PersistentListenerMode.Int:
				return new CachedInvokableCall<int>(this.target, methodInfo, this.m_Arguments.intArgument);
			case PersistentListenerMode.Float:
				return new CachedInvokableCall<float>(this.target, methodInfo, this.m_Arguments.floatArgument);
			case PersistentListenerMode.String:
				return new CachedInvokableCall<string>(this.target, methodInfo, this.m_Arguments.stringArgument);
			case PersistentListenerMode.Bool:
				return new CachedInvokableCall<bool>(this.target, methodInfo, this.m_Arguments.boolArgument);
			default:
				return null;
			}
		}
        public static string CollectEvent(Object parent, UnityEventBase eventBase, SLUIUnityEventHelper helper, out string varName)
        {
            var eventVar = FixVarName("e_" + parent.GetInstanceID());
            var sb       = new StringBuilder();

            sb.AppendLine($"local {eventVar} = SLUIUnityEvent()");

            for (int index = 0; index < eventBase.GetPersistentEventCount(); index++)
            {
                var methodName      = eventBase.GetPersistentMethodName(index);
                var eventTarget     = eventBase.GetPersistentTarget(index);
                var eventTargetName = "nil";
                if (eventTarget is RectTransform t)
                {
                    eventTargetName = CollectVar(t);
                }
                else if (eventTarget is GameObject g)
                {
                    eventTargetName = CollectVar(g.GetComponent <RectTransform>());
                }
                else if (eventTarget is Component c)
                {
                    eventTargetName = CollectVar(c);
                }
                else
                {
                    Debug.LogWarning($"Event collecting problem. Unable to collect name of a target. ({eventTarget.name}({eventTarget.GetType()}))");
                }

                var methodVar = FixVarName($"{eventVar}_m{index}");
                sb.AppendLine($"local {methodVar} = SLUIEventItem({eventTargetName}, '{methodName}')");
                if (helper != null && helper.Items != null && helper.Items.Count > 0)
                {
                    var objRow = helper.Items[index].obj;
                    foreach (var s in objRow)
                    {
                        if (bool.TryParse(s, out var b))
                        {
                            sb.AppendLine($"{methodVar}:Add({b.ToString().ToLower()})");
                        }
                        else if (int.TryParse(s, out var i))
                        {
                            sb.AppendLine($"{methodVar}:Add({i})");
                        }
                        else if (float.TryParse(s, out var f))
                        {
                            sb.AppendLine($"{methodVar}:Add({f.ToString(CultureInfo.InvariantCulture)})");
                        }
                        else
                        {
                            sb.AppendLine($"{methodVar}:Add('{s}')");
                        }
                    }
                }
                sb.AppendLine($"{eventVar}:Add({methodVar})");
            }
            varName = eventVar;
            return(sb.ToString());
        }
Example #3
0
 public UMADataWardrobeEvent(UMADataWardrobeEvent source)
 {
     for (int i = 0; i < source.GetPersistentEventCount(); i++)
     {
         var target = source.GetPersistentTarget(i);
         AddListener(target, UnityEventBase.GetValidMethodInfo(target, source.GetPersistentMethodName(i), new Type[] { typeof(UMAData), typeof(UMAWardrobeRecipe) }));
     }
 }
Example #4
0
 public UMADataSlotMaterialRectEvent(UMADataSlotMaterialRectEvent source)
 {
     for (int i = 0; i < source.GetPersistentEventCount(); i++)
     {
         var target = source.GetPersistentTarget(i);
         AddListener(target, UnityEventBase.GetValidMethodInfo(target, source.GetPersistentMethodName(i), new Type[] { typeof(UMAData), typeof(SlotData), typeof(Material), typeof(Rect) }));
     }
 }
Example #5
0
 public UMARandomAvatarEvent(UMARandomAvatarEvent source)
 {
     for (int i = 0; i < source.GetPersistentEventCount(); i++)
     {
         var target = source.GetPersistentTarget(i);
         AddListener(target, UnityEventBase.GetValidMethodInfo(target, source.GetPersistentMethodName(i), new Type[] { typeof(GameObject), typeof(GameObject) }));
     }
 }
 public static void ActuallyRemoveAllListeners(this UnityEventBase evt)
 {
     evt.RemoveAllListeners();
     for (var i = 0; i < evt.GetPersistentEventCount(); i++)
     {
         evt.SetPersistentListenerState(i, UnityEventCallState.Off);
     }
 }
Example #7
0
        /// <summary>
        /// 处理委托
        /// </summary>
        /// <param name="event_"></param>
        /// <param name="action"></param>
        void processAction(UnityEventBase event_, Delegate action, bool add)
        {
            var eType   = event_.GetType();
            var method  = add ? "AddListener" : "RemoveListener";
            var process = eType.GetMethod(method);

            process.Invoke(event_, new object[] { action });             // 添加/删除回调函数
        }
Example #8
0
 public UMAExpressionEvent(UMAExpressionEvent source)
 {
     for (int i = 0; i < source.GetPersistentEventCount(); i++)
     {
         var target = source.GetPersistentTarget(i);
         AddListener(target, UnityEventBase.GetValidMethodInfo(target, source.GetPersistentMethodName(i), new Type[] { typeof(UMAData), typeof(string), typeof(float) }));
     }
 }
        public static void AddVoidPersistentListener(this UnityEventBase unityEvent, UnityEngine.Object targetObj, string methodName)
        {
            var persistentCalls = kPersistentCallsField.GetValue(unityEvent);

            kAddListenerMethod.Invoke(persistentCalls, null);
            kRegisterVoidListenerMethod.Invoke(persistentCalls, new object[] { 0, targetObj, methodName });
            kDirtyPersistentCallsMethod.Invoke(unityEvent, null);
        }
    private static int RemoveAllListeners(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 1);
        UnityEventBase unityEventBase = (UnityEventBase)LuaScriptMgr.GetNetObjectSelf(L, 1, "UnityEngine.Events.UnityEventBase");

        unityEventBase.RemoveAllListeners();
        return(0);
    }
Example #11
0
 /// <summary> Adds a child GameObject to the calling new parent GameObject </summary>
 public static bool IsNullOrEmpty(this UnityEventBase self)
 {
     if (self == null)
     {
         return(true);
     }
     return(self.GetAllEventCount() == 0);
 }
Example #12
0
 public static bool IsPersistantListenerValid(UnityEventBase dummyEvent, string methodName, UnityEngine.Object uObject, PersistentListenerMode modeEnum, Type argumentType)
 {
     if (uObject == null || string.IsNullOrEmpty(methodName))
     {
         return(false);
     }
     return(GetMethod(dummyEvent, methodName, uObject, modeEnum, argumentType) != null);
 }
Example #13
0
        public static int GetListenerNumber(this UnityEventBase unityEvent)
        {
            var field          = typeof(UnityEventBase).GetField("m_Calls", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
            var invokeCallList = field.GetValue(unityEvent);
            var property       = invokeCallList.GetType().GetProperty("Count");

            return((int)property.GetValue(invokeCallList));
        }
Example #14
0
        protected virtual void SendMsg()
        {
            if (m_clickMsg.MsgSendType != MsgSendType.None)
            {
                if (m_messenger == null)
                {
                    Debug.Log("<color=red> Want Send Msg ,But can't find Messenger at " + gameObject.name + "</color> ");
                    return;
                }

                if (m_messenger != null && !m_messenger.isReciverAvaliable())
                {
                    Debug.Log("<color=red> Want Send Msg at [" + gameObject.name + "],But can't find Reciver In Panel [" + m_messenger.name + "] </color> ", m_messenger);
                    return;
                }

                if (m_messenger != null && !m_messenger.IsClickHandlerAvaliable())
                {
                    Debug.Log("<color=red> Want Send Msg at [" + gameObject.name + "] ,But can't find Handle In Panel [" + m_messenger.name + "] </color> ", m_messenger);
                    return;
                }

                switch (m_clickMsg.DataType)
                {
                case MsgOption.ConstDataType.None:
                    m_messenger.SendMsg(m_clickMsg.MsgName, gameObject, new UIEventArgs(m_clickMsg.MsgName));
                    break;

                case MsgOption.ConstDataType.Int:
                    m_messenger.SendMsg(m_clickMsg.MsgName, gameObject, new UIEventArgs <int>(m_clickMsg.MsgName, m_clickMsg.intData));
                    break;

                case MsgOption.ConstDataType.Float:
                    m_messenger.SendMsg(m_clickMsg.MsgName, gameObject, new UIEventArgs <float>(m_clickMsg.MsgName, m_clickMsg.floatData));
                    break;

                case MsgOption.ConstDataType.String:
                    m_messenger.SendMsg(m_clickMsg.MsgName, gameObject, new UIEventArgs <string>(m_clickMsg.MsgName, m_clickMsg.stringData));
                    break;

                case MsgOption.ConstDataType.Customer:
                    var    callEvent  = m_clickMsg.callEvent;
                    string methodName = callEvent.MethodName;
                    if (methodName.Length > 0)
                    {
                        MethodInfo method     = UnityEventBase.GetValidMethodInfo(callEvent.Script, methodName, new Type[] { typeof(string) });
                        var        returnType = method.Invoke(callEvent.Script, new System.Object[] { m_clickMsg.MsgName });

                        m_messenger.SendMsg(m_clickMsg.MsgName, gameObject, (UIEventArgs)returnType);
                    }
                    else
                    {
                        m_messenger.SendMsg(m_clickMsg.MsgName, gameObject, new UIEventArgs <string>(m_clickMsg.MsgName, "MethodName Error! No Method [ " + m_clickMsg.callEvent.MethodName + " ] in [" + m_clickMsg.callEvent.Target + "]"));
                    }
                    break;
                }
            }
        }
Example #15
0
        public static void TriggerEvent <T, U>(string eventName, T value1, U value2)
        {
            UnityEventBase thisEvent = null;

            if (Instance.eventDictionary.TryGetValue(eventName, out thisEvent))
            {
                ((UnityEvent <T, U>)thisEvent).Invoke(value1, value2);
            }
        }
Example #16
0
        public static void TriggerEvent(string eventName)
        {
            UnityEventBase thisEvent = null;

            if (Instance.eventDictionary.TryGetValue(eventName, out thisEvent))
            {
                ((UnityEvent)thisEvent).Invoke();
            }
        }
Example #17
0
    public void RemoveEvent <T>(UnityAction <T> listener)
    {
        UnityEventBase unityEventBase = GetEventType(typeof(ObjectUnityEvent <T>));

        if (unityEventBase != null)
        {
            (unityEventBase as ObjectUnityEvent <T>).RemoveListener(listener);
        }
    }
        private void UnregisterAllPersistedListeners(UnityEventBase connectionEvent)
        {
            var persistentEventCount = connectionEvent.GetPersistentEventCount();

            for (int i = 0; i < persistentEventCount; i++)
            {
                connectionEvent.UnregisterPersistentListener(i);
            }
        }
Example #19
0
        public static void TriggerEvent <TData>(EventNames eventName, TData data) where TData : struct
        {
            UnityEventBase thisEvent = null;

            if (Instance.EventDictionary.TryGetValue(eventName, out thisEvent))
            {
                ((GenericEvent <TData>)thisEvent).Invoke(data);
            }
        }
    public static IEnumerable <UnityEngine.Object> GetAllTargets(this UnityEventBase ev)
    {
        int len = ev.GetPersistentEventCount();

        for (int i = 0; i < len; i++)
        {
            yield return(ev.GetPersistentTarget(i));
        }
    }
    private static int ToString(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 1);
        UnityEventBase unityEventBase = (UnityEventBase)LuaScriptMgr.GetNetObjectSelf(L, 1, "UnityEngine.Events.UnityEventBase");
        string         str            = unityEventBase.ToString();

        LuaScriptMgr.Push(L, str);
        return(1);
    }
Example #22
0
 public static void AddPersistentListener(UnityEventBase unityEventBase, UnityAction unityAction)
 {
     UnityEventTools.AddPersistentListener(unityEventBase);
     UnityEventTools.RegisterVoidPersistentListener(
         unityEventBase,
         unityEventBase.GetPersistentEventCount() - 1,
         unityAction
         );
 }
    private static int GetPersistentEventCount(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 1);
        UnityEventBase unityEventBase       = (UnityEventBase)LuaScriptMgr.GetNetObjectSelf(L, 1, "UnityEngine.Events.UnityEventBase");
        int            persistentEventCount = unityEventBase.GetPersistentEventCount();

        LuaScriptMgr.Push(L, persistentEventCount);
        return(1);
    }
Example #24
0
    public static void TriggerEvent(BaseEvent someEventData)
    {
        UnityEventBase thisEvent = null;

        if (instance.eventDictionary.TryGetValue(someEventData.myEventType, out thisEvent))
        {
            thisEvent.Invoke(someEventData);
        }
    }
Example #25
0
 protected void UnbindUnityEventCompletely(UnityEventBase unityEvent)
 {
     if (!_bindings.TryGetValue(unityEvent, out var binding))
     {
         return;
     }
     binding.Destroy();
     _bindings.Remove(unityEvent);
 }
        public static void UnregisterPersistentListeners(this UnityEventBase self)
        {
            var count = self.GetPersistentEventCount();

            for (var i = 0; i < count; ++i)
            {
                UnityEventTools.UnregisterPersistentListener(self, i);
            }
        }
Example #27
0
        public static List <EventBind> GetList(UnityEventBase @event)
        {
            List <EventBind> eb = new List <EventBind>();

            for (int i = 0; i < @event.GetPersistentEventCount(); ++i)
            {
                eb.Add(new EventBind(@event.GetPersistentTarget(i), @event.GetPersistentMethodName(i)));
            }
            return(eb);
        }
    private static int GetPersistentMethodName(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 2);
        UnityEventBase unityEventBase       = (UnityEventBase)LuaScriptMgr.GetNetObjectSelf(L, 1, "UnityEngine.Events.UnityEventBase");
        int            index                = (int)LuaScriptMgr.GetNumber(L, 2);
        string         persistentMethodName = unityEventBase.GetPersistentMethodName(index);

        LuaScriptMgr.Push(L, persistentMethodName);
        return(1);
    }
Example #29
0
    public static void TriggerEvent <T>(T theEvent) where T : GameEvent
    {
        UnityEventBase thisEvent = null;
        string         name      = theEvent.GetType().Name;

        if (instance.eventDictionary.TryGetValue(name, out thisEvent))
        {
            ((UnityEvent <T>)thisEvent).Invoke(theEvent);
        }
    }
Example #30
0
        public static List <UnityEngine.Object> GetListComponents(this UnityEventBase ev)
        {
            List <UnityEngine.Object> result = new List <UnityEngine.Object>();

            for (int i = 0; i < ev.GetPersistentEventCount(); i++)
            {
                result.Add(ev.GetPersistentTarget(i));
            }
            return(result);
        }
    private static int SetPersistentListenerState(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 3);
        UnityEventBase      unityEventBase = (UnityEventBase)LuaScriptMgr.GetNetObjectSelf(L, 1, "UnityEngine.Events.UnityEventBase");
        int                 index          = (int)LuaScriptMgr.GetNumber(L, 2);
        UnityEventCallState state          = (UnityEventCallState)((int)LuaScriptMgr.GetNetObject(L, 3, typeof(UnityEventCallState)));

        unityEventBase.SetPersistentListenerState(index, state);
        return(0);
    }
 public void Initialize(InvokableCallList invokableList, UnityEventBase unityEventBase)
 {
     foreach (PersistentCall call in this.m_Calls)
     {
         if (call.IsValid())
         {
             BaseInvokableCall runtimeCall = call.GetRuntimeCall(unityEventBase);
             if (runtimeCall != null)
             {
                 invokableList.AddPersistentInvokableCall(runtimeCall);
             }
         }
     }
 }
 private static string GetEventParams(UnityEventBase evt)
 {
   MethodInfo method = evt.FindMethod("Invoke", (object) evt, PersistentListenerMode.EventDefined, (System.Type) null);
   StringBuilder stringBuilder = new StringBuilder();
   stringBuilder.Append(" (");
   System.Type[] array = ((IEnumerable<System.Reflection.ParameterInfo>) method.GetParameters()).Select<System.Reflection.ParameterInfo, System.Type>((Func<System.Reflection.ParameterInfo, System.Type>) (x => x.ParameterType)).ToArray<System.Type>();
   for (int index = 0; index < array.Length; ++index)
   {
     stringBuilder.Append(array[index].Name);
     if (index < array.Length - 1)
       stringBuilder.Append(", ");
   }
   stringBuilder.Append(")");
   return stringBuilder.ToString();
 }
Example #34
0
 // extracts the data of all listeners of the event.
 public static IEnumerable<ListenerData> GetListenerData( UnityEventBase ev, SerializedProperty eventProp )
 {
     int numListeners = ev.GetPersistentEventCount();
     for ( int i = 0; i < numListeners; i++ )
     {
         Object target = ev.GetPersistentTarget( i );
         string method = ev.GetPersistentMethodName( i );
         ListenerCallArgument methodArg = GetEventArgumentObject( eventProp, i );
         yield return new ListenerData()
         {
             target = target,
             method = method,
             argument = methodArg
         };
     }
 }
Example #35
0
        public BaseInvokableCall GetRuntimeCall(UnityEventBase theEvent)
        {
            if ((this.m_CallState != UnityEventCallState.RuntimeOnly) || Application.isPlaying)
            {
                if ((this.m_CallState == UnityEventCallState.Off) || (theEvent == null))
                {
                    return null;
                }
                MethodInfo theFunction = theEvent.FindMethod(this);
                if (theFunction != null)
                {
                    switch (this.m_Mode)
                    {
                        case PersistentListenerMode.EventDefined:
                            return theEvent.GetDelegate(this.target, theFunction);

                        case PersistentListenerMode.Void:
                            return new InvokableCall(this.target, theFunction);

                        case PersistentListenerMode.Object:
                            return GetObjectCall(this.target, theFunction, this.m_Arguments);

                        case PersistentListenerMode.Int:
                            return new CachedInvokableCall<int>(this.target, theFunction, this.m_Arguments.intArgument);

                        case PersistentListenerMode.Float:
                            return new CachedInvokableCall<float>(this.target, theFunction, this.m_Arguments.floatArgument);

                        case PersistentListenerMode.String:
                            return new CachedInvokableCall<string>(this.target, theFunction, this.m_Arguments.stringArgument);

                        case PersistentListenerMode.Bool:
                            return new CachedInvokableCall<bool>(this.target, theFunction, this.m_Arguments.boolArgument);
                    }
                }
            }
            return null;
        }
 public void Initialize(InvokableCallList invokableList, UnityEventBase unityEventBase)
 {
   using (List<PersistentCall>.Enumerator enumerator = this.m_Calls.GetEnumerator())
   {
     while (enumerator.MoveNext())
     {
       PersistentCall current = enumerator.Current;
       if (current.IsValid())
       {
         BaseInvokableCall runtimeCall = current.GetRuntimeCall(unityEventBase);
         if (runtimeCall != null)
           invokableList.AddPersistentInvokableCall(runtimeCall);
       }
     }
   }
 }
Example #37
0
        // Try to create a link between two nodes.
        // Returns true if the link is established successfully.
        public static bool TryLinkNodes(
            Wiring.NodeBase nodeFrom, UnityEventBase triggerEvent,
            Wiring.NodeBase nodeTo, MethodInfo targetMethod
        )
        {
            // Determine the type of the target action.
            var actionType = GetUnityActionToInvokeMethod(targetMethod);

            if (actionType == null) return false; // invalid target method type

            // Create an action that is bound to the target method.
            var targetAction = Delegate.CreateDelegate(
                actionType, nodeTo, targetMethod
            );

            if (triggerEvent is UnityEvent)
            {
                // The trigger event has no parameter.
                // Add the action to the event with a default parameter.
                if (actionType == typeof(UnityAction))
                {
                    UnityEventTools.AddVoidPersistentListener(
                        triggerEvent, (UnityAction)targetAction
                    );
                    return true;
                }
                if (actionType == typeof(UnityAction<float>))
                {
                    UnityEventTools.AddFloatPersistentListener(
                        triggerEvent, (UnityAction<float>)targetAction, 1.0f
                    );
                    return true;
                }
            }
            else if (triggerEvent is UnityEvent<float>)
            {
                // The trigger event has a float parameter.
                // Then the target method should have a float parameter too.
                if (actionType == typeof(UnityAction<float>))
                {
                    // Add the action to the event.
                    UnityEventTools.AddPersistentListener(
                       (UnityEvent<float>)triggerEvent,
                       (UnityAction<float>)targetAction
                    );
                    return true;
                }
            }
            else if (triggerEvent is UnityEvent<Vector3>)
            {
                // The trigger event has a Vector3 parameter.
                // Then the target method should have a Vector3 parameter too.
                if (actionType == typeof(UnityAction<Vector3>))
                {
                    // Add the action to the event.
                    UnityEventTools.AddPersistentListener(
                       (UnityEvent<Vector3>)triggerEvent,
                       (UnityAction<Vector3>)targetAction
                    );
                    return true;
                }
            }
            else if (triggerEvent is UnityEvent<Quaternion>)
            {
                // The trigger event has a Quaternion parameter.
                // Then the target method should have a Quaternion parameter too.
                if (actionType == typeof(UnityAction<Quaternion>))
                {
                    // Add the action to the event.
                    UnityEventTools.AddPersistentListener(
                       (UnityEvent<Quaternion>)triggerEvent,
                       (UnityAction<Quaternion>)targetAction
                    );
                    return true;
                }
            }
            else if (triggerEvent is UnityEvent<Color>)
            {
                // The trigger event has a color parameter.
                // Then the target method should have a color parameter too.
                if (actionType == typeof(UnityAction<Color>))
                {
                    // Add the action to the event.
                    UnityEventTools.AddPersistentListener(
                       (UnityEvent<Color>)triggerEvent,
                       (UnityAction<Color>)targetAction
                    );
                    return true;
                }
            }

            return false; // trigger-target mismatch
        }
Example #38
0
        // Remove a link between two nodes.
        public static void RemoveLinkNodes(
            Wiring.NodeBase nodeFrom, UnityEventBase triggerEvent,
            Wiring.NodeBase nodeTo, MethodInfo targetMethod
        )
        {
            var methodName = targetMethod.Name;

            var eventCount = triggerEvent.GetPersistentEventCount();
            for (var i = 0; i < eventCount; i++)
            {
                if (nodeTo == triggerEvent.GetPersistentTarget(i) &&
                    methodName == triggerEvent.GetPersistentMethodName(i))
                {
                    UnityEventTools.RemovePersistentListener(triggerEvent, i);
                    break;
                }
            }
        }
		public static bool IsPersistantListenerValid(UnityEventBase dummyEvent, string methodName, UnityEngine.Object uObject, PersistentListenerMode modeEnum, Type argumentType)
		{
			return !(uObject == null) && !string.IsNullOrEmpty(methodName) && dummyEvent.FindMethod(methodName, uObject, modeEnum, argumentType) != null;
		}
		private static string GetEventParams(UnityEventBase evt)
		{
			MethodInfo methodInfo = evt.FindMethod("Invoke", evt, PersistentListenerMode.EventDefined, null);
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append(" (");
			Type[] array = (
				from x in methodInfo.GetParameters()
				select x.ParameterType).ToArray<Type>();
			for (int i = 0; i < array.Length; i++)
			{
				stringBuilder.Append(array[i].Name);
				if (i < array.Length - 1)
				{
					stringBuilder.Append(", ");
				}
			}
			stringBuilder.Append(")");
			return stringBuilder.ToString();
		}
		private static GenericMenu BuildPopupList(UnityEngine.Object target, UnityEventBase 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(UnityEventDrawer.ClearEventFunction), new UnityEventDrawer.UnityEventFunction(listener, null, null, PersistentListenerMode.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>();
			UnityEventDrawer.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))
					{
						UnityEventDrawer.GeneratePopUpForType(genericMenu, component, list.Contains(component.GetType().Name), listener, delegateArgumentsTypes);
					}
				}
			}
			return genericMenu;
		}
Example #42
0
 public Outlet(string memberName, UnityEventBase boundEvent)
 {
     _memberName = memberName;
     _displayName = MakeDisplayName(memberName);
     _event = boundEvent;
 }
 public void OnGUI(Rect position)
 {
   if (this.m_ListenersArray == null || !this.m_ListenersArray.isArray)
     return;
   this.m_DummyEvent = UnityEventDrawer.GetDummyEvent(this.m_Prop);
   if (this.m_DummyEvent == null)
     return;
   if (this.m_Styles == null)
     this.m_Styles = new UnityEventDrawer.Styles();
   if (this.m_ReorderableList == null)
     return;
   int indentLevel = EditorGUI.indentLevel;
   EditorGUI.indentLevel = 0;
   this.m_ReorderableList.DoList(position);
   EditorGUI.indentLevel = indentLevel;
 }
 public static bool IsPersistantListenerValid(UnityEventBase dummyEvent, string methodName, UnityEngine.Object uObject, PersistentListenerMode modeEnum, System.Type argumentType)
 {
   if (uObject == (UnityEngine.Object) null || string.IsNullOrEmpty(methodName))
     return false;
   return dummyEvent.FindMethod(methodName, (object) uObject, modeEnum, argumentType) != null;
 }
 private static GenericMenu BuildPopupList(UnityEngine.Object target, UnityEventBase dummyEvent, SerializedProperty listener)
 {
   UnityEngine.Object target1 = target;
   if (target1 is Component)
     target1 = (UnityEngine.Object) (target as Component).gameObject;
   SerializedProperty propertyRelative = listener.FindPropertyRelative("m_MethodName");
   GenericMenu menu = new GenericMenu();
   menu.AddItem(new GUIContent("No Function"), string.IsNullOrEmpty(propertyRelative.stringValue), new GenericMenu.MenuFunction2(UnityEventDrawer.ClearEventFunction), (object) new UnityEventDrawer.UnityEventFunction(listener, (UnityEngine.Object) null, (MethodInfo) null, PersistentListenerMode.EventDefined));
   if (target1 == (UnityEngine.Object) null)
     return menu;
   menu.AddSeparator(string.Empty);
   System.Type[] array = ((IEnumerable<System.Reflection.ParameterInfo>) dummyEvent.GetType().GetMethod("Invoke").GetParameters()).Select<System.Reflection.ParameterInfo, System.Type>((Func<System.Reflection.ParameterInfo, System.Type>) (x => x.ParameterType)).ToArray<System.Type>();
   UnityEventDrawer.GeneratePopUpForType(menu, target1, false, listener, array);
   if (target1 is GameObject)
   {
     Component[] components = (target1 as GameObject).GetComponents<Component>();
     List<string> list = ((IEnumerable<Component>) components).Where<Component>((Func<Component, bool>) (c => (UnityEngine.Object) c != (UnityEngine.Object) null)).Select<Component, string>((Func<Component, string>) (c => c.GetType().Name)).GroupBy<string, string>((Func<string, string>) (x => x)).Where<IGrouping<string, string>>((Func<IGrouping<string, string>, bool>) (g => g.Count<string>() > 1)).Select<IGrouping<string, string>, string>((Func<IGrouping<string, string>, string>) (g => g.Key)).ToList<string>();
     foreach (Component component in components)
     {
       if (!((UnityEngine.Object) component == (UnityEngine.Object) null))
         UnityEventDrawer.GeneratePopUpForType(menu, (UnityEngine.Object) component, list.Contains(component.GetType().Name), listener, array);
     }
   }
   return menu;
 }