Matching
How do I use Matching
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
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
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: NetworkingPeer.cs
Copy
968 public override bool OpJoinRandomRoom(Hashtable expectedCustomRoomProperties, byte expectedMaxPlayers, Hashtable playerProperties, MatchmakingMode matchingType, TypedLobby typedLobby, string sqlLobbyFilter)
969 {
970 this.mRoomToGetInto = new Room(null, null);
971 this.mRoomToEnterLobby = null; // join random never stores the lobby. the following join will not affect the room lobby
972 // if typedLobby is null, the server will automatically use the active lobby or default, which is what we want anyways
973
974 this.mLastJoinType = JoinType.JoinRandomGame;
975 return base.OpJoinRandomRoom(expectedCustomRoomProperties, expectedMaxPlayers, playerProperties, matchingType, typedLobby, sqlLobbyFilter);
976 }
File name: PhotonNetwork.cs
Copy
1687 /// This method looks up a room in the specified lobby or the currently active lobby (if none specified)
1701 public static bool JoinRandomRoom(Hashtable expectedCustomRoomProperties, byte expectedMaxPlayers, MatchmakingMode matchingType, TypedLobby typedLobby, string sqlLobbyFilter)
1702 {
1703 if (offlineMode)
1704 {
1705 if (offlineModeRoom != null)
1706 {
1707 Debug.LogError("JoinRandomRoom failed. In offline mode you still have to leave a room to enter another.");
1708 return false;
1709 }
1710
1711 offlineModeRoom = new Room("offline room", null);
1712 NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnJoinedRoom);
1713 return true;
1714 }
1715
1716
1717 if (networkingPeer.server != ServerConnection.MasterServer || !connectedAndReady)
1718 {
1719 Debug.LogError("JoinRandomRoom failed. Client is not on Master Server or not yet ready to call operations. Wait for callback: OnJoinedLobby or OnConnectedToMaster.");
1720 return false;
1721 }
1722
1723 return networkingPeer.OpJoinRandomRoom(expectedCustomRoomProperties, expectedMaxPlayers, null, matchingType, typedLobby, sqlLobbyFilter);
1724 }
File name: ImportTiled2Unity.Material.cs
Copy
19 public Material FixMaterialForMeshRenderer(string objName, Renderer renderer)
20 {
21 string xmlPath = ImportUtils.GetXmlPath(objName);
22
23 XDocument xml = XDocument.Load(xmlPath);
24
25 // The mesh to match
26 string meshName = renderer.name;
27
28 // The mesh name may be decorated by Unity
29 string pattern = @"_MeshPart[\d]$";
30 Regex regex = new Regex(pattern);
31 meshName = regex.Replace(meshName, "");
32
33 var assignMaterials = xml.Root.Elements("AssignMaterial");
34
35 // Find an assignment that matches the mesh renderer
36 XElement match = assignMaterials.FirstOrDefault(el => el.Attribute("mesh").Value == meshName);
37
38 if (match == null)
39 {
40 // The names of our meshes in the AssignMaterials elements may be wrong
41 // This happened before when Unity replaced whitespace with underscore in our named meshes
42 // That case is handled now, but there may be others
43 StringBuilder builder = new StringBuilder();
44 builder.AppendFormat("Could not find mesh named '{0}' for material matching\n", renderer.name);
45 string choices = String.Join("\n ", assignMaterials.Select(m => m.Attribute("mesh").Value).ToArray());
46 builder.AppendFormat("Choices are:\n {0}", choices);
47
48 Debug.LogError(builder.ToString());
49 return null;
50 }
51
52 string materialName = match.Attribute("material").Value;
53 string materialPath = ImportUtils.GetMaterialPath(materialName);
54
55 // Assign the material
56 renderer.sharedMaterial = AssetDatabase.LoadAssetAtPath(materialPath, typeof(Material)) as Material;
57
58 // Set the sorting layer for the mesh
59 string sortingLayer = match.Attribute("sortingLayerName").Value;
60 if (!String.IsNullOrEmpty(sortingLayer) && !SortingLayerExposedEditor.GetSortingLayerNames().Contains(sortingLayer))
61 {
62 Debug.LogError(string.Format("Sorting Layer \"{0}\" does not exist. Check your Project Settings -> Tags and Layers", sortingLayer));
63 renderer.sortingLayerName = "Default";
64 }
65 else
66 {
67 renderer.sortingLayerName = sortingLayer;
68 }
69
70 // Set the sorting order
71 renderer.sortingOrder = ImportUtils.GetAttributeAsInt(match, "sortingOrder");
72
73 // Do we have an alpha color key?
74 string htmlColor = ImportUtils.GetAttributeAsString(match, "alphaColorKey", "");
75 if (!String.IsNullOrEmpty(htmlColor))
76 {
77 // Take for granted color is in the form '#RRGGBB'
78 byte r = byte.Parse(htmlColor.Substring(1, 2), System.Globalization.NumberStyles.HexNumber);
79 byte g = byte.Parse(htmlColor.Substring(3, 2), System.Globalization.NumberStyles.HexNumber);
80 byte b = byte.Parse(htmlColor.Substring(5, 2), System.Globalization.NumberStyles.HexNumber);
81 Color color = new Color32(r, g, b, 255);
82 renderer.sharedMaterial.SetColor("_AlphaColorKey", color);
83 }
84
85 return renderer.sharedMaterial;
86 }
Matching 123 lượt xem
Gõ tìm kiếm nhanh...