ReceiverGroup
How do I use Receiver Group
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: LoadbalancingPeer.cs
Copy
463 public virtual bool OpRaiseEvent(byte eventCode, object customEventContent, bool sendReliable, RaiseEventOptions raiseEventOptions)
464 {
465 opParameters.Clear(); // re-used private variable to avoid many new Dictionary() calls (garbage collection)
466 opParameters[(byte)LiteOpKey.Code] = (byte)eventCode;
467 if (customEventContent != null)
468 {
469 opParameters[(byte) LiteOpKey.Data] = customEventContent;
470 }
471
472 if (raiseEventOptions == null)
473 {
474 raiseEventOptions = RaiseEventOptions.Default;
475 }
476 else
477 {
478 if (raiseEventOptions.CachingOption != EventCaching.DoNotCache)
479 {
480 opParameters[(byte) LiteOpKey.Cache] = (byte) raiseEventOptions.CachingOption;
481 }
482 if (raiseEventOptions.Receivers != ReceiverGroup.Others)
483 {
484 opParameters[(byte) LiteOpKey.ReceiverGroup] = (byte) raiseEventOptions.Receivers;
485 }
486 if (raiseEventOptions.InterestGroup != 0)
487 {
488 opParameters[(byte) LiteOpKey.Group] = (byte) raiseEventOptions.InterestGroup;
489 }
490 if (raiseEventOptions.TargetActors != null)
491 {
492 opParameters[(byte) LiteOpKey.ActorList] = raiseEventOptions.TargetActors;
493 }
494 if (raiseEventOptions.ForwardToWebhook)
495 {
496 opParameters[(byte) ParameterCode.EventForward] = true; //TURNBASED
497 }
498 }
499
500 return this.OpCustom((byte)LiteOpCode.RaiseEvent, opParameters, sendReliable, raiseEventOptions.SequenceChannel, raiseEventOptions.Encrypt);
501 }
File name: NetworkingPeer.cs
Copy
2642 internal protected void RequestOwnership(int viewID, int fromOwner)
2643 {
2644 Debug.Log("RequestOwnership(): " + viewID + " from: " + fromOwner + " Time: " + Environment.TickCount % 1000);
2645 //PhotonNetwork.networkingPeer.OpRaiseEvent(PunEvent.OwnershipRequest, true, new int[] { viewID, fromOwner }, 0, EventCaching.DoNotCache, null, ReceiverGroup.All, 0);
2646 this.OpRaiseEvent(PunEvent.OwnershipRequest, new int[] {viewID, fromOwner}, true, new RaiseEventOptions() { Receivers = ReceiverGroup.All }); // All sends to all via server (including self)
2647 }
File name: NetworkingPeer.cs
Copy
2649 internal protected void TransferOwnership(int viewID, int playerID)
2650 {
2651 Debug.Log("TransferOwnership() view " + viewID + " to: " + playerID + " Time: " + Environment.TickCount % 1000);
2652 //PhotonNetwork.networkingPeer.OpRaiseEvent(PunEvent.OwnershipTransfer, true, new int[] {viewID, playerID}, 0, EventCaching.DoNotCache, null, ReceiverGroup.All, 0);
2653 this.OpRaiseEvent(PunEvent.OwnershipTransfer, new int[] { viewID, playerID }, true, new RaiseEventOptions() { Receivers = ReceiverGroup.All }); // All sends to all via server (including self)
2654 }
File name: NetworkingPeer.cs
Copy
2773 public void OpRemoveCompleteCache()
2774 {
2775 RaiseEventOptions options = new RaiseEventOptions() { CachingOption = EventCaching.RemoveFromRoomCache, Receivers = ReceiverGroup.MasterClient };
2776 this.OpRaiseEvent(0, null, true, options);
2777 //this.OpRaiseEvent(0, null, true, 0, EventCaching.RemoveFromRoomCache, ReceiverGroup.MasterClient); // TODO: check who gets this event?
2778 }
File name: NetworkingPeer.cs
Copy
2890 /// (byte)0 -> (int) ViewId (combined from actorNr and actor-unique-id)
2891 /// (byte)1 -> (short) prefix (level)
2895 /// (byte)5 -> (byte) method shortcut (alternative to name)
2899 internal void RPC(PhotonView view, string methodName, PhotonTargets target, bool encrypt, params object[] parameters)
2900 {
2901 if (this.blockSendingGroups.Contains(view.group))
2902 {
2903 return; // Block sending on this group
2904 }
2905
2906 if (view.viewID < 1)
2907 {
2908 Debug.LogError("Illegal view ID:" + view.viewID + " method: " + methodName + " GO:" + view.gameObject.name);
2909 }
2910
2911 if (PhotonNetwork.logLevel >= PhotonLogLevel.Full)
2912 Debug.Log("Sending RPC \"" + methodName + "\" to " + target);
2913
2914
2915 //ts: changed RPCs to a one-level hashtable as described in internal.txt
2916 Hashtable rpcEvent = new Hashtable();
2917 rpcEvent[(byte)0] = (int)view.viewID; // LIMITS NETWORKVIEWS&PLAYERS
2918 if (view.prefix > 0)
2919 {
2920 rpcEvent[(byte)1] = (short)view.prefix;
2921 }
2922 rpcEvent[(byte)2] = this.ServerTimeInMilliSeconds;
2923
2924
2925 // send name or shortcut (if available)
2926 int shortcut = 0;
2927 if (rpcShortcuts.TryGetValue(methodName, out shortcut))
2928 {
2929 rpcEvent[(byte)5] = (byte)shortcut; // LIMITS RPC COUNT
2930 }
2931 else
2932 {
2933 rpcEvent[(byte)3] = methodName;
2934 }
2935
2936 if (parameters != null && parameters.Length > 0)
2937 {
2938 rpcEvent[(byte)4] = (object[])parameters;
2939 }
2940
2941 // Check scoping
2942 if (target == PhotonTargets.All)
2943 {
2944 RaiseEventOptions options = new RaiseEventOptions() { InterestGroup = (byte)view.group, Encrypt = encrypt };
2945 this.OpRaiseEvent(PunEvent.RPC, rpcEvent, true, options);
2946
2947 // Execute local
2948 this.ExecuteRPC(rpcEvent, this.mLocalActor);
2949 }
2950 else if (target == PhotonTargets.Others)
2951 {
2952 RaiseEventOptions options = new RaiseEventOptions() { InterestGroup = (byte)view.group, Encrypt = encrypt };
2953 this.OpRaiseEvent(PunEvent.RPC, rpcEvent, true, options);
2954 }
2955 else if (target == PhotonTargets.AllBuffered)
2956 {
2957 RaiseEventOptions options = new RaiseEventOptions() { CachingOption = EventCaching.AddToRoomCache, Encrypt = encrypt };
2958 this.OpRaiseEvent(PunEvent.RPC, rpcEvent, true, options);
2959
2960 // Execute local
2961 this.ExecuteRPC(rpcEvent, this.mLocalActor);
2962 }
2963 else if (target == PhotonTargets.OthersBuffered)
2964 {
2965 RaiseEventOptions options = new RaiseEventOptions() { CachingOption = EventCaching.AddToRoomCache, Encrypt = encrypt };
2966 this.OpRaiseEvent(PunEvent.RPC, rpcEvent, true, options);
2967 }
2968 else if (target == PhotonTargets.MasterClient)
2969 {
2970 if (this.mMasterClient == this.mLocalActor)
2971 {
2972 this.ExecuteRPC(rpcEvent, this.mLocalActor);
2973 }
2974 else
2975 {
2976 RaiseEventOptions options = new RaiseEventOptions() { Receivers = ReceiverGroup.MasterClient, Encrypt = encrypt };
2977 this.OpRaiseEvent(PunEvent.RPC, rpcEvent, true, options);
2978 }
2979 }
2980 else if (target == PhotonTargets.AllViaServer)
2981 {
2982 RaiseEventOptions options = new RaiseEventOptions() { InterestGroup = (byte)view.group, Receivers = ReceiverGroup.All, Encrypt = encrypt };
2983 this.OpRaiseEvent(PunEvent.RPC, rpcEvent, true, options);
2984 if (PhotonNetwork.offlineMode)
2985 {
2986 this.ExecuteRPC(rpcEvent, this.mLocalActor);
2987 }
2988 }
2989 else if (target == PhotonTargets.AllBufferedViaServer)
2990 {
2991 RaiseEventOptions options = new RaiseEventOptions() { InterestGroup = (byte)view.group, Receivers = ReceiverGroup.All, CachingOption = EventCaching.AddToRoomCache, Encrypt = encrypt };
2992 this.OpRaiseEvent(PunEvent.RPC, rpcEvent, true, options);
2993 if (PhotonNetwork.offlineMode)
2994 {
2995 this.ExecuteRPC(rpcEvent, this.mLocalActor);
2996 }
2997 }
2998 else
2999 {
3000 Debug.LogError("Unsupported target enum: " + target);
3001 }
3002 }
File name: NetworkingPeer.cs
Copy
3147 public void RunViewUpdate()
3148 {
3149 if (!PhotonNetwork.connected || PhotonNetwork.offlineMode)
3150 {
3151 return;
3152 }
3153
3154 if (this.mActors == null ||
3155#if !PHOTON_DEVELOP
3156 this.mActors.Count <= 1
3157#endif
3158 )
3159 {
3160 return; // No need to send OnSerialize messages (these are never buffered anyway)
3161 }
3162
3163 dataPerGroupReliable.Clear();
3164 dataPerGroupUnreliable.Clear();
3165
3166 /* Format of the data hashtable:
3167 * Hasthable dataPergroup*
3168 * [(byte)0] = this.ServerTimeInMilliSeconds;
3169 * OPTIONAL: [(byte)1] = currentLevelPrefix;
3170 * + data
3171 */
3172
3173 foreach (KeyValuePair
3174 {
3175 PhotonView view = kvp.Value;
3176
3177 if (view.synchronization != ViewSynchronization.Off)
3178 {
3179 // Fetch all sending photonViews
3180 if (view.isMine)
3181 {
3182 #if UNITY_2_6_1 || UNITY_2_6 || UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5
3183 if (!view.gameObject.active)
3184 {
3185 continue; // Only on actives
3186 }
3187 #else
3188 if (!view.gameObject.activeInHierarchy)
3189 {
3190 continue; // Only on actives
3191 }
3192 #endif
3193
3194 if (this.blockSendingGroups.Contains(view.group))
3195 {
3196 continue; // Block sending on this group
3197 }
3198
3199 // Run it trough its OnSerialize
3200 Hashtable evData = this.OnSerializeWrite(view);
3201 if (evData == null)
3202 {
3203 continue;
3204 }
3205
3206 if (view.synchronization == ViewSynchronization.ReliableDeltaCompressed || view.mixedModeIsReliable)
3207 {
3208 if (!evData.ContainsKey((byte)1) && !evData.ContainsKey((byte)2))
3209 {
3210 // Everything has been removed by compression, nothing to send
3211 }
3212 else
3213 {
3214 if (!dataPerGroupReliable.ContainsKey(view.group))
3215 {
3216 dataPerGroupReliable[view.group] = new Hashtable();
3217 dataPerGroupReliable[view.group][(byte)0] = this.ServerTimeInMilliSeconds;
3218 if (currentLevelPrefix >= 0)
3219 {
3220 dataPerGroupReliable[view.group][(byte)1] = this.currentLevelPrefix;
3221 }
3222 }
3223 Hashtable groupHashtable = dataPerGroupReliable[view.group];
3224 groupHashtable.Add((short)groupHashtable.Count, evData);
3225 }
3226 }
3227 else
3228 {
3229 if (!dataPerGroupUnreliable.ContainsKey(view.group))
3230 {
3231 dataPerGroupUnreliable[view.group] = new Hashtable();
3232 dataPerGroupUnreliable[view.group][(byte)0] = this.ServerTimeInMilliSeconds;
3233 if (currentLevelPrefix >= 0)
3234 {
3235 dataPerGroupUnreliable[view.group][(byte)1] = this.currentLevelPrefix;
3236 }
3237 }
3238 Hashtable groupHashtable = dataPerGroupUnreliable[view.group];
3239 groupHashtable.Add((short)groupHashtable.Count, evData);
3240 }
3241 }
3242 else
3243 {
3244 // Debug.Log(" NO OBS on " + view.name + " " + view.owner);
3245 }
3246 }
3247 else
3248 {
3249 }
3250 }
3251
3252 //Send the messages: every group is send in it's own message and unreliable and reliable are split as well
3253 RaiseEventOptions options = new RaiseEventOptions();
3254
3255#if PHOTON_DEVELOP
3256 options.Receivers = ReceiverGroup.All;
3257#endif
3258
3259 foreach (KeyValuePair
3260 {
3261 options.InterestGroup = (byte)kvp.Key;
3262 this.OpRaiseEvent(PunEvent.SendSerializeReliable, kvp.Value, true, options);
3263 }
3264 foreach (KeyValuePair
3265 {
3266 options.InterestGroup = (byte)kvp.Key;
3267 this.OpRaiseEvent(PunEvent.SendSerialize, kvp.Value, false, options);
3268 }
3269 }
ReceiverGroup 122 lượt xem
Gõ tìm kiếm nhanh...