Continue
How do I use Continue
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
57 | GUILayout.Label("To continue, configure your Chat AppId.\nIt's listed in the Chat Dashboard (online).\nStop play-mode and edit:\nScripts/ChatGUI in the Hierarchy."); | 1 |
109 | continue; | 2 |
173 | continue; | 3 |
985 | continue; | 4 |
745 | continue; | 5 |
1182 | continue; | 6 |
2081 | continue; | 7 |
2544 | continue; | 8 |
3047 | continue; | 9 |
3185 | continue; // Only on actives | 10 |
File name: NamePickGui.cs
Copy
38 public void OnGUI()
39 {
40 // Enter-Key handling:
41 if (Event.current.type == EventType.KeyDown && (Event.current.keyCode == KeyCode.KeypadEnter || Event.current.keyCode == KeyCode.Return))
42 {
43 if (!string.IsNullOrEmpty(this.InputLine))
44 {
45 this.StartChat();
46 return;
47 }
48 }
49
50
51 GUI.skin.label.wordWrap = true;
52 GUILayout.BeginArea(guiCenteredRect);
53
54
55 if (this.chatComponent != null && string.IsNullOrEmpty(this.chatComponent.ChatAppId))
56 {
57 GUILayout.Label("To continue, configure your Chat AppId.\nIt's listed in the Chat Dashboard (online).\nStop play-mode and edit:\nScripts/ChatGUI in the Hierarchy.");
58 if (GUILayout.Button("Open Chat Dashboard"))
59 {
60 Application.OpenURL("https://www.exitgames.com/en/Chat/Dashboard");
61 }
62 GUILayout.EndArea();
63 return;
64 }
65
66 GUILayout.Label(this.helpText);
67
68 GUILayout.BeginHorizontal();
69 GUI.SetNextControlName("NameInput");
70 this.InputLine = GUILayout.TextField(this.InputLine);
71 if (GUILayout.Button("Connect", GUILayout.ExpandWidth(false)))
72 {
73 this.StartChat();
74 }
75 GUILayout.EndHorizontal();
76
77 GUILayout.EndArea();
78
79
80 GUI.FocusControl("NameInput");
81 }
File name: PunStartup.cs
Copy
80 public static void SetPunDemoBuildSettings()
81 {
82 // find path of pun guide
83 string[] tempPaths = Directory.GetDirectories(Application.dataPath + "/Photon Unity Networking", "Demos", SearchOption.AllDirectories);
84 if (tempPaths == null || tempPaths.Length != 1)
85 {
86 return;
87 }
88
89 // find scenes of guide
90 string guidePath = tempPaths[0];
91 tempPaths = Directory.GetFiles(guidePath, "*.unity", SearchOption.AllDirectories);
92
93 if (tempPaths == null || tempPaths.Length == 0)
94 {
95 return;
96 }
97
98 // add found guide scenes to build settings
99 List
100 for (int i = 0; i < tempPaths.Length; i++)
101 {
102 //Debug.Log(tempPaths[i]);
103 string path = tempPaths[i].Substring(Application.dataPath.Length - "Assets".Length);
104 path = path.Replace('\\', '/');
105 //Debug.Log(path);
106
107 if (path.Contains("PUNGuide_M2H"))
108 {
109 continue;
110 }
111
112 if (path.Contains("Hub"))
113 {
114 sceneAr.Insert(0, new EditorBuildSettingsScene(path, true));
115 continue;
116 }
117
118 sceneAr.Add(new EditorBuildSettingsScene(path, true));
119 }
120
121 EditorBuildSettings.scenes = sceneAr.ToArray();
122 EditorApplication.OpenScene(sceneAr[0].path);
123 }
File name: PhotonConverter.cs
Copy
160 static void ConvertScripts(List161 {
162 bool ignoreWarningIsLogged = false;
163
164 foreach (string script in scriptPathList)
165 {
166 if (script.Contains("PhotonNetwork")) //Don't convert this file (and others)
167 {
168 if (!ignoreWarningIsLogged)
169 {
170 ignoreWarningIsLogged = true;
171 Debug.LogWarning("Conversion to PUN ignores all files with \"PhotonNetwork\" in their file-path.\nCheck: " + script);
172 }
173 continue;
174 }
175 if (script.Contains("Image Effects"))
176 {
177 continue;
178 }
179
180 ConvertToPhotonAPI(script);
181 }
182
183 foreach (string script in scriptPathList)
184 {
185 AssetDatabase.ImportAsset(script, ImportAssetOptions.ForceUpdate);
186 }
187 }
File name: PhotonEditor.cs
Copy
975 public static System.Type[] GetAllSubTypesInScripts(System.Type aBaseClass)
976 {
977 var result = new System.Collections.Generic.List
978 System.Reflection.Assembly[] AS = System.AppDomain.CurrentDomain.GetAssemblies();
979 foreach (var A in AS)
980 {
981 // this skips all but the Unity-scripted assemblies for RPC-list creation. You could remove this to search all assemblies in project
982 if (!A.FullName.StartsWith("Assembly-"))
983 {
984 // Debug.Log("Skipping Assembly: " + A);
985 continue;
986 }
987
988 //Debug.Log("Assembly: " + A.FullName);
989 System.Type[] types = A.GetTypes();
990 foreach (var T in types)
991 {
992 if (T.IsSubclassOf(aBaseClass))
993 result.Add(T);
994 }
995 }
996 return result.ToArray();
997 }
File name: NetworkingPeer.cs
Copy
732 private static int ReturnLowestPlayerId(PhotonPlayer[] players, int playerIdToIgnore)
733 {
734 if (players == null || players.Length == 0)
735 {
736 return -1;
737 }
738
739 int lowestActorNumber = Int32.MaxValue;
740 for (int i = 0; i < players.Length; i++)
741 {
742 PhotonPlayer photonPlayer = players[i];
743 if (photonPlayer.ID == playerIdToIgnore)
744 {
745 continue;
746 }
747
748 if (photonPlayer.ID < lowestActorNumber)
749 {
750 lowestActorNumber = photonPlayer.ID;
751 }
752 }
753
754 return lowestActorNumber;
755 }
File name: NetworkingPeer.cs
Copy
1016 public void OnOperationResponse(OperationResponse operationResponse)
1017 {
1018 if (PhotonNetwork.networkingPeer.State == global::PeerState.Disconnecting)
1019 {
1020 if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
1021 {
1022 Debug.Log("OperationResponse ignored while disconnecting. Code: " + operationResponse.OperationCode);
1023 }
1024 return;
1025 }
1026
1027 // extra logging for error debugging (helping developers with a bit of automated analysis)
1028 if (operationResponse.ReturnCode == 0)
1029 {
1030 if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
1031 Debug.Log(operationResponse.ToString());
1032 }
1033 else
1034 {
1035 if (operationResponse.ReturnCode == ErrorCode.OperationNotAllowedInCurrentState)
1036 {
1037 Debug.LogError("Operation " + operationResponse.OperationCode + " could not be executed (yet). Wait for state JoinedLobby or ConnectedToMaster and their callbacks before calling operations. WebRPCs need a server-side configuration. Enum OperationCode helps identify the operation.");
1038 }
1039 else if (operationResponse.ReturnCode == ErrorCode.WebHookCallFailed)
1040 {
1041 Debug.LogError("Operation " + operationResponse.OperationCode + " failed in a server-side plugin. Check the configuration in the Dashboard. Message from server-plugin: " + operationResponse.DebugMessage);
1042 }
1043 else if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
1044 {
1045 Debug.LogError("Operation failed: " + operationResponse.ToStringFull() + " Server: " + this.server);
1046 }
1047 }
1048
1049 // use the "secret" or "token" whenever we get it. doesn't really matter if it's in AuthResponse.
1050 if (operationResponse.Parameters.ContainsKey(ParameterCode.Secret))
1051 {
1052 if (this.CustomAuthenticationValues == null)
1053 {
1054 this.CustomAuthenticationValues = new AuthenticationValues();
1055 // this.DebugReturn(DebugLevel.ERROR, "Server returned secret. Created CustomAuthenticationValues.");
1056 }
1057
1058 this.CustomAuthenticationValues.Secret = operationResponse[ParameterCode.Secret] as string;
1059 }
1060
1061 switch (operationResponse.OperationCode)
1062 {
1063 case OperationCode.Authenticate:
1064 {
1065 // PeerState oldState = this.State;
1066
1067 if (operationResponse.ReturnCode != 0)
1068 {
1069 if (operationResponse.ReturnCode == ErrorCode.InvalidOperationCode)
1070 {
1071 Debug.LogError(string.Format("If you host Photon yourself, make sure to start the 'Instance LoadBalancing' "+ this.ServerAddress));
1072 }
1073 else if (operationResponse.ReturnCode == ErrorCode.InvalidAuthentication)
1074 {
1075 Debug.LogError(string.Format("The appId this client sent is unknown on the server (Cloud). Check settings. If using the Cloud, check account."));
1076 SendMonoMessage(PhotonNetworkingMessage.OnFailedToConnectToPhoton, DisconnectCause.InvalidAuthentication);
1077 }
1078 else if (operationResponse.ReturnCode == ErrorCode.CustomAuthenticationFailed)
1079 {
1080 Debug.LogError(string.Format("Custom Authentication failed (either due to user-input or configuration or AuthParameter string format). Calling: OnCustomAuthenticationFailed()"));
1081 SendMonoMessage(PhotonNetworkingMessage.OnCustomAuthenticationFailed, operationResponse.DebugMessage);
1082 }
1083 else
1084 {
1085 Debug.LogError(string.Format("Authentication failed: '{0}' Code: {1}", operationResponse.DebugMessage, operationResponse.ReturnCode));
1086 }
1087
1088 this.State = global::PeerState.Disconnecting;
1089 this.Disconnect();
1090
1091 if (operationResponse.ReturnCode == ErrorCode.MaxCcuReached)
1092 {
1093 if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
1094 Debug.LogWarning(string.Format("Currently, the limit of users is reached for this title. Try again later. Disconnecting"));
1095 SendMonoMessage(PhotonNetworkingMessage.OnPhotonMaxCccuReached);
1096 SendMonoMessage(PhotonNetworkingMessage.OnConnectionFail, DisconnectCause.MaxCcuReached);
1097 }
1098 else if (operationResponse.ReturnCode == ErrorCode.InvalidRegion)
1099 {
1100 if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
1101 Debug.LogError(string.Format("The used master server address is not available with the subscription currently used. Got to Photon Cloud Dashboard or change URL. Disconnecting."));
1102 SendMonoMessage(PhotonNetworkingMessage.OnConnectionFail, DisconnectCause.InvalidRegion);
1103 }
1104 else if (operationResponse.ReturnCode == ErrorCode.AuthenticationTicketExpired)
1105 {
1106 if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
1107 Debug.LogError(string.Format("The authentication ticket expired. You need to connect (and authenticate) again. Disconnecting."));
1108 SendMonoMessage(PhotonNetworkingMessage.OnConnectionFail, DisconnectCause.AuthenticationTicketExpired);
1109 }
1110 break;
1111 }
1112 else
1113 {
1114 if (this.server == ServerConnection.NameServer)
1115 {
1116 // on the NameServer, authenticate returns the MasterServer address for a region and we hop off to there
1117 this.MasterServerAddress = operationResponse[ParameterCode.Address] as string;
1118 this.DisconnectToReconnect();
1119 }
1120 else if (this.server == ServerConnection.MasterServer)
1121 {
1122 if (PhotonNetwork.autoJoinLobby)
1123 {
1124 this.State = global::PeerState.Authenticated;
1125 this.OpJoinLobby(this.lobby);
1126 }
1127 else
1128 {
1129 this.State = global::PeerState.ConnectedToMaster;
1130 NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnConnectedToMaster);
1131 }
1132 }
1133 else if (this.server == ServerConnection.GameServer)
1134 {
1135 this.State = global::PeerState.Joining;
1136
1137 if (this.mLastJoinType == JoinType.JoinGame || this.mLastJoinType == JoinType.JoinRandomGame || this.mLastJoinType == JoinType.JoinOrCreateOnDemand)
1138 {
1139 // if we just "join" the game, do so. if we wanted to "create the room on demand", we have to send this to the game server as well.
1140 this.OpJoinRoom(this.mRoomToGetInto.name, this.mRoomOptionsForCreate, this.mRoomToEnterLobby, this.mLastJoinType == JoinType.JoinOrCreateOnDemand);
1141 }
1142 else if (this.mLastJoinType == JoinType.CreateGame)
1143 {
1144 // on the game server, we have to apply the room properties that were chosen for creation of the room, so we use this.mRoomToGetInto
1145 this.OpCreateGame(this.mRoomToGetInto.name, this.mRoomOptionsForCreate, this.mRoomToEnterLobby);
1146 }
1147
1148 break;
1149 }
1150 }
1151 break;
1152 }
1153
1154 case OperationCode.GetRegions:
1155 // Debug.Log("GetRegions returned: " + operationResponse.ToStringFull());
1156
1157 if (operationResponse.ReturnCode == ErrorCode.InvalidAuthentication)
1158 {
1159 Debug.LogError(string.Format("The appId this client sent is unknown on the server (Cloud). Check settings. If using the Cloud, check account."));
1160 SendMonoMessage(PhotonNetworkingMessage.OnFailedToConnectToPhoton, DisconnectCause.InvalidAuthentication);
1161
1162 this.State = global::PeerState.Disconnecting;
1163 this.Disconnect();
1164 return;
1165 }
1166
1167 string[] regions = operationResponse[ParameterCode.Region] as string[];
1168 string[] servers = operationResponse[ParameterCode.Address] as string[];
1169
1170 if (regions == null || servers == null || regions.Length != servers.Length)
1171 {
1172 Debug.LogError("The region arrays from Name Server are not ok. Must be non-null and same length.");
1173 break;
1174 }
1175
1176 this.AvailableRegions = new List
1177 for (int i = 0; i < regions.Length; i++)
1178 {
1179 string regionCodeString = regions[i];
1180 if (string.IsNullOrEmpty(regionCodeString))
1181 {
1182 continue;
1183 }
1184 regionCodeString = regionCodeString.ToLower();
1185
1186 CloudRegionCode code = Region.Parse(regionCodeString);
1187 this.AvailableRegions.Add(new Region() { Code = code, HostAndPort = servers[i] });
1188 }
1189
1190 // PUN assumes you fetch the name-server's list of regions to ping them
1191 if (PhotonNetwork.PhotonServerSettings.HostType == ServerSettings.HostingOption.BestRegion)
1192 {
1193 PhotonHandler.PingAvailableRegionsAndConnectToBest();
1194 }
1195 break;
1196
1197 case OperationCode.CreateGame:
1198 {
1199 if (this.server == ServerConnection.GameServer)
1200 {
1201 this.GameEnteredOnGameServer(operationResponse);
1202 }
1203 else
1204 {
1205 if (operationResponse.ReturnCode != 0)
1206 {
1207 if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
1208 Debug.LogWarning(string.Format("CreateRoom failed, client stays on masterserver: {0}.", operationResponse.ToStringFull()));
1209
1210 SendMonoMessage(PhotonNetworkingMessage.OnPhotonCreateRoomFailed);
1211 break;
1212 }
1213
1214 string gameID = (string) operationResponse[ParameterCode.RoomName];
1215 if (!string.IsNullOrEmpty(gameID))
1216 {
1217 // is only sent by the server's response, if it has not been
1218 // sent with the client's request before!
1219 this.mRoomToGetInto.name = gameID;
1220 }
1221
1222 this.mGameserver = (string)operationResponse[ParameterCode.Address];
1223 this.DisconnectToReconnect();
1224 }
1225
1226 break;
1227 }
1228
1229 case OperationCode.JoinGame:
1230 {
1231 if (this.server != ServerConnection.GameServer)
1232 {
1233 if (operationResponse.ReturnCode != 0)
1234 {
1235 if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
1236 Debug.Log(string.Format("JoinRoom failed (room maybe closed by now). Client stays on masterserver: {0}. State: {1}", operationResponse.ToStringFull(), this.State));
1237
1238 SendMonoMessage(PhotonNetworkingMessage.OnPhotonJoinRoomFailed);
1239 break;
1240 }
1241
1242 this.mGameserver = (string)operationResponse[ParameterCode.Address];
1243 this.DisconnectToReconnect();
1244 }
1245 else
1246 {
1247 this.GameEnteredOnGameServer(operationResponse);
1248 }
1249
1250 break;
1251 }
1252
1253 case OperationCode.JoinRandomGame:
1254 {
1255 // happens only on master. on gameserver, this is a regular join (we don't need to find a random game again)
1256 // the operation OpJoinRandom either fails (with returncode 8) or returns game-to-join information
1257 if (operationResponse.ReturnCode != 0)
1258 {
1259 if (operationResponse.ReturnCode == ErrorCode.NoRandomMatchFound)
1260 {
1261 if (PhotonNetwork.logLevel >= PhotonLogLevel.Full)
1262 Debug.Log("JoinRandom failed: No open game. Calling: OnPhotonRandomJoinFailed() and staying on master server.");
1263 }
1264 else if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
1265 {
1266 Debug.LogWarning(string.Format("JoinRandom failed: {0}.", operationResponse.ToStringFull()));
1267 }
1268
1269 SendMonoMessage(PhotonNetworkingMessage.OnPhotonRandomJoinFailed, operationResponse.ReturnCode, operationResponse.DebugMessage);
1270 break;
1271 }
1272
1273 string roomName = (string)operationResponse[ParameterCode.RoomName];
1274 this.mRoomToGetInto.name = roomName;
1275 this.mGameserver = (string)operationResponse[ParameterCode.Address];
1276 this.DisconnectToReconnect();
1277 break;
1278 }
1279
1280 case OperationCode.JoinLobby:
1281 this.State = global::PeerState.JoinedLobby;
1282 this.insideLobby = true;
1283 SendMonoMessage(PhotonNetworkingMessage.OnJoinedLobby);
1284
1285 // this.mListener.joinLobbyReturn();
1286 break;
1287 case OperationCode.LeaveLobby:
1288 this.State = global::PeerState.Authenticated;
1289 this.LeftLobbyCleanup(); // will set insideLobby = false
1290 break;
1291
1292 case OperationCode.Leave:
1293 this.DisconnectToReconnect();
1294 break;
1295
1296 case OperationCode.SetProperties:
1297 // this.mListener.setPropertiesReturn(returnCode, debugMsg);
1298 break;
1299
1300 case OperationCode.GetProperties:
1301 {
1302 Hashtable actorProperties = (Hashtable)operationResponse[ParameterCode.PlayerProperties];
1303 Hashtable gameProperties = (Hashtable)operationResponse[ParameterCode.GameProperties];
1304 this.ReadoutProperties(gameProperties, actorProperties, 0);
1305
1306 // RemoveByteTypedPropertyKeys(actorProperties, false);
1307 // RemoveByteTypedPropertyKeys(gameProperties, false);
1308 // this.mListener.getPropertiesReturn(gameProperties, actorProperties, returnCode, debugMsg);
1309 break;
1310 }
1311
1312 case OperationCode.RaiseEvent:
1313 // this usually doesn't give us a result. only if the caching is affected the server will send one.
1314 break;
1315
1316 case OperationCode.FindFriends:
1317 bool[] onlineList = operationResponse[ParameterCode.FindFriendsResponseOnlineList] as bool[];
1318 string[] roomList = operationResponse[ParameterCode.FindFriendsResponseRoomIdList] as string[];
1319
1320 if (onlineList != null && roomList != null && this.friendListRequested != null && onlineList.Length == this.friendListRequested.Length)
1321 {
1322 List
1323 for (int index = 0; index < this.friendListRequested.Length; index++)
1324 {
1325 FriendInfo friend = new FriendInfo();
1326 friend.Name = this.friendListRequested[index];
1327 friend.Room = roomList[index];
1328 friend.IsOnline = onlineList[index];
1329 friendList.Insert(index, friend);
1330 }
1331 PhotonNetwork.Friends = friendList;
1332 }
1333 else
1334 {
1335 // any of the lists is null and shouldn't. print a error
1336 Debug.LogError("FindFriends failed to apply the result, as a required value wasn't provided or the friend list length differed from result.");
1337 }
1338
1339 this.friendListRequested = null;
1340 this.isFetchingFriends = false;
1341 this.friendListTimestamp = Environment.TickCount;
1342 if (this.friendListTimestamp == 0)
1343 {
1344 this.friendListTimestamp = 1; // makes sure the timestamp is not accidentally 0
1345 }
1346
1347 SendMonoMessage(PhotonNetworkingMessage.OnUpdatedFriendList);
1348 break;
1349
1350 case OperationCode.WebRpc:
1351 SendMonoMessage(PhotonNetworkingMessage.OnWebRpcResponse, operationResponse);
1352 break;
1353
1354 default:
1355 Debug.LogWarning(string.Format("OperationResponse unhandled: {0}", operationResponse.ToString()));
1356 break;
1357 }
1358
1359 this.externalListener.OnOperationResponse(operationResponse);
1360 }
File name: NetworkingPeer.cs
Copy
1962 public void ExecuteRPC(Hashtable rpcData, PhotonPlayer sender)
1963 {
1964 if (rpcData == null || !rpcData.ContainsKey((byte)0))
1965 {
1966 Debug.LogError("Malformed RPC; this should never occur. Content: " + SupportClass.DictionaryToString(rpcData));
1967 return;
1968 }
1969
1970 // ts: updated with "flat" event data
1971 int netViewID = (int)rpcData[(byte)0]; // LIMITS PHOTONVIEWS&PLAYERS
1972 int otherSidePrefix = 0; // by default, the prefix is 0 (and this is not being sent)
1973 if (rpcData.ContainsKey((byte)1))
1974 {
1975 otherSidePrefix = (short)rpcData[(byte)1];
1976 }
1977
1978 string inMethodName;
1979 if (rpcData.ContainsKey((byte)5))
1980 {
1981 int rpcIndex = (byte)rpcData[(byte)5]; // LIMITS RPC COUNT
1982 if (rpcIndex > PhotonNetwork.PhotonServerSettings.RpcList.Count - 1)
1983 {
1984 Debug.LogError("Could not find RPC with index: " + rpcIndex + ". Going to ignore! Check PhotonServerSettings.RpcList");
1985 return;
1986 }
1987 else
1988 {
1989 inMethodName = PhotonNetwork.PhotonServerSettings.RpcList[rpcIndex];
1990 }
1991 }
1992 else
1993 {
1994 inMethodName = (string)rpcData[(byte)3];
1995 }
1996
1997 object[] inMethodParameters = null;
1998 if (rpcData.ContainsKey((byte)4))
1999 {
2000 inMethodParameters = (object[])rpcData[(byte)4];
2001 }
2002
2003 if (inMethodParameters == null)
2004 {
2005 inMethodParameters = new object[0];
2006 }
2007
2008 PhotonView photonNetview = this.GetPhotonView(netViewID);
2009 if (photonNetview == null)
2010 {
2011 int viewOwnerId = netViewID/PhotonNetwork.MAX_VIEW_IDS;
2012 bool owningPv = (viewOwnerId == this.mLocalActor.ID);
2013 bool ownerSent = (viewOwnerId == sender.ID);
2014
2015 if (owningPv)
2016 {
2017 Debug.LogWarning("Received RPC \"" + inMethodName + "\" for viewID " + netViewID + " but this PhotonView does not exist! View was/is ours." + (ownerSent ? " Owner called." : " Remote called.") + " By: " + sender.ID);
2018 }
2019 else
2020 {
2021 Debug.LogWarning("Received RPC \"" + inMethodName + "\" for viewID " + netViewID + " but this PhotonView does not exist! Was remote PV." + (ownerSent ? " Owner called." : " Remote called.") + " By: " + sender.ID + " Maybe GO was destroyed but RPC not cleaned up.");
2022 }
2023 return;
2024 }
2025
2026 if (photonNetview.prefix != otherSidePrefix)
2027 {
2028 Debug.LogError(
2029 "Received RPC \"" + inMethodName + "\" on viewID " + netViewID + " with a prefix of " + otherSidePrefix
2030 + ", our prefix is " + photonNetview.prefix + ". The RPC has been ignored.");
2031 return;
2032 }
2033
2034 // Get method name
2035 if (inMethodName == string.Empty)
2036 {
2037 Debug.LogError("Malformed RPC; this should never occur. Content: " + SupportClass.DictionaryToString(rpcData));
2038 return;
2039 }
2040
2041 if (PhotonNetwork.logLevel >= PhotonLogLevel.Full)
2042 Debug.Log("Received RPC: " + inMethodName);
2043
2044
2045 // SetReceiving filtering
2046 if (photonNetview.group != 0 && !allowedReceivingGroups.Contains(photonNetview.group))
2047 {
2048 return; // Ignore group
2049 }
2050
2051 Type[] argTypes = new Type[0];
2052 if (inMethodParameters.Length > 0)
2053 {
2054 argTypes = new Type[inMethodParameters.Length];
2055 int i = 0;
2056 for (int index = 0; index < inMethodParameters.Length; index++)
2057 {
2058 object objX = inMethodParameters[index];
2059 if (objX == null)
2060 {
2061 argTypes[i] = null;
2062 }
2063 else
2064 {
2065 argTypes[i] = objX.GetType();
2066 }
2067
2068 i++;
2069 }
2070 }
2071
2072 int receivers = 0;
2073 int foundMethods = 0;
2074 MonoBehaviour[] mbComponents = photonNetview.GetComponents
2075 for (int componentsIndex = 0; componentsIndex < mbComponents.Length; componentsIndex++)
2076 {
2077 MonoBehaviour monob = mbComponents[componentsIndex];
2078 if (monob == null)
2079 {
2080 Debug.LogError("ERROR You have missing MonoBehaviours on your gameobjects!");
2081 continue;
2082 }
2083
2084 Type type = monob.GetType();
2085
2086 // Get [RPC] methods from cache
2087 List
2088 if (this.monoRPCMethodsCache.ContainsKey(type))
2089 {
2090 cachedRPCMethods = this.monoRPCMethodsCache[type];
2091 }
2092
2093 if (cachedRPCMethods == null)
2094 {
2095 List
2096
2097 this.monoRPCMethodsCache[type] = entries;
2098 cachedRPCMethods = entries;
2099 }
2100
2101 if (cachedRPCMethods == null)
2102 {
2103 continue;
2104 }
2105
2106 // Check cache for valid methodname+arguments
2107 for (int index = 0; index < cachedRPCMethods.Count; index++)
2108 {
2109 MethodInfo mInfo = cachedRPCMethods[index];
2110 if (mInfo.Name == inMethodName)
2111 {
2112 foundMethods++;
2113 ParameterInfo[] pArray = mInfo.GetParameters();
2114 if (pArray.Length == argTypes.Length)
2115 {
2116 // Normal, PhotonNetworkMessage left out
2117 if (this.CheckTypeMatch(pArray, argTypes))
2118 {
2119 receivers++;
2120 object result = mInfo.Invoke((object)monob, inMethodParameters);
2121 if (mInfo.ReturnType == typeof(IEnumerator))
2122 {
2123 monob.StartCoroutine((IEnumerator)result);
2124 }
2125 }
2126 }
2127 else if ((pArray.Length - 1) == argTypes.Length)
2128 {
2129 // Check for PhotonNetworkMessage being the last
2130 if (this.CheckTypeMatch(pArray, argTypes))
2131 {
2132 if (pArray[pArray.Length - 1].ParameterType == typeof(PhotonMessageInfo))
2133 {
2134 receivers++;
2135
2136 int sendTime = (int)rpcData[(byte)2];
2137 object[] deParamsWithInfo = new object[inMethodParameters.Length + 1];
2138 inMethodParameters.CopyTo(deParamsWithInfo, 0);
2139 deParamsWithInfo[deParamsWithInfo.Length - 1] = new PhotonMessageInfo(sender, sendTime, photonNetview);
2140
2141 object result = mInfo.Invoke((object)monob, deParamsWithInfo);
2142 if (mInfo.ReturnType == typeof(IEnumerator))
2143 {
2144 monob.StartCoroutine((IEnumerator)result);
2145 }
2146 }
2147 }
2148 }
2149 else if (pArray.Length == 1 && pArray[0].ParameterType.IsArray)
2150 {
2151 receivers++;
2152 object result = mInfo.Invoke((object)monob, new object[] { inMethodParameters });
2153 if (mInfo.ReturnType == typeof(IEnumerator))
2154 {
2155 monob.StartCoroutine((IEnumerator)result);
2156 }
2157 }
2158 }
2159 }
2160 }
2161
2162 // Error handling
2163 if (receivers != 1)
2164 {
2165 string argsString = string.Empty;
2166 for (int index = 0; index < argTypes.Length; index++)
2167 {
2168 Type ty = argTypes[index];
2169 if (argsString != string.Empty)
2170 {
2171 argsString += ", ";
2172 }
2173
2174 if (ty == null)
2175 {
2176 argsString += "null";
2177 }
2178 else
2179 {
2180 argsString += ty.Name;
2181 }
2182 }
2183
2184 if (receivers == 0)
2185 {
2186 if (foundMethods == 0)
2187 {
2188 Debug.LogError("PhotonView with ID " + netViewID + " has no method \"" + inMethodName + "\" marked with the [RPC](C#) or @RPC(JS) property! Args: " + argsString);
2189 }
2190 else
2191 {
2192 Debug.LogError("PhotonView with ID " + netViewID + " has no method \"" + inMethodName + "\" that takes " + argTypes.Length + " argument(s): " + argsString);
2193 }
2194 }
2195 else
2196 {
2197 Debug.LogError("PhotonView with ID " + netViewID + " has " + receivers + " methods \"" + inMethodName + "\" that takes " + argTypes.Length + " argument(s): " + argsString + ". Should be just one?");
2198 }
2199 }
2200 }
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
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: NetworkingPeer.cs
Copy
3034 public void SetReceivingEnabled(int[] enableGroups, int[] disableGroups)
3035 {
3036 List
3037 List
3038
3039 if (enableGroups != null)
3040 {
3041 for (int index = 0; index < enableGroups.Length; index++)
3042 {
3043 int i = enableGroups[index];
3044 if (i <= 0)
3045 {
3046 Debug.LogError("Error: PhotonNetwork.SetReceivingEnabled was called with an illegal group number: " + i + ". The group number should be at least 1.");
3047 continue;
3048 }
3049 if (!this.allowedReceivingGroups.Contains(i))
3050 {
3051 this.allowedReceivingGroups.Add(i);
3052 enableList.Add((byte)i);
3053 }
3054 }
3055 }
3056 if (disableGroups != null)
3057 {
3058 for (int index = 0; index < disableGroups.Length; index++)
3059 {
3060 int i = disableGroups[index];
3061 if (i <= 0)
3062 {
3063 Debug.LogError("Error: PhotonNetwork.SetReceivingEnabled was called with an illegal group number: " + i + ". The group number should be at least 1.");
3064 continue;
3065 }
3066 if (enableList.Contains((byte)i))
3067 {
3068 Debug.LogError("Error: PhotonNetwork.SetReceivingEnabled disableGroups contains a group that is also in the enableGroups: " + i + ".");
3069 continue;
3070 }
3071 if (this.allowedReceivingGroups.Contains(i))
3072 {
3073 this.allowedReceivingGroups.Remove(i);
3074 disableList.Add((byte)i);
3075 }
3076 }
3077 }
3078
3079 this.OpChangeGroups(disableList.Count > 0 ? disableList.ToArray() : null, enableList.Count > 0 ? enableList.ToArray() : null); //Passing a 0 sized array != passing null
3080 }
File name: NetworkingPeer.cs
Copy
3147 public void RunViewUpdate()
3148 {
3149 if (!PhotonNetwork.connected || PhotonNetwork.offlineMode)
3150 {
3151 return;
3152 }
3153
3154 if (this.mActors == null ||
3155#if !PHOTON_DEVELOP
3156 this.mActors.Count <= 1
3157#endif
3158 )
3159 {
3160 return; // No need to send OnSerialize messages (these are never buffered anyway)
3161 }
3162
3163 dataPerGroupReliable.Clear();
3164 dataPerGroupUnreliable.Clear();
3165
3166 /* Format of the data hashtable:
3167 * Hasthable dataPergroup*
3168 * [(byte)0] = this.ServerTimeInMilliSeconds;
3169 * OPTIONAL: [(byte)1] = currentLevelPrefix;
3170 * + data
3171 */
3172
3173 foreach (KeyValuePair
3174 {
3175 PhotonView view = kvp.Value;
3176
3177 if (view.synchronization != ViewSynchronization.Off)
3178 {
3179 // Fetch all sending photonViews
3180 if (view.isMine)
3181 {
3182 #if UNITY_2_6_1 || UNITY_2_6 || UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5
3183 if (!view.gameObject.active)
3184 {
3185 continue; // Only on actives
3186 }
3187 #else
3188 if (!view.gameObject.activeInHierarchy)
3189 {
3190 continue; // Only on actives
3191 }
3192 #endif
3193
3194 if (this.blockSendingGroups.Contains(view.group))
3195 {
3196 continue; // Block sending on this group
3197 }
3198
3199 // Run it trough its OnSerialize
3200 Hashtable evData = this.OnSerializeWrite(view);
3201 if (evData == null)
3202 {
3203 continue;
3204 }
3205
3206 if (view.synchronization == ViewSynchronization.ReliableDeltaCompressed || view.mixedModeIsReliable)
3207 {
3208 if (!evData.ContainsKey((byte)1) && !evData.ContainsKey((byte)2))
3209 {
3210 // Everything has been removed by compression, nothing to send
3211 }
3212 else
3213 {
3214 if (!dataPerGroupReliable.ContainsKey(view.group))
3215 {
3216 dataPerGroupReliable[view.group] = new Hashtable();
3217 dataPerGroupReliable[view.group][(byte)0] = this.ServerTimeInMilliSeconds;
3218 if (currentLevelPrefix >= 0)
3219 {
3220 dataPerGroupReliable[view.group][(byte)1] = this.currentLevelPrefix;
3221 }
3222 }
3223 Hashtable groupHashtable = dataPerGroupReliable[view.group];
3224 groupHashtable.Add((short)groupHashtable.Count, evData);
3225 }
3226 }
3227 else
3228 {
3229 if (!dataPerGroupUnreliable.ContainsKey(view.group))
3230 {
3231 dataPerGroupUnreliable[view.group] = new Hashtable();
3232 dataPerGroupUnreliable[view.group][(byte)0] = this.ServerTimeInMilliSeconds;
3233 if (currentLevelPrefix >= 0)
3234 {
3235 dataPerGroupUnreliable[view.group][(byte)1] = this.currentLevelPrefix;
3236 }
3237 }
3238 Hashtable groupHashtable = dataPerGroupUnreliable[view.group];
3239 groupHashtable.Add((short)groupHashtable.Count, evData);
3240 }
3241 }
3242 else
3243 {
3244 // Debug.Log(" NO OBS on " + view.name + " " + view.owner);
3245 }
3246 }
3247 else
3248 {
3249 }
3250 }
3251
3252 //Send the messages: every group is send in it's own message and unreliable and reliable are split as well
3253 RaiseEventOptions options = new RaiseEventOptions();
3254
3255#if PHOTON_DEVELOP
3256 options.Receivers = ReceiverGroup.All;
3257#endif
3258
3259 foreach (KeyValuePair
3260 {
3261 options.InterestGroup = (byte)kvp.Key;
3262 this.OpRaiseEvent(PunEvent.SendSerializeReliable, kvp.Value, true, options);
3263 }
3264 foreach (KeyValuePair
3265 {
3266 options.InterestGroup = (byte)kvp.Key;
3267 this.OpRaiseEvent(PunEvent.SendSerialize, kvp.Value, false, options);
3268 }
3269 }
Download file with original file name:Continue
Continue 149 lượt xem
Gõ tìm kiếm nhanh...