Hub
How do I use Hub
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: PunStartup.cs
Copy
10 // paths to demo scenes to setup (if needed)
13 {
14 "DemoHub/DemoHub-Scene.unity",
15 "DemoBoxes/DemoBoxes-Scene.unity",
16 "DemoWorker/DemoWorker-Scene.unity",
17 "DemoWorker/DemoWorkerGame-Scene.unity",
18 "MarcoPolo-Tutorial/MarcoPolo-Scene.unity",
19 "DemoSynchronization/DemoSynchronization-Scene.unity",
20 "DemoFriendsAndCustomAuth/DemoFriends-Scene.unity",
21 "DemoFriendsAndCustomAuth/DemoPickup-Scene.unity",
22 "DemoChat/DemoChat-Scene.unity"
23 };
File name: PunStartup.cs
Copy
34 static void OnUpdate()
35 {
36 bool doneBefore = EditorPrefs.GetBool("PunDemosOpenedBefore");
37 if (doneBefore)
38 {
39 EditorApplication.update -= OnUpdate;
40 return;
41 }
42
43 if (String.IsNullOrEmpty(EditorApplication.currentScene) && EditorBuildSettings.scenes.Length == 0)
44 {
45 #if UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_5 || UNITY_5_1 || UNITY_5_2
46 if (EditorApplication.isUpdating) return;
47 #endif
48
49 LoadPunDemoHub();
50 SetPunDemoBuildSettings();
51 EditorPrefs.SetBool("PunDemosOpenedBefore", true);
52 Debug.Log("No scene was open. Loaded PUN Demo Hub Scene and added demos to build settings. Ready to go! This auto-setup is now disabled in this Editor.");
53 }
54 }
File name: PunStartup.cs
Copy
68 public static void LoadPunDemoHub()
69 {
70 bool ret = EditorApplication.OpenScene(demoBasePath + demoPaths[0]);
71 if (ret)
72 {
73 Selection.activeObject = AssetDatabase.LoadMainAssetAtPath(demoBasePath + demoPaths[0]);
74 }
75 }
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: VSCode.cs
Copy
194 {
195 get
196 {
197 return EditorPrefs.GetFloat("VSCode_GitHubVersion", Version);
198 }
199 set
200 {
201 EditorPrefs.SetFloat("VSCode_GitHubVersion", value);
202 }
203 }
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 }
Download file with original file name:Hub
Hub 133 lượt xem
Gõ tìm kiếm nhanh...