public override void Draw() { EditorUI.DrawBtn("添加所有场景", "", () => { HashSet <string> nameSet = new HashSet <string>(); string txt = ""; string[] resFiles = AssetDatabase.FindAssets("t:Scene", new string[] { "Assets" }); EditorBuildSettingsScene[] scenes = new EditorBuildSettingsScene[resFiles.Length]; // 加入 Build In Scene for (int i = 0; i < resFiles.Length; ++i) { string path = AssetDatabase.GUIDToAssetPath(resFiles[i]); Debug.LogFormat("--- path: {0}", path); scenes[i] = new EditorBuildSettingsScene(path, true); // 写入名字 string fileName = Path.GetFileNameWithoutExtension(path); EditorUtils.Assert(!nameSet.Contains(fileName), "--- 包含重复场景名: {0}", fileName); nameSet.Add(fileName); txt += fileName + "\n"; } EditorBuildSettings.scenes = scenes; Utils.WriteFileUTF8(EditorUtils.GetDesktop("all_scene.txt"), txt); Debug.LogFormat("--- EditorBuildSettings ok"); }, 35, 100); }
public static int[] GetImagePixels(string path) { UnityEngine.Object obj = AssetImporter.GetAtPath(path); TextureImporter importer = obj as TextureImporter; EditorUtils.Assert(importer != null, string.Format("检测到非图片资源, path:{0}", path)); return(GetImagePixels(importer)); }
// 弹窗执行 py, 新开线程, 不阻塞 gui public static void ProcCmdOnWin(string command, string argument) { UnityEngine.Debug.LogFormat("--- ProcCmdOnWin: {0} {1}", command, argument); #if UNITY_EDITOR_WIN ProcCmdOnWindows(command, argument); #elif UNITY_EDITOR_OSX ProcCmdOnMacOs(command, argument); #else EditorUtils.Assert(false, "--- do not support"); #endif }
private void SaveImage() { GameObject go = Selection.activeGameObject; EditorUtils.Assert(go != null, "--- 未选中场景对象"); Debug.LogFormat("--- name: {0}", go.name); RawImage ri = go.GetComponent <RawImage>(); EditorUtils.Assert(ri != null, "--- go: {0} 获取不到 RawImage 组件", go.name); Texture tex = ri.texture; EditorUtils.Assert(tex != null, "--- 获取不到 Texture 组件"); string file = EditorUtils.GetDesktop("noise.png"); Utils.SaveTexToPng(tex, file, tex.width, tex.height); Debug.LogFormat("--- save ok, path: {0}", file); }