public ResizeDialog(Sector sector, Tilemap tilemap)
    {
        this.sector = sector;
        this.tilemap = tilemap;
        Glade.XML gxml = new Glade.XML("editor.glade", "resizeDialog");
        gxml.Autoconnect(this);

        if (resizeDialog == null ||
            XOffsetEntry == null ||
            YOffsetEntry == null ||
            WidthEntry   == null ||
            HeightEntry  == null)
        {
            throw new Exception("Couldn't load resize Dialog");
        }

        if (tilemap == null) {
            XOffsetEntry.Text = "0";
            YOffsetEntry.Text = "0";
            WidthEntry.Text = sector.Width.ToString();
            HeightEntry.Text = sector.Height.ToString();
            undoTitleBase = "Sector \"" + sector.Name + "\"";
        } else {
            XOffsetEntry.Text = "0";
            YOffsetEntry.Text = "0";
            WidthEntry.Text = tilemap.Width.ToString();
            HeightEntry.Text = tilemap.Height.ToString();
            undoTitleBase = "Tilemap \"" + tilemap.Name + "\"";
        }
        resizeDialog.Title += " " + undoTitleBase;
        resizeDialog.Icon = EditorStock.WindowIcon;
        resizeDialog.ShowAll();
    }
 public TilemapModifyCommand(string title, Tilemap changedTilemap, TileBlock.StateData oldState, TileBlock.StateData newState)
     : base(title)
 {
     this.changedTilemap = changedTilemap;
     this.oldState = oldState;
     this.newState = newState;
 }
 public TilemapEditorWindow(Tilemap t)
 {
     InitializeComponent();
     this.t = t;
     t.beginEdit();
     tilemapEditor1.showSaveButton();
     tilemapEditor1.load(t);
 }
 public BrushEditor(IEditorApplication application, Tilemap Tilemap, Tileset Tileset, string brushFile)
 {
     selection = new Selection();
     selection.Changed += OnSelectionChanged;
     this.application = application;
     this.Tilemap = Tilemap;
     brush = Brush.loadFromFile(brushFile, Tileset);
 }
 public FillEditor(IEditorApplication application, Tilemap Tilemap, Tileset Tileset, Selection selection)
 {
     this.application = application;
     this.Tilemap = Tilemap;
     this.Tileset = Tileset;
     this.selection = selection;
     application.TilemapChanged += OnTilemapChanged;
     selection.Changed += OnSelectionChanged;
 }
 public TilemapEditorWindow(Tilemap t)
 {
     InitializeComponent();
     LanguageManager.ApplyToContainer(this, "TilemapEditor");
     this.t = t;
     t.beginEdit();
     tilemapEditor1.showSaveButton();
     tilemapEditor1.load(t);
 }
Example #7
0
 public void load(Tilemap t)
 {
     this.t = t;
     panel1.Width = t.width * 8 + 30;
     tilePicker1.init(t.buffers, 8);
     tilemapEditorControl1.picker = tilePicker1;
     tilemapEditorControl1.undobutton = undoButton;
     tilemapEditorControl1.redobutton = redoButton;
     tilemapEditorControl1.load(t);
 }
Example #8
0
        public Level(GameState game, float width, float height)
        {
            var w = width + levelPadding * 2;
            var h = height + levelPadding * 2;

            var tilesX = Mathf.CeilToInt(w / gridSize);
            var tilesY = Mathf.CeilToInt(h / gridSize);

            this.tilemap = new Tilemap<TileInfo>(tilesX, tilesY);

            this.offsetX = -tilesX * gridSizeHalf;
            this.offsetY = -tilesY * gridSizeHalf;

            this.fillTiles();

            this.fillBuildingsIntoTiles(game);
        }
    // Use this for initialization
    void Start()
    {
        //Pulls the
        var passObject = GameObject.Find ("passingObject");
        var helpScript = passObject.GetComponent<menuHelper>();
        int map = helpScript.numRooms;
        int npc = helpScript.numNPC;
        mapSize = map;
        numberOfNPC = npc;

        GameObject tempTilemapObject = Instantiate(tilemapObject) as GameObject;
        tilemap = tempTilemapObject.GetComponent<Tilemap>();
        tilemap.GenerateTilemap (mapSize);
        playerObject.transform.position = tilemap.RandomStartPlayer();

        npcList = new List<NPC>();
        for(int i = 0; i < numberOfNPC; i++){

            GameObject tempNPCObject = Instantiate(npcObject) as GameObject;
            tempNPCObject.transform.parent = this.transform;
            tempNPCObject.layer = LayerMask.NameToLayer("NPC");

            npcList.Add(tempNPCObject.GetComponent<NPC>());
            npcList[i].SetTilemap(tilemap);
            npcList[i].player = playerObject.GetComponent<Player>();

            Tile currentTile = tilemap.RandomStartNPC();
            npcList[i].SetCurrentTile(currentTile);
            npcList[i].SetLocation (new Vector3(currentTile.x,currentTile.y,-1));

        }

        silverList = new List<Silver> ();
        for (int i = 0; i < numberOfNPC/2; i++) {
            GameObject tempSilverObject = Instantiate(silverObject) as GameObject;
            tempSilverObject.transform.parent = this.transform;
            tempSilverObject.layer = LayerMask.NameToLayer("Silver");

            silverList.Add(tempSilverObject.GetComponent<Silver>());
            Tile currentTile = tilemap.RandomStartNPC();
            silverList[i].SetLocation(new Vector3(currentTile.x,currentTile.y,-1));
        }

        GameObject.FindObjectOfType<Music>().GetComponent<Music>().StartMusic();
    }
    public GameObject ParseObject(string Name, List Data)
    {
        switch(Name) {
            case "tilemap":
                Tilemap tilemap = new Tilemap(Level.Tileset, Data);
                if(tilemap.Solid) {
                    if(Solids != null)
                        Console.WriteLine("Warning: 2 solid tilemaps specified");
                    Solids = tilemap;
                }
                return tilemap;
            default:
                Console.WriteLine("Unknown Object " + Name);
                break;
        }

        return null;
    }
    /// <summary>
    /// Initialises a new sector with some default values.
    /// </summary>
    /// <param name="Name">Name of new sector.</param>
    /// <returns>The created sector.</returns>
    public static Sector CreateSector(string Name)
    {
        Sector sector = new Sector();
        sector.Name = Name;

        Tilemap tilemap = new Tilemap();
        tilemap.Resize(100, 35, 0);
        tilemap.ZPos = -100;
        tilemap.Name = "Background";
        sector.Add(tilemap);

        tilemap = new Tilemap();
        tilemap.Resize(100, 35, 0);
        tilemap.ZPos = 0;
        tilemap.Solid = true;
        tilemap.Name = "Interactive";
        sector.Add(tilemap);

        tilemap = new Tilemap();
        tilemap.Resize(100, 35, 0);
        tilemap.ZPos = 100;
        tilemap.Name = "Foreground";
        sector.Add(tilemap);

        SpawnPoint spawnpoint = new SpawnPoint();
        spawnpoint.X = 96;
        spawnpoint.Y = 96;
        spawnpoint.Name = "main";
        sector.Add(spawnpoint);

        Camera camera = new Camera();
        sector.Add(camera);

        Background background = new Background();
        background.Image = "images/background/BlueRock_Forest/blue-middle.jpg";
        background.ImageTop = "images/background/BlueRock_Forest/blue-top.jpg";
        background.ImageBottom = "images/background/BlueRock_Forest/blue-bottom.jpg";
        sector.Add(background);

        return sector;
    }
