GetNextFor









How do I use Get Next For
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: PhotonPlayer.cs Copy
227     public PhotonPlayer GetNext()
228     {
229         return GetNextFor(this.ID);
230     }
File name: PhotonPlayer.cs Copy
232     public PhotonPlayer GetNextFor(PhotonPlayer currentPlayer)
233     {
234         if (currentPlayer == null)
235         {
236             return null;
237         }
238         return GetNextFor(currentPlayer.ID);
239     }
File name: PhotonPlayer.cs Copy
241     public PhotonPlayer GetNextFor(int currentPlayerId)
242     {
243         if (PhotonNetwork.networkingPeer == null || PhotonNetwork.networkingPeer.mActors == null || PhotonNetwork.networkingPeer.mActors.Count < 2)
244         {
245             return null;
246         }
247
248         Dictionary players = PhotonNetwork.networkingPeer.mActors;
249         int nextHigherId = int.MaxValue; // we look for the next higher ID
250         int lowestId = currentPlayerId; // if we are the player with the highest ID, there is no higher and we return to the lowest player's id
251
252         foreach (int playerid in players.Keys)
253         {
254             if (playerid < lowestId)
255             {
256                 lowestId = playerid; // less than any other ID (which must be at least less than this player's id).
257             }
258             else if (playerid > currentPlayerId && playerid < nextHigherId)
259             {
260                 nextHigherId = playerid; // more than our ID and less than those found so far.
261             }
262         }
263
264         //UnityEngine.Debug.LogWarning("Debug. " + currentPlayerId + " lower: " + lowestId + " higher: " + nextHigherId + " ");
265         //UnityEngine.Debug.LogWarning(this.RoomReference.GetPlayer(currentPlayerId));
266         //UnityEngine.Debug.LogWarning(this.RoomReference.GetPlayer(lowestId));
267         //if (nextHigherId != int.MaxValue) UnityEngine.Debug.LogWarning(this.RoomReference.GetPlayer(nextHigherId));
268         return (nextHigherId != int.MaxValue) ? players[nextHigherId] : players[lowestId];
269     }

GetNextFor 114 lượt xem

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