LocalCleanPhotonView
How do I use Local Clean Photon View
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
2550 | this.LocalCleanPhotonView(view); | 1 |
2656 | public void LocalCleanPhotonView(PhotonView view) | 2 |
299 | PhotonNetwork.networkingPeer.LocalCleanPhotonView(this); | 3 |
File name: NetworkingPeer.cs
Copy
2493 protected internal void RemoveInstantiatedGO(GameObject go, bool localOnly)
2494 {
2495 if (go == null)
2496 {
2497 Debug.LogError("Failed to 'network-remove' GameObject because it's null.");
2498 return;
2499 }
2500
2501 // Don't remove the GO if it doesn't have any PhotonView
2502 PhotonView[] views = go.GetComponentsInChildren
2503 if (views == null || views.Length <= 0)
2504 {
2505 Debug.LogError("Failed to 'network-remove' GameObject because has no PhotonView components: " + go);
2506 return;
2507 }
2508
2509 PhotonView viewZero = views[0];
2510 int creatorId = viewZero.CreatorActorNr; // creatorId of obj is needed to delete EvInstantiate (only if it's from that user)
2511 int instantiationId = viewZero.instantiationId; // actual, live InstantiationIds start with 1 and go up
2512
2513 // Don't remove GOs that are owned by others (unless this is the master and the remote player left)
2514 if (!localOnly)
2515 {
2516 if (!viewZero.isMine)
2517 {
2518 Debug.LogError("Failed to 'network-remove' GameObject. Client is neither owner nor masterClient taking over for owner who left: " + viewZero);
2519 return;
2520 }
2521
2522 // Don't remove the Instantiation from the server, if it doesn't have a proper ID
2523 if (instantiationId < 1)
2524 {
2525 Debug.LogError("Failed to 'network-remove' GameObject because it is missing a valid InstantiationId on view: " + viewZero + ". Not Destroying GameObject or PhotonViews!");
2526 return;
2527 }
2528 }
2529
2530
2531 // cleanup instantiation (event and local list)
2532 if (!localOnly)
2533 {
2534 this.ServerCleanInstantiateAndDestroy(instantiationId, creatorId, viewZero.isRuntimeInstantiated); // server cleaning
2535 }
2536
2537
2538 // cleanup PhotonViews and their RPCs events (if not localOnly)
2539 for (int j = views.Length - 1; j >= 0; j--)
2540 {
2541 PhotonView view = views[j];
2542 if (view == null)
2543 {
2544 continue;
2545 }
2546
2547 // we only destroy/clean PhotonViews that were created by PhotonNetwork.Instantiate (and those have an instantiationId!)
2548 if (view.instantiationId >= 1)
2549 {
2550 this.LocalCleanPhotonView(view);
2551 }
2552 if (!localOnly)
2553 {
2554 this.OpCleanRpcBuffer(view);
2555 }
2556 }
2557
2558 if (PhotonNetwork.logLevel >= PhotonLogLevel.Full)
2559 Debug.Log("Network destroy Instantiated GO: " + go.name);
2560
2561 GameObject.Destroy(go);
2562 }
File name: NetworkingPeer.cs
Copy
2656 public void LocalCleanPhotonView(PhotonView view)
2657 {
2658 view.destroyedByPhotonNetworkOrQuit = true;
2659 this.photonViewList.Remove(view.viewID);
2660 }
File name: PhotonView.cs
Copy
295 protected internal void OnDestroy()
296 {
297 if (!this.destroyedByPhotonNetworkOrQuit)
298 {
299 PhotonNetwork.networkingPeer.LocalCleanPhotonView(this);
300 }
301
302 if (!this.destroyedByPhotonNetworkOrQuit && !Application.isLoadingLevel)
303 {
304 if (this.instantiationId > 0)
305 {
306 // if this viewID was not manually assigned (and we're not shutting down or loading a level), you should use PhotonNetwork.Destroy() to get rid of GOs with PhotonViews
307 Debug.LogError("OnDestroy() seems to be called without PhotonNetwork.Destroy()?! GameObject: " + this.gameObject + " Application.isLoadingLevel: " + Application.isLoadingLevel);
308 }
309 else
310 {
311 // this seems to be a manually instantiated PV. if it's local, we could warn if the ID is not in the allocated-list
312 if (this.viewID <= 0)
313 {
314 Debug.LogWarning(string.Format("OnDestroy manually allocated PhotonView {0}. The viewID is 0. Was it ever (manually) set?", this));
315 }
316 else if (this.isMine && !PhotonNetwork.manuallyAllocatedViewIds.Contains(this.viewID))
317 {
318 Debug.LogWarning(string.Format("OnDestroy manually allocated PhotonView {0}. The viewID is local (isMine) but not in manuallyAllocatedViewIds list. Use UnAllocateViewID() after you destroyed the PV.", this));
319 }
320 }
321 }
322 }
LocalCleanPhotonView 221 lượt xem
Gõ tìm kiếm nhanh...