/// <summary>
        /// Cache the callback and create the list of the necessary parameters.
        /// </summary>

        void Cache()
        {
            mCached = true;
            if (mRawDelegate)
            {
                return;
            }

#if REFLECTION_SUPPORT
            if (mCachedCallback == null || (mCachedCallback.Target as MonoBehaviour) != mTarget || GetMethodName(mCachedCallback) != mMethodName)
            {
                if (mTarget != null && !string.IsNullOrEmpty(mMethodName))
                {
                    System.Type type = mTarget.GetType();
#if NETFX_CORE
                    try
                    {
                        IEnumerable <MethodInfo> methods = type.GetRuntimeMethods();

                        foreach (MethodInfo mi in methods)
                        {
                            if (mi.Name == mMethodName)
                            {
                                mMethod = mi;
                                break;
                            }
                        }
                    }
                    catch (System.Exception ex)
                    {
                        Debug.LogError("Failed to bind " + type + "." + mMethodName + "\n" + ex.Message);
                        return;
                    }
#else // NETFX_CORE
                    for (mMethod = null; type != null;)
                    {
                        try
                        {
                            if (ParamTypes != null)
                            {
                                if (ParamTypes.Contains("GenericType") && this.mParamGenericTypes.Count == 0)
                                {
                                    Debug.Log("fwefefe");
                                    this.IsGenericFunc = true;
                                    mParameters        = new Parameter[ParamTypes.Count];
                                    for (int j = 0, imax = mParameters.Length; j < imax; ++j)
                                    {
                                        mParameters[j] = new Parameter();
                                    }
                                    return;
                                }
                                else
                                {
                                    if (this.IsGenericFunc)
                                    {
                                        Type[] types = new Type[ParamTypes.Count];
                                        for (int i = 0; i < ParamTypes.Count; i++)
                                        {
                                            if (!ParamTypes[i].Equals("GenericType"))
                                            {
                                                types[i] = Type.GetType(ParamTypes[i]);
                                            }
                                            else
                                            {
                                                int j = i;
                                                foreach (var v in this.mParamGenericTypes)
                                                {
                                                    types[j] = Type.GetType(v);
                                                    j++;
                                                }
                                            }
                                        }
                                        mMethod = type.GetMethod(mMethodName).MakeGenericMethod();
                                    }
                                    else
                                    {
                                        Debug.Log("333333");
                                        Type[] types = new Type[ParamTypes.Count];
                                        for (int i = 0; i < ParamTypes.Count; i++)
                                        {
                                            types[i] = Type.GetType(ParamTypes[i]);
                                        }
                                        mMethod = type.GetMethod(mMethodName, types);
                                    }
                                }
                            }
                            else
                            {
                                Debug.Log("2e2e2e2e");
                                mMethod = type.GetMethod(mMethodName, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
                            }
                            if (mMethod != null)
                            {
                                break;
                            }
                        }
                        catch (System.Exception) { }
#if UNITY_WP8 || UNITY_WP_8_1
                        // For some odd reason Type.GetMethod(name, bindingFlags) doesn't seem to work on WP8...
                        try
                        {
                            mMethod = type.GetMethod(mMethodName);
                            if (mMethod != null)
                            {
                                break;
                            }
                        }
                        catch (System.Exception) { }
#endif
                        type = type.BaseType;
                    }
#endif // NETFX_CORE

                    if (mMethod == null)
                    {
                        Debug.LogError("Could not find method '" + mMethodName + "' on " + mTarget.GetType(), mTarget);
                        return;
                    }

                    if (mMethod.ReturnType != typeof(void))
                    {
                        Debug.LogError(mTarget.GetType() + "." + mMethodName + " must have a 'void' return type.", mTarget);
                        return;
                    }

                    // Get the list of expected parameters
                    mParameterInfos = mMethod.GetParameters();

                    if (mParameterInfos.Length == 0)
                    {
                        // No parameters means we can create a simple delegate for it, optimizing the call
#if NETFX_CORE
                        mCachedCallback = (Callback)mMethod.CreateDelegate(typeof(Callback), mTarget);
#else
                        mCachedCallback = (Callback)System.Delegate.CreateDelegate(typeof(Callback), mTarget, mMethodName);
#endif

                        mArgs       = null;
                        mParameters = null;
                        return;
                    }
                    else
                    {
                        mCachedCallback = null;
                    }

                    // Allocate the initial list of parameters
                    if (mParameters == null || mParameters.Length != mParameterInfos.Length)
                    {
                        mParameters = new Parameter[mParameterInfos.Length];
                        for (int i = 0, imax = mParameters.Length; i < imax; ++i)
                        {
                            mParameters[i] = new Parameter();
                        }
                    }

                    // Save the parameter type
                    for (int i = 0, imax = mParameters.Length; i < imax; ++i)
                    {
                        mParameters[i].expectedType = mParameterInfos[i].ParameterType;
                    }
                }
            }
#endif // REFLECTION_SUPPORT
        }