Example #12
0
    /// <summary>
    /// Initializes a new sector with some default values.
    /// </summary>
    /// <param name="Name">Name of new sector.</param>
    /// <returns>The created <see cref="Sector"/> object.</returns>
    public static Sector CreateSector(string Name)
    {
        Sector sector = new Sector();
        sector.Name = Name;

        Tilemap tilemap = new Tilemap();
        tilemap.Resize(100, 35, 0);
        tilemap.Layer = -100;
        tilemap.Name = "Background";
        sector.Add(tilemap, true);

        tilemap = new Tilemap();
        tilemap.Resize(100, 35, 0);
        tilemap.Layer = 0;
        tilemap.Solid = true;
        tilemap.Name = "Interactive";
        sector.Add(tilemap, true);

        tilemap = new Tilemap();
        tilemap.Resize(100, 35, 0);
        tilemap.Layer = 100;
        tilemap.Name = "Foreground";
        sector.Add(tilemap, true);

        SpawnPoint spawnpoint = new SpawnPoint();
        spawnpoint.X = 96;
        spawnpoint.Y = 96;
        spawnpoint.Name = "main";
        sector.Add(spawnpoint, true);

        Camera camera = new Camera();
        sector.Add(camera, true);

        sector.FinishRead(); //let sector detect it's dimensions

        return sector;
    }
Example #13
0
 private void Start()
 {
     baseTilemap = GetComponentsInChildren <Tilemap>()[0];
 }
Example #14
0
 public TilemapNode(Tilemap tilemap, Tileset Tileset)
 {
     this.tilemap = tilemap;
     this.Tileset = Tileset;
 }
Example #15
0
 void OnEnable()
 {
     Tools.current = Tool.None;
     map = target as Tilemap;
 }
Example #16
0
 public void CheckMap(Tilemap tilemap)
 {
     Debug.Log(string.Format("Tilemap {0} - Size: {1}  ", tilemap.cellBounds, tilemap.cellBounds.size));
 }
        public static T GetComponentAtCell <T>(this Tilemap tilemap, Vector3Int position)
        {
            Vector3 worldPos = tilemap.GetCellCenterWorld(position);

            return(Utils.GetComponentAtPosition2D <T>(worldPos));
        }
Example #18
0
 private TileBase getTile(Tilemap tilemap, Vector2 worldPos)
 {
     return(tilemap.GetTile(tilemap.WorldToCell(worldPos)));
 }
Example #19
0
    private Vector3Int GetTilemapBottomLeft(Tilemap tilemap)
    {
        var parentPos = tilemap.transform.parent.localPosition;

        return(new Vector3Int(Mathf.FloorToInt(parentPos.x), Mathf.FloorToInt(parentPos.y), 0));
    }
Example #20
0
 // Use this for initialization
 void Start()
 {
     ReunaTilemap = GameObject.Find("IlmastointiReunaTilemap").GetComponent <Tilemap>();
 }
Example #21
0
 void Start()
 {
     player     = GameObject.FindGameObjectWithTag("Player");
     targetTile = GameObject.FindGameObjectWithTag("AstarTarget").GetComponent <Tilemap>();
     InvokeRepeating("LoadTile", 0.0f, 0.1f);
 }
Example #22
0
 public void Load(Tilemap tilemap)
 {
     _tilemap = tilemap;
 }
Example #23
0
    private void SetTile(Vector3 pos, Tilemap tilemap, TileBase tile)
    {
        var cell = tilemap.WorldToCell(pos);

        tilemap.SetTile(cell, tile);
    }
Example #24
0
 private void ClearTile(Vector3 pos, Tilemap tilemap)
 {
     tilemap.SetTile(tilemap.WorldToCell(pos), null);
 }
