Beispiel #1
0
    /// <summary>
    /// Rebuild the list of known RFC calls.
    /// </summary>

    void RebuildMethodList()
    {
        rebuildMethodList = false;
        mRFCs.Clear();
        MonoBehaviour[] mbs = GetComponentsInChildren <MonoBehaviour>();

        for (int i = 0, imax = mbs.Length; i < imax; ++i)
        {
            MonoBehaviour mb   = mbs[i];
            System.Type   type = mb.GetType();

            MethodInfo[] methods = type.GetMethods(
                BindingFlags.Public |
                BindingFlags.NonPublic |
                BindingFlags.Instance);

            for (int b = 0; b < methods.Length; ++b)
            {
                if (methods[b].IsDefined(typeof(RFC), true))
                {
                    CachedRFC ent = new CachedRFC();
                    ent.obj  = mb;
                    ent.func = methods[b];

                    RFC tnc = (RFC)ent.func.GetCustomAttributes(typeof(RFC), true)[0];
                    ent.rfcID = tnc.id;
                    mRFCs.Add(ent);
                }
            }
        }
    }
Beispiel #2
0
    /// <summary>
    /// Invoke the function specified by the function name.
    /// </summary>

    public bool Execute(string funcName, params object[] parameters)
    {
        if (mParent != null)
        {
            return(mParent.Execute(funcName, parameters));
        }
        if (rebuildMethodList)
        {
            RebuildMethodList();
        }

        bool retVal = false;

        for (int i = 0; i < mRFCs.size; ++i)
        {
            CachedRFC ent = mRFCs[i];

            if (ent.func.Name == funcName)
            {
                retVal = true;
#if UNITY_EDITOR
                try
                {
                    ent.func.Invoke(ent.obj, parameters);
                }
                catch (System.Exception ex)
                {
                    string types = "";

                    for (int b = 0; b < parameters.Length; ++b)
                    {
                        if (b != 0)
                        {
                            types += ", ";
                        }
                        types += parameters[b].GetType().ToString();
                    }
                    Debug.LogError(ex.Message + "\n" + ent.obj.GetType() + "." + ent.func.Name + " (" + types + ")");
                }
#else
                ent.func.Invoke(ent.obj, parameters);
#endif
            }
        }
        return(retVal);
    }
Beispiel #3
0
        public void RFC <T>(string methodName, params object[] parameters)
        {
            string    target = typeof(T).Name;
            RFCObject obj    = RFCObject.Find(target);

            if (obj == null)
            {
                Debug.LogError("Cannot Find The RFCObject: " + target);
                return;
            }

            for (int i = 0; i < obj.mRFCs.Count; ++i)
            {
                CachedRFC rfc = obj.mRFCs[i];
                if (rfc.func.Name == methodName)
                {
                    rfc.func.Invoke(obj, parameters);
                }
            }
        }
Beispiel #4
0
 public void RFC(RFCType type, object param, params object[] parameters)
 {
     for (int i = 0; i < mList.Count; ++i)
     {
         RFCObject obj = mList[i];
         for (int j = 0; j < obj.mRFCs.Count; ++j)
         {
             CachedRFC rfc = obj.mRFCs[j];
             if (rfc.type == type && rfc.Param == param)
             {
                 if (obj.ProxyTarget != null)
                 {
                     rfc.func.Invoke(obj.ProxyTarget, parameters);
                 }
                 else
                 {
                     rfc.func.Invoke(obj, parameters);
                 }
             }
         }
     }
 }
Beispiel #5
0
        /// <summary>
        /// 构建远程方法列表.
        /// </summary>
        private void RebuildMethodList()
        {
            mRFCs.Clear();

            MethodInfo[] methods = this.GetType().GetMethods(
                BindingFlags.Public |
                BindingFlags.NonPublic |
                BindingFlags.Instance);

            for (int b = 0; b < methods.Length; ++b)
            {
                if (methods[b].IsDefined(typeof(RFC), true))
                {
                    CachedRFC ent = new CachedRFC();
                    ent.func = methods[b];
                    RFC tnc = (RFC)ent.func.GetCustomAttributes(typeof(RFC), true)[0];
                    ent.type  = tnc.Type;
                    ent.Param = tnc.Param;
                    mRFCs.Add(ent);
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// 设置代理对象
        /// </summary>
        /// <param name="target">代理对象.</param>
        public void SetProxy(MonoBehaviour target)
        {
            mProxyTarget = target;
            Name         = target.transform.name;
            mRFCs.Clear();
            MethodInfo[] methods = target.GetType().GetMethods(
                BindingFlags.Public |
                BindingFlags.NonPublic |
                BindingFlags.Instance);

            for (int b = 0; b < methods.Length; ++b)
            {
                if (methods[b].IsDefined(typeof(RFC), true))
                {
                    CachedRFC ent = new CachedRFC();
                    ent.func = methods[b];
                    RFC tnc = (RFC)ent.func.GetCustomAttributes(typeof(RFC), true)[0];
                    ent.type  = tnc.Type;
                    ent.Param = tnc.Param;
                    mRFCs.Add(ent);
                }
            }
        }
Beispiel #7
0
    /// <summary>
    /// Invoke the function specified by the ID.
    /// </summary>

    public bool Execute(byte funcID, params object[] parameters)
    {
        if (mParent != null)
        {
            return(mParent.Execute(funcID, parameters));
        }
        if (rebuildMethodList)
        {
            RebuildMethodList();
        }

        bool retVal = false;

        for (int i = 0; i < mRFCs.size; ++i)
        {
            CachedRFC ent = mRFCs[i];

            if (ent.rfcID == funcID)
            {
                retVal = true;
#if UNITY_EDITOR
                try
                {
                    ParameterInfo[] infos = ent.func.GetParameters();

                    if (infos.Length == 1 && infos[0].ParameterType == typeof(object[]))
                    {
                        ent.func.Invoke(ent.obj, new object[] { parameters });
                    }
                    else
                    {
                        ent.func.Invoke(ent.obj, parameters);
                    }
                }
                catch (System.Exception ex)
                {
                    string types = "";

                    if (parameters != null)
                    {
                        for (int b = 0; b < parameters.Length; ++b)
                        {
                            if (b != 0)
                            {
                                types += ", ";
                            }
                            types += parameters[b].GetType().ToString();
                        }
                    }
                    Debug.LogError(ex.Message + "\n" + ent.obj.GetType() + "." + ent.func.Name + " (" + types + ")");
                }
#else
                ParameterInfo[] infos = ent.func.GetParameters();

                if (infos.Length == 1 && infos[0].ParameterType == typeof(object[]))
                {
                    ent.func.Invoke(ent.obj, new object[] { parameters });
                }
                else
                {
                    ent.func.Invoke(ent.obj, parameters);
                }
#endif
            }
        }
        return(retVal);
    }