//Get a PackedFile from a system file path static public PackedFile PackFile(string windowsPath) { if (!File.Exists(windowsPath)) { EditorApplication.Beep(); Debug.LogError("[FunDream_ PackFile] File doesn't exist:" + windowsPath); return(null); } //Get properties // Content string content = File.ReadAllText(windowsPath, System.Text.Encoding.UTF8); // File relative path string tcpRoot = FunDream_Utils.FindReadmePath(); if (tcpRoot == null) { EditorApplication.Beep(); Debug.LogError("[FunDream_ PackFile] Can't find FunDream_ Readme file!\nCan't determine root folder to pack/unpack files."); return(null); } tcpRoot = UnityToSystemPath(tcpRoot); string relativePath = windowsPath.Replace(tcpRoot, ""); PackedFile pf = new PackedFile(relativePath, content); return(pf); }
Texture2D TryFindDefaultRampTexture() { string rootPath = FunDream_Utils.FindReadmePath(true); if (!string.IsNullOrEmpty(rootPath)) { string defaultTexPath = "Assets" + rootPath + "/Textures/FunDream__Ramp_3Levels.png"; return(AssetDatabase.LoadAssetAtPath <Texture2D>(defaultTexPath)); } return(null); }
static private void UnpackShaders(string filter) { string[] archFiles = Directory.GetFiles(FunDream_Utils.UnityToSystemPath(Application.dataPath), "FunDream_ Packed Shaders.tcp2data", SearchOption.AllDirectories); if (archFiles == null || archFiles.Length == 0) { EditorApplication.Beep(); Debug.LogError("[FunDream_ Unpack Shaders] Couldn't find file: \"FunDream_ Packed Shaders.tcp2data\"\nPlease reimport Toony Colors Pro 2."); return; } string archivePath = archFiles[0]; if (archivePath.EndsWith(".tcp2data")) { FunDream_Utils.PackedFile[] files = FunDream_Utils.ExtractArchive(archivePath, filter); int @continue = 0; if (files.Length > 8) { do { @continue = EditorUtility.DisplayDialogComplex("FunDream_ : Unpack Shaders", "You are about to import " + files.Length + " shaders in Unity.\nIt could take a few minutes!\nContinue?", "Yes", "No", "Help"); if (@continue == 2) { FunDream_GUI.OpenHelpFor("Unpack Shaders"); } }while(@continue == 2); } if (@continue == 0 && files.Length > 0) { string tcpRoot = FunDream_Utils.FindReadmePath(); foreach (FunDream_Utils.PackedFile f in files) { string filePath = tcpRoot + f.path; string fileDir = Path.GetDirectoryName(filePath); if (!Directory.Exists(fileDir)) { Directory.CreateDirectory(fileDir); } File.WriteAllText(filePath, f.content); } Debug.Log("Toony Colors Pro 2 - Unpack Shaders:\n" + files.Length + (files.Length > 1 ? " shaders extracted." : " shader extracted.")); AssetDatabase.Refresh(); } if (files.Length == 0) { Debug.Log("Toony Colors Pro 2 - Unpack Shaders:\nNothing to unpack. Shaders are probably already unpacked!"); } } }
static public void OpenHelp() { string rootDir = FunDream_Utils.FindReadmePath(); if (rootDir == null) { EditorUtility.DisplayDialog("FunDream_ Documentation", "Couldn't find FunDream_ root folder! (the readme file is missing)\nYou can still access the documentation manually in the Documentation folder.", "Ok"); } else { string helpLink = "file:///" + rootDir.Replace(@"\", "/") + "/Documentation/FunDream_ Documentation.html"; Application.OpenURL(helpLink); } }
static public Texture2D GetHelpBoxIcon(MessageType msgType) { string iconName = null; switch (msgType) { case MessageType.Error: if (errorIconCached != null) { return(errorIconCached); } iconName = "FunDream__ErrorIcon"; break; case MessageType.Warning: if (warningIconCached != null) { return(warningIconCached); } iconName = "FunDream__WarningIcon"; break; case MessageType.Info: if (infoIconCached != null) { return(infoIconCached); } iconName = "FunDream__InfoIcon"; break; } if (string.IsNullOrEmpty(iconName)) { return(null); } string rootPath = FunDream_Utils.FindReadmePath(true); Texture2D icon = AssetDatabase.LoadAssetAtPath("Assets" + rootPath + "/Editor/Icons/" + iconName + ".png", typeof(Texture2D)) as Texture2D; switch (msgType) { case MessageType.Error: errorIconCached = icon; break; case MessageType.Warning: warningIconCached = icon; break; case MessageType.Info: infoIconCached = icon; break; } return(icon); }
static public void OpenHelpFor(string helpTopic) { string rootDir = FunDream_Utils.FindReadmePath(); if (rootDir == null) { EditorUtility.DisplayDialog("FunDream_ Documentation", "Couldn't find FunDream_ root folder! (the readme file is missing)\nYou can still access the documentation manually in the Documentation folder.", "Ok"); } else { string helpAnchor = helpTopic.Replace("/", "_").Replace(@"\", "_").Replace(" ", "_").ToLowerInvariant() + ".htm"; string topicLink = "file:///" + rootDir.Replace(@"\", "/") + "/Documentation/Documentation Data/Anchors/" + helpAnchor; Application.OpenURL(topicLink); } }
//Extract an archive into an array of PackedFile static public PackedFile[] ExtractArchive(string archivePath, string filter = null) { string archive = File.ReadAllText(archivePath); string[] archiveLines = File.ReadAllLines(archivePath); if (archiveLines[0] != "# FunDream_ PACKED SHADERS") { EditorApplication.Beep(); Debug.LogError("[FunDream_ ExtractArchive] Invalid FunDream_ archive:\n" + archivePath); return(null); } //Find offset int offset = archive.IndexOf("###") + 4; if (offset < 20) { Debug.LogError("[FunDream_ ExtractArchive] Invalid FunDream_ archive:\n" + archivePath); return(null); } string tcpRoot = FunDream_Utils.FindReadmePath(); List <PackedFile> packedFilesList = new List <PackedFile>(); for (int line = 1; line < archiveLines.Length; line++) { //Index end, start content parsing if (archiveLines[line].StartsWith("#")) { break; } string[] shaderIndex = archiveLines[line].Split(new string[] { ";" }, System.StringSplitOptions.RemoveEmptyEntries); if (shaderIndex.Length != 3) { EditorApplication.Beep(); Debug.LogError("[FunDream_ ExtractArchive] Invalid format in FunDream_ archive, at line " + line + ":\n" + archivePath); return(null); } //Get data string relativePath = shaderIndex[0]; int start = int.Parse(shaderIndex[1]); int length = int.Parse(shaderIndex[2]); //Get content string content = archive.Substring(offset + start, length); //Skip if file already extracted if (File.Exists(tcpRoot + relativePath)) { continue; } //Filter? if (!string.IsNullOrEmpty(filter)) { string[] filters = filter.Split(new string[] { " " }, System.StringSplitOptions.RemoveEmptyEntries); bool skip = false; foreach (string f in filters) { if (!relativePath.ToLower().Contains(f.ToLower())) { skip = true; break; } } if (skip) { continue; } } //Add File packedFilesList.Add(new PackedFile(relativePath, content)); } return(packedFilesList.ToArray()); }