Exists
How do I use Exists
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: WorkerMenu.cs
Copy
206 public void OnPhotonCreateRoomFailed()
207 {
208 this.ErrorDialog = "Error: Can't create room (room name maybe already used).";
209 Debug.Log("OnPhotonCreateRoomFailed got called. This can happen if the room exists (even if not visible). Try another room name.");
210 }
File name: PhotonConverter.cs
Copy
341 static void EnsureFolder(string path)
342 {
343 if (!Directory.Exists(path))
344 {
345 Directory.CreateDirectory(path);
346 AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
347 AssetDatabase.Refresh();
348 }
349 }
File name: PhotonEditor.cs
Copy
241 internal protected static bool CheckPunPlus()
242 {
243 androidLibExists = File.Exists("Assets/Plugins/Android/libPhotonSocketPlugin.so");
244 iphoneLibExists = File.Exists("Assets/Plugins/IPhone/libPhotonSocketPlugin.a");
245
246 isPunPlus = androidLibExists || iphoneLibExists;
247 return isPunPlus;
248 }
File name: PhotonEditor.cs
Copy
250 private static void ImportWin8Support()
251 {
252 if (EditorApplication.isCompiling || EditorApplication.isPlayingOrWillChangePlaymode)
253 {
254 return; // don't import while compiling
255 }
256
257 #if UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_5 || UNITY_5_1 || UNITY_5_2
258 const string win8Package = "Assets/Plugins/Photon3Unity3D-Win8.unitypackage";
259
260 bool win8LibsExist = File.Exists("Assets/Plugins/WP8/Photon3Unity3D.dll") && File.Exists("Assets/Plugins/Metro/Photon3Unity3D.dll");
261 if (!win8LibsExist && File.Exists(win8Package))
262 {
263 AssetDatabase.ImportPackage(win8Package, false);
264 }
265 #endif
266 }
File name: PhotonEditor.cs
Copy
827 {
828 get
829 {
830 if (currentSettings == null)
831 {
832 // find out if ServerSettings can be instantiated (existing script check)
833 ScriptableObject serverSettingTest = CreateInstance("ServerSettings");
834 if (serverSettingTest == null)
835 {
836 Debug.LogError(CurrentLang.ServerSettingsMissingLabel);
837 return null;
838 }
839 DestroyImmediate(serverSettingTest);
840
841 // try to load settings from file
842 ReLoadCurrentSettings();
843
844 // if still not loaded, create one
845 if (currentSettings == null)
846 {
847 string settingsPath = Path.GetDirectoryName(PhotonNetwork.serverSettingsAssetPath);
848 if (!Directory.Exists(settingsPath))
849 {
850 Directory.CreateDirectory(settingsPath);
851 AssetDatabase.ImportAsset(settingsPath);
852 }
853
854 currentSettings = (ServerSettings)ScriptableObject.CreateInstance("ServerSettings");
855 if (currentSettings != null)
856 {
857 AssetDatabase.CreateAsset(currentSettings, PhotonNetwork.serverSettingsAssetPath);
858 }
859 else
860 {
861 Debug.LogError(CurrentLang.ServerSettingsMissingLabel);
862 }
863 }
864
865 // settings were loaded or created. set this editor's initial selected region now (will be changed in GUI)
866 if (currentSettings != null)
867 {
868 selectedRegion = currentSettings.PreferredRegion;
869 }
870 }
871
872 return currentSettings;
873 }
874
875 protected set
876 {
877 currentSettings = value;
878 }
879 }
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
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: NetworkingPeer.cs
Copy
947 public bool OpJoinRoom(string roomName, RoomOptions roomOptions, TypedLobby typedLobby, bool createIfNotExists)
948 {
949 bool onGameServer = this.server == ServerConnection.GameServer;
950 if (!onGameServer)
951 {
952 // roomOptions and typedLobby will be null, unless createIfNotExists is true
953 this.mRoomOptionsForCreate = roomOptions;
954 this.mRoomToGetInto = new Room(roomName, roomOptions);
955 this.mRoomToEnterLobby = null;
956 if (createIfNotExists)
957 {
958 this.mRoomToEnterLobby = typedLobby ?? ((this.insideLobby) ? this.lobby : null); // use given lobby, or active lobby (if any active) or none
959 }
960 }
961
962 this.mLastJoinType = (createIfNotExists) ? JoinType.JoinOrCreateOnDemand : JoinType.JoinGame;
963 return base.OpJoinRoom(roomName, roomOptions, this.mRoomToEnterLobby, createIfNotExists, this.GetLocalActorProperties(), onGameServer);
964 }
File name: PhotonNetwork.cs
Copy
1510 public static bool JoinRoom(string roomName, bool createIfNotExists)
1511 {
1512 if (connectionStateDetailed == PeerState.Joining || connectionStateDetailed == PeerState.Joined || connectionStateDetailed == PeerState.ConnectedToGameserver)
1513 {
1514 Debug.LogError("JoinRoom aborted: You can only join a room while not currently connected/connecting to a room.");
1515 }
1516 else if (room != null)
1517 {
1518 Debug.LogError("JoinRoom aborted: You are already in a room!");
1519 }
1520 else if (roomName == string.Empty)
1521 {
1522 Debug.LogError("JoinRoom aborted: You must specifiy a room name!");
1523 }
1524 else
1525 {
1526 if (offlineMode)
1527 {
1528 offlineModeRoom = new Room(roomName, null);
1529 NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnJoinedRoom);
1530 return true;
1531 }
1532 else
1533 {
1534 return networkingPeer.OpJoinRoom(roomName, null, null, createIfNotExists);
1535 }
1536 }
1537
1538 return false; // offline and OpJoin both return but the error-cases don't
1539 }
File name: VSCode.cs
Copy
48 {
49 get
50 {
51 string current = EditorPrefs.GetString("VSCode_CodePath", "");
52 if(current == "" || !VSCodeExists(current))
53 {
54 //Value not set, set to "" or current path is invalid, try to autodetect it
55 //If autodetect fails, a error will be printed and the default value set
56 EditorPrefs.SetString("VSCode_CodePath", AutodetectCodePath());
57 //If its not installed or the install folder isn't a "normal" one,
58 //AutodetectCodePath will print a error message to the Unity Console
59 }
60 return EditorPrefs.GetString("VSCode_CodePath", current);
61 }
62 set
63 {
64 EditorPrefs.SetString("VSCode_CodePath", value);
65 }
66 }
File name: VSCode.cs
Copy
403 static string AutodetectCodePath()
404 {
405 string[] possiblePaths =
406#if UNITY_EDITOR_OSX
407 {
408 "/Applications/Visual Studio Code.app",
409 "/Applications/Visual Studio Code - Insiders.app"
410 };
411#elif UNITY_EDITOR_WIN
412 {
413 ProgramFilesx86() + Path.DirectorySeparatorChar + "Microsoft VS Code"
414 + Path.DirectorySeparatorChar + "bin" + Path.DirectorySeparatorChar + "code.cmd",
415 ProgramFilesx86() + Path.DirectorySeparatorChar + "Microsoft VS Code Insiders"
416 + Path.DirectorySeparatorChar + "bin" + Path.DirectorySeparatorChar + "code-insiders.cmd"
417 };
418#else
419 {
420 "/usr/bin/code",
421 "/bin/code",
422 "/usr/local/bin/code"
423 };
424#endif
425 for(int i = 0; i < possiblePaths.Length; i++)
426 {
427 if(VSCodeExists(possiblePaths[i]))
428 {
429 return possiblePaths[i];
430 }
431 }
432 PrintNotFound(possiblePaths[0]);
433 return possiblePaths[0]; //returns the default one, printing a warning message 'executable not found'
434 }
Exists 89 lượt xem
Gõ tìm kiếm nhanh...