コード例 #1
0
ファイル: Play.cs プロジェクト: wujun4code/Play-SDK-dotNET
        internal static void RegisterBehaviour <T>(PlayMonoBehaviour behaviour, IDictionary <string, IList <PlayMonoBehaviour> > methodBehaviours)
            where T : Attribute
        {
            var methods = Play.Find <T>(behaviour);

            methods.Every(m =>
            {
                if (methodBehaviours.ContainsKey(m.Name))
                {
                    var behaviours = methodBehaviours[m.Name];
                    if (behaviours == null)
                    {
                        behaviours = new List <PlayMonoBehaviour>();
                    }
                    behaviours.Add(behaviour);
                }
                else
                {
                    methodBehaviours.Add(m.Name, new List <PlayMonoBehaviour>()
                    {
                        behaviour
                    });
                }
            });
        }
コード例 #2
0
        /// <summary>
        /// Invoke this instance.
        /// </summary>
        public override void Invoke()
        {
            var pt = rpcMessage.Paramters.Select(p => p.GetType()).ToArray();

            var rpcMethods = from behaviour in Play.Behaviours
                             let method = Play.Find(behaviour, rpcMessage.MethodName, pt)
                                          where method != null
                                          select new
            {
                host   = behaviour,
                method = method
            };

            rpcMethods.Every(hm => hm.method.Invoke(hm.host, parameters: rpcMessage.Paramters.ToArray()));
        }
コード例 #3
0
 /// <summary>
 /// Invoke this instance.
 /// </summary>
 public virtual void Invoke()
 {
     // get all the behaviours that subscibed the callback method with the same name.
     if (Play.EventBehaviours.ContainsKey(MethodName))
     {
         // all behaviours subscibed the callback method.
         var behaviours = Play.EventBehaviours[MethodName];
         behaviours.Every(behaviour =>
         {
             // find the method object in a behaviour.
             var method = Play.Find <PlayEventAttribute>(behaviour, MethodName);
             // invoke it.
             method.Invoke(behaviour, MethodParameters.Length > 0 ? MethodParameters : null);
         });
     }
 }
コード例 #4
0
ファイル: Play.cs プロジェクト: wujun4code/Play-SDK-dotNET
        /// <summary>
        ///
        /// </summary>
        /// <param name="eventCode"></param>
        /// <param name="parameters"></param>
        public static void InvokeEvent(PlayEventCode eventCode, params object[] parameters)
        {
#if UNITY
            EnqueueEventMessage(eventCode, parameters);
#else
            Play.EventBehaviours.When(kv => kv.Key == eventCode.ToString()).Every(kv =>
            {
                kv.Value.Every(b =>
                {
                    var callbackMethod = Play.Find <PlayEventAttribute>(b, kv.Key);
                    if (callbackMethod != null)
                    {
                        callbackMethod.Invoke(b, parameters.Length > 0 ? parameters : null);
                    }
                });
            });
#endif
        }
コード例 #5
0
ファイル: Play.cs プロジェクト: wujun4code/Play-SDK-dotNET
        internal static void ReceivedRPC(PlayRpcMessage rpcMessage)
        {
            //EventNotification.NotifyUnityGameObjects(rpcMessage.MethodName, rpcMessage.Paramters.ToArray());
            var playRpcEventMessage = new PlayRPCEventMessage()
            {
                rpcMessage = rpcMessage
            };

#if UNITY
            EnqueueEventMessage(playRpcEventMessage);
#else
            var pt = rpcMessage.Paramters.Select(p => p.GetType()).ToArray();

            var rpcMethods = from behaviour in Play.Behaviours
                             let method = Play.Find(behaviour, rpcMessage.MethodName, pt)
                                          where method != null
                                          select new
            {
                host   = behaviour,
                method = method
            };
            rpcMethods.Every(hm => hm.method.Invoke(hm.host, parameters: rpcMessage.Paramters.ToArray()));
#endif
        }