Example #1
0
    public void move(Vector3Int endGridPos, bool comeback, bool sliding)
    {
        if (!isMoving)
        {
            isMoving = true;
            Vector3    startPosition = transform.position;
            Vector3    endPosition   = tilemap_Obstacle.CellToLocal(endGridPos);
            CustomTile endTile       = tilemap_Obstacle.GetTile <CustomTile>(endGridPos);

            if (sliding && comeback)
            {
                Vector3 direction = (endPosition - startPosition).normalized;
                endGridPos -= Vector3Int.FloorToInt(direction);
                endPosition = tilemap_Obstacle.CellToLocal(endGridPos);
                endTile     = tilemap_Obstacle.GetTile <CustomTile>(endGridPos);
                comeback    = false;
            }

            if (startPosition != endPosition)
            {
                playerOverTarget = endTile.type == "target";
                StartCoroutine(LerpMove(startPosition, endPosition, endTile, comeback));
            }
            else
            {
                EventManager.TriggerEvent("ready");
                isMoving = false;
            }
        }
    }
Example #2
0
 private void CreateLevel()
 {
     for (int j = 0; j < 7; j++)
     {
         for (int i = 0; i < 17; i++)
         {
             prefabBulle.GetComponent <SpriteRenderer>().color = color.GetRandomColor();
             GameObject tmp = Instantiate(prefabBulle, tilemap.LocalToWorld(tilemap.CellToLocal(new Vector3Int(-17 + i, 19 - j, 0))), Quaternion.identity);
             board.SetEmplacement(-17 + i, 19 - j, tmp);
         }
     }
 }
Example #3
0
    public void AddCapitalStructure(Vector3Int buildPos, int playerId)
    {
        GameTile gameTile = tiles[buildPos];

        gameTile.OwnerId           = playerId;
        gameTile.OwnerInfluence    = 1000;
        gameTile.GameFieldTileType = GameTile.TileType.Structure;
        gameTile.StructType        = GameTile.StructureType.Capital;
        gameTile.BuildingLvl       = 1;
        if (gameTile.tileGameObject != null)
        {
            Destroy(gameTile.tileGameObject);
        }
        gameTile.tileGameObject = Instantiate(capitalPrefab, tilemap.CellToLocal(buildPos), Quaternion.identity);
    }
 private void SelectTile(Vector3Int gridPos)
 {
     _selectedTile    = tileMap.GetTile(gridPos);
     _selectedTilePos = gridPos;
     _tileSelection   = Instantiate(Resources.Load("TileSelectionSprite"), tileMap.CellToLocal(new Vector3Int(-gridPos.x, gridPos.y, 0)), Quaternion.identity) as GameObject;
     _isTileSelected  = true;
 }
Example #5
0
    void Start()
    {
        t = GetComponent <Tilemap>();
        BoundsInt bounds = t.cellBounds;

        var s = t.layoutGrid.cellSize / 2;

        var availablePlaces = new List <Vector3>();

        for (int n = t.cellBounds.xMin; n < t.cellBounds.xMax; n++)
        {
            for (int p = t.cellBounds.yMin; p < t.cellBounds.yMax; p++)
            {
                Vector3Int localPlace = (new Vector3Int(n, p, (int)t.transform.position.y));
                Vector3    place      = t.CellToWorld(localPlace);

                var tile = t.GetTile(localPlace);

                if (tile)
                {
                    availablePlaces.Add(place);

                    var c = new GameObject().AddComponent <BoxCollider2D>();
                    c.isTrigger               = true;
                    c.transform.parent        = t.transform;
                    c.transform.localPosition = t.CellToLocal(localPlace) + s;
                    c.gameObject.layer        = LayerMask.NameToLayer("SpeedBoost");
                }
            }
        }
    }
