Plugins
How do I use Plugins
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
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: ChatClient.cs
Copy
94 public bool Connect(string address, ConnectionProtocol protocol, string appId, string appVersion, string userId, AuthenticationValues authValues)
95 {
96 if (!this.HasPeer)
97 {
98 this.chatPeer = new ChatPeer(this, protocol);
99 }
100 else
101 {
102 this.Disconnect();
103 if (this.chatPeer.UsedProtocol != protocol)
104 {
105 this.chatPeer = new ChatPeer(this, protocol);
106 }
107 }
108
109#if UNITY
110#pragma warning disable 0162 // the library variant defines if we should use PUN's SocketUdp variant (at all)
111 if (PhotonPeer.NoSocket)
112 {
113#if !UNITY_EDITOR && (UNITY_PS3 || UNITY_ANDROID)
114 UnityEngine.Debug.Log("Using class SocketUdpNativeDynamic");
115 this.chatPeer.SocketImplementation = typeof(SocketUdpNativeDynamic);
116#elif !UNITY_EDITOR && UNITY_IPHONE
117 UnityEngine.Debug.Log("Using class SocketUdpNativeStatic");
118 this.chatPeer.SocketImplementation = typeof(SocketUdpNativeStatic);
119#elif !UNITY_EDITOR && (UNITY_WINRT)
120 // this automatically uses a separate assembly-file with Win8-style Socket usage (not possible in Editor)
121#else
122 Type udpSocket = Type.GetType("ExitGames.Client.Photon.SocketUdp, Assembly-CSharp");
123 this.chatPeer.SocketImplementation = udpSocket;
124 if (udpSocket == null)
125 {
126 UnityEngine.Debug.Log("ChatClient could not find a suitable C# socket class. The Photon3Unity3D.dll only supports native socket plugins.");
127 }
128#endif
129 if (this.chatPeer.SocketImplementation == null)
130 {
131 UnityEngine.Debug.Log("No socket implementation set for 'NoSocket' assembly. Please contact Exit Games.");
132 }
133 }
134#pragma warning restore 0162
135#endif
136
137 this.chatPeer.TimePingInterval = 3000;
138 this.DisconnectedCause = ChatDisconnectCause.None;
139
140 this.CustomAuthenticationValues = authValues;
141 this.UserId = userId;
142 this.AppId = appId;
143 this.AppVersion = appVersion;
144 this.didAuthenticate = false;
145 this.msDeltaForServiceCalls = 100;
146
147
148 // clean all channels
149 this.PublicChannels.Clear();
150 this.PrivateChannels.Clear();
151
152 if (!address.Contains(":"))
153 {
154 int port = 0;
155 ProtocolToNameServerPort.TryGetValue(protocol, out port);
156 address = string.Format("{0}:{1}", address, port);
157 }
158
159 bool isConnecting = this.chatPeer.Connect(address, "NameServer");
160 if (isConnecting)
161 {
162 this.State = ChatState.ConnectingToNameServer;
163 }
164 return isConnecting;
165 }
File name: VSCode.cs
Copy
480 static void CheckForUpdate()
481 {
482 var fileContent = string.Empty;
483
484 EditorUtility.DisplayProgressBar("VSCode", "Checking for updates ...", 0.5f);
485
486 // Because were not a runtime framework, lets just use the simplest way of doing this
487 try
488 {
489 using (var webClient = new System.Net.WebClient())
490 {
491 fileContent = webClient.DownloadString("https://raw.githubusercontent.com/dotBunny/VSCode/master/Plugins/Editor/VSCode.cs");
492 }
493 }
494 catch (Exception e)
495 {
496 if (Debug)
497 {
498 UnityEngine.Debug.Log("[VSCode] " + e.Message);
499
500 }
501
502 // Don't go any further if there is an error
503 return;
504 }
505 finally
506 {
507 EditorUtility.ClearProgressBar();
508 }
509
510 // Set the last update time
511 LastUpdate = DateTime.Now;
512
513 // Fix for oddity in downlo
514 if (fileContent.Substring(0, 2) != "/*")
515 {
516 int startPosition = fileContent.IndexOf("/*", StringComparison.CurrentCultureIgnoreCase);
517
518 // Jump over junk characters
519 fileContent = fileContent.Substring(startPosition);
520 }
521
522 string[] fileExploded = fileContent.Split('\n');
523 if (fileExploded.Length > 7)
524 {
525 float github = Version;
526 if (float.TryParse(fileExploded[6].Replace("*", "").Trim(), out github))
527 {
528 GitHubVersion = github;
529 }
530
531
532 if (github > Version)
533 {
534 var GUIDs = AssetDatabase.FindAssets("t:Script VSCode");
535 var path = Application.dataPath.Substring(0, Application.dataPath.Length - "/Assets".Length) + System.IO.Path.DirectorySeparatorChar +
536 AssetDatabase.GUIDToAssetPath(GUIDs[0]).Replace('/', System.IO.Path.DirectorySeparatorChar);
537
538 if (EditorUtility.DisplayDialog("VSCode Update", "A newer version of the VSCode plugin is available, would you like to update your version?", "Yes", "No"))
539 {
540 // Always make sure the file is writable
541 System.IO.FileInfo fileInfo = new System.IO.FileInfo(path);
542 fileInfo.IsReadOnly = false;
543
544 // Write update file
545 File.WriteAllText(path, fileContent);
546
547 // Force update on text file
548 AssetDatabase.ImportAsset(AssetDatabase.GUIDToAssetPath(GUIDs[0]), ImportAssetOptions.ForceUpdate);
549 }
550
551 }
552 }
553 }
Plugins 181 lượt xem
Gõ tìm kiếm nhanh...