LocalCleanupAnythingInstantiated
How do I use Local Cleanup Anything Instantiated
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: NetworkingPeer.cs
Copy
459 private void LeftRoomCleanup()
460 {
461 bool wasInRoom = mRoomToGetInto != null;
462 // when leaving a room, we clean up depending on that room's settings.
463 bool autoCleanupSettingOfRoom = (this.mRoomToGetInto != null) ? this.mRoomToGetInto.autoCleanUp : PhotonNetwork.autoCleanUpPlayerObjects;
464
465 this.hasSwitchedMC = false;
466 this.mRoomToGetInto = null;
467 this.mActors = new Dictionary
468 this.mPlayerListCopy = new PhotonPlayer[0];
469 this.mOtherPlayerListCopy = new PhotonPlayer[0];
470 this.mMasterClient = null;
471 this.allowedReceivingGroups = new HashSet
472 this.blockSendingGroups = new HashSet
473 this.mGameList = new Dictionary
474 this.mGameListCopy = new RoomInfo[0];
475 this.isFetchingFriends = false;
476
477 this.ChangeLocalID(-1);
478
479 // Cleanup all network objects (all spawned PhotonViews, local and remote)
480 if (autoCleanupSettingOfRoom)
481 {
482 this.LocalCleanupAnythingInstantiated(true);
483 PhotonNetwork.manuallyAllocatedViewIds = new List
484 }
485
486 if (wasInRoom)
487 {
488 SendMonoMessage(PhotonNetworkingMessage.OnLeftRoom);
489 }
490 }
File name: NetworkingPeer.cs
Copy
495 protected internal void LocalCleanupAnythingInstantiated(bool destroyInstantiatedGameObjects)
496 {
497 if (tempInstantiationData.Count > 0)
498 {
499 Debug.LogWarning("It seems some instantiation is not completed, as instantiation data is used. You should make sure instantiations are paused when calling this method. Cleaning now, despite this.");
500 }
501
502 // Destroy GO's (if we should)
503 if (destroyInstantiatedGameObjects)
504 {
505 // Fill list with Instantiated objects
506 HashSet
507 foreach (PhotonView view in this.photonViewList.Values)
508 {
509 if (view.isRuntimeInstantiated)
510 {
511 instantiatedGos.Add(view.gameObject); // HashSet keeps each object only once
512 }
513 }
514
515 foreach (GameObject go in instantiatedGos)
516 {
517 this.RemoveInstantiatedGO(go, true);
518 }
519 }
520
521 // photonViewList is cleared of anything instantiated (so scene items are left inside)
522 // any other lists can be
523 this.tempInstantiationData.Clear(); // should be empty but to be safe we clear (no new list needed)
524 PhotonNetwork.lastUsedViewSubId = 0;
525 PhotonNetwork.lastUsedViewSubIdStatic = 0;
526 }
File name: NetworkingPeer.cs
Copy
2476 public void DestroyAll(bool localOnly)
2477 {
2478 if (!localOnly)
2479 {
2480 this.OpRemoveCompleteCache();
2481 this.SendDestroyOfAll();
2482 }
2483
2484 this.LocalCleanupAnythingInstantiated(true);
2485 }
LocalCleanupAnythingInstantiated 161 lượt xem
Gõ tìm kiếm nhanh...