DebugOut
How do I use Debug Out
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: LoadbalancingPeer.cs
Copy
48 public virtual bool OpJoinLobby(TypedLobby lobby)
49 {
50 if (this.DebugOut >= DebugLevel.INFO)
51 {
52 this.Listener.DebugReturn(DebugLevel.INFO, "OpJoinLobby()");
53 }
54
55 Dictionary
56 if (lobby != null && !lobby.IsDefault)
57 {
58 parameters = new Dictionary
59 parameters[(byte)ParameterCode.LobbyName] = lobby.Name;
60 parameters[(byte)ParameterCode.LobbyType] = (byte)lobby.Type;
61 }
62
63 return this.OpCustom(OperationCode.JoinLobby, parameters, true);
64 }
File name: LoadbalancingPeer.cs
Copy
71 public virtual bool OpLeaveLobby()
72 {
73 if (this.DebugOut >= DebugLevel.INFO)
74 {
75 this.Listener.DebugReturn(DebugLevel.INFO, "OpLeaveLobby()");
76 }
77
78 return this.OpCustom(OperationCode.LeaveLobby, null, true);
79 }
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
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
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: LoadbalancingPeer.cs
Copy
287 protected bool OpSetPropertiesOfActor(int actorNr, Hashtable actorProperties, bool broadcast, byte channelId)
288 {
289 if (this.DebugOut >= DebugLevel.INFO)
290 {
291 this.Listener.DebugReturn(DebugLevel.INFO, "OpSetPropertiesOfActor()");
292 }
293
294 if (actorNr <= 0 || actorProperties == null)
295 {
296 if (this.DebugOut >= DebugLevel.INFO)
297 {
298 this.Listener.DebugReturn(DebugLevel.INFO, "OpSetPropertiesOfActor not sent. ActorNr must be > 0 and actorProperties != null.");
299 }
300 return false;
301 }
302
303 Dictionary
304 opParameters.Add(ParameterCode.Properties, actorProperties);
305 opParameters.Add(ParameterCode.ActorNr, actorNr);
306 if (broadcast)
307 {
308 opParameters.Add(ParameterCode.Broadcast, broadcast);
309 }
310
311 return this.OpCustom((byte)OperationCode.SetProperties, opParameters, broadcast, channelId);
312 }
File name: LoadbalancingPeer.cs
Copy
326 public bool OpSetPropertiesOfRoom(Hashtable gameProperties, bool broadcast, byte channelId)
327 {
328 if (this.DebugOut >= DebugLevel.INFO)
329 {
330 this.Listener.DebugReturn(DebugLevel.INFO, "OpSetPropertiesOfRoom()");
331 }
332
333 Dictionary
334 opParameters.Add(ParameterCode.Properties, gameProperties);
335 if (broadcast)
336 {
337 opParameters.Add(ParameterCode.Broadcast, true);
338 }
339
340 return this.OpCustom((byte)OperationCode.SetProperties, opParameters, broadcast, channelId);
341 }
File name: LoadbalancingPeer.cs
Copy
358 public virtual bool OpAuthenticate(string appId, string appVersion, string userId, AuthenticationValues authValues, string regionCode)
359 {
360 if (this.DebugOut >= DebugLevel.INFO)
361 {
362 this.Listener.DebugReturn(DebugLevel.INFO, "OpAuthenticate()");
363 }
364
365 Dictionary
366 if (authValues != null && authValues.Secret != null)
367 {
368 opParameters[ParameterCode.Secret] = authValues.Secret;
369 return this.OpCustom(OperationCode.Authenticate, opParameters, true, (byte)0, false);
370 }
371
372 opParameters[ParameterCode.AppVersion] = appVersion;
373 opParameters[ParameterCode.ApplicationId] = appId;
374
375 if (!string.IsNullOrEmpty(regionCode))
376 {
377 opParameters[ParameterCode.Region] = regionCode;
378 }
379
380 if (!string.IsNullOrEmpty(userId))
381 {
382 opParameters[ParameterCode.UserId] = userId;
383 }
384
385
386 if (authValues != null && authValues.AuthType != CustomAuthenticationType.None)
387 {
388 if (!this.IsEncryptionAvailable)
389 {
390 this.Listener.DebugReturn(DebugLevel.ERROR, "OpAuthenticate() failed. When you want Custom Authentication encryption is mandatory.");
391 return false;
392 }
393
394 opParameters[ParameterCode.ClientAuthenticationType] = (byte)authValues.AuthType;
395 if (!string.IsNullOrEmpty(authValues.Secret))
396 {
397 opParameters[ParameterCode.Secret] = authValues.Secret;
398 }
399 //else
400 //{
401 if (!string.IsNullOrEmpty(authValues.AuthParameters))
402 {
403 opParameters[ParameterCode.ClientAuthenticationParams] = authValues.AuthParameters;
404 }
405 if (authValues.AuthPostData != null)
406 {
407 opParameters[ParameterCode.ClientAuthenticationData] = authValues.AuthPostData;
408 }
409 //}
410 }
411
412 bool sent = this.OpCustom(OperationCode.Authenticate, opParameters, true, (byte)0, this.IsEncryptionAvailable);
413 if (!sent)
414 {
415 this.Listener.DebugReturn(DebugLevel.ERROR, "Error calling OpAuthenticate! Did not work. Check log output, CustomAuthenticationValues and if you're connected.");
416 }
417 return sent;
418 }
File name: LoadbalancingPeer.cs
Copy
433 public virtual bool OpChangeGroups(byte[] groupsToRemove, byte[] groupsToAdd)
434 {
435 if (this.DebugOut >= DebugLevel.ALL)
436 {
437 this.Listener.DebugReturn(DebugLevel.ALL, "OpChangeGroups()");
438 }
439
440 Dictionary
441 if (groupsToRemove != null)
442 {
443 opParameters[(byte)LiteOpKey.Remove] = groupsToRemove;
444 }
445 if (groupsToAdd != null)
446 {
447 opParameters[(byte)LiteOpKey.Add] = groupsToAdd;
448 }
449
450 return this.OpCustom((byte)LiteOpCode.ChangeGroups, opParameters, true, 0);
451 }
File name: NetworkingPeer.cs
Copy
1631 public void OnEvent(EventData photonEvent)
1632 {
1633 if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
1634 Debug.Log(string.Format("OnEvent: {0}", photonEvent.ToString()));
1635
1636 int actorNr = -1;
1637 PhotonPlayer originatingPlayer = null;
1638
1639 if (photonEvent.Parameters.ContainsKey(ParameterCode.ActorNr))
1640 {
1641 actorNr = (int)photonEvent[ParameterCode.ActorNr];
1642 if (this.mActors.ContainsKey(actorNr))
1643 {
1644 originatingPlayer = (PhotonPlayer)this.mActors[actorNr];
1645 }
1646 //else
1647 //{
1648 // // the actor sending this event is not in actorlist. this is usually no problem
1649 // if (photonEvent.Code != (byte)LiteOpCode.Join)
1650 // {
1651 // Debug.LogWarning("Received event, but we do not have this actor: " + actorNr);
1652 // }
1653 //}
1654 }
1655
1656 switch (photonEvent.Code)
1657 {
1658 case PunEvent.OwnershipRequest:
1659 {
1660 int[] requestValues = (int[]) photonEvent.Parameters[ParameterCode.CustomEventContent];
1661 int requestedViewId = requestValues[0];
1662 int currentOwner = requestValues[1];
1663 Debug.Log("Ev OwnershipRequest: " + photonEvent.Parameters.ToStringFull() + " ViewID: " + requestedViewId + " from: " + currentOwner + " Time: " + Environment.TickCount%1000);
1664
1665 PhotonView requestedView = PhotonView.Find(requestedViewId);
1666 if (requestedView == null)
1667 {
1668 Debug.LogWarning("Can't find PhotonView of incoming OwnershipRequest. ViewId not found: " + requestedViewId);
1669 break;
1670 }
1671
1672 Debug.Log("Ev OwnershipRequest PhotonView.ownershipTransfer: " + requestedView.ownershipTransfer + " .ownerId: " + requestedView.ownerId + " isOwnerActive: " + requestedView.isOwnerActive + ". This client's player: " + PhotonNetwork.player.ToStringFull());
1673
1674 switch (requestedView.ownershipTransfer)
1675 {
1676 case OwnershipOption.Fixed:
1677 Debug.LogWarning("Ownership mode == fixed. Ignoring request.");
1678 break;
1679 case OwnershipOption.Takeover:
1680 if (currentOwner == requestedView.ownerId)
1681 {
1682 // a takeover is successful automatically, if taken from current owner
1683 requestedView.ownerId = actorNr;
1684 }
1685 break;
1686 case OwnershipOption.Request:
1687 if (currentOwner == PhotonNetwork.player.ID || PhotonNetwork.player.isMasterClient)
1688 {
1689 if ((requestedView.ownerId == PhotonNetwork.player.ID) || (PhotonNetwork.player.isMasterClient && !requestedView.isOwnerActive))
1690 {
1691 SendMonoMessage(PhotonNetworkingMessage.OnOwnershipRequest, new object[] {requestedView, originatingPlayer});
1692 }
1693 }
1694 break;
1695 default:
1696 break;
1697 }
1698 }
1699 break;
1700
1701 case PunEvent.OwnershipTransfer:
1702 {
1703 int[] transferViewToUserID = (int[]) photonEvent.Parameters[ParameterCode.CustomEventContent];
1704 Debug.Log("Ev OwnershipTransfer. ViewID " + transferViewToUserID[0] + " to: " + transferViewToUserID[1] + " Time: " + Environment.TickCount%1000);
1705
1706 int requestedViewId = transferViewToUserID[0];
1707 int newOwnerId = transferViewToUserID[1];
1708
1709 PhotonView pv = PhotonView.Find(requestedViewId);
1710 pv.ownerId = newOwnerId;
1711
1712 break;
1713 }
1714 case EventCode.GameList:
1715 {
1716 this.mGameList = new Dictionary
1717 Hashtable games = (Hashtable)photonEvent[ParameterCode.GameList];
1718 foreach (DictionaryEntry game in games)
1719 {
1720 string gameName = (string)game.Key;
1721 this.mGameList[gameName] = new RoomInfo(gameName, (Hashtable)game.Value);
1722 }
1723 mGameListCopy = new RoomInfo[mGameList.Count];
1724 mGameList.Values.CopyTo(mGameListCopy, 0);
1725 SendMonoMessage(PhotonNetworkingMessage.OnReceivedRoomListUpdate);
1726 break;
1727 }
1728
1729 case EventCode.GameListUpdate:
1730 {
1731 Hashtable games = (Hashtable)photonEvent[ParameterCode.GameList];
1732 foreach (DictionaryEntry room in games)
1733 {
1734 string gameName = (string)room.Key;
1735 RoomInfo game = new RoomInfo(gameName, (Hashtable)room.Value);
1736 if (game.removedFromList)
1737 {
1738 this.mGameList.Remove(gameName);
1739 }
1740 else
1741 {
1742 this.mGameList[gameName] = game;
1743 }
1744 }
1745 this.mGameListCopy = new RoomInfo[this.mGameList.Count];
1746 this.mGameList.Values.CopyTo(this.mGameListCopy, 0);
1747 SendMonoMessage(PhotonNetworkingMessage.OnReceivedRoomListUpdate);
1748 break;
1749 }
1750
1751 case EventCode.QueueState:
1752 // not used anymore
1753 break;
1754
1755 case EventCode.AppStats:
1756 // Debug.LogInfo("Received stats!");
1757 this.mPlayersInRoomsCount = (int)photonEvent[ParameterCode.PeerCount];
1758 this.mPlayersOnMasterCount = (int)photonEvent[ParameterCode.MasterPeerCount];
1759 this.mGameCount = (int)photonEvent[ParameterCode.GameCount];
1760 break;
1761
1762 case EventCode.Join:
1763 // actorNr is fetched out of event above
1764 Hashtable actorProperties = (Hashtable)photonEvent[ParameterCode.PlayerProperties];
1765 if (originatingPlayer == null)
1766 {
1767 bool isLocal = this.mLocalActor.ID == actorNr;
1768 this.AddNewPlayer(actorNr, new PhotonPlayer(isLocal, actorNr, actorProperties));
1769 this.ResetPhotonViewsOnSerialize(); // This sets the correct OnSerializeState for Reliable OnSerialize
1770 }
1771
1772 if (actorNr == this.mLocalActor.ID)
1773 {
1774 // in this player's 'own' join event, we get a complete list of players in the room, so check if we know all players
1775 int[] actorsInRoom = (int[])photonEvent[ParameterCode.ActorList];
1776 foreach (int actorNrToCheck in actorsInRoom)
1777 {
1778 if (this.mLocalActor.ID != actorNrToCheck && !this.mActors.ContainsKey(actorNrToCheck))
1779 {
1780 this.AddNewPlayer(actorNrToCheck, new PhotonPlayer(false, actorNrToCheck, string.Empty));
1781 }
1782 }
1783
1784 // joinWithCreateOnDemand can turn an OpJoin into creating the room. Then actorNumber is 1 and callback: OnCreatedRoom()
1785 if (this.mLastJoinType == JoinType.JoinOrCreateOnDemand && this.mLocalActor.ID == 1)
1786 {
1787 SendMonoMessage(PhotonNetworkingMessage.OnCreatedRoom);
1788 }
1789 SendMonoMessage(PhotonNetworkingMessage.OnJoinedRoom); //Always send OnJoinedRoom
1790
1791 }
1792 else
1793 {
1794 SendMonoMessage(PhotonNetworkingMessage.OnPhotonPlayerConnected, this.mActors[actorNr]);
1795 }
1796 break;
1797
1798 case EventCode.Leave:
1799 this.HandleEventLeave(actorNr);
1800 break;
1801
1802 case EventCode.PropertiesChanged:
1803 int targetActorNr = (int)photonEvent[ParameterCode.TargetActorNr];
1804 Hashtable gameProperties = null;
1805 Hashtable actorProps = null;
1806 if (targetActorNr == 0)
1807 {
1808 gameProperties = (Hashtable)photonEvent[ParameterCode.Properties];
1809 }
1810 else
1811 {
1812 actorProps = (Hashtable)photonEvent[ParameterCode.Properties];
1813 }
1814
1815 this.ReadoutProperties(gameProperties, actorProps, targetActorNr);
1816 break;
1817
1818 case PunEvent.RPC:
1819 //ts: each event now contains a single RPC. execute this
1820 // Debug.Log("Ev RPC from: " + originatingPlayer);
1821 this.ExecuteRPC(photonEvent[ParameterCode.Data] as Hashtable, originatingPlayer);
1822 break;
1823
1824 case PunEvent.SendSerialize:
1825 case PunEvent.SendSerializeReliable:
1826 Hashtable serializeData = (Hashtable)photonEvent[ParameterCode.Data];
1827 //Debug.Log(serializeData.ToStringFull());
1828
1829 int remoteUpdateServerTimestamp = (int)serializeData[(byte)0];
1830 short remoteLevelPrefix = -1;
1831 short initialDataIndex = 1;
1832 if (serializeData.ContainsKey((byte)1))
1833 {
1834 remoteLevelPrefix = (short)serializeData[(byte)1];
1835 initialDataIndex = 2;
1836 }
1837
1838 for (short s = initialDataIndex; s < serializeData.Count; s++)
1839 {
1840 this.OnSerializeRead(serializeData[s] as Hashtable, originatingPlayer, remoteUpdateServerTimestamp, remoteLevelPrefix);
1841 }
1842 break;
1843
1844 case PunEvent.Instantiation:
1845 this.DoInstantiate((Hashtable)photonEvent[ParameterCode.Data], originatingPlayer, null);
1846 break;
1847
1848 case PunEvent.CloseConnection:
1849 // MasterClient "requests" a disconnection from us
1850 if (originatingPlayer == null || !originatingPlayer.isMasterClient)
1851 {
1852 Debug.LogError("Error: Someone else(" + originatingPlayer + ") then the masterserver requests a disconnect!");
1853 }
1854 else
1855 {
1856 PhotonNetwork.LeaveRoom();
1857 }
1858
1859 break;
1860
1861 case PunEvent.DestroyPlayer:
1862 Hashtable evData = (Hashtable)photonEvent[ParameterCode.Data];
1863 int targetPlayerId = (int)evData[(byte)0];
1864 if (targetPlayerId >= 0)
1865 {
1866 this.DestroyPlayerObjects(targetPlayerId, true);
1867 }
1868 else
1869 {
1870 if (this.DebugOut >= DebugLevel.INFO) Debug.Log("Ev DestroyAll! By PlayerId: " + actorNr);
1871 this.DestroyAll(true);
1872 }
1873 break;
1874
1875 case PunEvent.Destroy:
1876 evData = (Hashtable)photonEvent[ParameterCode.Data];
1877 int instantiationId = (int)evData[(byte)0];
1878 // Debug.Log("Ev Destroy for viewId: " + instantiationId + " sent by owner: " + (instantiationId / PhotonNetwork.MAX_VIEW_IDS == actorNr) + " this client is owner: " + (instantiationId / PhotonNetwork.MAX_VIEW_IDS == this.mLocalActor.ID));
1879
1880
1881 PhotonView pvToDestroy = null;
1882 if (this.photonViewList.TryGetValue(instantiationId, out pvToDestroy))
1883 {
1884 this.RemoveInstantiatedGO(pvToDestroy.gameObject, true);
1885 }
1886 else
1887 {
1888 if (this.DebugOut >= DebugLevel.ERROR) Debug.LogError("Ev Destroy Failed. Could not find PhotonView with instantiationId " + instantiationId + ". Sent by actorNr: " + actorNr);
1889 }
1890
1891 break;
1892
1893 case PunEvent.AssignMaster:
1894 evData = (Hashtable)photonEvent[ParameterCode.Data];
1895 int newMaster = (int)evData[(byte)1];
1896 this.SetMasterClient(newMaster, false);
1897 break;
1898
1899 default:
1900 if (photonEvent.Code < 200 && PhotonNetwork.OnEventCall != null)
1901 {
1902 object content = photonEvent[ParameterCode.Data];
1903 PhotonNetwork.OnEventCall(photonEvent.Code, content, actorNr);
1904 }
1905 else
1906 {
1907 // actorNr might be null. it is fetched out of event on top of method
1908 // Hashtable eventContent = (Hashtable) photonEvent[ParameterCode.Data];
1909 // this.mListener.customEventAction(actorNr, eventCode, eventContent);
1910 Debug.LogError("Error. Unhandled event: " + photonEvent);
1911 }
1912 break;
1913 }
1914
1915 this.externalListener.OnEvent(photonEvent);
1916 }
File name: PhotonNetwork.cs
Copy
1025 /// Connect(serverAddress, 1036 public static void SwitchToProtocol(ConnectionProtocol cp)
1037 {
1038 if (networkingPeer.UsedProtocol == cp)
1039 {
1040 return;
1041 }
1042 try
1043 {
1044 networkingPeer.Disconnect();
1045 networkingPeer.StopThread();
1046 }
1047 catch
1048 {
1049
1050 }
1051
1052 // set up a new NetworkingPeer
1053 NetworkingPeer newPeer = new NetworkingPeer(photonMono, String.Empty, cp);
1054 newPeer.mAppVersion = networkingPeer.mAppVersion;
1055 newPeer.CustomAuthenticationValues = networkingPeer.CustomAuthenticationValues;
1056 newPeer.PlayerName= networkingPeer.PlayerName;
1057 newPeer.mLocalActor = networkingPeer.mLocalActor;
1058 newPeer.DebugOut = networkingPeer.DebugOut;
1059 newPeer.CrcEnabled = networkingPeer.CrcEnabled;
1060 newPeer.lobby = networkingPeer.lobby;
1061 newPeer.LimitOfUnreliableCommands = networkingPeer.LimitOfUnreliableCommands;
1062 newPeer.SentCountAllowance = networkingPeer.SentCountAllowance;
1063 newPeer.TrafficStatsEnabled = networkingPeer.TrafficStatsEnabled;
1064
1065 networkingPeer = newPeer;
1066 Debug.LogWarning("Protocol switched to: " + cp + ".");
1067 }
DebugOut 92 lượt xem
Gõ tìm kiếm nhanh...