예제 #1
0
        /// <summary>
        /// Invoke the specified function. It's unlikely that you will need to call this function yourself.
        /// </summary>

        static public void FindAndExecute(int channelID, uint objID, byte funcID, params object[] parameters)
        {
            TNObject obj = TNObject.Find(channelID, objID);

            if (obj != null)
            {
                if (obj.Execute(funcID, parameters))
                {
                    return;
                }
#if UNITY_EDITOR
                Debug.LogError("[TNet] Unable to execute function with ID of '" + funcID + "'. Make sure there is a script that can receive this call.\n" +
                               "GameObject: " + GetHierarchy(obj.gameObject), obj.gameObject);
#endif
            }
#if UNITY_EDITOR
            else if (TNManager.isJoiningChannel)
            {
                Debug.Log("[TNet] Trying to execute RFC #" + funcID + " on TNObject #" + objID + " before it has been created.");
            }
            else
            {
                Debug.LogWarning("[TNet] Trying to execute RFC #" + funcID + " on TNObject #" + objID + " before it has been created.");
            }
#endif
        }
예제 #2
0
        /// <summary>
        /// Invoke the specified function. It's unlikely that you will need to call this function yourself.
        /// </summary>

        static public void FindAndExecute(int channelID, uint objID, string funcName, params object[] parameters)
        {
            TNObject obj = TNObject.Find(channelID, objID);

            if (obj != null)
            {
                if (obj.Execute(funcName, parameters))
                {
                    return;
                }
#if UNITY_EDITOR
                Debug.LogError("[TNet] Unable to execute function '" + funcName + "'. Did you forget an [RFC] prefix, perhaps?\n" +
                               "GameObject: " + GetHierarchy(obj.gameObject), obj.gameObject);
#endif
            }
#if UNITY_EDITOR
            else if (TNManager.isJoiningChannel)
            {
                Debug.Log("[TNet] Trying to execute a function '" + funcName + "' on TNObject #" + objID +
                          " before it has been created.");
            }
            else
            {
                Debug.LogWarning("[TNet] Trying to execute a function '" + funcName + "' on TNObject #" + objID +
                                 " before it has been created.");
            }
#endif
        }
예제 #3
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();
            }

            CachedFunc ent;

            if (mDict0.TryGetValue(funcID, out ent))
            {
                if (ent.parameters == null)
                {
                    ent.parameters = ent.func.GetParameters();
                }

                try
                {
                    ent.func.Invoke(ent.obj, parameters);
                    return(true);
                }
                catch (System.Exception ex)
                {
                    if (ex.GetType() == typeof(System.NullReferenceException))
                    {
                        return(false);
                    }
                    UnityTools.PrintException(ex, ent, funcID, "", parameters);
                    return(false);
                }
            }
            return(false);
        }