Ejemplo n.º 1
0
        /// <summary>
        /// Subscribe all the marked rpcs on the supplied component
        /// </summary>
        /// <param name="behaviour"> </param>
        public void SubscribeMarkedRPCsOnBehaviour(RoomBehaviour behaviour)
        {
            if (behaviour == null)
            {
                return;
            }

            var thisType = behaviour.GetType();

            //get all the methods of the derived type
            MethodInfo[] methods = thisType.GetMethods(
                BindingFlags.NonPublic |
                BindingFlags.Instance |
                BindingFlags.Static |
                BindingFlags.Public |
                BindingFlags.FlattenHierarchy
                );

            foreach (var method in methods)
            {
                var tokens = Attribute.GetCustomAttributes(method, typeof(RpcAttribute), false) as RpcAttribute[];

                foreach (var token in tokens)
                {
                    if (token == null)
                    {
                        continue;
                    }

                    var del = Delegate.CreateDelegate(typeof(Action <NetIncomingMessage, NetMessageInfo>), behaviour, method, false) as Action <NetIncomingMessage, NetMessageInfo>;

                    if (del != null)
                    {
                        SubscribeToRPC(token.rpcId, del, defaultContinueForwarding: token.defaultContinueForwarding);
                    }
                    else
                    {
                        Debug.LogWarning("The method {0} for type {1} does not match the RPC delegate of Action<NetInComingMessage, NetMessageInfo>, but is marked to process RPC's. Please either fix this method, or remove the attribute",
                                         method.Name,
                                         method.DeclaringType.Name
                                         );
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Remove the behaviour
        /// </summary>
        /// <param name="behaviour"></param>
        public void RemoveBehaviour(RoomBehaviour behaviour)
        {
            var ind = _roomBehaviours.FindIndex(o => object.ReferenceEquals(behaviour, o));

            if (ind != -1)
            {
                try
                {
                    _roomBehaviours[ind].Disposing();
                }catch (Exception e)
                {
                    Debug.LogError("[Disposing behaviour] {0}", e);
                }

                _roomBehaviours.RemoveAt(ind);
                behaviour.Room = null;
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// run when a room behaviour is added to the room we're attached to
 /// </summary>
 /// <param name="behaviour"></param>
 public virtual void OnBehaviourAdded(RoomBehaviour behaviour){}
Ejemplo n.º 4
0
 /// <summary>
 /// run when a room behaviour is added to the room we're attached to
 /// </summary>
 /// <param name="behaviour"></param>
 public virtual void OnBehaviourAdded(RoomBehaviour behaviour)
 {
 }