Example #6
0
    public bool openSpace(Vector3Int spot)
    {
        if (!(walkAble(spot)))
        {
            return(false);
        }

        Vector3 irl = walkableMap.CellToLocal(spot);

        Vector3Int up_left    = spot + new Vector3Int(-1, 1, 0);
        Vector3Int left       = spot + new Vector3Int(-1, 0, 0);
        Vector3Int down_left  = spot + new Vector3Int(-1, -1, 0);
        Vector3Int down       = spot + new Vector3Int(0, -1, 0);
        Vector3Int down_right = spot + new Vector3Int(1, -1, 0);
        Vector3Int right      = spot + new Vector3Int(1, 0, 0);
        Vector3Int up_right   = spot + new Vector3Int(1, 1, 0);
        Vector3Int up         = spot + new Vector3Int(0, 1, 0);

        Vector3 top_left     = walkableMap.CellToWorld(up_left) * 5;
        Vector3 bottom_right = walkableMap.CellToWorld(down_right) * 5;

        //Debug.DrawLine (top_left, bottom_right);


        Collider2D[] mobs   = Physics2D.OverlapAreaAll(new Vector2(top_left.x, top_left.y), new Vector2(bottom_right.x, bottom_right.y));
        bool         mobbed = (mobs.Length > 0);

//		Debug.Log (mobs.Length);

        return(walkAble(spot) && !mobbed && walkAble(up_left) && walkAble(left) && walkAble(down_left) && walkAble(down) &&
               walkAble(down_right) && walkAble(right) && walkAble(up_right) && walkAble(up));
    }
Example #7
0
    void Start()
    {
        t = gameObject.GetComponent <Tilemap>();
        BoundsInt bounds = t.cellBounds;

        TileBase[] allTiles = t.GetTilesBlock(bounds);

        var s = t.cellSize / 2;

        var availablePlaces = new List <Vector3>();

        for (int n = t.cellBounds.xMin; n < t.cellBounds.xMax; n++)
        {
            for (int p = t.cellBounds.yMin; p < t.cellBounds.yMax; p++)
            {
                Vector3Int localPlace = (new Vector3Int(n, p, (int)t.transform.position.y));
                Vector3    place      = t.CellToWorld(localPlace);

                var tile = t.GetTile(localPlace);

                if (tile)
                {
                    availablePlaces.Add(place);

                    var c = new GameObject().AddComponent <BoxCollider2D>();
                    c.isTrigger               = true;
                    c.transform.parent        = t.transform;
                    c.transform.localPosition = t.CellToLocal(localPlace) + s;

                    Debug.Log("x:" + n + " y:" + p + " tile:" + tile.name);
                }
            }
        }
    }
Example #8
0
    private void AddResource(GameObject resourceGameObject, GameTile.ResourceType resourceType, Vector3Int pos)
    {
        GameTile gameTile = GameFieldTiles.instance.tiles[pos];

        gameTile.GameFieldTileType = GameTile.TileType.Resource;
        gameTile.ResType           = resourceType;
        gameTile.tileGameObject    = Instantiate(resourceGameObject, gameField.CellToLocal(pos), Quaternion.identity);
        gameTile.tileGameObject.transform.parent = gameField.transform;
    }
Example #9
0
    public Vector3 LocalCoordinateForTileWithCurrentMousePosition()
    {
        Vector3 rawPosition   = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        Vector3 fixedPosition = new Vector3(rawPosition.x, rawPosition.y, 0);

        Vector3Int cellPosition = tilemap.WorldToCell(fixedPosition);

        return(tilemap.CellToLocal(cellPosition));
    }
Example #10
0
    public Vector3 TileToWorld(Vector3Int tileSelected)
    {
        Vector3 tile;

        tile = tm.CellToLocal(tileSelected);

        Debug.Log("Tile : " + tileSelected + " World : " + tile);

        return(tile);
    }