Example #25
0
    private void CreateWallSortingGroups()
    {
        var parent = wallDecor.transform.parent;

        wallDecor.CompressBounds();
        var bounds     = wallDecor.cellBounds;
        var outerWalls = CreateTilemap(parent, "OuterWalls", bounds.min);

        Tilemap currTilemap    = null;
        Tilemap highestTilemap = null;
        var     lastPoint      = Vector3Int.zero;
        bool    started        = false;
        int     wallNum        = 0;

        var tilemaps = new List <Tilemap>();

        for (int x = bounds.xMin; x < bounds.xMax; x++)
        {
            started = false;
            for (int y = bounds.yMin; y < bounds.yMax; y++)
            {
                var pos = new Vector3Int(x, y, 0);

                // On the outside
                if (pos.x == bounds.xMin || pos.x == bounds.xMax - 1 || pos.y == bounds.yMin || pos.y == bounds.yMax - 1)
                {
                    outerWalls.SetTile(pos - GetTilemapBottomLeft(outerWalls), wallDecor.GetTile(pos));
                    continue;
                }

                var tile = wallDecor.GetTile(pos);
                if (tile == null)
                {
                    started = false;
                    continue;
                }

                if (!started)
                {
                    started   = true;
                    lastPoint = pos;
                    bool found = false;
                    foreach (var tilemap in tilemaps)
                    {
                        var bottomRight = new Vector3Int(tilemap.cellBounds.xMax, tilemap.cellBounds.yMin, 0);
                        if (bottomRight + GetTilemapBottomLeft(tilemap) == pos)
                        {
                            currTilemap = tilemap;
                            found       = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        currTilemap        = CreateTilemap(parent, $"Wall{wallNum++}", pos);
                        currTilemap.origin = Vector3Int.zero;
                        highestTilemap     = (highestTilemap == null || highestTilemap.origin.y < pos.y) ? currTilemap : highestTilemap;
                        tilemaps.Add(currTilemap);
                    }
                }

                if (pos.y - lastPoint.y <= 1)
                {
                    currTilemap.SetTile(pos - GetTilemapBottomLeft(currTilemap), tile);
                    lastPoint = pos;
                }
                else
                {
                    started = false;
                }
            }
        }
        var backwallParent = highestTilemap.transform.parent;

        computers.transform.parent = backwallParent;
        door.transform.parent      = backwallParent;
        wallDecor.gameObject.SetActive(false);
    }
 public void OnTilemapChanged(Tilemap newTilemap)
 {
     Tilemap = newTilemap;
 }
        private void fileTreeView_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (e.Node.Tag is Directory)
            {
                e.Node.Expand();
                return;
            }
            File f = e.Node.Tag as File;

            String filename = f.name;
            filename = filename.ToLowerInvariant();

            try
            {
                if (filename == "banner.bin")
                {
                    LevelChooser.showImgMgr();
                    File imgFile = new InlineFile(f, 0x20, 0x200, f.name);
                    File palFile = new InlineFile(f, 0x220, 0x20, f.name);
                    LevelChooser.imgMgr.m.addImage(new Image2D(imgFile, 32, true, false));
                    LevelChooser.imgMgr.m.addPalette(new FilePalette(palFile));
                }
                else if (filename.EndsWith(".enpg"))
                {
                    LevelChooser.showImgMgr();
		            LZFile fileLz = new LZFile(f, LZFile.CompressionType.LZ);
                    File imgFile = new InlineFile(fileLz, 0, 0x10000, f.name);
                    File palFile = new InlineFile(fileLz, 0x10000, 0x200, f.name);
                    LevelChooser.imgMgr.m.addImage(new EnpgImage2D(imgFile));
                    LevelChooser.imgMgr.m.addPalette(new FilePalette(palFile));
                }
                else if (filename.EndsWith(".bncd"))
                	new Bncd(f);
                if (filename.EndsWith(".nsbtx") || filename.EndsWith(".nsbmd"))
                    new NSBTX(f);
                else if (filename.EndsWith(".nscr") ||
                         filename.EndsWith(".ncgr") ||
                         filename.EndsWith(".nclr"))
                    SectionFileLoader.load(f);
                else if (filename.EndsWith(".narc"))
                    new FilesystemBrowserDialog(new NarcFilesystem(f)).Show();
                else if (filename.EndsWith(".carc"))
                    new FilesystemBrowserDialog(new NarcFilesystem(f, true)).Show();
                else if (filename.Contains("_ncl.bin"))
                    new PaletteViewer(new LZFile(f, LZFile.CompressionType.MaybeLZ)).Show();
                else if (filename.Contains("_nsc.bin"))
                {
                    if (LevelChooser.imgMgr == null) return;
                    Image2D img = LevelChooser.imgMgr.m.getSelectedImage();
                    Palette[] pals = LevelChooser.imgMgr.m.getPalettes();
                    if (img == null) return;
                    if (pals == null) return;
                    if (pals.Length == 0) return;

                    Tilemap t = new Tilemap(f, 32, img, pals, 0, 0);
                    new TilemapEditorWindow(t).Show();
                }
                else if (filename.Contains("_ncg.bin"))
                {
                    LevelChooser.showImgMgr();
                    LevelChooser.imgMgr.m.addImage(new Image2D(f, 256, false));
                }
            }
            catch (AlreadyEditingException ex)
            {
                MessageBox.Show(this, (LanguageManager.Get("Errors", "File")));
            }
        }
