CreatorActorNr









How do I use Creator Actor Nr
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


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 playersGameObjects = new 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(true);
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: PhotonView.cs Copy
176     public int instantiationId; // if the view was instantiated with a GO, this GO has a instantiationID (first view's viewID)
185     {
186         get { return this.CreatorActorNr == 0; }
187     }

CreatorActorNr 128 lượt xem

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