Example #11
0
        /// <summary>
        ///     Creates a tile at the given coordinates
        /// </summary>
        /// <param name="cord">The position of the engine</param>
        /// <param name="tilemap">The tilemap to use</param>
        /// <param name="direction">The direction it is facing</param>
        public override void Instantiate(Vector3Int cord, Tilemap tilemap, Direction direction)
        {
            base.Instantiate(cord, tilemap, direction);
            Quaternion rot        = TileInfo.TransformMatrix[direction].rotation;
            GameObject gameObject = Instantiate(exhaust,
                                                tilemap.CellToLocal(cord) +
                                                new Vector3(0.5f * tilemap.cellSize.x, 0.5f * tilemap.cellSize.y),
                                                rot * Quaternion.Euler(90, 0, 0),
                                                tilemap.transform);

            gameObject.transform.position += rot * exhaustPos + 2 * Vector3.forward;
            tilemap.transform.parent.GetComponent <ShipManager>().MovementManager
            .AddEngine(cord, this, gameObject, direction);
        }
Example #12
0
        /// <summary>
        ///     Creates a tile at the given coordinates
        /// </summary>
        /// <param name="cord">The position of the engine</param>
        /// <param name="tilemap">The tilemap to use</param>
        /// <param name="direction">The direction it is facing</param>
        public override void Instantiate(Vector3Int cord, Tilemap tilemap, Direction direction)
        {
            base.Instantiate(cord, tilemap, direction);
            GameObject gameObject = Instantiate(turretTemplate,
                                                tilemap.CellToLocal(cord) +
                                                new Vector3(0.5f * tilemap.cellSize.x, 0.5f * tilemap.cellSize.y),
                                                TileInfo.TransformMatrix[direction].rotation,
                                                tilemap.transform);

            var spriteRenderer = gameObject.GetComponent <SpriteRenderer>();

            spriteRenderer.sprite       = turret;
            spriteRenderer.sortingOrder = layer + 1;
            tilemap.transform.parent.GetComponent <ShipManager>().WeaponsManager.AddWeapon(cord, this, gameObject);
        }
    IEnumerator SmoothMove(Vector3Int newTile)
    {
        moving = true;

        float movementSpeedLocal;

        Vector3 positionToMove = tilemap.CellToLocal(newTile) + tilemap.tileAnchor;
        Vector3 originPosition = tilemap.CellToLocal(currentTile) + tilemap.tileAnchor;

        if (originPosition.y != positionToMove.y && originPosition.x == positionToMove.x)
        {
            movementSpeedLocal = verticalMovementSpeed;
        }
        else
        {
            movementSpeedLocal = horizontalMovementSpeed;
        }

        // SFX stuff.  Messy.  Need to clean up
        if ((positionToMove.x > originPosition.x || positionToMove.x < originPosition.x) && originPosition.y == positionToMove.y && AudioManager.instance != null)
        {
            AudioManager.instance.PlaySound("BoxMove");
        }


        while (transform.position != positionToMove)
        {
            float ratio = Mathf.Abs((Mathf.Abs((transform.position - originPosition).magnitude) + movementSpeedLocal * Time.deltaTime) / (positionToMove - originPosition).magnitude);

            transform.position = Vector3.Lerp(originPosition, positionToMove, ratio);

            yield return(null);
        }
        currentTile = newTile;
        moving      = false;
    }
Example #14
0
    void UpdateCursorPosition(Vector3Int offset)
    {
        Vector3Int newPosition = _currentPosition + offset;

        if (!_board.ContainsPoint(newPosition.x, newPosition.y))
        {
            return;
        }

        _currentPosition += offset;

        CustomTileData tileData = _board.tileData[_currentPosition.x, _currentPosition.y];
        Vector3Int     offsetNeededForRenderingOnMap = new Vector3Int(1, 1, tileData.position.z);

        transform.position = _tilemap.CellToLocal(_currentPosition + offsetNeededForRenderingOnMap);
    }
    public void HighlightTile(Vector3 globalPos)
    {
        var cell = Tilemap.WorldToCell(globalPos);

        Decal.transform.localPosition = Tilemap.CellToLocal(cell);
        Decal.SetActive(true);
        var construction = DataHolder.SelectedCity.Constructions.Find(x => x.X == cell.x & x.Y == cell.y);

        if (construction == null)
        {
            UIController.ShowConstructionList(cell.x, cell.y);
        }
        else
        {
            UIController.ShowInfoAboutConstruction(construction);
        }
    }