Example #28
0
        public override void Initialize()
        {
            base.Initialize();

            new ControlHandler(this);

            _manager = new GameOfLifeManager(this, "Manager");
            _manager.UpdateTimer.LastEvent += CheckAllCells;

            //Cells = new Tilemap(this, "Cells", EntityGame.Game.Content.Load<Texture2D>(@"GameOfLife\tiles"), new Point(30,30),new Point(16,16));

            Cells = new Tilemap(this, "Cells", EntityGame.Self.Content.Load <Texture2D>(@"GameOfLife\tilesSmall"),
                                new Point(30, 30), new Point(1, 1));
            Cells.Render.Scale = new Vector2(16, 16);
            Cells.SetAllTiles(new Tile(DEAD)
            {
                Color = Color.Red.ToRGBColor()
            });
            //Position Tilemap to center
            Cells.Body.Position = new Vector2(EntityGame.Viewport.Width / 2f - Cells.Width / 2f * Cells.Render.Scale.X, 10);

            Cells.TileSelected += OnTileSelected;
            _tiles              = Cells.CloneTiles();

            //GUI
            Page page = new Page(this, "Page");

            page.Show();

            LinkLabel startLink = new LinkLabel(page, "StartLink", new Point(0, 0));

            startLink.Body.Position = new Vector2(Cells.Body.X, 500);
            startLink.OnFocusGain();
            startLink.Text        = "Start";
            startLink.OnReleased += control => _manager.Start();

            LinkLabel stopLink = new LinkLabel(page, "StopLink", new Point(0, 1));

            stopLink.Body.Position = new Vector2(Cells.Body.X, startLink.Body.Bottom);
            stopLink.Text          = "Stop";
            stopLink.OnReleased   += control => _manager.Stop();

            LinkLabel resetLink = new LinkLabel(page, "ResetLink", new Point(0, 2));

            resetLink.Body.Position = new Vector2(Cells.Body.X, stopLink.Body.Bottom);
            resetLink.Text          = "ResetTimer";
            resetLink.OnReleased   += control => ResetCells();

            LinkLabel downMillisecondsLink = new LinkLabel(page, "downMillisecondsLink", new Point(1, 0));

            downMillisecondsLink.Body.Position = new Vector2(Cells.Body.X + 100, startLink.Body.Bottom);
            downMillisecondsLink.Text          = "<-";
            downMillisecondsLink.OnDown       += control => _manager.UpdateTimer.Milliseconds -= 50;

            _millisecondsText = new Label(page, "millisecondsText", new Point(2, 0));
            _millisecondsText.Body.Position = new Vector2(downMillisecondsLink.Body.Right + 2, startLink.Body.Bottom);
            _millisecondsText.Text          = _manager.UpdateTimer.Milliseconds.ToString();

            LinkLabel upMillisecondsLink = new LinkLabel(page, "upMillisecondsLink", new Point(3, 0));

            upMillisecondsLink.Body.Position = new Vector2(_millisecondsText.Body.Right + 25, startLink.Body.Bottom);
            upMillisecondsLink.Text          = "->";
            upMillisecondsLink.OnDown       += control => _manager.UpdateTimer.Milliseconds += 50;
        }
Example #29
0
 void Start()
 {
     wallTilemap = GetComponent <Tilemap>();
 }
Example #30
0
 // Start is called before the first frame update
 void Start()
 {
     tilemap = gameObject.GetComponent <Tilemap>();
 }
 public static Vector3Int MousePositionToCell(this Tilemap tilemap)
 {
     return(tilemap.WorldToCell(Camera.main.ScreenToWorldPoint(Input.mousePosition)));
 }
