/// <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 ); } } } }
/// <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; } }
/// <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){}
/// <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) { }