OpCleanRpcBuffer
How do I use Op Clean Rpc Buffer
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
2442 | this.OpCleanRpcBuffer(playerId); | 1 |
2554 | this.OpCleanRpcBuffer(view); | 2 |
2754 | public void OpCleanRpcBuffer(int actorNumber) | 3 |
2799 | this.OpCleanRpcBuffer(view); | 4 |
2803 | public void OpCleanRpcBuffer(PhotonView view) | 5 |
2435 | networkingPeer.OpCleanRpcBuffer(targetPlayer.ID); | 6 |
File name: NetworkingPeer.cs
Copy
2430 public void DestroyPlayerObjects(int playerId, bool localOnly)
2431 {
2432 if (playerId <= 0)
2433 {
2434 Debug.LogError("Failed to Destroy objects of playerId: " + playerId);
2435 return;
2436 }
2437
2438 if (!localOnly)
2439 {
2440 // clean server's Instantiate and RPC buffers
2441 this.OpRemoveFromServerInstantiationsOfPlayer(playerId);
2442 this.OpCleanRpcBuffer(playerId);
2443
2444 // send Destroy(player) to anyone else
2445 this.SendDestroyOfPlayer(playerId);
2446 }
2447
2448 // locally cleaning up that player's objects
2449 HashSet
2450 foreach (PhotonView view in this.photonViewList.Values)
2451 {
2452 if (view.CreatorActorNr == playerId)
2453 {
2454 playersGameObjects.Add(view.gameObject);
2455 }
2456 }
2457
2458 // any non-local work is already done, so with the list of that player's objects, we can clean up (locally only)
2459 foreach (GameObject gameObject in playersGameObjects)
2460 {
2461 this.RemoveInstantiatedGO(gameObject, true);
2462 }
2463
2464 // with ownership transfer, some objects might lose their owner.
2465 // in that case, the creator becomes the owner again. every client can apply this. done below.
2466 foreach (PhotonView view in this.photonViewList.Values)
2467 {
2468 if (view.ownerId == playerId)
2469 {
2470 view.ownerId = view.CreatorActorNr;
2471 //Debug.Log("Creator is: " + view.ownerId);
2472 }
2473 }
2474 }
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
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
2790 // Remove RPCs of view (if they are local player's RPCs)
2791 public void CleanRpcBufferIfMine(PhotonView view)
2792 {
2793 if (view.ownerId != this.mLocalActor.ID && !mLocalActor.isMasterClient)
2794 {
2795 Debug.LogError("Cannot remove cached RPCs on a PhotonView thats not ours! " + view.owner + " scene: " + view.isSceneView);
2796 return;
2797 }
2798
2799 this.OpCleanRpcBuffer(view);
2800 }
File name: NetworkingPeer.cs
Copy
2803 public void OpCleanRpcBuffer(PhotonView view)
2804 {
2805 Hashtable rpcFilterByViewId = new Hashtable();
2806 rpcFilterByViewId[(byte)0] = view.viewID;
2807
2808 RaiseEventOptions options = new RaiseEventOptions() { CachingOption = EventCaching.RemoveFromRoomCache };
2809 this.OpRaiseEvent(PunEvent.RPC, rpcFilterByViewId, true, options);
2810 //this.OpRaiseEvent(PunEvent.RPC, rpcFilterByViewId, true, 0, EventCaching.RemoveFromRoomCache, ReceiverGroup.Others);
2811 }
File name: PhotonNetwork.cs
Copy
2422 public static void RemoveRPCs(PhotonPlayer targetPlayer)
2423 {
2424 if (!VerifyCanUseNetwork())
2425 {
2426 return;
2427 }
2428
2429 if (!targetPlayer.isLocal && !isMasterClient)
2430 {
2431 Debug.LogError("Error; Only the MasterClient can call RemoveRPCs for other players.");
2432 return;
2433 }
2434
2435 networkingPeer.OpCleanRpcBuffer(targetPlayer.ID);
2436 }
OpCleanRpcBuffer 135 lượt xem
Gõ tìm kiếm nhanh...