public void OnAddButtonPressed() { string propName = addMenuPropDropdown.captionText.text; string spritePath = addMenuOptions[addMenuCategoryDropdown.captionText.text][addMenuPropDropdown.captionText.text]; BattleMapProp prop = BattleMapProp.Create(propName, spritePath); BattleMapProp.selectedProp = prop; OnPropSelected(); }
public void Load(string mapName, Transform mapTransform, bool loadProps) { EnsureDirectoryExists(); string filePath = Application.persistentDataPath + "/BattleMaps/" + mapName + ".battleMap"; if (!File.Exists(filePath)) { Debug.LogWarning("Can't load map; path does not exist: " + filePath); return; } string[] fileData = File.ReadAllLines(filePath); bool mapTransformLoaded = false; bool loadingProps = false; tiles.Clear(); foreach (string dataEntry in fileData) { // The very first entry is the map's transform info... if (!mapTransformLoaded) { string[] data = new string[3]; int dataIndex = -1; for (int i = 0; i < dataEntry.Length; i++) { if (char.IsDigit(dataEntry[i]) || dataEntry[i] == '-' || dataEntry[i] == '.') { if (dataIndex >= data.Length) { Debug.LogError("Error"); } data[dataIndex] += dataEntry[i]; } else { dataIndex++; } } mapTransform.localPosition = new Vector3( float.Parse(data[0]), float.Parse(data[1]), 0f ); float zoom = float.Parse(data[2]); mapTransform.localScale = new Vector3(zoom, zoom, zoom); mapTransformLoaded = true; continue; } // Load data for a tile... if (!loadingProps) { // Switch to prop mode if prompted if (dataEntry == "PROPS") { if (loadProps) { loadingProps = true; } else { return; } } else { string[] data = new string[5]; int dataIndex = -1; for (int i = 0; i < dataEntry.Length; i++) { if (char.IsDigit(dataEntry[i]) || dataEntry[i] == '-') { data[dataIndex] += dataEntry[i]; } else { dataIndex++; } } AddTile(new TileData( int.Parse(data[0]), int.Parse(data[1]), int.Parse(data[2]), (TileData.Type) int.Parse(data[3]), int.Parse(data[4]))); } } // Load data for a prop and add it to the map... else { string[] data = new string[5]; int dataIndex = -1; bool stringMode = false; for (int i = 0; i < dataEntry.Length; i++) { if ((!stringMode && (char.IsDigit(dataEntry[i]) || dataEntry[i] == '-' || dataEntry[i] == '.')) || (stringMode && dataEntry[i] != '\'')) { data[dataIndex] += dataEntry[i]; } else if (dataEntry[i] == '\'') { stringMode = !stringMode; } else { dataIndex++; } } BattleMapProp prop = BattleMapProp.Create(data[0], data[1]); prop.transform.localPosition = new Vector3( float.Parse(data[2]), float.Parse(data[3]), 0f); prop.SetVisibleToPlayers(data[4] == "1"); } } }