Example #16
0
    public void GenerateSpriteMask()
    {
        DestroySpriteMasks();
        t = GetComponent <Tilemap>();
        BoundsInt bounds = t.cellBounds;

        var s = t.layoutGrid.cellSize / 2;

        var availablePlaces = new List <Vector3>();

        for (int n = t.cellBounds.xMin; n < t.cellBounds.xMax; n++)
        {
            for (int p = t.cellBounds.yMin; p < t.cellBounds.yMax; p++)
            {
                Vector3Int localPlace = (new Vector3Int(n, p, (int)t.transform.position.y));
                Vector3    place      = t.CellToWorld(localPlace);

                TileBase tile = t.GetTile(localPlace);
                //CompositeCollider2D compositeCollider = t.GetComponent<CompositeCollider2D>();
                //for (int i = 0; i < compositeCollider.pathCount; i++)
                //{
                //    Vector2[] points = new Vector2[compositeCollider.GetPathPointCount(i)];

                //}

                if (tile)
                {
                    availablePlaces.Add(place);

                    var c = new GameObject().AddComponent <SpriteMask>();
                    c.GetComponent <SpriteMask>().sprite = tileMask;
                    c.transform.parent        = t.transform;
                    c.transform.localPosition = t.CellToLocal(localPlace) + s;
                    c.name = "SpriteMask";
                    generatedSpriteMasks.Add(c.gameObject);
                }
            }
        }
    }
