public static void AddPath(string path) { #if UNITY_EDITOR //Debug.Log("AddPath TextureBlockMgr."+ path); var _files = System.IO.Directory.GetFiles(System.IO.Path.GetFullPath(path), "sheet*.xml", System.IO.SearchOption.AllDirectories); foreach (var f in _files) { string file = f.ToLower(); var i = file.ToLower().LastIndexOf("resources"); file = file.Substring(i + "resources".Length + 1); var i2 = file.LastIndexOf('.'); file = file.Substring(0, i2); //must be。 remove ext name file = file.Replace('\\', '/'); //must be。 use / symble var tex2 = Resources.Load(file, typeof(TextAsset)) as TextAsset; var tdata = TextureAtlas.CreateFromStringXML(tex2.text); //selectTex = Resources.Load(filename, typeof(Texture2D)) as Texture2D; srcTexs[file] = null; allBlocks[file] = new DetailBlock(); foreach (var s in tdata.sprites) { allBlocks[file].details[s.n.ToLower()] = new Rect((float)s.x / (float)tdata.width, (float)s.y / (float)tdata.height, (float)s.w / (float)tdata.width, (float)s.h / (float)tdata.height); } Debug.Log("Init TextureBlockMgr." + f); } var _filescsv = System.IO.Directory.GetFiles(System.IO.Path.GetFullPath(path), "*.csv.txt", System.IO.SearchOption.AllDirectories); foreach (var f in _filescsv) { string file = f.ToLower(); var i = file.ToLower().LastIndexOf("resources"); file = file.Substring(i + "resources".Length + 1); var i2 = file.LastIndexOf('.'); file = file.Substring(0, i2); //must be。 remove ext name file = file.Replace('\\', '/'); //must be。 use / symble var tex2 = Resources.Load(file, typeof(TextAsset)) as TextAsset; var tdata = TextureAtlas.CreateFromStringCSV(tex2.text); ////selectTex = Resources.Load(filename, typeof(Texture2D)) as Texture2D; var name = file.Split('.')[0]; srcTexs[name] = null; allBlocks[name] = new DetailBlock(); foreach (var s in tdata.sprites) { allBlocks[name].details[s.n.ToLower()] = new Rect((float)s.x / 8192.0f, (float)s.y / 8192.0f, (float)s.w / 8192.0f, (float)s.h / 8192.0f); } //Debug.Log("csv=" + file); } #endif }
static void Load() { var texsdata = Resources.Load(texsfilenameXML, typeof(TextAsset)) as TextAsset; var texs = texsdata.text.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); foreach (var file in texs) { if (file.Contains("sheet")) { var tex2 = Resources.Load(file, typeof(TextAsset)) as TextAsset; var tdata = TextureAtlas.CreateFromStringXML(tex2.text); //selectTex = Resources.Load(filename, typeof(Texture2D)) as Texture2D; srcTexs[file] = null; allBlocks[file] = new DetailBlock(); foreach (var s in tdata.sprites) { allBlocks[file].details[s.n.ToLower()] = new Rect((float)s.x / (float)tdata.width, (float)s.y / (float)tdata.height, (float)s.w / (float)tdata.width, (float)s.h / (float)tdata.height); } } else { var tex2 = Resources.Load(file + ".packet.csv", typeof(TextAsset)) as TextAsset; var tdata = TextureAtlas.CreateFromStringCSV(tex2.text); //selectTex = Resources.Load(filename, typeof(Texture2D)) as Texture2D; srcTexs[file] = null; allBlocks[file] = new DetailBlock(); foreach (var s in tdata.sprites) { allBlocks[file].details[s.n.ToLower()] = new Rect((float)s.x / 8192.0f, (float)s.y / 8192.0f, (float)s.w / 8192.0f, (float)s.h / 8192.0f); } } Debug.Log("add tex=" + file); } }