Merge









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

Featured Snippets


File name: Extensions.cs Copy
61     public static void Merge(this IDictionary target, IDictionary addHash)
62     {
63         if (addHash == null || target.Equals(addHash))
64         {
65             return;
66         }
67
68         foreach (object key in addHash.Keys)
69         {
70             target[key] = addHash[key];
71         }
72     }
File name: Extensions.cs Copy
82     public static void MergeStringKeys(this IDictionary target, IDictionary addHash)
83     {
84         if (addHash == null || target.Equals(addHash))
85         {
86             return;
87         }
88
89         foreach (object key in addHash.Keys)
90         {
91             // only merge keys of type string
92             if (key is string)
93             {
94                 target[key] = addHash[key];
95             }
96         }
97     }
File name: LoadbalancingPeer.cs Copy
86         public virtual bool OpCreateRoom(string roomName, RoomOptions roomOptions, TypedLobby lobby, Hashtable playerProperties, bool onGameServer)
87         {
88             if (this.DebugOut >= DebugLevel.INFO)
89             {
90                 this.Listener.DebugReturn(DebugLevel.INFO, "OpCreateRoom()");
91             }
92
93             Dictionary op = new Dictionary();
94
95             if (!string.IsNullOrEmpty(roomName))
96             {
97                 op[ParameterCode.RoomName] = roomName;
98             }
99             if (lobby != null)
100             {
101                 op[ParameterCode.LobbyName] = lobby.Name;
102                 op[ParameterCode.LobbyType] = (byte)lobby.Type;
103             }
104
105             if (onGameServer)
106             {
107                 if (playerProperties != null && playerProperties.Count > 0)
108                 {
109                     op[ParameterCode.PlayerProperties] = playerProperties;
110                     op[ParameterCode.Broadcast] = true; // TODO: check if this also makes sense when creating a room?! // broadcast actor properties
111                 }
112
113
114                 if (roomOptions == null)
115                 {
116                     roomOptions = new RoomOptions();
117                 }
118
119                 Hashtable gameProperties = new Hashtable();
120                 op[ParameterCode.GameProperties] = gameProperties;
121                 gameProperties.MergeStringKeys(roomOptions.customRoomProperties);
122
123                 gameProperties[GameProperties.IsOpen] = roomOptions.isOpen; // TODO: check default value. dont send this then
124                 gameProperties[GameProperties.IsVisible] = roomOptions.isVisible; // TODO: check default value. dont send this then
125                 gameProperties[GameProperties.PropsListedInLobby] = roomOptions.customRoomPropertiesForLobby;
126                 if (roomOptions.maxPlayers > 0)
127                 {
128                     gameProperties[GameProperties.MaxPlayers] = roomOptions.maxPlayers;
129                 }
130                 if (roomOptions.cleanupCacheOnLeave)
131                 {
132                     op[ParameterCode.CleanupCacheOnLeave] = true; // this is actually setting the room's config
133                     gameProperties[GameProperties.CleanupCacheOnLeave] = true; // this is only informational for the clients which join
134                 }
135             }
136
137             // UnityEngine.Debug.Log("CreateGame: " + SupportClass.DictionaryToString(op));
138             return this.OpCustom(OperationCode.CreateGame, op, true);
139         }
File name: LoadbalancingPeer.cs Copy
143         public virtual bool OpJoinRoom(string roomName, RoomOptions roomOptions, TypedLobby lobby, bool createIfNotExists, Hashtable playerProperties, bool onGameServer)
144         {
145             Dictionary op = new Dictionary();
146
147             if (!string.IsNullOrEmpty(roomName))
148             {
149                 op[ParameterCode.RoomName] = roomName;
150             }
151             if (createIfNotExists)
152             {
153                 op[ParameterCode.CreateIfNotExists] = true;
154                 if (lobby != null)
155                 {
156                     op[ParameterCode.LobbyName] = lobby.Name;
157                     op[ParameterCode.LobbyType] = (byte)lobby.Type;
158                 }
159             }
160
161             if (onGameServer)
162             {
163                 if (playerProperties != null && playerProperties.Count > 0)
164                 {
165                     op[ParameterCode.PlayerProperties] = playerProperties;
166                     op[ParameterCode.Broadcast] = true; // broadcast actor properties
167                 }
168
169
170                 if (createIfNotExists)
171                 {
172                     if (roomOptions == null)
173                     {
174                         roomOptions = new RoomOptions();
175                     }
176
177                     Hashtable gameProperties = new Hashtable();
178                     op[ParameterCode.GameProperties] = gameProperties;
179                     gameProperties.MergeStringKeys(roomOptions.customRoomProperties);
180
181                     gameProperties[GameProperties.IsOpen] = roomOptions.isOpen;
182                     gameProperties[GameProperties.IsVisible] = roomOptions.isVisible;
183                     gameProperties[GameProperties.PropsListedInLobby] = roomOptions.customRoomPropertiesForLobby;
184                     if (roomOptions.maxPlayers > 0)
185                     {
186                         gameProperties[GameProperties.MaxPlayers] = roomOptions.maxPlayers;
187                     }
188                     if (roomOptions.cleanupCacheOnLeave)
189                     {
190                         op[ParameterCode.CleanupCacheOnLeave] = true; // this is actually setting the room's config
191                         gameProperties[GameProperties.CleanupCacheOnLeave] = true; // this is only informational for the clients which join
192                     }
193                 }
194             }
195
196             // UnityEngine.Debug.Log("JoinGame: " + SupportClass.DictionaryToString(op));
197             return this.OpCustom(OperationCode.JoinGame, op, true);
198         }
File name: LoadbalancingPeer.cs Copy
212         public virtual bool OpJoinRandomRoom(Hashtable expectedCustomRoomProperties, byte expectedMaxPlayers, Hashtable playerProperties, MatchmakingMode matchingType, TypedLobby typedLobby, string sqlLobbyFilter)
213         {
214             if (this.DebugOut >= DebugLevel.INFO)
215             {
216                 this.Listener.DebugReturn(DebugLevel.INFO, "OpJoinRandomRoom()");
217             }
218
219             Hashtable expectedRoomProperties = new Hashtable();
220             expectedRoomProperties.MergeStringKeys(expectedCustomRoomProperties);
221             if (expectedMaxPlayers > 0)
222             {
223                 expectedRoomProperties[GameProperties.MaxPlayers] = expectedMaxPlayers;
224             }
225
226             Dictionary opParameters = new Dictionary();
227             if (expectedRoomProperties.Count > 0)
228             {
229                 opParameters[ParameterCode.GameProperties] = expectedRoomProperties;
230             }
231
232             if (playerProperties != null && playerProperties.Count > 0)
233             {
234                 opParameters[ParameterCode.PlayerProperties] = playerProperties;
235             }
236
237             if (matchingType != MatchmakingMode.FillRoom)
238             {
239                 opParameters[ParameterCode.MatchMakingType] = (byte)matchingType;
240             }
241
242             if (typedLobby != null)
243             {
244                 opParameters[ParameterCode.LobbyName] = typedLobby.Name;
245                 opParameters[ParameterCode.LobbyType] = (byte)typedLobby.Type;
246             }
247
248             if (!string.IsNullOrEmpty(sqlLobbyFilter))
249             {
250                 opParameters[ParameterCode.Data] = sqlLobbyFilter;
251             }
252
253             // UnityEngine.Debug.LogWarning("OpJoinRandom: " + opParameters.ToStringFull());
254             return this.OpCustom(OperationCode.JoinRandomGame, opParameters, true);
255         }
File name: PhotonPlayer.cs Copy
80     {
81         get
82         {
83             Hashtable allProps = new Hashtable();
84             allProps.Merge(this.customProperties);
85             allProps[ActorProperties.PlayerName] = this.name;
86             return allProps;
87         }
88     }
File name: PhotonPlayer.cs Copy
152     internal void InternalCacheProperties(Hashtable properties)
153     {
154         if (properties == null || properties.Count == 0 || this.customProperties.Equals(properties))
155         {
156             return;
157         }
158
159         if (properties.ContainsKey(ActorProperties.PlayerName))
160         {
161             this.nameField = (string)properties[ActorProperties.PlayerName];
162         }
163
164         this.customProperties.MergeStringKeys(properties);
165         this.customProperties.StripKeysWithNullValues();
166     }
File name: PhotonPlayer.cs Copy
184     public void SetCustomProperties(Hashtable propertiesToSet)
185     {
186         if (propertiesToSet == null)
187         {
188             return;
189         }
190
191         // merge (delete null-values)
192         this.customProperties.MergeStringKeys(propertiesToSet); // includes a Equals check (simplifying things)
193         this.customProperties.StripKeysWithNullValues();
194
195         // send (sync) these new values
196         Hashtable customProps = propertiesToSet.StripToStringKeys() as Hashtable;
197         if (this.actorID > 0 && !PhotonNetwork.offlineMode)
198         {
199             PhotonNetwork.networkingPeer.OpSetCustomPropertiesOfActor(this.actorID, customProps, true, 0);
200         }
201         NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnPhotonPlayerPropertiesChanged, this, propertiesToSet);
202     }
File name: Room.cs Copy
196     public void SetCustomProperties(Hashtable propertiesToSet)
197     {
198         if (propertiesToSet == null)
199         {
200             return;
201         }
202
203         // merge (delete null-values)
204         this.customProperties.MergeStringKeys(propertiesToSet); // includes a Equals check (simplifying things)
205         this.customProperties.StripKeysWithNullValues();
206
207
208         // send (sync) these new values
209         Hashtable customProps = propertiesToSet.StripToStringKeys() as Hashtable;
210         if (!PhotonNetwork.offlineMode)
211         {
212             PhotonNetwork.networkingPeer.OpSetCustomPropertiesOfRoom(customProps, true, 0);
213         }
214         NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnPhotonCustomRoomPropertiesChanged, propertiesToSet);
215     }
File name: RoomInfo.cs Copy
176     protected internal void CacheProperties(Hashtable propertiesToCache)
177     {
178         if (propertiesToCache == null || propertiesToCache.Count == 0 || this.customPropertiesField.Equals(propertiesToCache))
179         {
180             return;
181         }
182
183         // check of this game was removed from the list. in that case, we don't
184         // need to read any further properties
185         // list updates will remove this game from the game listing
186         if (propertiesToCache.ContainsKey(GameProperties.Removed))
187         {
188             this.removedFromList = (Boolean)propertiesToCache[GameProperties.Removed];
189             if (this.removedFromList)
190             {
191                 return;
192             }
193         }
194
195         // fetch the "well known" properties of the room, if available
196         if (propertiesToCache.ContainsKey(GameProperties.MaxPlayers))
197         {
198             this.maxPlayersField = (byte)propertiesToCache[GameProperties.MaxPlayers];
199         }
200
201         if (propertiesToCache.ContainsKey(GameProperties.IsOpen))
202         {
203             this.openField = (bool)propertiesToCache[GameProperties.IsOpen];
204         }
205
206         if (propertiesToCache.ContainsKey(GameProperties.IsVisible))
207         {
208             this.visibleField = (bool)propertiesToCache[GameProperties.IsVisible];
209         }
210
211         if (propertiesToCache.ContainsKey(GameProperties.PlayerCount))
212         {
213             this.playerCount = (int)((byte)propertiesToCache[GameProperties.PlayerCount]);
214         }
215
216         if (propertiesToCache.ContainsKey(GameProperties.CleanupCacheOnLeave))
217         {
218             this.autoCleanUpField = (bool)propertiesToCache[GameProperties.CleanupCacheOnLeave];
219         }
220
221         //if (propertiesToCache.ContainsKey(GameProperties.PropsListedInLobby))
222         //{
223         // // could be cached but isn't useful
224         //}
225
226         // merge the custom properties (from your application) to the cache (only string-typed keys will be kept)
227         this.customPropertiesField.MergeStringKeys(propertiesToCache);
228     }

Download file with original file name:Merge

Merge 114 lượt xem

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