public void updateState(string name) { if (selectedServer == null) { return; } if (mList == null) { return; } Hashtable item = null; for (int i = 0; i < mList.Count; i++) { item = ListEx.getMap(mList, i); if (name.Equals(MapEx.getString(item, "name"))) { // item ["upload"] = true; Hashtable m = MapEx.getMap(item, "upload"); m = m == null ? new Hashtable() : m; m [selectedServer.key] = true; item ["upload"] = m; break; } } string str = JSON.JsonEncode(mList); File.WriteAllText(Application.dataPath + "/" + cfgPath, str); }
public override void Deserialize(Hashtable map) { #if UNITY_EDITOR base.Deserialize(map); begainIndex = MapEx.getInt(map, "begainIndex"); maxIndex = MapEx.getInt(map, "maxIndex"); string actionClass = MapEx.getString(map, "actionClass"); if (string.IsNullOrEmpty(actionClass)) { monoScript = null; } else { monoScript = AssetDatabase.LoadAssetAtPath(actionClass, typeof(MonoScript)) as MonoScript; if (monoScript != null) { Type tp = monoScript.GetClass(); attr = Activator.CreateInstance(tp) as ActionBase; if (attr != null) { attr.Deserialize(MapEx.getMap(map, "attr")); } } } #endif }
static public Hashtable create2Map(string path) { basePath = Application.dataPath + "/"; basePath = basePath.Replace("/Assets/", "/"); replaces.Clear(); replaces.Add(basePath + "Assets/StreamingAssets/"); replaces.Add(basePath + "Assets/Resources/"); replaces.Add(basePath + "Assets/"); path = basePath + path; string lastVerPath = Application.dataPath + "/" + ECLProjectManager.ver4DevelopeMd5; Hashtable lastVerMap = Utl.fileToMap(lastVerPath); if (lastVerMap == null) { lastVerMap = new Hashtable(); } Hashtable lastOtherVer = MapEx.getMap(lastVerMap, "other"); Hashtable lastPriorityVer = MapEx.getMap(lastVerMap, "priority"); Hashtable lastCfgdataVer = MapEx.getMap(lastVerMap, "cfgData"); Hashtable outMap = new Hashtable(); doCreate(path, lastOtherVer, lastPriorityVer, lastCfgdataVer, ref outMap); return(outMap); }
public static void saveMaterialTexCfg(string matName, ArrayList propNames, ArrayList texNames, ArrayList texPaths) { if (propNames == null || propNames.Count <= 0) { Debug.Log("There is no textures"); return; } if (!needSave(matName, propNames, texNames, texPaths)) { return; } Hashtable map = MapEx.getMap(CLMaterialPool.materialTexRefCfg, matName); if (map == null) { map = new Hashtable(); } map ["pp"] = propNames; map ["tn"] = texNames; map ["tp"] = texPaths; CLMaterialPool.materialTexRefCfg [matName] = map; MemoryStream ms = new MemoryStream(); B2OutputStream.writeObject(ms, CLMaterialPool.materialTexRefCfg); Directory.CreateDirectory(Path.GetDirectoryName(CLMaterialPool.materialTexRefCfgPath)); //File.WriteAllBytes (CLMaterialPool.materialTexRefCfgPath, ms.ToArray ()); byte[] bytes = ms.ToArray(); FileStream fs = new FileStream(CLMaterialPool.materialTexRefCfgPath, FileMode.OpenOrCreate); fs.Write(bytes, 0, bytes.Length); fs.Close(); }
int CompareSprite2(Hashtable a, Hashtable b) { // A is null b is not b is greater so put it at the front of the list if (a == null && b != null) { return(1); } // A is not null b is null a is greater so put it at the front of the list if (a != null && b == null) { return(-1); } Hashtable d1 = MapEx.getMap(a, "data"); Hashtable d2 = MapEx.getMap(b, "data"); // Get the total pixels used for each sprite int w = MapEx.getInt(d1, "width"); int h = MapEx.getInt(d1, "height"); int aPixels = w > h ? w : h; w = MapEx.getInt(d2, "width"); h = MapEx.getInt(d2, "height"); int bPixels = w > h ? w : h; if (aPixels > bPixels) { return(-1); } else if (aPixels < bPixels) { return(1); } return(0); }
public static bool needSave(string matName, ArrayList propNames, ArrayList texNames, ArrayList texPaths) { if (propNames == null || propNames.Count <= 0) { Debug.Log("There is no textures"); return(false); } //Debug.Log("matName===" + matName); Hashtable map = MapEx.getMap(CLMaterialPool.materialTexRefCfg, matName); if (map == null) { return(true); } ArrayList _propNames = MapEx.getList(map, "pp"); ArrayList _texNames = MapEx.getList(map, "tn"); ArrayList _texPaths = MapEx.getList(map, "tp"); if (!arrayList2Str(_propNames).Equals(arrayList2Str(propNames)) || !arrayList2Str(_texNames).Equals(arrayList2Str(texNames)) || !arrayList2Str(_texPaths).Equals(arrayList2Str(texPaths))) { return(true); } return(false); }
public bool isUploaded(Hashtable item) { if (selectedServer == null) { return(false); } Hashtable m = MapEx.getMap(item, "upload"); return(MapEx.getBool(m, selectedServer.key)); }
public void onGetUpgradePkg(params object[] paras) { string oldMd5 = ""; Hashtable d = paras [0] as Hashtable; ArrayList orgsList = paras [1] as ArrayList; string key = orgsList [0] as string; string platform = orgsList [1] as string; Hashtable server = MapEx.getMap(servers, key); string verKey = ""; string vetType = "1"; if (platform.Equals("ios")) { verKey = "iosversion"; vetType = "1"; } else if (platform.Equals("Android")) { verKey = "androidversion"; vetType = "2"; } else if (platform.Equals("win")) { verKey = "winversion"; vetType = "3"; } else if (platform.Equals("osx")) { verKey = "osxversion"; vetType = "4"; } oldMd5 = MapEx.getString(server, verKey); string newMd5 = MapEx.getString(d, "md5"); if (!newMd5.Equals(oldMd5)) { if (EditorUtility.DisplayDialog("Alert", "Really want to upgrade this server!!", "Okay", "Cancel")) { server [verKey] = newMd5; server ["pkgName"] = MapEx.getString(d, "name"); server ["pkgRemark"] = MapEx.getString(d, "remark"); servers [key] = server; saveData(MapEx.getString(server, "idx"), newMd5, vetType); } } }
void showCellSprite(Hashtable m) { Hashtable d = MapEx.getMap(m, "data"); Texture tex = ECLEditorUtl.getObjectByPath(MapEx.getString(d, "path")) as Texture; if (tex == null) { return; } // NGUIEditorTools.DrawTiledTexture (rect, NGUIEditorTools.backdropTexture); Rect uv = new Rect(MapEx.getInt(d, "x"), MapEx.getInt(d, "y"), MapEx.getInt(d, "width"), MapEx.getInt(d, "height")); uv = NGUIMath.ConvertToTexCoords(uv, tex.width, tex.height); float scaleX = rect.width / uv.width; float scaleY = rect.height / uv.height; // Stretch the sprite so that it will appear proper float aspect = (scaleY / scaleX) / ((float)tex.height / tex.width); Rect clipRect = rect; if (aspect != 1f) { if (aspect < 1f) { // The sprite is taller than it is wider float padding = cellSize * (1f - aspect) * 0.5f; clipRect.xMin += padding; clipRect.xMax -= padding; } else { // The sprite is wider than it is taller float padding = cellSize * (1f - 1f / aspect) * 0.5f; clipRect.yMin += padding; clipRect.yMax -= padding; } } if (GUI.Button(rect, "")) { mSelectedSprite = MapEx.getString(d, "name"); isShowParckerView = false; currSelectSprite = m; } GUI.DrawTextureWithTexCoords(clipRect, tex, uv); // Draw the selection if (mSelectedSprite == MapEx.getString(d, "name")) { NGUIEditorTools.DrawOutline(rect, new Color(0.4f, 1f, 0f, 1f)); } GUI.backgroundColor = new Color(1f, 1f, 1f, 0.5f); GUI.contentColor = new Color(1f, 1f, 1f, 0.7f); GUI.Label(new Rect(rect.x, rect.y + rect.height, rect.width, 32f), MapEx.getString(d, "name"), "ProgressBarBack"); GUI.contentColor = Color.white; GUI.backgroundColor = Color.white; GUILayout.Space(cellSize + 30); //这句主要目的是为了可以滑动 rect.y += (cellSize + 30); }
void showSpriteInfor() { if (currSelectSprite == null) { return; } Hashtable d = MapEx.getMap(currSelectSprite, "data"); int times = MapEx.getInt(currSelectSprite, "times"); string name = MapEx.getString(d, "name"); string path = MapEx.getString(d, "path"); int x = MapEx.getInt(d, "x"); int y = MapEx.getInt(d, "y"); int width = MapEx.getInt(d, "width"); int height = MapEx.getInt(d, "height"); int borderLeft = MapEx.getInt(d, "borderLeft"); int borderRight = MapEx.getInt(d, "borderRight"); int borderTop = MapEx.getInt(d, "borderTop"); int borderBottom = MapEx.getInt(d, "borderBottom"); int paddingLeft = MapEx.getInt(d, "paddingLeft"); int paddingRight = MapEx.getInt(d, "paddingRight"); int paddingTop = MapEx.getInt(d, "paddingTop"); int paddingBottom = MapEx.getInt(d, "paddingBottom"); Hashtable atlas = MapEx.getMap(currSelectSprite, "atlas"); string atlasStr = ""; foreach (DictionaryEntry item in atlas) { atlasStr = PStr.b().a(atlasStr).a(",").a(item.Key.ToString()).e(); } Texture tex = ECLEditorUtl.getObjectByPath(path) as Texture; Rect r = Rect.zero; if (tex != null) { float h = 0; float w = position.width - 160; float rate = w / tex.width; if (rate < 1) { h = tex.height * rate; } else { h = tex.height; } h = h > 200 ? h : 200; r = new Rect(0, 0, NumEx.getIntPart(w), NumEx.getIntPart(h)); GUI.DrawTexture(r, tex, ScaleMode.ScaleToFit); GUILayout.Space(r.height + r.y); //这句主要目的是为了可以滑动 } else { r = new Rect(0, 0, position.width - 160, 100); GUILayout.Space(r.height + r.y); //这句主要目的是为了可以滑动 } GUILayout.Space(10); ECLEditorUtl.BeginContents(); { EditorGUILayout.BeginHorizontal(); { EditorGUILayout.TextField("name", name); EditorGUILayout.IntField("times", times); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.IntField("x", x); EditorGUILayout.IntField("y", y); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.IntField("width", width); EditorGUILayout.IntField("height", height); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.IntField("borderLeft", borderLeft); EditorGUILayout.IntField("borderRight", borderRight); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.IntField("borderTop", borderTop); EditorGUILayout.IntField("borderBottom", borderBottom); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.IntField("paddingLeft", paddingLeft); EditorGUILayout.IntField("paddingRight", paddingRight); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.IntField("paddingTop", paddingTop); EditorGUILayout.IntField("paddingBottom", paddingBottom); } EditorGUILayout.EndHorizontal(); EditorGUILayout.TextField("path", path); EditorGUILayout.TextField("Atlas", atlasStr); } ECLEditorUtl.EndContents(); }
bool packTextures(int maxSize, bool unityPacking) //, ref ArrayList outSprites, ref Rect[] rects) { if (packTex != null) { DestroyImmediate(packTex, true); packTex = null; } refreshSelectedCount(); if (selectedCount == 0) { Debug.LogError("Please select some sprites, that need packe"); return(false); } packSprites.Clear(); List <Texture2D> listTexs = new List <Texture2D> (); for (int i = 0; i < mSpriteList.Count; i++) { Hashtable m = mSpriteList [i] as Hashtable; if (MapEx.getBool(m, "selected")) { Hashtable d = MapEx.getMap(m, "data"); string name = MapEx.getString(d, "name"); string path = MapEx.getString(d, "path"); Texture2D tex = ECLEditorUtl.getObjectByPath(path) as Texture2D; listTexs.Add(tex); packSprites.Add(m); } } if (sortSprite != SortSprite.none) { if (sortSprite == SortSprite.SortArea) { packSprites.Sort(CompareSprite); } else { packSprites.Sort(CompareSprite2); } listTexs.Clear(); for (int i = 0; i < packSprites.Count; i++) { Hashtable d = MapEx.getMap(packSprites [i], "data"); string path = MapEx.getString(d, "path"); setTextureReadable("Assets/" + path, TextureImporterFormat.RGBA32, TextureImporterCompression.Uncompressed, true); Texture2D tex = ECLEditorUtl.getObjectByPath(path) as Texture2D; listTexs.Add(tex); } } // for (int i = 0; i < listTexs.Count; i++) { // setTextureReadable (listTexs [i] as Texture, TextureImporterFormat.RGBA32, TextureImporterCompression.Uncompressed, true); // } packTex = new Texture2D(1, 1, TextureFormat.ARGB32, false); if (unityPacking) { packRects = packTex.PackTextures(listTexs.ToArray(), NGUISettings.atlasPadding, maxSize); } else { packRects = UITexturePacker.PackTextures(packTex, listTexs.ToArray(), 4, 4, NGUISettings.atlasPadding, maxSize); } _empty = new Texture2D(packTex.width, packTex.height, TextureFormat.ARGB32, false); bool ret = true; for (int i = 0; i < listTexs.Count; ++i) { Rect rect = NGUIMath.ConvertToPixels(packRects [i], packTex.width, packTex.height, true); packRects [i] = rect; // Apparently Unity can take the liberty of destroying temporary textures without any warning if (listTexs [i] == null) { Debug.LogWarning("Apparently Unity can take the liberty of destroying temporary textures without any warning"); ret = false; break; } // Make sure that we don't shrink the textures if (Mathf.RoundToInt(rect.width) != listTexs [i].width) { Debug.LogError(rect.width + "====" + listTexs [i].width); Debug.LogWarning("Make sure that we don't shrink the textures=" + listTexs [i].name); ret = false; break; } } // for (int i = 0; i < listTexs.Count; i++) { // setTextureReadable (listTexs [i] as Texture, TextureImporterFormat.Automatic, false); // } return(ret); }
void applyPackTexture(int maxSize, bool unityPacking) { string texturePath = EditorUtility.OpenFolderPanel("Save packed texture", Application.dataPath + "/" + CLPathCfg.self.basePath + "/upgradeRes4Dev/other", ""); if (string.IsNullOrEmpty(texturePath)) { return; } if (packTex == null || packRects == null || packRects.Length == 0 || packSprites == null || packSprites.Count == 0 || packRects.Length != packSprites.Count) { packTextures(maxSize, isUseUnityPacking); } string packTextureFile = Path.Combine(texturePath, packedName + ".png"); string packTextureFile4Atlas = packTextureFile.Replace(Application.dataPath + "/", ""); Debug.LogWarning(packTextureFile4Atlas); byte[] bytes = packTex.EncodeToPNG(); Directory.CreateDirectory(Path.GetDirectoryName(packTextureFile)); File.WriteAllBytes(packTextureFile, bytes); AssetDatabase.ImportAsset("Assets/" + packTextureFile4Atlas); TextureImporter textureImporter = AssetImporter.GetAtPath("Assets/" + packTextureFile4Atlas) as TextureImporter; textureImporter.textureType = TextureImporterType.GUI; textureImporter.mipmapEnabled = false; textureImporter.wrapMode = TextureWrapMode.Clamp; textureImporter.alphaIsTransparency = true; textureImporter.npotScale = TextureImporterNPOTScale.None; textureImporter.filterMode = FilterMode.Trilinear; //改成这种模式好像更省内存 AssetDatabase.ImportAsset("Assets/" + packTextureFile4Atlas); Hashtable m = null; Hashtable d = null; Hashtable atlasMap = null; UIAtlas atlas = null; UISpriteData spData = null; Rect _rect; for (int i = 0; i < packSprites.Count; i++) { m = packSprites [i] as Hashtable; _rect = packRects [i]; d = MapEx.getMap(m, "data"); atlasMap = MapEx.getMap(m, "atlas"); foreach (DictionaryEntry item in atlasMap) { atlas = getAtlasByName(item.Key.ToString()); if (atlas == null) { Debug.LogError("Get atlas is null!!==" + item.Key); continue; } // spData = atlas.GetSprite (MapEx.getString (d, "name")); string spName = MapEx.getString(d, "name"); if (!atlas.spriteMap.ContainsKey(spName)) { Debug.LogError("atlas.GetSprite is null!!==" + spName); continue; } int index = MapEx.getInt(atlas.spriteMap, spName); spData = atlas.spriteList [index]; if (spData == null) { Debug.LogError("atlas.GetSprite is null!!==" + spName); continue; } string toPath = texturePath + "/" + spData.path.Replace(CLPathCfg.self.basePath + "/upgradeRes4Dev/other/", ""); Directory.CreateDirectory(Path.GetDirectoryName(toPath)); toPath = toPath.Replace(Application.dataPath + "/", ""); AssetDatabase.ImportAsset(Path.GetDirectoryName("Assets/" + toPath)); string err = AssetDatabase.MoveAsset("Assets/" + spData.path, "Assets/" + toPath); if (!string.IsNullOrEmpty(err)) { Debug.LogError(err); } if (removePublishRes) { string fromPath = Path.GetDirectoryName(spData.path) + "/Android/" + Path.GetFileNameWithoutExtension(spData.path) + ".unity3d"; fromPath = fromPath.Replace("/upgradeRes4Dev/", "/upgradeRes4Publish/"); if (File.Exists(Application.dataPath + "/" + fromPath)) { File.Delete(Application.dataPath + "/" + fromPath); } fromPath = Path.GetDirectoryName(spData.path) + "/IOS/" + Path.GetFileNameWithoutExtension(spData.path) + ".unity3d"; fromPath = fromPath.Replace("/upgradeRes4Dev/", "/upgradeRes4Publish/"); if (File.Exists(Application.dataPath + "/" + fromPath)) { File.Delete(Application.dataPath + "/" + fromPath); } } spData.path = packTextureFile4Atlas; spData.x = Mathf.RoundToInt(_rect.x); spData.y = Mathf.RoundToInt(_rect.y); EditorUtility.SetDirty(atlas.gameObject); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(atlas.gameObject)); } } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport); EditorUtility.DisplayDialog("success", "Finished!", "Okay"); }
void showPackerView() { if (packTex != null) { //================= float h = 0; float w = position.width - 160; float rate = w / packTex.width; if (rate < 1) { h = packTex.height * rate; } else { h = packTex.height; } h = h > 512 ? h : 512; Rect r = new Rect(0, 0, NumEx.getIntPart(w), NumEx.getIntPart(h)); NGUIEditorTools.DrawTiledTexture(r, NGUIEditorTools.backdropTexture); if (isShowParckerTextureBg) { GUI.DrawTexture(r, _empty, ScaleMode.ScaleToFit, false); } GUI.DrawTexture(r, packTex, ScaleMode.ScaleToFit); GUILayout.Space(r.height + r.y); //这句主要目的是为了可以滑动 ECLEditorUtl.BeginContents(); { EditorGUILayout.BeginHorizontal(); { EditorGUILayout.IntField("width", packTex.width); EditorGUILayout.IntField("height", packTex.height); } EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Show/Hide Detail")) { showDeltail = !showDeltail; } if (showDeltail) { if (packSprites != null) { Hashtable m = null; Hashtable d = null; Rect _rect; for (int i = 0; i < packSprites.Count; i++) { _rect = packRects [i]; m = packSprites [i] as Hashtable; d = MapEx.getMap(m, "data"); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.LabelField(MapEx.getString(d, "name")); EditorGUILayout.LabelField(Mathf.RoundToInt(_rect.x) + "x" + Mathf.RoundToInt(_rect.y)); EditorGUILayout.LabelField(Mathf.RoundToInt(_rect.width) + "x" + Mathf.RoundToInt(_rect.height)); } EditorGUILayout.EndHorizontal(); } } } } ECLEditorUtl.EndContents(); } isShowParckerTextureBg = EditorGUILayout.ToggleLeft("Show Background", isShowParckerTextureBg); textureSize = (PackerTextureSize)EditorGUILayout.EnumPopup("", textureSize); isUseUnityPacking = EditorGUILayout.ToggleLeft("UnityPacking", isUseUnityPacking); sortSprite = (SortSprite)EditorGUILayout.EnumPopup("", sortSprite); GUILayout.Space(5); GUI.color = Color.yellow; if (GUILayout.Button("Review Pack Texture")) { if (!packTextures((int)textureSize, isUseUnityPacking)) { Debug.LogError("Some errors happened!"); } } GUI.color = Color.white; GUILayout.Space(10); ECLEditorUtl.BeginContents(); { packedName = EditorGUILayout.TextField("Packed Texture Name", string.IsNullOrEmpty(packedName) ? "Packed" + (int)packerSize : packedName); GUI.color = Color.red; removePublishRes = EditorGUILayout.ToggleLeft("Remove Publish AssetsBundle", removePublishRes); if (GUILayout.Button("Apply Pack Texture")) { applyPackTexture((int)textureSize, isUseUnityPacking); } GUI.color = Color.white; } ECLEditorUtl.EndContents(); }