Example #32
0
 public BossLevel(Tilemap terrain, DecorativeTileMap decorativeTileMap) : base(terrain, decorativeTileMap)
 {
 }
        public static TileBase GetTile(this Tilemap tilemap, Vector3 position)
        {
            Vector3Int pos = tilemap.WorldToCell(position);

            return(tilemap.GetTile(pos));
        }
        private bool UploadData( HEU_SessionBase session, HAPI_NodeId inputNodeID, HEU_InputData inputData)
        {
            HEU_InputDataTilemap inputTilemap = inputData as HEU_InputDataTilemap;
            if(inputTilemap == null)
            {
                Debug.LogError("Expected HEU_InputDataTilemap type for inputData, but received unssupported type.");
                return false;
            }

            List<Vector3> vertices = new List<Vector3>();            
            List<Vector3> colors = new List<Vector3>();
            //List<Vector3> uvs = new List<Vector3>();
            List<Vector3> normals = new List<Vector3>();

            List<string> tileNames = new List<string>();            
            List<Vector3> tileSizes = new List<Vector3>();
            List<Vector3Int> tileCoords = new List<Vector3Int>();

            Tilemap tileMap = inputTilemap._tilemap;
            Grid gridLayout = tileMap.layoutGrid;

            //Get a list of unique tiles used
            TileBase[] usedTiles = new TileBase[ tileMap.GetUsedTilesCount() ];
            tileMap.GetUsedTilesNonAlloc(usedTiles);

            TileBase[] tileArray = tileMap.GetTilesBlock( tileMap.cellBounds );
            //tileArray = tileArray.Where( x => x != null).ToArray(); //only existing tiles

            int tileCount = 0;            
            Vector3 anchorOffset = tileMap.tileAnchor;
            anchorOffset.Scale(gridLayout.cellSize);

            Vector3 pointPos;
            Vector3 pointNormal = new Vector3(0.0f, 0.0f, 1.0f);

            Vector3Int boundsMin = new Vector3Int(int.MaxValue, int.MaxValue, int.MaxValue);
            Vector3Int boundsMax = new Vector3Int(int.MinValue, int.MinValue, int.MinValue);

            foreach (Vector3Int tilePos in tileMap.cellBounds.allPositionsWithin)
            {
                if (tileMap.HasTile(tilePos))
                {
                    boundsMin = Vector3Int.Min(tilePos, boundsMin);
                    boundsMax = Vector3Int.Max(tilePos, boundsMax);
                }
            }

            boundsMax += Vector3Int.one;
            BoundsInt tileMapBounds = new BoundsInt
            {
                min = boundsMin,
                max = boundsMax
            };

            //foreach (Vector3Int tilePos in tileMap.cellBounds.allPositionsWithin)
            Vector3Int tilePosReverseX = new Vector3Int();
            foreach(Vector3Int tilePos in tileMapBounds.allPositionsWithin)
            {
#if !EXPORT_RECT_GRID
                if(!tileMap.HasTile(tilePos))
                    continue;
#endif

                tilePosReverseX = tilePos;
                //For Hudini (to use Labs Wang Tile tools, we need to reverse point order on the x axis)
                //so we just iterate in reverse order on the x                
                tilePosReverseX.x = tileMapBounds.size.x - 1 - tilePos.x + 2 * tileMapBounds.min.x;

                tileCount++;
                pointPos = tileMap.CellToLocal(tilePosReverseX) + anchorOffset;
                vertices.Add(pointPos);
                normals.Add(pointNormal);

                if (tileMap.HasTile(tilePosReverseX))
                {
                    Tile tile = tileMap.GetTile<Tile>(tilePosReverseX);
                    tileNames.Add(tile.name);
                    colors.Add(new Vector3(tile.color.r, tile.color.g, tile.color.b));
                    tileSizes.Add(new Vector3(tile.sprite.rect.size.x / tile.sprite.pixelsPerUnit, tile.sprite.rect.size.y / tile.sprite.pixelsPerUnit, 0.0f));

                }
                else
                {
                    tileNames.Add("");
                    colors.Add(Vector3.zero);
                    tileSizes.Add(Vector3.zero);
                }

                tileCoords.Add(tilePosReverseX);
            }            

            HAPI_PartInfo partInfo = new HAPI_PartInfo();
            partInfo.faceCount = 0;
            partInfo.vertexCount = 0;
            partInfo.pointCount = tileCount;
            partInfo.pointAttributeCount = 1;
            partInfo.vertexAttributeCount = 0;
            partInfo.primitiveAttributeCount = 0;
            partInfo.detailAttributeCount = 0;

            HAPI_GeoInfo displayGeoInfo = new HAPI_GeoInfo();
            if(!session.GetDisplayGeoInfo(inputNodeID, ref displayGeoInfo))
            {
                return false;
            }

            HAPI_NodeId displayNodeID = displayGeoInfo.nodeId;
            if(!session.SetPartInfo(displayNodeID, 0, ref partInfo))
            {
                Debug.LogError("Failed to set input part info. ");
		        return false;
            }

            if(!HEU_InputMeshUtility.SetMeshPointAttribute(session, displayNodeID, 0, HEU_Defines.HAPI_ATTRIB_POSITION, 3, vertices.ToArray(), ref partInfo, true))
            {
                Debug.LogError("Failed to set point positions.");
                return false;
            }

            if (!HEU_InputMeshUtility.SetMeshPointAttribute(session, displayNodeID, 0, "size", 2, tileSizes.ToArray(), ref partInfo, false))
            {
                Debug.Log("Failed to set tile size attributes. ");
                return false;
            }

            if(!HEU_InputMeshUtility.SetMeshPointAttribute(session, displayNodeID, 0, HEU_Defines.HAPI_ATTRIB_COLOR, 3, colors.ToArray(), ref partInfo, false))
            {
                Debug.Log("Failed to set tile color attributes. ");
                return false;
            }

            if(!HEU_InputMeshUtility.SetMeshPointAttribute(session, displayNodeID, 0, HEU_Defines.HAPI_ATTRIB_NORMAL, 3, normals.ToArray(), ref partInfo, true))
            {
                Debug.Log("Failed to set point normal attributes.");
                return false;
            }

            if(!HEU_InputMeshUtilityExt.SetMeshPointAttribute(session, displayNodeID, 0, "tilepos", 2, tileCoords.ToArray(), ref partInfo))
            {
                Debug.Log("Failed to set point tile coordinates attributes.");
                return false;
            }


#if TILENAME_GROUPS
            //Set point groups based on tile type
            int[] pointGroupMembership = new int[tileCount];
            foreach(TileBase tileType in usedTiles)
            {
                if(!session.AddGroup( displayNodeID, 0, HAPI_GroupType.HAPI_GROUPTYPE_POINT, tileType.name))
                    return false;

                int index = 0;
                foreach( string tileName in tileNames)
                {
                    if(tileName.Equals(tileType.name))
                        pointGroupMembership[index] = 1;
                    else
                        pointGroupMembership[index] = 0;
                    index++;
                }

                if(!session.SetGroupMembership(displayNodeID, 0, HAPI_GroupType.HAPI_GROUPTYPE_POINT, tileType.name, pointGroupMembership, 0, tileCount))
                    return false;
            }
#else
            if(!HEU_InputMeshUtilityExt.SetMeshPointAttribute(session, displayNodeID, 0, "tilename", tileNames.ToArray(), ref partInfo))
            {
                Debug.Log("Failed to set point tile name attributes.");
                return false;
            }
#endif
            if(!HEU_InputMeshUtilityExt.SetMeshDetailAttribute(session, displayNodeID, 0, "bounds", 2, tileMapBounds.size, ref partInfo))
            {
                Debug.Log("Failed to set detail tile map bounds attribute.");
                return false;
            }

            return session.CommitGeo(displayNodeID);
        }
