public override bool IsPassable() { AutoTileMap autoTileMap = AutoTileMap.Instance; if (autoTileMap.IsValidAutoTilePos(TileX, TileY)) { for (int iLayer = autoTileMap.GetLayerCount() - 1; iLayer >= 0; --iLayer) { if (autoTileMap.MapLayers[iLayer].LayerType == eLayerType.Ground) { AutoTile autoTile = autoTileMap.GetAutoTile(TileX, TileY, iLayer); eTileCollisionType collType = autoTile.Id >= 0 ? autoTileMap.Tileset.AutotileCollType[autoTile.Id] : eTileCollisionType.EMPTY; if (IsEmptyTilePassable && collType == eTileCollisionType.EMPTY || collType == eTileCollisionType.PASSABLE || collType == eTileCollisionType.WALL) { return(true); } else if (collType == eTileCollisionType.BLOCK || collType == eTileCollisionType.FENCE) { return(false); } } } } return(false); }
public void CopyRelative(AutoTileMap _autoTileMap, TileAction _action, int tile_x, int tile_y) { foreach (TileData tileData in _action.aTileData) { Push(_autoTileMap, tileData.Tile_x + tile_x, tileData.Tile_y + tile_y, tileData.Tile_type, tileData.Tile_layer); } }
public void Init() { m_autoTileMap = GetComponent <AutoTileMap>(); if (m_autoTileMap != null && m_autoTileMap.IsInitialized) { m_isInitialized = true; if (m_autoTileMap.ViewCamera == null) { Debug.LogWarning("AutoTileMap has no ViewCamera set. Camera.main will be set as ViewCamera"); m_autoTileMap.ViewCamera = Camera.main; } m_camera2D = m_autoTileMap.ViewCamera.GetComponent <Camera2DController>(); if (m_camera2D == null) { m_camera2D = m_autoTileMap.ViewCamera.gameObject.AddComponent <Camera2DController>(); } //MinimapEnabled // m_autoTileMap.BrushGizmo.gameObject.SetActive(true); m_autoTileMap.RefreshMinimapTexture(); } }
void Awake() { //hideFlags = HideFlags.HideInInspector; MyAutoTileMap = GetComponent <AutoTileMap>(); OnRenderObject(); }
public void DoAction(AutoTileMap _autoTileMap) { int tileMinX = _autoTileMap.MapTileWidth - 1; int tileMinY = _autoTileMap.MapTileHeight - 1; int tileMaxX = 0; int tileMaxY = 0; for (int i = 0; i < aTileData.Count; ++i) { TileData tileData = aTileData[i]; // save prev tile type for undo action tileData.Tile_type_prev = _autoTileMap.GetAutoTile(tileData.Tile_x, tileData.Tile_y, tileData.Tile_layer).Id; _autoTileMap.SetAutoTile(tileData.Tile_x, tileData.Tile_y, tileData.Tile_type, tileData.Tile_layer); tileMinX = Mathf.Min(tileMinX, tileData.Tile_x); tileMinY = Mathf.Min(tileMinY, tileData.Tile_y); tileMaxX = Mathf.Max(tileMaxX, tileData.Tile_x); tileMaxY = Mathf.Max(tileMaxY, tileData.Tile_y); } if (_autoTileMap.BrushGizmo.IsRefreshMinimapEnabled) { _autoTileMap.RefreshMinimapTexture(tileMinX, tileMinY, (tileMaxX - tileMinX) + 1, (tileMaxY - tileMinY) + 1); } _autoTileMap.UpdateChunks(); }
private void _applyFixVersionBelow124(AutoTileMap _autoTileMap) { for (int iLayer = 0; iLayer < TileData.Count; ++iLayer) { TileLayer tileData = TileData[iLayer]; tileData.Visible = true; switch (iLayer) { case 0: tileData.Name = "Ground"; tileData.LayerType = eLayerType.Ground; tileData.Depth = 1f; break; case 1: tileData.Name = "Ground Overlay"; tileData.LayerType = eLayerType.Ground; tileData.Depth = 0.5f; break; case 2: tileData.Name = "Overlay"; tileData.LayerType = eLayerType.Overlay; tileData.Depth = -1f; break; } } }
public ComboBox MapList(AutoTileMap autoTileMap) { if (_mapList == null) { UpdateDataMapList(autoTileMap); } return(_mapList); }
public ComboBox InteriorList(AutoTileMap autoTileMap) { if (_interiorList == null) { var modelList = autoTileMap.Tileset.InteriorList; _interiorList = ComboBox.CreateComboBox(0, modelList, "Pick model interior..."); } return(_interiorList); }
public ComboBox AnimationNPC(AutoTileMap autoTileMap) { if (_AnimationNPC == null) { var modelList = autoTileMap.Tileset.NPCModel; _AnimationNPC = ComboBox.CreateComboBox(0, modelList, "Pick model NPC..."); } return(_AnimationNPC); }
public ComboBox NPCModel(AutoTileMap autoTileMap) { if (_NPCModel == null) { var modelList = autoTileMap.Tileset.NPCModel; _NPCModel = ComboBox.CreateComboBox(0, modelList, "Pick model NPC..."); } return(_NPCModel); }
public ComboBox HouseListModel(AutoTileMap autoTileMap) { if (_houseListModel == null) { var modelList = autoTileMap.Tileset.HouseList; _houseListModel = ComboBox.CreateComboBox(0, modelList, "Pick model house..."); } return(_houseListModel); }
public void UpdateDataMapList(AutoTileMap autoTileMap) { var data = autoTileMap.MapsData.Maps; var comboBoxMapList = new GUIContent[data.Count]; for (int i = 0; i < data.Count; ++i) { comboBoxMapList[i] = new GUIContent("Map: " + i.ToString()); } _mapList = new ComboBox(new Rect(0, 0, 150, 20), comboBoxMapList); }
/// <summary> /// Configure this chunk /// </summary> /// <param name="autoTileMap"></param> /// <param name="layer"></param> /// <param name="startTileX"></param> /// <param name="startTileY"></param> /// <param name="tileChunkWidth"></param> /// <param name="tileChunkHeight"></param> public void Configure(AutoTileMap autoTileMap, int layer, int startTileX, int startTileY, int tileChunkWidth, int tileChunkHeight) { MyAutoTileMap = autoTileMap; TileWidth = tileChunkWidth; TileHeight = tileChunkHeight; MapLayerIdx = layer; StartTileX = startTileX; StartTileY = startTileY; transform.gameObject.name = "TileChunk" + startTileX + "" + startTileY; Vector3 vPosition = new Vector3(); vPosition.x = startTileX * MyAutoTileMap.Tileset.TileWorldWidth; vPosition.y = -startTileY * MyAutoTileMap.Tileset.TileWorldHeight; transform.localPosition = vPosition; MeshRenderer meshRenderer = GetComponent <MeshRenderer>(); if (meshRenderer == null) { meshRenderer = transform.gameObject.AddComponent <MeshRenderer>(); } if (autoTileMap.MapLayers[layer].LayerType == AutoTileMap.eLayerType.FogOfWar) { if (s_fogOfWarMaterial == null) { s_fogOfWarMaterial = new Material(Shader.Find("Sprites/Default")); Texture2D fogOfWarTexture = new Texture2D(1, 1); fogOfWarTexture.SetPixel(0, 0, Color.gray); fogOfWarTexture.Apply(); s_fogOfWarMaterial.SetTexture(0, fogOfWarTexture); } meshRenderer.sharedMaterial = s_fogOfWarMaterial; } else { meshRenderer.sharedMaterial = MyAutoTileMap.Tileset.AtlasMaterial; } #if UNITY_5_0 || UNITY_5_1 meshRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; #else meshRenderer.castShadows = false; #endif meshRenderer.receiveShadows = false; m_meshFilter = GetComponent <MeshFilter>(); if (m_meshFilter == null) { m_meshFilter = transform.gameObject.AddComponent <MeshFilter>(); } }
public ComboBox Filer3DList(AutoTileMap autoTileMap, int idRef) { if (_filer3DIdRef != idRef) { _filer3DIdRef = idRef; _filer3DList = null; } if (_filer3DList == null) { var modelList = autoTileMap.Tileset.Filer3DListByIdRef(idRef); _filer3DList = ComboBox.CreateComboBox(0, modelList, "Pick model filler..."); } return(_filer3DList); }
/* * void DoKeepInsideMapBounds() * { * float fPad = 4f; * float fScrollBarWidth = 16f; * float tilesWidth = 32 * 8; * float minimapRectW = tilesWidth + 2 * fPad + fScrollBarWidth; * * Rect rCamera = new Rect(); * rCamera.width = (Screen.width - minimapRectW) / (PixelToUnits * Zoom); * rCamera.height = Screen.height / (PixelToUnits * Zoom); * var p = Camera.transform.position; * float offsetX = (minimapRectW / (PixelToUnits * Zoom)); * p.x = p.x - offsetX *0.5f; * rCamera.center = p; * * Rect rMap = new Rect(); * AutoTileMap autoTileMap = CreativeSpore.RpgMapEditor.AutoTileMap_Editor.Instance; * rMap.width = autoTileMap.MapTileWidth * autoTileMap.CellSize.x; * rMap.height = autoTileMap.MapTileHeight * autoTileMap.CellSize.y; * rMap.x = autoTileMap.transform.position.x; * rMap.y = autoTileMap.transform.position.y; * * rMap.y -= rMap.height; * * Vector3 vOffset = Vector3.zero; * * // CreativeSpore.RpgMapEditor.RpgMapHelper.DebugDrawRect(Vector3.zero, rCamera, Color.cyan); * // CreativeSpore.RpgMapEditor.RpgMapHelper.DebugDrawRect(Vector3.zero, rMap, Color.green); * // if(rMap.width <= rCamera.width && rMap.height <= rCamera.height) * // return; * float right = (rCamera.x < rMap.x) ? rMap.x - rCamera.x : 0; * float left = (rCamera.xMax > rMap.xMax) ? rMap.xMax - rCamera.xMax : 0; * float down = (rCamera.y < rMap.y) ? rMap.y - rCamera.y : 0f; * float up = (rCamera.yMax > rMap.yMax) ? rMap.yMax - rCamera.yMax : 0f; * if(right == 0 || left == 0) * vOffset.x = (right != 0f && left != 0f) ? rMap.center.x - Camera.transform.position.x : right + left; * if(down == 0 || up == 0) * vOffset.y = (down != 0f && up != 0f) ? rMap.center.y - Camera.transform.position.y : up + down; * * Camera.transform.position += vOffset; * m_vCamRealPos += vOffset; * } */ void DoKeepInsideMapBoundsAdd1Cell() { float fPad = 4f; float fScrollBarWidth = 16f; float tilesWidth = 32 * 8; float minimapRectW = tilesWidth + 2 * fPad + fScrollBarWidth; Rect rCamera = new Rect(); rCamera.width = (Screen.width - minimapRectW) / (PixelToUnits * Zoom); rCamera.height = Screen.height / (PixelToUnits * Zoom); var p = Camera.transform.position; float offsetX = (minimapRectW / (PixelToUnits * Zoom)); p.x = p.x - offsetX * 0.5f; rCamera.center = p; Rect rMap = new Rect(); AutoTileMap autoTileMap = RpgMapEditor.AutoTileMap_Editor.Instance; rMap.width = autoTileMap.MapTileWidth * autoTileMap.CellSize.x + 2; rMap.height = autoTileMap.MapTileHeight * autoTileMap.CellSize.y + 2; rMap.x = autoTileMap.transform.position.x - 1; rMap.y = autoTileMap.transform.position.y + 1; rMap.y -= rMap.height; Vector3 vOffset = Vector3.zero; // CreativeSpore.RpgMapEditor.RpgMapHelper.DebugDrawRect(Vector3.zero, rCamera, Color.cyan); // CreativeSpore.RpgMapEditor.RpgMapHelper.DebugDrawRect(Vector3.zero, rMap, Color.green); // if(rMap.width <= rCamera.width && rMap.height <= rCamera.height) // return; float right = (rCamera.x < rMap.x) ? rMap.x - rCamera.x : 0; float left = (rCamera.xMax > rMap.xMax) ? rMap.xMax - rCamera.xMax : 0; float down = (rCamera.y < rMap.y) ? rMap.y - rCamera.y : 0f; float up = (rCamera.yMax > rMap.yMax) ? rMap.yMax - rCamera.yMax : 0f; if (right == 0 || left == 0) { vOffset.x = (right != 0f && left != 0f) ? rMap.center.x - Camera.transform.position.x : right + left; } if (down == 0 || up == 0) { vOffset.y = (down != 0f && up != 0f) ? rMap.center.y - Camera.transform.position.y : up + down; } Camera.transform.position += vOffset; m_vCamRealPos += vOffset; }
// special case for walls bool _IsWallPassable(MapTileNode neighNode) { AutoTileMap autoTileMap = AutoTileMap.Instance; eTileCollisionType collType = eTileCollisionType.EMPTY; eTileCollisionType collTypeNeigh = eTileCollisionType.EMPTY; for (int iLayer = autoTileMap.GetLayerCount() - 1; iLayer >= 0; --iLayer) { if (autoTileMap.MapLayers[iLayer].LayerType == eLayerType.Ground) { AutoTile autoTile = autoTileMap.GetAutoTile(TileX, TileY, iLayer); AutoTile autoTileNeigh = autoTileMap.GetAutoTile(neighNode.TileX, neighNode.TileY, iLayer); if (autoTile.Id == autoTileNeigh.Id) // you can walk over two wall tiles if they have the same type { if (autoTile.Id >= 0) { return(true); } else { continue; } } else { // collType will keep the first collision type found of type wall or passable if (collType != eTileCollisionType.PASSABLE && collType != eTileCollisionType.WALL) { collType = autoTile.Id >= 0 ? autoTileMap.Tileset.AutotileCollType[autoTile.Id] : eTileCollisionType.EMPTY; } if (collTypeNeigh != eTileCollisionType.PASSABLE && collTypeNeigh != eTileCollisionType.WALL) { collTypeNeigh = autoTileNeigh.Id >= 0 ? autoTileMap.Tileset.AutotileCollType[autoTileNeigh.Id] : eTileCollisionType.EMPTY; } if (collType == eTileCollisionType.PASSABLE && collTypeNeigh == eTileCollisionType.PASSABLE) { return(true); } else if (collType == eTileCollisionType.WALL || collTypeNeigh == eTileCollisionType.WALL) { return(false); } } } } return(true); }
public void Initialize(AutoTileMap autoTileMap) { /* * m_autoTileMap = autoTileMap; * IsShowArt = true; * if(rs0 == null){ * var art = transform.Find("art"); * if(art != null){ * rs0 = art.GetComponentsInChildren<Renderer>(false).ToArray (); * } * } */ // rs0 = transform.GetComponentsInChildren<Renderer>(false).Where( // x => x.gameObject.GetComponent<Light>() == null // ).ToArray (); }
public void Configure(AutoTileMap autoTileMap, int layer, int startTileX, int startTileY, int tileChunkWidth, int tileChunkHeight) { MyAutoTileMap = autoTileMap; TileWidth = tileChunkWidth; TileHeight = tileChunkHeight; MapLayerIdx = layer; StartTileX = startTileX; StartTileY = startTileY; // transform.gameObject.name = "TileChunk_"+startTileX+"_"+startTileY; // Vector3 vPosition = new Vector3(); // vPosition.x = startTileX * MyAutoTileMap.CellSize.x; // vPosition.y = -startTileY * MyAutoTileMap.CellSize.y; // transform.localPosition = vPosition; }
public bool WarpOnGUI(Warps warp, Rect rect, AutoTileMap autoTileMap, TilesetAON tilesetAON) { bool hasUpdateUI = false; float left = 80f; // Input Name float yGui = rect.y + 8f; AONGUI.Label(new Rect(rect.x, yGui, rect.width, 32f), string.Format("Edit Warp {0}", warp.NameWarps)); yGui += 32; AONGUI.Label(new Rect(rect.x, yGui, left, 32), "Name: "); AONGUI.TextField(new Rect(rect.x + left, yGui + 32 - heighTextField, rect.width - left, heighTextField), warp.NameWarps, 25, (string text) => { warp.NameWarps = text; }); yGui += 32; // Pick Map AONGUI.Label(new Rect(rect.x, yGui, left, 32), "Map: "); var ComboBoxMap = ComboBoxHelper.Instance.MapList(autoTileMap); ComboBoxMap.SelectedItemIndex = warp.map; ComboBoxMap.Rect.x = rect.x + left; ComboBoxMap.Rect.y = yGui; ComboBoxMap.Rect.width = rect.width - left; ComboBoxMap.Rect.height = 32f; ComboBoxMap.Show(rect.height - yGui - 32, (int selectedMap) => { warp.map = selectedMap; }); yGui += 32f; if (ComboBoxMap.IsDropDownListVisible) { return(hasUpdateUI); } if (warp.map != -1) { AONGUI.Label(new Rect(rect.x + 4f, yGui + 4f, rect.width - 8f, 32 - 8f), "x: " + warp.x); yGui += 16f; AONGUI.Label(new Rect(rect.x + 4f, yGui + 4f, rect.width - 8f, 32 - 8f), "y: " + warp.y); yGui += 32f; AONGUI.Button(new Rect(rect.x, yGui, rect.width, 32), "Select position on map...", () => { tilesetAON.PickPosOnMap(warp.map, warp.x, warp.y, (PickMapAON p, int _x, int _y) => { warp.x = _x; warp.y = _y; }); }); } return(hasUpdateUI); }
public void Push(AutoTileMap _autoTileMap, int tile_x, int tile_y, int tileId, int tile_layer, int high_brush = -2) { // int high_brush = -2; // if(tile_layer == 0){//Ground // high_brush = _autoTileMap.MapSelect.GetHighRef(tile_x, tile_y); // } TileData tileData = new TileData() { Tile_x = tile_x, Tile_y = tile_y, Tile_id = tileId, Tile_layer = tile_layer, Tile_high = high_brush }; aTileData.Add(tileData); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { camera = new Camera(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height); int[,] grid = new int[, ] { { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0 }, { 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0 }, { 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0 }, { 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0 }, { 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0 }, { 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0 }, { 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0 }, { 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 }, { 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0 }, { 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 } }; Model.Terrain[,] data = new Model.Terrain[15, 20]; for (int j = 0; j < 15; j++) { for (int i = 0; i < 20; i++) { switch (grid[j, i]) { case 0: data[j, i] = Model.Terrain.Wall; break; case 1: data[j, i] = Model.Terrain.Floor; break; } } } tileMap = new AutoTileMap(); tileMap.Create(grid); tileMap.SetTexture(Content.Load <Texture2D>("Sprites\\Terrain\\sprAutoTileSequence"), 32, 32); base.Initialize(); }
public void Initialize(AutoTileMap autoTileMap) { hideFlags = HideFlags.NotEditable; m_autoTileMap = autoTileMap; foreach (TileChunkLayer tileChunkLayer in TileChunkLayers) { if (tileChunkLayer.ObjNode != null) { #if UNITY_EDITOR DestroyImmediate(tileChunkLayer.ObjNode); #else Destroy(tileChunkLayer.ObjNode); #endif } } TileChunkLayers.Clear(); m_tileChunkToBeUpdated.Clear(); }
void OnRenderObject() { if (MyAutoTileMap == null) { MyAutoTileMap = GetComponent <AutoTileMap>(); } if (MyAutoTileMap != null) { if (!MyAutoTileMap.IsInitialized) { if (MyAutoTileMap.CanBeInitialized()) { MyAutoTileMap.LoadMap(); } } } }
public bool HouseOnGUIWithNPC(House house, House.NpcInHouse npc, Rect rect, AutoTileMap autoTileMap, TilesetAON tilesetAON, ref float yGui) { { float left = 80f; AONGUI.Label(new Rect(rect.x, yGui, left, 28), "Npc ref:"); var comboBox = ComboBoxHelper.Instance.NPCList(autoTileMap.MapSelect); comboBox.SelectedItemIndex = npc.IdxNPC; comboBox.Rect.x = rect.x + left; comboBox.Rect.y = yGui; comboBox.Rect.width = rect.width - left; comboBox.Rect.height = 32f; if (comboBox.IsDropDownListVisible) { AONGUI.Button(new Rect(rect.x + left, rect.y + rect.height - 64, rect.width - left, 28), "Add NPC", () => { npc.IdxNPC = autoTileMap.MapSelect.CreateNewNPC(); }); return(true); } comboBox.Show(rect.height - yGui - 64, (int selectedNpc) => { npc.IdxNPC = selectedNpc; }); yGui += 32f; if (comboBox.IsDropDownListVisible) { return(true); } } if (npc.IdxNPC >= 0 && npc.IdxNPC < autoTileMap.MapSelect.NPCData.Count) { AONGUI.Button(new Rect(rect.x + rect.width - 100, yGui, 100, 28), "Edit NPC", () => { tilesetAON.TriggerShowMoreInfo = autoTileMap.MapSelect.NPCData[npc.IdxNPC]; }); } yGui += 32f; AONGUI.Button(new Rect(rect.x, yGui, rect.width, 28), "Setup pos and face NPC", () => { tilesetAON.PickPosOnInterior(house.IdxInterior, npc.NPC_OffsetOut, npc.NPC_CamOut, (TilesetAON t, Vector3 p, Vector3 cam) => { npc.NPC_OffsetOut = p; npc.NPC_CamOut = cam; }); }); yGui += 32f; return(false); }
private void OnGuiGeneral(TilesetAON tilesetAON, AutoTileMap autoTileMap, Rect rect) { float yBeginGui = rect.y + 4f; AONGUI.Label(new Rect(rect.x + 10f, yBeginGui, 200, DefineAON.GUI_Height_Label), "Map " + autoTileMap.MapIdxSelect); // yBeginGui += 32; AONGUI.Button(new Rect(rect.x + rect.width - 220, yBeginGui, 200, DefineAON.GUI_Height_Label), "Reset map", () => { tilesetAON._isShowDialogClearMap = true; }); yBeginGui += 32; AONGUI.Label(new Rect(rect.x + 10f, yBeginGui, rect.width - 8f, DefineAON.GUI_Height_Label), string.Format("Start at: ({0}, {1})", autoTileMap.MapSelect.StartX, autoTileMap.MapSelect.StartY)); yBeginGui += 32; AONGUI.Button(new Rect(rect.x + 10f, yBeginGui, 200, DefineAON.GUI_Height_Button), "Pick start position", () => { tilesetAON.PickPosOnMap(autoTileMap.MapIdxSelect, autoTileMap.MapSelect.StartX, autoTileMap.MapSelect.StartY, (PickMapAON p, int _x, int _y) => { autoTileMap.MapSelect.StartX = _x; autoTileMap.MapSelect.StartY = _y; }); }); }
public void Init() { m_autoTileMap = GetComponent <AutoTileMap>(); m_miniMapAON = GetComponent <MiniMapAON>(); if (m_autoTileMap != null) { m_isInitialized = true; if (m_autoTileMap.ViewCamera == null) { Debug.LogWarning("AutoTileMap has no ViewCamera set. Camera.main will be set as ViewCamera"); m_autoTileMap.ViewCamera = Camera.main; } m_camera2D = m_autoTileMap.ViewCamera.GetComponent <Camera2DController>(); if (m_camera2D == null) { m_camera2D = m_autoTileMap.ViewCamera.gameObject.AddComponent <Camera2DController>(); } } }
public void Push(AutoTileMap _autoTileMap, int tile_x, int tile_y, int tileId, int tile_layer) { if ( tileId <= -2 || tile_layer >= _autoTileMap.MapLayers.Count || !_autoTileMap.MapLayers[tile_layer].Visible || _autoTileMap.MapLayers[tile_layer].LayerType == AutoTileMap.eLayerType.FogOfWar || _autoTileMap.MapLayers[tile_layer].LayerType == AutoTileMap.eLayerType.Objects ) { ; // do nothing, skip tile } else { TileData tileData = new TileData() { Tile_x = tile_x, Tile_y = tile_y, Tile_type = tileId, Tile_layer = tile_layer, }; aTileData.Add(tileData); } }
/// <summary> /// Save the map configuration /// </summary> /// <param name="_autoTileMap"></param> /// <returns></returns> public bool SaveData(AutoTileMap _autoTileMap, int width = -1, int height = -1) { if (width < 0) { width = TileMapWidth; } if (height < 0) { height = TileMapHeight; } // avoid clear map data when auto tile map is not initialized if (!_autoTileMap.IsInitialized) { //Debug.LogError(" Error saving data. Autotilemap is not initialized! Map will not be saved. "); return(false); } Metadata.version = k_version; TileData.Clear(); for (int iLayer = 0; iLayer < _autoTileMap.GetLayerCount(); ++iLayer) { AutoTileMap.MapLayer mapLayer = _autoTileMap.MapLayers[iLayer]; List <int> tileData = new List <int>(width * height); int iTileRepetition = 0; int savedTileId = 0; int mapWidth = _autoTileMap.MapTileWidth; int mapHeight = _autoTileMap.MapTileHeight; for (int tile_y = 0; tile_y < height; ++tile_y) { for (int tile_x = 0; tile_x < width; ++tile_x) { int iType = -1; if (tile_x < mapWidth && tile_y < mapHeight) { AutoTile autoTile = _autoTileMap.TileLayers[_autoTileMap.MapLayers[iLayer].TileLayerIdx][tile_x + tile_y * mapWidth]; iType = autoTile != null? autoTile.Id : -1; } //+++fix: FogOfWar tiles could be < -1, and this is not good for compress system, excepting ids >= -1 if (mapLayer.LayerType == eLayerType.FogOfWar) { iType = ((iType >> 1) & 0x7FFFFFFF); // remove the last bit of the last byte. Will be << 1 later when loading } //--- if (iTileRepetition == 0) { savedTileId = iType; iTileRepetition = 1; } else { // compression data. All tiles of the same type are store with number of repetitions ( negative number ) and type // ex: 5|5|5|5 --> |-4|5| (4 times 5) ex: -1|-1|-1 --> |-3|-1| ( 3 times -1 ) if (iType == savedTileId) { ++iTileRepetition; } else { if (iTileRepetition > 1) { tileData.Add(-iTileRepetition); // save number of repetition with negative sign } if (savedTileId < -1) { Debug.LogError(" Wrong tile id found when compressing the tile layer " + mapLayer.Name); savedTileId = -1; } tileData.Add(savedTileId); savedTileId = iType; iTileRepetition = 1; } } } } // save last tile type found if (iTileRepetition > 1) { tileData.Add(-iTileRepetition); } tileData.Add(savedTileId); // TileData.Add(new TileLayer() { Tiles = tileData, Depth = mapLayer.Depth, LayerType = mapLayer.LayerType, SortingLayer = mapLayer.SortingLayer, SortingOrder = mapLayer.SortingOrder, Name = mapLayer.Name, Visible = mapLayer.Visible }); } TileMapWidth = width; TileMapHeight = height; return(true); }
/// <summary> /// Load map serialized data into a map /// </summary> /// <param name="_autoTileMap"></param> public IEnumerator LoadToMap(AutoTileMap _autoTileMap) { _autoTileMap.Initialize(); _autoTileMap.ClearMap(); if (!Metadata.IsVersionAboveOrEqual("1.2.4")) { _applyFixVersionBelow124(_autoTileMap); } int totalMapTiles = TileMapWidth * TileMapHeight; for (int iLayer = 0; iLayer < TileData.Count; ++iLayer) { TileLayer tileData = TileData[iLayer]; _autoTileMap.MapLayers.Add( new AutoTileMap.MapLayer() { Name = tileData.Name, Visible = tileData.Visible, LayerType = tileData.LayerType, SortingOrder = tileData.SortingOrder, SortingLayer = tileData.SortingLayer, Depth = tileData.Depth, TileLayerIdx = iLayer, }); _autoTileMap.TileLayers.Add(new AutoTile[TileMapWidth * TileMapHeight]); int iTileRepetition = 1; int iTileIdx = 0; for (int i = 0; i < tileData.Tiles.Count; ++i) { int iType = tileData.Tiles[i]; //see compression notes in CreateFromTilemap if (iType < -1) { iTileRepetition = -iType; } else { //+++fix: FogOfWar tiles could be < -1, and this is not good for compress system, excepting ids >= -1 if (tileData.LayerType == eLayerType.FogOfWar) { iType = (iType << 1); //restore value so the lost bit was the less significant of last byte } //--- if (iTileRepetition > totalMapTiles) { Debug.LogError("Error uncompressing layer " + tileData.Name + ". The repetition of a tile was higher than map tiles " + iTileRepetition + " > " + totalMapTiles); iTileRepetition = 0; } for (; iTileRepetition > 0; --iTileRepetition, ++iTileIdx) { if (iTileIdx % 10000 == 0) { //float loadingPercent = ((float)(iTileIdx + iLayer * TileMapWidth * TileMapHeight)) / (TileMapWidth * TileMapHeight * TileData.Count); //Debug.Log(" Loading " + (int)(loadingPercent * 100) + "%"); yield return(null); } int tile_x = iTileIdx % TileMapWidth; int tile_y = iTileIdx / TileMapWidth; if (iType >= 0 || tileData.LayerType == eLayerType.FogOfWar) { _autoTileMap.SetAutoTile(tile_x, tile_y, iType, iLayer, false); } } iTileRepetition = 1; } } } _autoTileMap.RefreshAllTiles(); _autoTileMap.UpdateChunkLayersData(); _autoTileMap.RefreshMinimapTexture(); }
//Return true if had change Trigger Ref public virtual bool ShowGUI(Rect rect, AutoTileMap autoTileMap, TilesetAON tilesetAON, ref bool isShowMoreInfo, AComponent_Button.OnClick onCloseDialog) { // GUI.Box( rect, "Edit Trigger"); return(false); }