示例#1
0
    /// <summary>
    /// Gets the methods.
    /// </summary>
    /// <returns>
    /// The methods.
    /// </returns>
    /// <param name='theObject'>
    /// The object.
    /// </param>
    public static MethodInfo[] GetMethods(Type theType, KGFEventData theData)
    {
        List <MethodInfo> aList = new List <MethodInfo> ();
        Type anObjectType       = theType;

        while (anObjectType != null)
        {
            // add methods
            MethodInfo[] aMethods = anObjectType.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);

            foreach (MethodInfo aMethodInfo in aMethods)
            {
                if (aMethodInfo.GetCustomAttributes(typeof(KGFEventExpose), true).Length > 0)
                {
                    if (theData.CheckMethod(aMethodInfo))
                    {
                        aList.Add(aMethodInfo);
                    }
                }
            }

            // move to base type
            anObjectType = anObjectType.BaseType;
        }

        return(aList.ToArray());
    }
示例#2
0
文件: KGFEvent.cs 项目: numaiomul/MDV
    /// <summary>
    /// Gets the methods.
    /// </summary>
    /// <returns>
    /// The methods.
    /// </returns>
    /// <param name='theObject'>
    /// The object.
    /// </param>
    public static MethodInfo[] GetMethods(Type theType, KGFEventData theData)
    {
        List<MethodInfo> aList = new List<MethodInfo> ();
        Type anObjectType = theType;
        while (anObjectType != null)
        {
            // add methods
            MethodInfo[] aMethods = anObjectType.GetMethods (BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);

            foreach (MethodInfo aMethodInfo in aMethods)
            {
                if (aMethodInfo.GetCustomAttributes (typeof(KGFEventExpose),true).Length > 0)
                {
                    if (theData.CheckMethod(aMethodInfo))
                    {
                        aList.Add (aMethodInfo);
                    }
                }
            }

            // move to base type
            anObjectType = anObjectType.BaseType;
        }

        return aList.ToArray ();
    }
示例#3
0
    /// <summary>
    /// Find method this event should call
    /// </summary>
    /// <returns></returns>
    static bool FindMethod(KGFEventData theEventData, out MethodInfo theMethod, out MonoBehaviour theComponent)
    {
        // init params
        theMethod    = null;
        theComponent = null;

        if (theEventData.itsRuntimeObjectSearch)
        {
            foreach (MethodInfo aMethod in GetMethods(theEventData.GetRuntimeType(), theEventData))
            {
                string aMethodString = GetMethodString(aMethod);
                if (aMethodString == theEventData.itsMethodName)
                {
                    // found method
                    theMethod = aMethod;
                    return(true);
                }
            }
        }
        else
        {
            if (theEventData.itsObject != null)
            {
                // find components of gameobject
                MonoBehaviour [] aListComponents = theEventData.itsObject.GetComponents <MonoBehaviour> ();

                // find method in components
                foreach (MonoBehaviour aComponent in aListComponents)
                {
                    if (aComponent.GetType().Name == theEventData.itsComponentName)
                    {
                        theComponent = aComponent;
                        foreach (MethodInfo aMethod in GetMethods(aComponent.GetType(), theEventData))
                        {
                            string aMethodString = GetMethodString(aMethod);
                            if (aMethodString == theEventData.itsMethodName)
                            {
                                // found method
                                theMethod = aMethod;
                                return(true);
                            }
                        }
                    }
                }
            }
        }

        return(false);
    }
示例#4
0
	/// <summary>
	/// Find method this event should call
	/// </summary>
	/// <returns></returns>
	static bool FindMethod (KGFEventData theEventData, out MethodInfo theMethod, out MonoBehaviour theComponent)
	{
		// init params
		theMethod = null;
		theComponent = null;
		
		if (theEventData.itsRuntimeObjectSearch)
		{
			foreach (MethodInfo aMethod in GetMethods(theEventData.GetRuntimeType(),theEventData))
			{
				string aMethodString = GetMethodString (aMethod);
				if (aMethodString == theEventData.itsMethodName)
				{
					// found method
					theMethod = aMethod;
					return true;
				}
			}
		}
		else
		{
			if (theEventData.itsObject != null)
			{
				// find components of gameobject
				MonoBehaviour [] aListComponents = theEventData.itsObject.GetComponents<MonoBehaviour> ();

				// find method in components
				foreach (MonoBehaviour aComponent in aListComponents)
				{
					if (aComponent.GetType ().Name == theEventData.itsComponentName)
					{
						theComponent = aComponent;
						foreach (MethodInfo aMethod in GetMethods(aComponent.GetType(),theEventData))
						{
							string aMethodString = GetMethodString (aMethod);
							if (aMethodString == theEventData.itsMethodName)
							{
								// found method
								theMethod = aMethod;
								return true;
							}
						}
					}
				}
			}
		}
		
		return false;
	}