Example #35
0
 public static void OnDrawGizmo(Tilemap map, GizmoType type)
 {
     Gizmos.color = Color.red;
     Gizmos.DrawWireCube(map.transform.position, new Vector3(10, 10, 10));
 }
Example #36
0
 public void SetTilemap(Tilemap t)
 {
     this.tilemap = t;
 }
 public void OnTilemapChanged(Tilemap newTilemap)
 {
     QueueDraw();
 }
Example #38
0
    public static TilePath DiscoverPath(Tilemap map, Vector3Int start, Vector3Int end)
    {
        //you will return this path to the user.  It should be the shortest path between
        //the start and end vertices
        TilePath discoveredPath = new TilePath();

        //TileFactory is how you get information on tiles that exist at a particular vector's
        //coordinates
        TileFactory tileFactory = TileFactory.GetInstance();

        //This is the priority queue of paths that you will use in your implementation of
        //Dijkstra's algorithm
        PriortyQueue <TilePath> pathQueue = new PriortyQueue <TilePath>();

        //You can slightly speed up your algorithm by remembering previously visited tiles.
        //This isn't strictly necessary.
        Dictionary <Vector3Int, int> discoveredTiles = new Dictionary <Vector3Int, int>();

        //quick sanity check
        if (map == null || start == null || end == null)
        {
            return(discoveredPath);
        }

        //This is how you get tile information for a particular map location
        //This gets the Unity tile, which contains a coordinate (.Position)
        var startingMapLocation = map.GetTile(start);

        //And this converts the Unity tile into an object model that tracks the
        //cost to visit the tile.
        var startingTile = tileFactory.GetTile(startingMapLocation.name);

        startingTile.Position = start;

        //Any discovered path must start at the origin!
        discoveredPath.AddTileToPath(startingTile);

        //This adds the starting tile to the PQ and we start off from there...
        pathQueue.Enqueue(discoveredPath);
        bool found = false;

        while (found == false && pathQueue.IsEmpty() == false)
        {
            //TODO: Implement Dijkstra's algorithm!
            var  path_  = new TilePath(pathQueue.Dequeue());
            Tile recent = new Tile(path_.GetMostRecentTile());
            if (recent.Position == end)
            {
                return(path_);
            }
            else
            {
                TilePath tempL     = new TilePath(path_);
                Tile     nextTile  = new Tile(recent);
                TileBase up        = map.GetTile(new Vector3Int(recent.Position.x, recent.Position.y + 1, recent.Position.z));
                Tile     uptemp    = new Tile(tileFactory.GetTile(up.name));
                TileBase down      = map.GetTile(new Vector3Int(recent.Position.x, recent.Position.y - 1, recent.Position.z));
                Tile     downtemp  = new Tile(tileFactory.GetTile(down.name));
                TileBase left      = map.GetTile(new Vector3Int(recent.Position.x - 1, recent.Position.y, recent.Position.z));
                Tile     lefttemp  = new Tile(tileFactory.GetTile(left.name));
                TileBase right     = map.GetTile(new Vector3Int(recent.Position.x + 1, recent.Position.y, recent.Position.z));
                Tile     righttemp = new Tile(tileFactory.GetTile(right.name));



                if (up != null)
                {
                    Tile upT = new Tile();
                    upT.Position = new Vector3Int(recent.Position.x, recent.Position.y + 1, recent.Position.z);
                    upT.Weight   = uptemp.Weight;
                    upT.Name     = uptemp.Name;
                    tempL.AddTileToPath(upT);
                    if (upT.Position == end)
                    {
                        return(tempL);
                    }
                    pathQueue.Enqueue(tempL);
                    tempL = new TilePath(path_);
                }
                if (down != null)
                {
                    Tile downT = new Tile();
                    downT.Position = new Vector3Int(recent.Position.x, recent.Position.y - 1, recent.Position.z);
                    downT.Weight   = downtemp.Weight;
                    downT.Name     = downtemp.Name;
                    tempL.AddTileToPath(downT);
                    if (downT.Position == end)
                    {
                        return(tempL);
                    }
                    pathQueue.Enqueue(tempL);
                    tempL = new TilePath(path_);
                }
                if (left != null)
                {
                    Tile leftT = new Tile();
                    leftT.Position = new Vector3Int(recent.Position.x - 1, recent.Position.y, recent.Position.z);
                    leftT.Weight   = lefttemp.Weight;
                    leftT.Name     = lefttemp.Name;
                    tempL.AddTileToPath(leftT);
                    if (leftT.Position == end)
                    {
                        return(tempL);
                    }
                    pathQueue.Enqueue(tempL);
                    tempL = new TilePath(path_);
                }
                if (right != null)
                {
                    Tile rightT = new Tile();
                    rightT.Position = new Vector3Int(recent.Position.x + 1, recent.Position.y, recent.Position.z);
                    rightT.Weight   = righttemp.Weight;
                    rightT.Name     = righttemp.Name;
                    tempL.AddTileToPath(rightT);
                    if (rightT.Position == end)
                    {
                        return(tempL);
                    }
                    pathQueue.Enqueue(tempL);
                }
            }

            //This line ensures that we don't get an infinite loop in Unity.
            //You will need to remove it in order for your pathfinding algorithm to work.
        }
        return(discoveredPath);
    }
