// int m_vSlots = 2; // int m_hSlots = 2; public override void OnInspectorGUI() { // Update the serializedProperty - always do this in the beginning of OnInspectorGUI. serializedObject.Update(); #if UNITY_EDITOR EditorGUILayout.Space(); if (GUILayout.Button("Export")) { string filePath = EditorUtility.SaveFilePanel("Save tileset", "", "tileset" + ".json", "json"); if (filePath.Length > 0) { // string json = JsonUtility.ToJson(MyAutoTileset, true); string json = UtilsAON.SerializeObject(this); File.WriteAllText(filePath, json); } } if (GUILayout.Button("Import")) { string filePath = EditorUtility.OpenFilePanel("Load tileset", "", "json"); if (filePath.Length > 0) { var s = File.ReadAllText(filePath); JsonUtility.FromJsonOverwrite(s, target); // AutoTileset obj = JsonUtility.FromJson<AutoTileset>(s); // target = obj; // UtilsAutoTileMap.ImportTexture(MyAutoTileset.AtlasTexture); } } #endif serializedObject.ApplyModifiedProperties(); DrawDefaultInspector(); }
/// <summary> /// Get this object serialized as an xml string /// </summary> /// <returns></returns> // public string GetXmlString() // { // return UtilsSerialize.Serialize<AutoTileMapSerializeData>(this); // } /// <summary> /// Save this object serialized in an xml file /// </summary> /// <param name="_filePath"></param> public void SaveToFile(string _filePath) { #if false //XML var serializer = new XmlSerializer(typeof(AutoTileMapSerializeData)); var stream = new FileStream(_filePath, FileMode.Create); serializer.Serialize(stream, this); stream.Close(); #else //JSON // string json = JsonUtility.ToJson(this, true); string json = UtilsAON.SerializeObject(this); File.WriteAllText(_filePath, json); #endif }
public static void KeyValueOnGUI(Flags flagsYaml, string key, ref float yGui, Rect rect, bool lockKey, List <string> resetList, int index) { int value = flagsYaml.ContainsKey(key) ? flagsYaml[key] : 0; float _w2 = 50; float _w3 = 60; float _wReset = resetList == null ? 0 : 100; float _w = (rect.width - _w2 - _w3 - _wReset - 8) / 2; float xGui = rect.x + 4; AONGUI.Label(new Rect(xGui, yGui + 32 - heighTextField, _w, heighTextField), key); xGui += _w; AONGUI.Label(new Rect(xGui + _w2 / 2, yGui, _w2, 32), "="); xGui += _w2; AONGUI.TextField(new Rect(xGui, yGui + 32 - heighTextField, _w, heighTextField), value.ToString(), 25, (string text) => { flagsYaml[key] = UtilsAON.StrToIntDef(text); }); xGui += _w; if (lockKey == false) { AONGUI.Button(new Rect(xGui, yGui + 32 - heighTextField, _w3, heighTextField), "Remove", () => { flagsYaml.Remove(key); //Check clear cache comboBoxFlags if (_instance != null && _instance.flagsCurrent == flagsYaml) { _instance.ResetCombobox(); } }); } xGui += _w3; if (resetList != null) { if (index == 0) { AONGUI.Label(new Rect(xGui + _wReset - 120, yGui - 18 + DefineAON.GUI_Y_Label, 120, DefineAON.GUI_Height_Label), "Reset when interact"); } bool isReset = resetList.IndexOf(key) >= 0; string v = " Reset"; AONGUI.Toggle(new Rect(xGui + _wReset - 60, yGui + 8 + DefineAON.GUI_Y_Label, 60, DefineAON.GUI_Height_Label), isReset, v, (bool resetNext) => { if (resetNext) { resetList.Add(key); } else { resetList.Remove(key); } }); } // xGui += _wReset; yGui += 32f; }
/// <summary> /// Create map serialized data from xml file /// </summary> /// <param name="_filePath"></param> /// <returns></returns> public static AutoTileMapSerializeData LoadFromFile(string _filePath) { #if false //XML var serializer = new XmlSerializer(typeof(AutoTileMapSerializeData)); var stream = new FileStream(_filePath, FileMode.Open); var obj = serializer.Deserialize(stream) as AutoTileMapSerializeData; stream.Close(); return(obj); #else // JSON // var obj = JsonUtility.FromJson<AutoTileMapSerializeData>(File.ReadAllText(_filePath)); AutoTileMapSerializeData mapData = UtilsAON.DeserializeObject <AutoTileMapSerializeData>(File.ReadAllText(_filePath)); return(mapData); #endif }
public int Copy(int slugIndex) { if (slugIndex < 0 || slugIndex >= data.Count) { return(-1); } var old_key = GetKey(data[slugIndex]); string new_key; int l = old_key.LastIndexOf('_'); if (l < 0 || l == old_key.Length - 1) { new_key = old_key + "_1"; } else { int next_l = old_key.Length - l - 1; string sub_b = old_key.Substring(l + 1, next_l); // int i = int.Parse(sub_b); int i = 0; Int32.TryParse(sub_b, out i); i++; new_key = old_key.Substring(0, l + 1) + i.ToString(); } var o = Keys.IndexOf(new_key); if (o >= 0) { return(o); } var old_value = data[slugIndex]; var n = UtilsAON.DeepCopy(old_value); if (n == null) { return(-1); } var new_value = (T)n; if (new_value == null) { return(-1); } SetKey(new_value, new_key); Add(new_value); return(data.Count - 1); }
private void _importAllFromResource(SerializablePropertys property) { // Pet var petlist = PetsDatabase.Instance.PetList; foreach (var pets in petlist) { var topic = pets.topic; var d = pets.data; foreach (var s in d) { string key = "pet/" + s; var p = property.PropertyBySlug(key); if (p == null) { p = property.Add(key); } p._Type = SerializablePropertys.EType.Pet; p.Name = UtilsAON.NameFormat(s); if (string.IsNullOrEmpty(p.Des)) { p.Des = UtilsAON.DesFormat(s); } p.RefSlug = topic + "/" + s; } } // Outfit // string[] str = AutoTileMap_Editor.Instance.ItemCharData.StrItemList; Item[] item = AutoTileMap_Editor.Instance.ItemCharData.ItemList; foreach (var i in item) { string s = i.SlugGlobal; string key = "outfit/" + s; var p = property.PropertyBySlug(key); if (p == null) { p = property.Add(key); } p._Type = SerializablePropertys.EType.Outfit; p.Name = UtilsAON.NameFormat(i.Slug); if (string.IsNullOrEmpty(p.Des)) { p.Des = UtilsAON.DesFormat(i.Slug); } p.RefSlug = s; } }
public bool LoadDataWorld(string data, bool isIncludeMap) { dataGame = UtilsAON.DeserializeObject <SerializableGame>(data); if (dataGame == null) { return(false); } if (isIncludeMap) { if (dataGame.Map == null || dataGame.Map.Count <= 0) { return(false); } Maps = dataGame.Map; } ApplyRaw(); return(true); }
public string GetDataWorld(bool isIncludeMap) { //Update RawFlag UpdateRaw(); if (isIncludeMap) { dataGame.Map = Maps; } else { dataGame.Map = null; } // string json = JsonUtility.ToJson(dataGame, true); // return json; string json = UtilsAON.SerializeObject(dataGame); return(json); }
private bool OnGuiBot(SerializablePackages packages, SerializablePropertys propertys, List <FlagAction> listFlagAction, TilesetAON tilesetAON, Rect rect) { if (packages == null) { return(false); } float yGui = rect.y + 4; float widthLeft = 250; AONGUI.Label(new Rect(rect.x + 4, yGui + DefineAON.GUI_Y_Label, widthLeft, DefineAON.GUI_Height_Label), "Edit package:"); yGui += 32f; { comboBoxSlug.UpdateListContent(packages.AllKey); comboBoxSlug.Empty = "Not selected"; comboBoxSlug.SelectedItemIndex = slugIndex; comboBoxSlug.Rect.x = rect.x; comboBoxSlug.Rect.y = yGui; comboBoxSlug.Rect.width = widthLeft; comboBoxSlug.Rect.height = 32f; comboBoxSlug.Show(rect.height - yGui, "defause", true, false, (int next) => { slugIndex = next; }); } // if(comboBoxSlug.IsDropDownListVisible){ // return true; // } yGui = rect.y + 4; rect.x = rect.x + widthLeft + 4; if (slugIndex < 0 || slugIndex >= packages.Count) { return(true); } AONGUI.Button(new Rect(rect.x, yGui + DefineAON.GUI_Y_Button, 120, DefineAON.GUI_Height_Button), "Remove by slug", () => { packages.Remove(slugIndex); slugIndex = -1; }); SerializablePackages.Package package = packages.PackageByIndex(slugIndex); AONGUI.Button(new Rect(rect.x + 130, yGui + DefineAON.GUI_Y_Button, 120, DefineAON.GUI_Height_Button), "Duplicate by slug", () => { var n = packages.Copy(slugIndex); if (n >= 0) { slugIndex = n; } }); AONGUI.Button(new Rect(rect.x + 260, yGui + DefineAON.GUI_Y_Button, 100, DefineAON.GUI_Height_Label), "Add all Pets", () => { _addAllPets(package, propertys); }); yGui += 32f; AONGUI.Label(new Rect(rect.x, yGui + DefineAON.GUI_Y_Label, 40, DefineAON.GUI_Height_Label), "Name"); AONGUI.TextField(new Rect(rect.x + 40, yGui + DefineAON.GUI_Y_TextField, widthLeft - 40, DefineAON.GUI_Height_TextField), package.Name, (string text) => { package.Name = text; }); yGui += 32f; AONGUI.Label(new Rect(rect.x, yGui + DefineAON.GUI_Y_Label, 40, DefineAON.GUI_Height_Label), "Des"); AONGUI.TextField(new Rect(rect.x + 40, yGui + DefineAON.GUI_Y_TextField, widthLeft - 40, DefineAON.GUI_Height_TextField), package.Des, (string text) => { package.Des = text; }); yGui += 32f; if (propertys == null || propertys.Count <= 0) { AONGUI.Label(new Rect(rect.x, yGui + DefineAON.GUI_Y_Label, widthLeft, DefineAON.GUI_Height_Label), "Propertys is empty"); return(false); } AONGUI.Label(new Rect(rect.x, yGui + DefineAON.GUI_Y_Label, widthLeft, DefineAON.GUI_Height_Label), "Propertys list:"); yGui += 32f; { comboBoxItem.UpdateListContent(package.data.Keys); comboBoxItem.Empty = "Not selected"; comboBoxItem.SelectedItemIndex = itemIndex; comboBoxItem.Rect.x = rect.x; comboBoxItem.Rect.y = yGui; comboBoxItem.Rect.width = widthLeft; comboBoxItem.Rect.height = 32f; comboBoxItem.Show(rect.height - yGui, "defause", true, true, ( int next) => { itemIndex = next; }); } AONGUI.Button(new Rect(rect.x + widthLeft + 10, yGui + DefineAON.GUI_Y_Button, 30, DefineAON.GUI_Height_Label), " + ", () => { if (itemIndex >= 0 && itemIndex < propertys.Count) { package.AddProperty(propertys.SlugByIndex(itemIndex)); } else { package.AddProperty(propertys.SlugByIndex(0)); } }); if (itemIndex < 0) { return(false); } AONGUI.Button(new Rect(rect.x + widthLeft + 50, yGui + DefineAON.GUI_Y_Button, 30, DefineAON.GUI_Height_Label), " - ", () => { package.Remove(itemIndex); }); if (package.data.Count == 0) { return(false); } if (itemIndex >= package.data.Count) { itemIndex = package.data.Count - 1; return(false); } rect.x = rect.x + widthLeft + 10; yGui += 32f; string slugProperty = package.data[itemIndex].property; { // Pick Property bool isWaitUI = false; PropertysGUI.Instance.PickSlugItem(slugIndex.ToString(), propertys, slugProperty, rect.x, yGui, widthLeft, ref yGui, ref isWaitUI, (string slugPropertyPick) => { package.data[itemIndex].property = slugPropertyPick; package.data.ResetKeys(); }); yGui += 32f; } AONGUI.Label(new Rect(rect.x, yGui + DefineAON.GUI_Y_Label, widthLeft, DefineAON.GUI_Height_Label), "Pay by:"); yGui += 32f; SerializablePackages.PayBy payBy = package.data[itemIndex].payBy; AONGUI.Label(new Rect(rect.x, yGui + DefineAON.GUI_Y_Label, 100, DefineAON.GUI_Height_Label), "Coin"); AONGUI.TextField(new Rect(rect.x + 100, yGui + DefineAON.GUI_Y_Label, widthLeft - 100, DefineAON.GUI_Height_Label), payBy.coin.ToString(), (string text) => { payBy.coin = UtilsAON.StrToIntDef(text); }); yGui += 32f; return(false); }
public static bool OnGUIFlagActionList(ref float yGui, ref bool waitUI, Rect rect, List <FlagAction> flagAction, Flags flagsYaml, GUIStyle backgroundTop) { if (backgroundTop != null) { float height_top = 68; AONGUI.Box(new Rect(rect.x, rect.y, rect.width, height_top), "", backgroundTop); } AONGUI.Label(new Rect(rect.x + 4, yGui + DefineAON.GUI_Y_Label, rect.width, DefineAON.GUI_Height_Label), "Action flag edit :"); yGui += 32f; { //Add Key float xGui = rect.x + 4; AONGUI.Label(new Rect(xGui, yGui + DefineAON.GUI_Y_Label, 90, DefineAON.GUI_Height_Label), "Slug action"); xGui += 94; AONGUI.TextField(new Rect(xGui, yGui + DefineAON.GUI_Y_TextField, 200, DefineAON.GUI_Height_TextField), NameAdd, (string text) => { NameAdd = text; }); xGui += 204; if (NameAdd.Length == 0) { } else { bool isUnique = (IndextFlagAction(flagAction, NameAdd) == -1); if (isUnique) { AONGUI.Button(new Rect(xGui, yGui + DefineAON.GUI_Y_Button, 40, DefineAON.GUI_Height_Button), "Add", () => { flagAction.Add(new FlagAction() { Name = NameAdd }); NameAdd = ""; }); } else { AONGUI.Label(new Rect(xGui, yGui + DefineAON.GUI_Y_Label, 200, DefineAON.GUI_Height_Label), "Slug should be unique"); } } yGui += 32f; } float size_sub_remove = 70; float size_next = 120; float size_o = 80; float size_v = 50; float size_text = (rect.width - size_sub_remove - size_v - size_o - size_next - 8) / 2; for (int k = 0; k < flagAction.Count; k++) { if (k == 0) { yGui += 32f; continue; } float xGui = rect.x + 4; FlagAction f = flagAction[k]; /* * if(k > 0){ * var name_next = GUI.TextField(new Rect(xGui, yGui + DefineAON.GUI_Y_TextField, size_text - 4, DefineAON.GUI_Height_TextField), f.Name, 25); * if(name_next != f.Name){ * f.Name = name_next; * return true; * } * }else{ * GUI.Label(new Rect(xGui, yGui + DefineAON.GUI_Y_TextField, size_text - 4, DefineAON.GUI_Height_TextField), f.Name); * } */ if (k == 1) { AONGUI.Label(new Rect(xGui, yGui - 25, size_next, 24), "Slug:"); } AONGUI.Label(new Rect(xGui, yGui + DefineAON.GUI_Y_TextField, size_text - 4, DefineAON.GUI_Height_TextField), f.Name); xGui += size_text; if (k == 1) { AONGUI.Label(new Rect(xGui, yGui - 25, size_next, 24), "Flag:"); } { var comboBoxFlags = FlagGui.Instance.UpdateFlagsData(flagsYaml, f.Key); int index_key = FlagGui.Instance.IndexOfKey(f.Key); comboBoxFlags.SelectedItemIndex = index_key; comboBoxFlags.Rect.x = xGui; comboBoxFlags.Rect.y = yGui; comboBoxFlags.Rect.width = size_text - 4; comboBoxFlags.Rect.height = 32f; // float limitHeight = rect.height - yGui - 32; float limitHeight = 32 * 6f; comboBoxFlags.Show(limitHeight, k.ToString(), (int flagNext) => { f.Key = FlagGui.Instance.KeyFromIndex(flagNext); }); if (comboBoxFlags.IsDropDownWithHash(k.ToString())) { yGui += limitHeight; waitUI = true; return(false); } } xGui += size_text; { //Operation int current = f.Operation; var comboBoxOperation = ComboBoxHelper.Instance.Operation(); comboBoxOperation.SelectedItemIndex = current; comboBoxOperation.Rect.x = xGui; comboBoxOperation.Rect.y = yGui; comboBoxOperation.Rect.width = size_o - 4; comboBoxOperation.Rect.height = 32f; float limitHeight = 32f * comboBoxOperation.ListContent.Length; comboBoxOperation.Show(limitHeight, k.ToString(), false, (int next) => { f.Operation = next; }); if (comboBoxOperation.IsDropDownWithHash(k.ToString())) { yGui += limitHeight; waitUI = true; return(false); } } float xGuiOperation = xGui; xGui += size_o; bool isHasInputValue = f.Operation < (int)AON.RpgMapEditor.ScriptGui.EOperation.Add_A_B; { if (isHasInputValue) { AONGUI.TextField(new Rect(xGui, yGui + DefineAON.GUI_Y_TextField, size_v - 10, DefineAON.GUI_Height_TextField), f.Value.ToString(), 25, (string text) => { f.Value = UtilsAON.StrToIntDef(text); }); } xGui += size_v; { //Next ( add) Action if (k == 1) { AONGUI.Label(new Rect(xGui + 10, yGui - 25, size_next, 24), "Add action:"); } var combobox = ComboBoxHelper.Instance.FlagAction(flagAction); var hash = k.ToString(); int currentFlagAction = FlagAction.IndextFlagAction(flagAction, f.Next); if (currentFlagAction == -1) { if (f.Next != null && f.Next != "") { combobox.Empty = f.Next + " (not found)"; } else { combobox.Empty = "NULL"; } } combobox.SelectedItemIndex = currentFlagAction; combobox.Rect.x = xGui + 10; combobox.Rect.y = yGui + 2; combobox.Rect.width = size_next - 20; combobox.Rect.height = 32f; float limitHeight = 32f * 6; combobox.Show(limitHeight, hash, (int nextAction) => { f.Next = flagAction[nextAction].Name; }); if (combobox.IsDropDownWithHash(hash)) { yGui += limitHeight; waitUI = true; return(false); } xGui += size_next; } AONGUI.Button(new Rect(xGui, yGui + DefineAON.GUI_Y_Button, size_sub_remove - 4, DefineAON.GUI_Height_Button), "Remove", () => { flagAction.RemoveAt(k); }); } /* * xGui += size_sub_e; * if(GUI.Button( new Rect(xGui, yGui + DefineAON.GUI_Y_Button, size_sub_e - 4, DefineAON.GUI_Height_Button), " + ")){ * FlagAction.Insert(k + 1, new FlagAction()); * return true; * } */ if (!isHasInputValue) { yGui += 32f; // float size_ab = (rect.x + rect.width - xGuiOperation - size_sub_remove) / 2; float size_ab = size_o + size_v; xGui = xGuiOperation; AONGUI.Label(new Rect(xGui - size_text, yGui, size_text, DefineAON.GUI_Height_Label), "= " + AON.RpgMapEditor.ScriptGui.StrEOperation[f.Operation]); AONGUI.Label(new Rect(xGui - 25, yGui, 20, DefineAON.GUI_Height_Label), "a ="); { string hash = "a" + k; var comboBoxFlags = FlagGui.Instance.UpdateFlagsData(flagsYaml, f.KeyA); int index_a = FlagGui.Instance.IndexOfKey(f.KeyA); comboBoxFlags.SelectedItemIndex = index_a; comboBoxFlags.Rect.x = xGui; comboBoxFlags.Rect.y = yGui; comboBoxFlags.Rect.width = size_ab; comboBoxFlags.Rect.height = 32f; // float limitHeight = rect.height - yGui - 32; float limitHeight = 32 * 6f; comboBoxFlags.Show(limitHeight, hash, (int flagNext) => { f.KeyA = FlagGui.Instance.KeyFromIndex(flagNext); }); if (comboBoxFlags.IsDropDownWithHash(hash)) { yGui += limitHeight; waitUI = true; return(false); } } // xGui += size_ab; yGui += 32f; AONGUI.Label(new Rect(xGui - 25, yGui, 20, DefineAON.GUI_Height_Label), "b = "); { string hash = "b" + k; var comboBoxFlags = FlagGui.Instance.UpdateFlagsData(flagsYaml, f.KeyB); int index_b = FlagGui.Instance.IndexOfKey(f.KeyB); comboBoxFlags.SelectedItemIndex = index_b; comboBoxFlags.Rect.x = xGui; comboBoxFlags.Rect.y = yGui; comboBoxFlags.Rect.width = size_ab; comboBoxFlags.Rect.height = 32f; // float limitHeight = rect.height - yGui - 32; float limitHeight = 32 * 6f; comboBoxFlags.Show(limitHeight, hash, (int flagNext) => { f.KeyB = FlagGui.Instance.KeyFromIndex(flagNext); }); if (comboBoxFlags.IsDropDownWithHash(hash)) { yGui += limitHeight; waitUI = true; return(false); } // var if_a_next = GUI.TextField(new Rect(rect.x + xGui, yGui + 32 - heighTextField, _w, heighTextField), if_a, 25); } yGui += 32f; yGui += 16f; } else { yGui += 32f; } } return(false); }