Example #17
0
    private void SetupPotentialPortalLocations()
    {
        for (int x = floorDecor.cellBounds.xMin; x < floorDecor.cellBounds.xMax; x++)
        {
            for (int y = floorDecor.cellBounds.yMin; y < floorDecor.cellBounds.yMax; y++)
            {
                var pos           = new Vector3Int(x, y, 0);
                var localPosition = floorDecor.CellToLocal(pos) + new Vector3(0.5f, 0.5f, 0);

                if (floorDecor.GetTile(pos) == null || wallDecor.GetTile(pos) != null)
                {
                    continue;
                }

                var worldPosition = floorDecor.LocalToWorld(localPosition);
                var result        = Physics2D.OverlapCircle(worldPosition, 1f, LayerMask.GetMask("Wall"));

                if (result != null)
                {
                    failedPortalLocations.Add(worldPosition);
                }
                else
                {
                    potentialPortalSpawnLocations.Add(localPosition);
                }
                //if (result == null)
                //{
                //    potentialPortalSpawnLocations.Add(localPosition);
                //}
            }
        }

        // The max distance between portals is roughly the distance between the first and last portal
        // since we're traversing the nodes from corner to corner
        maxPortalDist = (potentialPortalSpawnLocations[0] - potentialPortalSpawnLocations[potentialPortalSpawnLocations.Count - 1]).magnitude;
    }
    public void GenerateMap()
    {
        // background
        if (backgroundFill && backGroundTile)
        {
            List <TileBase> tiles = new List <TileBase>();
            foreach (Vector3Int p in mapSize.allPositionsWithin)
            {
                //tilemap.SetTile(p, backGroundTile);
                tiles.Add(backGroundTile);
            }
            tilemap.SetTilesBlock(mapSize, tiles.ToArray());
        }

        // cities centers
        //citiesCenters = new Vector3Int[6];
        int generatedCities = citiesCenters.Length;

        tilemap.SetTile(new Vector3Int(0, 0, 0), waterTile);
        for (int i = 0; i < citiesCenters.Length; i++)
        {
            float   angle = 60 * i * Mathf.Deg2Rad;
            Vector3 p1    = new Vector3(citiesDistances * Mathf.Cos(angle), citiesDistances * Mathf.Sin(angle), 0);
            citiesCenters[i] = tilemap.LocalToCell(p1);// new Vector3Int((int)p1.x, (int)p1.y, (int)p1.z);
        }

        // forest
        for (int i = 0; i < generatedCities; i++)
        {
            BoundsInt cityBound = new BoundsInt(citiesCenters[i] - new Vector3Int(cityRadius, cityRadius, 0), new Vector3Int(2 * cityRadius, 2 * cityRadius, 1));

            foreach (Vector3Int cell in cityBound.allPositionsWithin)
            {
                Vector3 p2 = tilemap.CellToLocal(cell);
                float   r  = Vector3.Distance(tilemap.CellToLocal(citiesCenters[i]), p2);

                if (r < cityRadius && RandomForest(r / cityRadius) > forestThreshold)
                {
                    tilemap.SetTile(cell, forestTile);
                    if (Random.Range(0, 2) != 0)
                    {
                        Matrix4x4 matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0f, 180f, 0f), Vector3.one);
                        tilemap.SetTransformMatrix(cell, matrix);
                    }
                }
                else if (r < cityRadius)
                {
                    tilemap.SetTile(cell, backGroundTile);
                }
            }
            tilemap.SetTile(citiesCenters[i], waterTile);
        }

        // rivers
        for (int i = 0; i < generatedCities; i++)
        {
            Vector3Int        start = citiesCenters[i];
            List <Vector3Int> path  = GetNoisyPath(start, new Vector3Int(0, 0, 0), waysDecimation, waysDisplacementNoise, true, riverDeadendsProbability);
            foreach (Vector3Int p2 in path)
            {
                tilemap.SetTile(p2, waterTile);
            }

            float             angle = 60 * i * Mathf.Deg2Rad;
            Vector3           p1    = new Vector3(2 * citiesDistances * Mathf.Cos(angle), 2 * citiesDistances * Mathf.Sin(angle), 0);
            List <Vector3Int> path2 = GetNoisyPath(start, new Vector3Int((int)p1.x, (int)p1.y, (int)p1.z), waysDecimation, waysDisplacementNoise, true, riverDeadendsProbability);
            foreach (Vector3Int p2 in path2)
            {
                tilemap.SetTile(p2, waterTile);
            }
        }

        // roads
        for (int i = 0; i < generatedCities; i++)
        {
            Vector3Int        start = citiesCenters[i];
            Vector3Int        end   = citiesCenters[(i + 1) % citiesCenters.Length];
            List <Vector3Int> path  = GetNoisyPath(start, end, waysDecimation, waysDisplacementNoise);
            foreach (Vector3Int p2 in path)
            {
                tilemap.SetTile(p2, roadTile);
            }
        }
        if (generatedCities != citiesCenters.Length)
        {
            Vector3Int        start = citiesCenters[0];
            Vector3Int        end   = citiesCenters[citiesCenters.Length - 1];
            List <Vector3Int> path  = GetNoisyPath(start, end, waysDecimation, waysDisplacementNoise);
            foreach (Vector3Int p2 in path)
            {
                tilemap.SetTile(p2, roadTile);
            }
        }

        for (int i = 0; i < generatedCities; i++)
        {
            tilemap.SetTile(citiesCenters[i], debugTile1);
        }
    }
    private void Generate(Tilemap tilemap)
    {
        int tileCount = tilemap.GetUsedTilesCount();

        TileBase[] tiles = new TileBase[tileCount];
        tilemap.GetUsedTilesNonAlloc(tiles);

        tilemap.CompressBounds();
        Vector2    tilemapSize  = tilemap.localBounds.size;
        Vector2Int textureSize  = Vector2Int.RoundToInt(tilemapSize * pixelsPerUnit);
        Vector2Int powerOf2Size = new Vector2Int(Mathf.NextPowerOfTwo(textureSize.x), Mathf.NextPowerOfTwo(textureSize.y));
        Texture2D  texture      = new Texture2D(powerOf2Size.x, powerOf2Size.y, TextureFormat.ARGB32, false);
        Color      zeroColor    = new Color(0, 0, 0, 0);

        for (int x = 0; x < powerOf2Size.x; x++)
        {
            for (int y = 0; y < powerOf2Size.y; y++)
            {
                texture.SetPixel(x, y, zeroColor);
            }
        }

        BoundsInt bounds = tilemap.cellBounds;

        TileBase[] allTiles = tilemap.GetTilesBlock(bounds);

        for (int x = 0; x < bounds.size.x; x++)
        {
            for (int y = 0; y < bounds.size.y; y++)
            {
                TileBase tileBase = allTiles[x + y * bounds.size.x];
                if (tileBase == null)
                {
                    continue;
                }
                Tile tile = tileBase as Tile;
                if (tile == null)
                {
                    continue;
                }

                Sprite  tileSprite = tilemap.GetSprite(new Vector3Int(x + bounds.x, y + bounds.y, 0));
                Vector2 tileSize   = tileSprite.bounds.size;
                tileSize.x /= transform.lossyScale.x;
                tileSize.y /= transform.lossyScale.y;
                Vector2Int tileSizePixels = Vector2Int.RoundToInt(tileSize * pixelsPerUnit);

                Vector2 pivot            = tileSprite.pivot;
                int     tileSpriteWidth  = Mathf.RoundToInt(tileSprite.rect.xMax);
                int     tileSpriteHeight = Mathf.RoundToInt(tileSprite.rect.yMax);
                pivot.x *= tileSize.x / tileSpriteWidth;
                pivot.y *= tileSize.y / tileSpriteHeight;

                Vector2 tilePos    = tilemap.CellToLocal(new Vector3Int(x, y, 0));
                Vector2 tileOrigin = tilePos;

                tileOrigin.x *= textureSize.x / tilemapSize.x;
                tileOrigin.y *= textureSize.y / tilemapSize.y;
                Vector2Int tileOriginPixels = Vector2Int.RoundToInt(tileOrigin);

                //Color[] pixels = tile.sprite.texture.GetPixels();
                //texture.SetPixels(tileOriginPixels.x, tileOriginPixels.y, tileSizePixels.x, tileSizePixels.y, pixels);

                Texture2D spriteTex = tileSprite.texture;

                for (int px = 0; px < tileSizePixels.x; px++)
                {
                    for (int py = 0; py < tileSizePixels.y; py++)
                    {
                        int   tx    = px * tileSpriteWidth / tileSizePixels.x;
                        int   ty    = py * tileSpriteHeight / tileSizePixels.y;
                        Color pixel = spriteTex.GetPixel(tx, ty);
                        texture.SetPixel(tileOriginPixels.x + px, tileOriginPixels.y + py, pixel);
                    }
                }
            }
        }

        texture.Apply();
        Rect rect = new Rect(Vector2.zero, textureSize);

        resultSprite = Sprite.Create(texture, rect, (Vector2)textureSize / 2f, pixelsPerUnit);

        CreateAsset();
    }