Example #39
0
    //private Vector3 GetEndPositionOfMap(string mapName)
    //{
    //    foreach (var data in MapDatas)
    //    {
    //        int index = 0;

    //        foreach (var nextMapName in data.Value.NextMapName)
    //        {
    //            if (nextMapName == CurrentMapName)
    //            {
    //                return data.Value.PlayerEndPosition[index];
    //            }
    //            index++;
    //        }
    //    }
    //    return Vector3.zero;
    //}
    #endregion

    //Tilemap 정보갱신
    private Tilemap UpdateTilemapDataWithCreate(TilemapData mapData)
    {
        var maps = transform.GetComponentsInChildren <Tilemap>();

        foreach (var m in maps)
        {
            //자식중에 같은게 있으면 리턴
            if (m.name == mapData.Name)
            {
                return(m);
            }
        }

        //없으면 새로만들어서 정보업데이트후 리턴
        GameObject go = new GameObject();

        go.transform.SetParent(transform);

        //데이터들 오브젝트와 연결
        TilemapRendererLinking(mapData.TilemapRenderer, go);
        TilemapColliderLinking(mapData.TilemapCollider, go);
        Rigidbody2DLinking(mapData.RigidBody2D, go);
        CompositeColliderLinking(mapData.CompositeCollider, go);
        PlatformEffectorLinking(mapData.PlatformEffector, go);
        BoxCollider2DLinking(mapData.BoxCollider, go);

        Tilemap map = go.GetComponent <Tilemap>();

        //정보 업데이트
        //데이터테이블 변경시 같이 변경해야함
        if (string.IsNullOrEmpty(mapData.Name))
        {
            Log.PrintWarning("MapData Name is NULL or Empty");
        }
        else
        {
            map.transform.name = mapData.Name;
        }
        if (string.IsNullOrEmpty(mapData.Tag))
        {
            Log.PrintWarning("MapData Tag is NULL or Empty");
        }
        else
        {
            map.tag = mapData.Tag;
        }
        if (LayerMask.NameToLayer(mapData.Tag) == -1)
        {
            map.gameObject.layer = 0;
        }
        else
        {
            map.gameObject.layer = LayerMask.NameToLayer(mapData.Tag);
        }
        map.transform.position   = mapData.Position;
        map.transform.rotation   = mapData.Rotation;
        map.transform.localScale = mapData.Scale;
        map.animationFrameRate   = mapData.AnimationFrameRate;
        map.color       = mapData.Color;
        map.tileAnchor  = mapData.TileAnchor;
        map.orientation = mapData.Orientation;

        return(map);
    }
 public void ChangeCurrentTilemap(Tilemap tilemap)
 {
     TilemapChanged(tilemap);
 }
    private void OnButtonPressed(object o, ButtonPressEventArgs args)
    {
        TreePath path;
        if(!GetPathAtPos((int) args.Event.X, (int) args.Event.Y, out path))
            return;

        TreeIter iter;
        if(!Model.GetIter(out iter, path))
            return;

        object obj = Model.GetValue(iter, 0);
        if(obj is Tilemap) {
            if(obj != currentTilemap) {
                currentTilemap = (Tilemap) obj;
                application.EditProperties(currentTilemap, "Tilemap (" + currentTilemap.ZPos + ")");
                application.ChangeCurrentTilemap(currentTilemap);
            }
        } else {
            currentTilemap = null;
        // TODO: clear properties window?
            application.ChangeCurrentTilemap(currentTilemap);
        }

        if((args.Event.Button == 3) && (obj is Tilemap)) {
            ShowPopupMenu();
        }
    }
 public bool isTileAt(Tilemap tilemap, int x, int y, Tile tile)
 {
     return(tilemap.GetTile(new Vector3Int(x, y, 0)) == tile);
 }
Example #43
0
 public void Awake()
 {
     tilemap = GetComponent <Tilemap>();
 }
Example #44
0
        /// <summary>
        /// Creates an Otter Tilemap from the data loaded from the Tiled Map Editor file.
        /// </summary>
        /// <param name="tileLayer">
        /// The Tiled Map Editor Layer to be turned into an Otter tilemap.
        /// </param>
        /// <returns>
        /// The Otter tilemap representation of the Tiled Map Editor Layer.
        /// </returns>
        public Tilemap CreateTilemap(TiledTileLayer tileLayer)
        {
            var path = GetTilemapPath(TileSets.First().ImageSource);

            CheckExists(path);

            var tilemap = new Tilemap(path, PixelWidth, PixelHeight, TileWidth, TileHeight);
            tilemap.DefaultLayerName = tileLayer.Name;

            var layerName = tileLayer.Name;
            tilemap.AddLayer(layerName, 1);

            for(var x = 0; x < Width; x++)
            {
                for(var y = 0; y < Height; y++)
                {
                    var i = y * Width + x;
                    var gid = (int)tileLayer.Tiles[i].Gid;
                    if(gid > 0)
                    {
                        tilemap.SetTile(x, y, gid - 1, layerName);
                    }
                }

            }

            return tilemap;
        }
Example #45
0
    /// <summary>
    /// Find the best pattern to use when changing tiles around the given position to one of the stored patterns.
    /// </summary>
    /// <param name="pos">The (center) position at the <paramref name="tilemap"/> to look at.</param>
    /// <param name="tilemap">The tilemap to look at.</param>
    /// <param name="bestPattern">A tileblock that will replace the area.</param>
    /// <returns>
    /// True if <paramref name="bestPattern"/> is different from the calculated
    /// pattern in <paramref name="tilemap"/>, otherwise false.
    /// </returns>
    public bool FindBestPattern(FieldPos pos, Tilemap tilemap, ref TileBlock bestPattern)
    {
        // find upper-left corner of where to apply brush
        int px = pos.X - (int) (width / 2);
        int py = pos.Y - (int) (height / 2);

        return FindBestPattern(px, py, tilemap, ref bestPattern);
    }
