RaiseEventOptions









How do I use Raise Event Options
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets

Line Code Ex..
463 public virtual bool OpRaiseEvent(byte eventCode, object customEventContent, bool sendReliable, RaiseEventOptions raiseEventOptions) 1
997 public override bool OpRaiseEvent(byte eventCode, object customEventContent, bool sendReliable, RaiseEventOptions raiseEventOptions) 2
2272 RaiseEventOptions options = new RaiseEventOptions(); 3
2597 RaiseEventOptions options = new RaiseEventOptions() { CachingOption = EventCaching.RemoveFromRoomCache, TargetActors = new int[] { creatorId } }; 4
2637 RaiseEventOptions options = new RaiseEventOptions() { CachingOption = EventCaching.RemoveFromRoomCache, TargetActors = new int[] { actorNr } }; 5
2646 this.OpRaiseEvent(PunEvent.OwnershipRequest, new int[] {viewID, fromOwner}, true, new RaiseEventOptions() { Receivers = ReceiverGroup.All }); // All sends to all via server (including self) 6
2653 this.OpRaiseEvent(PunEvent.OwnershipTransfer, new int[] { viewID, playerID }, true, new RaiseEventOptions() { Receivers = ReceiverGroup.All }); // All sends to all via server (including self) 7
2756 RaiseEventOptions options = new RaiseEventOptions() { CachingOption = EventCaching.RemoveFromRoomCache, TargetActors = new int[] { actorNumber } }; 8
2767 RaiseEventOptions options = new RaiseEventOptions() { CachingOption = EventCaching.RemoveFromRoomCache, TargetActors = new int[] { actorNumber } }; 9
2775 RaiseEventOptions options = new RaiseEventOptions() { CachingOption = EventCaching.RemoveFromRoomCache, Receivers = ReceiverGroup.MasterClient }; 10

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
997     public override bool OpRaiseEvent(byte eventCode, object customEventContent, bool sendReliable, RaiseEventOptions raiseEventOptions)
998     {
999         if (PhotonNetwork.offlineMode)
1000         {
1001             return false;
1002         }
1003
1004         return base.OpRaiseEvent(eventCode, customEventContent, sendReliable, raiseEventOptions);
1005     }
File name: NetworkingPeer.cs Copy
2228     internal Hashtable SendInstantiate(string prefabName, Vector3 position, Quaternion rotation, int group, int[] viewIDs, object[] data, bool isGlobalObject)
2229     {
2230         // first viewID is now also the gameobject's instantiateId
2231         int instantiateId = viewIDs[0]; // LIMITS PHOTONVIEWS&PLAYERS
2232
2233         //TODO: reduce hashtable key usage by using a parameter array for the various values
2234         Hashtable instantiateEvent = new Hashtable(); // This players info is sent via ActorID
2235         instantiateEvent[(byte)0] = prefabName;
2236
2237         if (position != Vector3.zero)
2238         {
2239             instantiateEvent[(byte)1] = position;
2240         }
2241
2242         if (rotation != Quaternion.identity)
2243         {
2244             instantiateEvent[(byte)2] = rotation;
2245         }
2246
2247         if (group != 0)
2248         {
2249             instantiateEvent[(byte)3] = group;
2250         }
2251
2252         // send the list of viewIDs only if there are more than one. else the instantiateId is the viewID
2253         if (viewIDs.Length > 1)
2254         {
2255             instantiateEvent[(byte)4] = viewIDs; // LIMITS PHOTONVIEWS&PLAYERS
2256         }
2257
2258         if (data != null)
2259         {
2260             instantiateEvent[(byte)5] = data;
2261         }
2262
2263         if (this.currentLevelPrefix > 0)
2264         {
2265             instantiateEvent[(byte)8] = this.currentLevelPrefix; // photonview's / object's level prefix
2266         }
2267
2268         instantiateEvent[(byte)6] = this.ServerTimeInMilliSeconds;
2269         instantiateEvent[(byte)7] = instantiateId;
2270
2271
2272         RaiseEventOptions options = new RaiseEventOptions();
2273         options.CachingOption = (isGlobalObject) ? EventCaching.AddToRoomCacheGlobal : EventCaching.AddToRoomCache;
2274
2275         this.OpRaiseEvent(PunEvent.Instantiation, instantiateEvent, true, options);
2276         return instantiateEvent;
2277     }
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
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
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
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     }

RaiseEventOptions 174 lượt xem

Gõ tìm kiếm nhanh...