OpRaiseEvent









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

Featured Snippets


File name: LoadbalancingPeer.cs Copy
29         private readonly Dictionary opParameters = new Dictionary(); // used in OpRaiseEvent() (avoids lots of new Dictionary() calls)
31         public LoadbalancingPeer(IPhotonPeerListener listener, ConnectionProtocol protocolType) : base(listener, protocolType)
32         {
33         }
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
757     internal protected bool SetMasterClient(int playerId, bool sync)
758     {
759         bool masterReplaced = this.mMasterClient != null && this.mMasterClient.ID != playerId;
760         if (!masterReplaced || !this.mActors.ContainsKey(playerId))
761         {
762             return false;
763         }
764
765         if (sync)
766         {
767             bool sent = this.OpRaiseEvent(PunEvent.AssignMaster, new Hashtable() { { (byte)1, playerId } }, true, null);
768             if (!sent)
769             {
770                 return false;
771             }
772         }
773
774         this.hasSwitchedMC = true;
775         this.mMasterClient = this.mActors[playerId];
776         SendMonoMessage(PhotonNetworkingMessage.OnMasterClientSwitched, this.mMasterClient); // we only callback when an actual change is done
777         return true;
778     }
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
1918     private void SendVacantViewIds()
1919     {
1920         Debug.Log("SendVacantViewIds()");
1921         List vacantViews = new List();
1922         foreach (PhotonView view in this.photonViewList.Values)
1923         {
1924             if (!view.isOwnerActive)
1925             {
1926                 vacantViews.Add(view.viewID);
1927             }
1928         }
1929
1930         Debug.Log("Sending vacant view IDs. Length: " + vacantViews.Count);
1931         //this.OpRaiseEvent(PunEvent.VacantViewIds, true, vacantViews.ToArray());
1932         this.OpRaiseEvent(PunEvent.VacantViewIds, vacantViews.ToArray(), true, null);
1933     }
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
2615     private void SendDestroyOfPlayer(int actorNr)
2616     {
2617         Hashtable evData = new Hashtable();
2618         evData[(byte)0] = actorNr;
2619
2620         this.OpRaiseEvent(PunEvent.DestroyPlayer, evData, true, null);
2621         //this.OpRaiseEvent(PunEvent.DestroyPlayer, evData, true, 0, EventCaching.DoNotCache, ReceiverGroup.Others);
2622     }
File name: NetworkingPeer.cs Copy
2624     private void SendDestroyOfAll()
2625     {
2626         Hashtable evData = new Hashtable();
2627         evData[(byte)0] = -1;
2628
2629
2630         this.OpRaiseEvent(PunEvent.DestroyPlayer, evData, true, null);
2631         //this.OpRaiseEvent(PunEvent.DestroyPlayer, evData, true, 0, EventCaching.DoNotCache, ReceiverGroup.Others);
2632     }
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     }

OpRaiseEvent 126 lượt xem

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