Example #46
0
 private bool hasTile(Tilemap tilemap, Vector2 worldPos)
 {
     return(tilemap.HasTile(tilemap.WorldToCell(worldPos)));
 }
    private GameObject ParseObject(string Name, List Data)
    {
        switch(Name) {
            case "tilemap":
                Tilemap tilemap = new Tilemap(Tileset, Data);
                if(tilemap.Solid) {
                    if(Solids != null)
                        Console.WriteLine("Warning: 2 solid tilemaps specified");
                    Solids = tilemap;
                    ObjectGrid = new Field<List<WorldmapObject> >(tilemap.Width, tilemap.Height, (List<WorldmapObject>) null);
                }
                return tilemap;
            case "level":
                return new WorldmapLevel(this, Data);
            default:
                Console.WriteLine("Unknown Object " + Name);
                break;
        }

        return null;
    }
 private void OnAdd(object o, EventArgs args)
 {
     Tilemap tilemap = new Tilemap();
     tilemap.Resize( sector.Width, sector.Height, 0);
     sector.Add(tilemap, "Tilemap");
 }
Example #49
0
 public void SetTilemap(Tilemap tilemap)
 {
     _tilemap = tilemap;
 }
Example #50
0
 public void ApplyToTilemap(FieldPos pos, Tilemap Tilemap, bool skipNull)
 {
     int StartX = Math.Max(0, -pos.X);
     int StartY = Math.Max(0, -pos.Y);
     int W = Math.Min(Tilemap.Width  - pos.X, Width);
     int H = Math.Min(Tilemap.Height - pos.Y, Height);
     for(int y = StartY; y < H; ++y) {
         for(int x = StartX; x < W; ++x) {
             if ((skipNull) && (this[x, y] == 0) && (Width > 1 || Height > 1)) continue;
             Tilemap[ pos.X + x, pos.Y + y ] = this[x, y];
         }
     }
 }
 public static void CopyBounds(this Tilemap tilemap, Tilemap other)
 {
     tilemap.origin = other.origin;
     tilemap.size   = other.size;
 }
Example #52
0
 private void Start()
 {
     map = GetComponent <Tilemap>();
 }
Example #53
0
    /// <summary>
    /// Smooths Tilemap by changing tiles around the given position to one of the stored patterns
    /// </summary>
    public void ApplyToTilemap(FieldPos pos, Tilemap tilemap)
    {
        // find upper-left corner of where to apply brush
        int px = pos.X - (width/2);
        int py = pos.Y - (height/2);

        TileBlock bestPattern = null;

        // if we find any usable pattern, we apply it
        if (FindBestPattern(px, py, tilemap, ref bestPattern)) {
            // Only apply to the center
            tilemap[pos] = bestPattern[width/2,height/2];
        }
    }
 public static bool IsInBounds(this Tilemap tilemap, Vector3Int position)
 {
     return(tilemap.cellBounds.Contains(position));
 }
Example #55
0
    /// <summary>
    /// Find the best pattern to use when changing tiles to one of the stored patterns (with topright position arguments).
    /// </summary>
    /// <param name="px">The starting X position at the <paramref name="tilemap"/> to look at.</param>
    /// <param name="py">The starting Y position at the <paramref name="tilemap"/> to look at.</param>
    /// <param name="tilemap">The tilemap to look at.</param>
    /// <param name="bestPattern">A tileblock that will replace the area.</param>
    /// <returns>
    /// True if <paramref name="bestPattern"/> is different from the calculated
    /// pattern in <paramref name="tilemap"/>, otherwise false.
    /// </returns>
    public bool FindBestPattern(int px, int py, Tilemap tilemap, ref TileBlock bestPattern)
    {
        // store subset of tilemap where brush will be applied as a reference pattern
        TileBlock tb = new TileBlock(tilemap, px, py, width, height);

        if(cache.ContainsKey(tb))
            bestPattern = (TileBlock) cache[tb];
        else {
            // find the stored pattern that matches this reference pattern best
            float bestSimilarity = 0;
            bestPattern = null;
            foreach (TileBlock pattern in patterns) {
                float sim = calculateSimilarity(pattern, tb);
                if (sim > bestSimilarity) {
                    bestSimilarity = sim;
                    bestPattern = pattern;
                }
            }
            if(cache.Count < 16)
                cache[tb] = bestPattern;
        }
        return ! ((bestPattern == null) || (bestPattern.EqualContents(tb)));
    }
        public static bool IsInBounds(this Tilemap tilemap, Vector3 position)
        {
            Vector3Int pos = tilemap.WorldToCell(position);

            return(tilemap.cellBounds.Contains(pos));
        }
 private void OnTilemapChanged(Tilemap Tilemap)
 {
     // Visibly select new Tilemap
     if (Tilemap != null) {
         TreePath path = TreePath.NewFirst();
         TreeIter iter;
         while (Model.GetIter(out iter, path)) {
             object obj = Model.GetValue(iter, 0);
             if(obj == Tilemap) {
                 HasFocus = true;
                 ActivateRow(path, GetColumn(0));
                 SetCursor(path, GetColumn(0), false);
             }
             path.Next();
         }
     }
 }
 public static bool IsCellEmpty(this Tilemap tilemap, Vector3Int position)
 {
     return(tilemap.IsInBounds(position) && tilemap.GetTile(position) == null);
 }
Example #59
0
 public void ApplyToTilemap(FieldPos pos, Tilemap Tilemap)
 {
     ApplyToTilemap(pos, Tilemap, true);
 }
        public static bool IsCellEmpty(this Tilemap tilemap, Vector3 position)
        {
            Vector3Int pos = tilemap.WorldToCell(position);

            return(tilemap.IsInBounds(pos) && tilemap.GetTile(pos) == null);
        }