LoadAll









How do I use Load All
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: PhotonConverter.cs Copy
18     public static void RunConversion()
19     {
20         //Ask if user has made a backup.
21         int option = EditorUtility.DisplayDialogComplex("Conversion", "Attempt automatic conversion from Unity Networking to Photon Unity Networking \"PUN\"?", "Yes", "No!", "Pick Script Folder");
22         switch (option)
23         {
24             case 0:
25                 break;
26             case 1:
27                 return;
28             case 2:
29                 PickFolderAndConvertScripts();
30                 return;
31             default:
32                 return;
33         }
34
35         //REAAAALY?
36         bool result = EditorUtility.DisplayDialog("Conversion", "Disclaimer: The code conversion feature is quite crude, but should do it's job well (see the sourcecode). A backup is therefore strongly recommended!", "Yes, I've made a backup: GO", "Abort");
37         if (!result)
38         {
39             return;
40         }
41         Output(EditorApplication.timeSinceStartup + " Started conversion of Unity networking -> Photon");
42
43         //Ask to save current scene (optional)
44         EditorApplication.SaveCurrentSceneIfUserWantsTo();
45
46         EditorUtility.DisplayProgressBar("Converting..", "Starting.", 0);
47
48         //Convert NetworkViews to PhotonViews in Project prefabs
49         //Ask the user if we can move all prefabs to a resources folder
50         bool movePrefabs = EditorUtility.DisplayDialog("Conversion", "Can all prefabs that use a PhotonView be moved to a Resources/ folder? You need this if you use Network.Instantiate.", "Yes", "No");
51
52
53         string[] prefabs = Directory.GetFiles("Assets/", "*.prefab", SearchOption.AllDirectories);
54         foreach (string prefab in prefabs)
55         {
56             EditorUtility.DisplayProgressBar("Converting..", "Object:" + prefab, 0.6f);
57
58             Object[] objs = (Object[])AssetDatabase.LoadAllAssetsAtPath(prefab);
59             int converted = 0;
60             foreach (Object obj in objs)
61             {
62                 if (obj != null && obj.GetType() == typeof(GameObject))
63                     converted += ConvertNetworkView(((GameObject)obj).GetComponents(), false);
64             }
65             if (movePrefabs && converted > 0)
66             {
67                 //This prefab needs to be under the root of a Resources folder!
68                 string path = prefab.Replace("\\", "/");
69                 int lastSlash = path.LastIndexOf("/");
70                 int resourcesIndex = path.LastIndexOf("/Resources/");
71                 if (resourcesIndex != lastSlash - 10)
72                 {
73                     if (path.Contains("/Resources/"))
74                     {
75                         Debug.LogWarning("Warning, prefab [" + prefab + "] was already in a resources folder. But has been placed in the root of another one!");
76                     }
77                     //This prefab NEEDS to be placed under a resources folder
78                     string resourcesFolder = path.Substring(0, lastSlash) + "/Resources/";
79                     EnsureFolder(resourcesFolder);
80                     string newPath = resourcesFolder + path.Substring(lastSlash + 1);
81                     string error = AssetDatabase.MoveAsset(prefab, newPath);
82                     if (error != "")
83                         Debug.LogError(error);
84                     Output("Fixed prefab [" + prefab + "] by moving it into a resources folder.");
85                 }
86             }
87         }
88
89         //Convert NetworkViews to PhotonViews in scenes
90         string[] sceneFiles = Directory.GetFiles("Assets/", "*.unity", SearchOption.AllDirectories);
91         foreach (string sceneName in sceneFiles)
92         {
93             EditorApplication.OpenScene(sceneName);
94             EditorUtility.DisplayProgressBar("Converting..", "Scene:" + sceneName, 0.2f);
95
96             int converted2 = ConvertNetworkView((NetworkView[])GameObject.FindObjectsOfType(typeof(NetworkView)), true);
97             if (converted2 > 0)
98             {
99                 //This will correct all prefabs: The prefabs have gotten new components, but the correct ID's were lost in this case
100                 PhotonViewHandler.HierarchyChange(); //TODO: most likely this is triggered on change or on save
101
102                 Output("Replaced " + converted2 + " NetworkViews with PhotonViews in scene: " + sceneName);
103                 EditorApplication.SaveScene(EditorApplication.currentScene);
104             }
105
106         }
107
108         //Convert C#/JS scripts (API stuff)
109         List scripts = GetScriptsInFolder("Assets");
110
111         EditorUtility.DisplayProgressBar("Converting..", "Scripts..", 0.9f);
112         ConvertScripts(scripts);
113
114         Output(EditorApplication.timeSinceStartup + " Completed conversion!");
115         EditorUtility.ClearProgressBar();
116
117         EditorUtility.DisplayDialog("Completed the conversion", "Don't forget to add \"PhotonNetwork.ConnectWithDefaultSettings();\" to connect to the Photon server before using any multiplayer functionality.", "OK");
118     }
File name: PhotonEditor.cs Copy
886     public static void ReLoadCurrentSettings()
887     {
888         // this now warns developers if there are more than one settings files in resources folders. first will be used.
889         UnityEngine.Object[] settingFiles = Resources.LoadAll(PhotonNetwork.serverSettingsAssetFile, typeof(ServerSettings));
890         if (settingFiles != null && settingFiles.Length > 0)
891         {
892             PhotonEditor.Current = (ServerSettings)settingFiles[0];
893
894             if (settingFiles.Length > 1)
895             {
896                 Debug.LogWarning(CurrentLang.MoreThanOneLabel + PhotonNetwork.serverSettingsAssetFile + CurrentLang.FilesInResourceFolderLabel + AssetDatabase.GetAssetPath(PhotonEditor.Current));
897             }
898         }
899     }
File name: PhotonViewHandler.cs Copy
173     //TODO: check if this can be internal protected (as source in editor AND as dll)
174     public static void LoadAllScenesToFix()
175     {
176         string[] scenes = System.IO.Directory.GetFiles(".", "*.unity", SearchOption.AllDirectories);
177
178         foreach (string scene in scenes)
179         {
180             EditorApplication.OpenScene(scene);
181
182             PhotonViewHandler.HierarchyChange();//TODO: most likely on load also triggers a hierarchy change
183
184             EditorApplication.SaveScene();
185         }
186
187         Debug.Log("Corrected scene views where needed.");
188     }
File name: AnimationBuilder.cs Copy
57         public List BuildAnimationClips(GameObject root, Entity entity, string scmlAssetPath)
58         {
59             var allAnimClips = AssetDatabase.LoadAllAssetRepresentationsAtPath(scmlAssetPath).OfType().ToList();
60             Debug.Log(string.Format("Found {0} animation clips at {1}", allAnimClips.Count, scmlAssetPath));
61
62             var newAnimClips = new List();
63
64             foreach (var animation in entity.Animations)
65             {
66                 var animClip = MakeAnimationClip(root, animation, Path.GetDirectoryName(scmlAssetPath));
67                 Debug.Log(string.Format("Added animClip({0}) to asset path ({1}) WrapMode:{2}", animClip.name, scmlAssetPath, animClip.wrapMode));
68                 newAnimClips.Add(animClip);
69
70                 var originalAnimClip = allAnimClips.Where(clip => clip.name == animClip.name).FirstOrDefault();
71                 if (originalAnimClip != null)
72                 {
73                     Debug.Log("Replacing animation clip " + animClip.name);
74                     EditorUtility.CopySerialized(animClip, originalAnimClip);
75                     allAnimClips.Remove(originalAnimClip);
76                 }
77                 else
78                     AssetDatabase.AddObjectToAsset(animClip, scmlAssetPath);
79             }
80
81             //Remove any animation clips that are no longer present in the SCML
82             foreach(var clip in allAnimClips)
83             {
84                 //This may be a bad idea
85                 UnityEngine.Object.DestroyImmediate(clip, true);
86             }
87
88             return newAnimClips;
89         }
File name: ImportTiled2Unity.Mesh.cs Copy
250         private GameObject CreateCopyFromMeshObj(string copyFromName, string objPath)
251         {
252             // Find a matching game object within the mesh object and "copy" it
253             // (In Unity terms, the Instantiated object is a copy)
254             UnityEngine.Object[] objects = AssetDatabase.LoadAllAssetsAtPath(objPath);
255             foreach (var obj in objects)
256             {
257                 if (obj.name != copyFromName)
258                     continue;
259
260                 // We have a match but is it a game object?
261                 GameObject gameObj = GameObject.Instantiate(obj) as GameObject;
262                 if (gameObj == null)
263                     continue;
264
265                 // Reset the name so it is not decorated by the Instantiate call
266                 gameObj.name = obj.name;
267                 return gameObj;
268             }
269
270             // If we're here then there's an error with the mesh name
271             Debug.LogError(String.Format("No mesh named '{0}' to copy from.", copyFromName));
272             return null;
273         }

LoadAll 157 lượt xem

Gõ tìm kiếm nhanh...