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 }
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 override void Deserialize(Hashtable map) { triggerType = MapEx.getInt(map, "triggerType"); hideSelf = MapEx.getBool(map, "hideSelf"); talkId = MapEx.getInt(map, "talkId"); npcCfg = MapEx.getString(map, "npcCfg"); boxCfg = MapEx.getString(map, "boxCfg"); }
public static WorldmapEditorCfg parse(Hashtable map) { WorldmapEditorCfg cfg = new WorldmapEditorCfg(); cfg.size = MapEx.getInt(map, "size"); cfg.pageSize = MapEx.getInt(map, "pageSize"); cfg.mapAreaTexturePath = MapEx.getString(map, "mapAreaTexturePath"); cfg.colors4MapAreaJson = MapEx.getString(map, "colors4MapAreaJson"); return(cfg); }
public virtual void Deserialize(Hashtable map) { float x = float.Parse(map ["editorx"].ToString()); float y = float.Parse(map ["editory"].ToString()); editorPosition = new Vector2(x, y); id = MapEx.getInt(map, "id"); desc = MapEx.getString(map, "desc"); index = MapEx.getInt(map, "index"); canMultTimes = MapEx.getBool(map, "canMultTimes"); }
int sortBorrowTimes(object a, object b) { Hashtable m1 = a as Hashtable; Hashtable m2 = b as Hashtable; int ret = 0; if (MapEx.getInt(m1, "times") > MapEx.getInt(m2, "times")) { ret = 1; } else { ret = -1; } return(ret); }
// Calls CaseInsensitiveComparer.Compare with the parameters reversed. int IComparer.Compare(object a, object b) { Hashtable m1 = a as Hashtable; Hashtable m2 = b as Hashtable; int ret = 0; int time1 = MapEx.getInt(m1, "times"); int time2 = MapEx.getInt(m2, "times"); if (time1 < time2) { ret = 1; } else if (time1 == time2) { ret = 0; } else { ret = -1; } return(ret); }
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(); }
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"); }
public override void Deserialize(Hashtable map) { fubenID = MapEx.getInt(map, "fubenID"); }
public BehaviorTree Deserialize() { Hashtable map = JSON.DecodeMap(serializedBehaviorTree); // Behavior Tree BehaviorTree bt = ScriptableObject.CreateInstance <BehaviorTree> (); ArrayList nodes = MapEx.getList(map, "nodes"); string type = ""; Node node = null; //先把所有的node创建好 for (int i = 0; i < nodes.Count; i++) { type = MapEx.getString(nodes [i], "type"); switch (type) { case "Hivemind.Root": node = bt.CreateNode <Root> (); ((Root)node).Deserialize(ListEx.getMap(nodes, i)); bt.SetRoot((Root)node); break; case "Hivemind.NodeAction": node = bt.CreateNode <NodeAction> (); node.Deserialize(ListEx.getMap(nodes, i)); bt.nodes.Add(node); break; case "Hivemind.NodeBranch": node = bt.CreateNode <NodeBranch> (); node.Deserialize(ListEx.getMap(nodes, i)); bt.nodes.Add(node); break; case "Hivemind.NodeTogether": node = bt.CreateNode <NodeTogether> (); node.Deserialize(ListEx.getMap(nodes, i)); bt.nodes.Add(node); break; default: node = bt.CreateNode <Node> (); node.Deserialize(ListEx.getMap(nodes, i)); bt.nodes.Add(node); break; } } // 处理子节点的的关系 for (int i = 0; i < nodes.Count; i++) { node = bt.getNodeByID(MapEx.getInt(nodes [i], "id")); node.DeserializeChildren(ListEx.getMap(nodes, i)); } behaviorTree = bt; return(bt); //============================= // XmlDocument doc = new XmlDocument(); // doc.LoadXml(serializedBehaviorTree); // Behavior Tree // BehaviorTree bt = ScriptableObject.CreateInstance<BehaviorTree>(); // Root // XmlElement rootEl = (XmlElement)doc.GetElementsByTagName ("root").Item (0); // Root root = (Root)DeserializeSubTree (rootEl, bt); // bt.SetRoot (root); // // // Unparented nodes // XmlElement unparentedRoot = (XmlElement)doc.GetElementsByTagName ("unparented").Item (0); // foreach (XmlNode xmlNode in unparentedRoot.ChildNodes) { // XmlElement el = xmlNode as XmlElement; // if (el != null) // DeserializeSubTree (el, bt); // } // // behaviorTree = bt; // return bt; }