AddToRoomCacheGlobal
How do I use Add To Room Cache Global
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
2273 | options.CachingOption = (isGlobalObject) ? EventCaching.AddToRoomCacheGlobal : EventCaching.AddToRoomCache; | 1 |
2609 | options.CachingOption = EventCaching.AddToRoomCacheGlobal; | 2 |
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 }
AddToRoomCacheGlobal 121 lượt xem
Gõ tìm kiếm nhanh...