static void _MakeAtlas() { //Debug.Log(string.Format("UI Texture To Prefab")); string spriteDir = Application.dataPath + "/Resources/UI/Sprites/"; var filesPath = GKFileUtil.GetFilesInDirectory(Application.dataPath + "/Art/_UI/Sprite2Prefab/"); foreach (var str in filesPath) { if (string.Empty != GKString.GetFromSuffix(str, ".png", true) || string.Empty != GKString.GetFromSuffix(str, ".jpg", true)) { string allPath = str; string assetPath = allPath.Substring(allPath.IndexOf("Assets")); Sprite sprite = AssetDatabase.LoadAssetAtPath <Sprite>(assetPath); GameObject go = new GameObject(sprite.name); go.AddComponent <SpriteRenderer>().sprite = sprite; var dir = GKFileUtil.GetDirctoryName(allPath); allPath = string.Format("{0}{1}/{2}.prefab", spriteDir, dir, sprite.name); GKFileUtil.CreateDirectoryFromFileName(allPath); string prefabPath = allPath.Substring(allPath.IndexOf("Assets")); PrefabUtility.CreatePrefab(prefabPath, go); GameObject.DestroyImmediate(go); } } }
static public void CreateAsset(UnityEngine.Object asset, string filename) { GKFileUtil.CreateDirectoryFromFileName(filename); Debug.Log("Create Asset File " + filename); AssetDatabase.CreateAsset(asset, filename); }
//! create prefab by filename and keep prefab connection if previous prefab exists static public GameObject CreateOrReplacePrefab(string filename, GameObject obj) { //Debug.Log("CreateOrReplacePrefab " + filename ); var prefab = AssetDatabase.LoadMainAssetAtPath(filename) as GameObject; if (prefab == null) { GKFileUtil.CreateDirectoryFromFileName(filename); return(PrefabUtility.CreatePrefab(filename, obj)); } else { var o = PrefabUtility.ReplacePrefab(obj, prefab, ReplacePrefabOptions.ReplaceNameBased); if (!o) { Debug.LogError("Cannot Replace Prefab " + filename); } return(o); } }
/* * Depending on your writing habits, * You need to develop various parsing methods that only implement simple parsing functions. * */ static public void ScoureCodeObfusation(string[] paths) { // One by one get directory. for (int i = 0; i < paths.Length; i++) { Debug.Log(string.Format("ScoureCodeObfusation file path: {0}", paths[i])); if (string.IsNullOrEmpty(paths[i])) { continue; } List <string> list = new List <string>(); string appendLine = "\tprivate void ObfuscationMethod_" + UnityEngine.Random.Range(0, 1000).ToString() + "(){} // For code obfuscation."; // Get files. var fs = GKFileUtil.GetFilesInDirectory(paths[i]); foreach (var f in fs) { if (!GKFileUtil.FilterInvalidFiles(f)) { continue; } bool bAppend = false; bool bFinished = false; list.Clear(); string strLine = ""; StreamReader sr = new StreamReader(f); while (null != (strLine = sr.ReadLine())) { list.Add(strLine); if (!bFinished) { // The new line contains '{', and meets the additional conditions. if (bAppend && strLine.Contains("{")) { list.Add(appendLine); bAppend = false; bFinished = true; } else { // At the beginning of the line is not to judge or / / / *, *. if (string.IsNullOrEmpty(strLine) || strLine.Trim().StartsWith("//") || strLine.Trim().StartsWith("/*") || strLine.Trim().StartsWith("*")) { continue; } // Check the read result and if it don't contains '{' lineNum++. if (strLine.Contains("public class")) { if (strLine.Contains("{")) { list.Add(appendLine); bAppend = false; bFinished = true; } else { bAppend = true; } } //... } } } sr.Close(); StreamWriter sw = new StreamWriter(f, false); foreach (var l in list) { sw.WriteLine(l); } sw.Close(); } } }
static public void CopyAsset(string srcPath, string dstPath) { if (!File.Exists(srcPath)) { Debug.LogError(string.Format("The source file cannot be found. file path: {0} ", srcPath)); return; } GKFileUtil.CreateDirectoryFromFileName(dstPath); // Copy asset to destination directory. File.Copy(srcPath, dstPath, true); string dstMetaPath = string.Format("{0}.meta", dstPath); string dstMetaGuid = null; string dstMetaTime = null; //Read the guid and timeCreated in the file. if (File.Exists(dstMetaPath)) { using (StreamReader sr = new StreamReader(dstMetaPath)) { while (!sr.EndOfStream) { string line = sr.ReadLine(); if (line.Contains("guid")) { dstMetaGuid = line; } else if (line.Contains("timeCreated")) { dstMetaTime = line; break; } } sr.Close(); } } // Copy meta to destination directory. File.Copy(string.Format("{0}.meta", srcPath), dstMetaPath, true); // Modify meta data. StringBuilder sb = new StringBuilder(); using (StreamReader sr = new StreamReader(dstMetaPath)) { while (!sr.EndOfStream) { string line = sr.ReadLine(); if (line.Contains("guid")) { #if UNITY_2017_1_OR_NEWER sb.AppendLine(dstMetaGuid ?? "guid: " + GUID.Generate().ToString()); #else sb.AppendLine(dstMetaGuid ?? "guid: " + Guid.NewGuid().ToString()); #endif } else if (line.Contains("timeCreated")) { sb.AppendLine(dstMetaTime ?? "timeCreated: " + GetGreenwichTime()); } else { sb.AppendLine(line); } } sr.Close(); } using (StreamWriter sw = new StreamWriter(dstMetaPath)) { sw.Write(sb.ToString()); sw.Close(); } }