Example #20
0
 void Place(string obj, int i, int j)
 {
     GameObject.Find(obj).transform.SetPositionAndRotation(gridLabirinto.CellToLocal(new Vector3Int(j, -i, 0)) + new Vector3(0.45f, 0.45f, -1f), Quaternion.identity);
 }
Example #21
0
 public Vector3 CellToLocal(Vector3Int cell) { return  tilemap.CellToLocal(cell); }
Example #22
0
    // Need to rework the animation stuff / this is messy as is
    IEnumerator SmoothMove(Vector3Int newTile)
    {
        moving = true;

        float movementSpeedLocal;

        Vector3 positionToMove = tilemap.CellToLocal(newTile) + tilemap.tileAnchor;
        Vector3 originPosition = tilemap.CellToLocal(currentTile) + tilemap.tileAnchor;

        if (originPosition.y != positionToMove.y && originPosition.x == positionToMove.x)
        {
            movementSpeedLocal = verticalMovementSpeed;
        }
        else
        {
            movementSpeedLocal = horizontalMovementSpeed;
        }

        // animation checks
        if (positionToMove.x > originPosition.x)
        {
            animator.SetBool("isSlidingRight", true);
        }
        else if (positionToMove.x < originPosition.x)
        {
            animator.SetBool("isSlidingLeft", true);
        }
        else if (positionToMove.y - originPosition.y < 0)
        {
            animator.SetBool("HasStartedFalling", true);
        }


        while (transform.position != positionToMove)
        {
            float ratio = Mathf.Abs((Mathf.Abs((transform.position - originPosition).magnitude) + movementSpeedLocal * Time.deltaTime) / (positionToMove - originPosition).magnitude);

            transform.position = Vector3.Lerp(originPosition, positionToMove, ratio);

            // If we are moving upwards and only have one tile length left to move, start the approach peak animation
            if (positionToMove.y - transform.position.y < tilelength / 2 && positionToMove.y - transform.position.y > 0 && hanging)
            {
                //animator.SetTrigger("ApproachJumpPeak");
                animator.SetBool("HaveApproachedPeak", true);
            }
            else if (positionToMove.y < transform.position.y && Mathf.Abs(positionToMove.y - transform.position.y) < tilelength / 2)
            {
                animator.SetBool("HasLanded", true);
            }
            else if (hanging && gridCollisionFlags.above)
            {
                animator.SetTrigger("HeadBonk");
            }

            yield return(null);
        }
        currentTile = newTile;
        moving      = false;

        if (hanging)
        {
            tilesMovedDuringHangtime += Mathf.Abs(originPosition.x - positionToMove.x);
        }

        //Reset animation flags
        animator.SetBool("isSlidingRight", false);
        animator.SetBool("isSlidingLeft", false);
        animator.SetBool("HaveApproachedPeak", false);
        animator.SetBool("HasStartedFalling", false);
        animator.SetBool("HasJumped", false);
        animator.SetBool("HasLanded", false);
        //animator.ResetTrigger("HeadBonk");
    }
        private bool UploadData(HEU_SessionBase session, HAPI_NodeId inputNodeID, HEU_InputData inputData)
        {
            if (settings == null)
            {
                HEU_Logger.LogError("Tilemap Settings not found!");
                return(false);
            }

            HEU_InputDataTilemap inputTilemap = inputData as HEU_InputDataTilemap;

            if (inputTilemap == null)
            {
                HEU_Logger.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 <string>     tileNames  = new List <string>();
            List <Vector3>    tileSizes  = new List <Vector3>();
            List <Vector3Int> tileCoords = new List <Vector3Int>();

            Tilemap tileMap = inputTilemap._tilemap;

            if (!tileMap.gameObject.activeInHierarchy)
            {
                HEU_Logger.LogWarning("Tilemap inputs must be active in the hierarchy in order to properly send input data");
            }

            Grid gridLayout = tileMap.layoutGrid;

            Matrix4x4 orientation              = tileMap.orientationMatrix;
            Vector3   orientationPosition      = orientation.DecomposeToPosition();
            Vector3   orientationRotationEuler = orientation.DecomposeToRotation().eulerAngles;

            orientationRotationEuler.y = -orientationRotationEuler.y;
            orientationRotationEuler.z = -orientationRotationEuler.z;
            Quaternion orientationRotation = Quaternion.Euler(orientationRotationEuler);
            Vector3    orientationScale    = orientation.DecomposeToScale();

            List <float>   pointOrient = new List <float>();
            List <Vector3> pointScale  = new List <Vector3>();

            TileBase[] tileArray = tileMap.GetTilesBlock(tileMap.cellBounds);

            int     tileCount    = 0;
            Vector3 anchorOffset = tileMap.tileAnchor;

            anchorOffset.Scale(gridLayout.cellSize);

            Vector3 pointPos;

            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 tileMapBounds.allPositionsWithin)
            {
                if (!settings._exportUnusedTiles && !tileMap.HasTile(tilePos))
                {
                    continue;
                }

                Vector3Int usedTilePos = tilePos;
                //For Houdini (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
                //usedTilePos.x = tileMapBounds.size.x - 1 - tilePos.x + 2 * tileMapBounds.min.x;

                tileCount++;
                pointPos = tileMap.CellToLocal(usedTilePos) + anchorOffset;
                if (settings._applyTilemapOrientation)
                {
                    pointPos += orientationPosition;
                    pointOrient.Add(orientationRotation[0]);
                    pointOrient.Add(orientationRotation[1]);
                    pointOrient.Add(orientationRotation[2]);
                    pointOrient.Add(orientationRotation[3]);

                    pointScale.Add(orientationScale);
                }

                vertices.Add(pointPos);

                if (tileMap.HasTile(usedTilePos))
                {
                    Tile tile = tileMap.GetTile <Tile>(usedTilePos);
                    tileNames.Add(tile.name);
                    if (settings._applyTileColor)
                    {
                        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("");
                    if (settings._applyTileColor)
                    {
                        colors.Add(Vector3.zero);
                    }
                    tileSizes.Add(Vector3.zero);
                }

                tileCoords.Add(usedTilePos);
            }

            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    = 1;

            if (tileSizes.Count > 0)
            {
                partInfo.pointAttributeCount++;
            }

            if (settings._applyTileColor && colors.Count > 0)
            {
                partInfo.pointAttributeCount++;
            }

            if (tileCoords.Count > 0)
            {
                partInfo.pointAttributeCount++;
            }

            if (pointOrient.Count > 0)
            {
                partInfo.pointAttributeCount++;
            }

            if (pointScale.Count > 0)
            {
                partInfo.pointAttributeCount++;
            }

            if (!settings._createGroupsForTiles && tileNames.Count > 0)
            {
                partInfo.pointAttributeCount++;
            }


            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_HAPIConstants.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, "unity_tile_size", 2, tileSizes.ToArray(), ref partInfo, false))
            {
                Debug.Log("Failed to set tile size attributes. ");
                return(false);
            }

            if (settings._applyTileColor)
            {
                if (!HEU_InputMeshUtility.SetMeshPointAttribute(session, displayNodeID, 0, HEU_HAPIConstants.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, "unity_tile_pos", 2, tileCoords.ToArray(), ref partInfo))
            {
                Debug.Log("Failed to set point tile coordinates attributes.");
                return(false);
            }

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

                //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_InputMeshUtility.SetMeshPointAttribute(session, displayNodeID, 0, "unity_tile_name", tileNames.ToArray(), ref partInfo))
                {
                    Debug.Log("Failed to set point tile name attributes.");
                    return(false);
                }
            }

            if (!HEU_InputMeshUtility.SetMeshDetailAttribute(session, displayNodeID, 0, "unity_tile_bounds", 2, tileMapBounds.size, ref partInfo))
            {
                Debug.Log("Failed to set detail tile map bounds attribute.");
                return(false);
            }

            if (settings._applyTilemapOrientation)
            {
                if (!HEU_InputMeshUtility.SetMeshPointAttribute(session, displayNodeID, 0, HEU_Defines.HAPI_ATTRIB_ORIENT, 4, pointOrient.ToArray(), ref partInfo))
                {
                    Debug.LogError("Failed to set point rotations.");
                    return(false);
                }

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

            return(session.CommitGeo(displayNodeID));
        }
        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);
        }