TargetActors
How do I use Target Actors
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
2592 private void ServerCleanInstantiateAndDestroy(int instantiateId, int creatorId, bool isRuntimeInstantiated)
2593 {
2594 Hashtable removeFilter = new Hashtable();
2595 removeFilter[(byte)7] = instantiateId;
2596
2597 RaiseEventOptions options = new RaiseEventOptions() { CachingOption = EventCaching.RemoveFromRoomCache, TargetActors = new int[] { creatorId } };
2598 this.OpRaiseEvent(PunEvent.Instantiation, removeFilter, true, options);
2599 //this.OpRaiseEvent(PunEvent.Instantiation, removeFilter, true, 0, new int[] { actorNr }, EventCaching.RemoveFromRoomCache);
2600
2601 Hashtable evData = new Hashtable();
2602 evData[(byte)0] = instantiateId;
2603 options = null;
2604 if (!isRuntimeInstantiated)
2605 {
2606 // if the view got loaded with the scene, the EvDestroy must be cached (there is no Instantiate-msg which we can remove)
2607 // reason: joining players will load the obj and have to destroy it (too)
2608 options = new RaiseEventOptions();
2609 options.CachingOption = EventCaching.AddToRoomCacheGlobal;
2610 Debug.Log("Destroying GO as global. ID: " + instantiateId);
2611 }
2612 this.OpRaiseEvent(PunEvent.Destroy, evData, true, options);
2613 }
File name: NetworkingPeer.cs
Copy
2634 private void OpRemoveFromServerInstantiationsOfPlayer(int actorNr)
2635 {
2636 // removes all "Instantiation" events of player actorNr. this is not an event for anyone else
2637 RaiseEventOptions options = new RaiseEventOptions() { CachingOption = EventCaching.RemoveFromRoomCache, TargetActors = new int[] { actorNr } };
2638 this.OpRaiseEvent(PunEvent.Instantiation, null, true, options);
2639 //this.OpRaiseEvent(PunEvent.Instantiation, null, true, 0, new int[] { actorNr }, EventCaching.RemoveFromRoomCache);
2640 }
File name: NetworkingPeer.cs
Copy
2754 public void OpCleanRpcBuffer(int actorNumber)
2755 {
2756 RaiseEventOptions options = new RaiseEventOptions() { CachingOption = EventCaching.RemoveFromRoomCache, TargetActors = new int[] { actorNumber } };
2757 this.OpRaiseEvent(PunEvent.RPC, null, true, options);
2758 //this.OpRaiseEvent(PunEvent.RPC, null, true, 0, new int[] { actorNumber }, EventCaching.RemoveFromRoomCache);
2759 }
File name: NetworkingPeer.cs
Copy
2765 public void OpRemoveCompleteCacheOfPlayer(int actorNumber)
2766 {
2767 RaiseEventOptions options = new RaiseEventOptions() { CachingOption = EventCaching.RemoveFromRoomCache, TargetActors = new int[] { actorNumber } };
2768 this.OpRaiseEvent(0, null, true, options);
2769 //this.OpRaiseEvent(0, null, true, 0, new int[] { actorNumber }, EventCaching.RemoveFromRoomCache);
2770 }
File name: NetworkingPeer.cs
Copy
2835 internal void RPC(PhotonView view, string methodName, PhotonPlayer player, bool encrypt, params object[] parameters)
2836 {
2837 if (this.blockSendingGroups.Contains(view.group))
2838 {
2839 return; // Block sending on this group
2840 }
2841
2842 if (view.viewID < 1) //TODO: check why 0 should be illegal
2843 {
2844 Debug.LogError("Illegal view ID:" + view.viewID + " method: " + methodName + " GO:" + view.gameObject.name);
2845 }
2846
2847 if (PhotonNetwork.logLevel >= PhotonLogLevel.Full)
2848 {
2849 Debug.Log("Sending RPC \"" + methodName + "\" to player[" + player + "]");
2850 }
2851
2852
2853 //ts: changed RPCs to a one-level hashtable as described in internal.txt
2854 Hashtable rpcEvent = new Hashtable();
2855 rpcEvent[(byte)0] = (int)view.viewID; // LIMITS PHOTONVIEWS&PLAYERS
2856 if (view.prefix > 0)
2857 {
2858 rpcEvent[(byte)1] = (short)view.prefix;
2859 }
2860 rpcEvent[(byte)2] = this.ServerTimeInMilliSeconds;
2861
2862 // send name or shortcut (if available)
2863 int shortcut = 0;
2864 if (rpcShortcuts.TryGetValue(methodName, out shortcut))
2865 {
2866 rpcEvent[(byte)5] = (byte)shortcut; // LIMITS RPC COUNT
2867 }
2868 else
2869 {
2870 rpcEvent[(byte)3] = methodName;
2871 }
2872
2873 if (parameters != null && parameters.Length > 0)
2874 {
2875 rpcEvent[(byte) 4] = (object[]) parameters;
2876 }
2877
2878 if (this.mLocalActor == player)
2879 {
2880 this.ExecuteRPC(rpcEvent, player);
2881 }
2882 else
2883 {
2884 RaiseEventOptions options = new RaiseEventOptions() { TargetActors = new int[] { player.ID }, Encrypt = encrypt };
2885 this.OpRaiseEvent(PunEvent.RPC, rpcEvent, true, options);
2886 }
2887 }
File name: PhotonNetwork.cs
Copy
2246 public static bool CloseConnection(PhotonPlayer kickPlayer)
2247 {
2248 if (!VerifyCanUseNetwork())
2249 {
2250 return false;
2251 }
2252
2253 if (!player.isMasterClient)
2254 {
2255 Debug.LogError("CloseConnection: Only the masterclient can kick another player.");
2256 return false;
2257 }
2258
2259 if (kickPlayer == null)
2260 {
2261 Debug.LogError("CloseConnection: No such player connected!");
2262 return false;
2263 }
2264
2265 RaiseEventOptions options = new RaiseEventOptions() { TargetActors = new int[] { kickPlayer.ID } };
2266 return networkingPeer.OpRaiseEvent(PunEvent.CloseConnection, null, true, options);
2267 }
TargetActors 128 lượt xem
Gõ tìm kiếm nhanh...