private void AddTileMapObject(Vector2 tile, Node2D tmpContainerNode)
        {
            var tileId        = pathfindingTileMap.GetCell((int)tile.x, (int)tile.y);
            var tileUniqueId  = pathfindingTileMap.GetIdForTile(tile);
            var worldPosition = pathfindingTileMap.MapToWorld(tile) + pathfindingTileMap.CellSize / 2;

            tileIdToPackedSceneMapping.TryGetValue(tileId, out var packedScene);

            if (packedScene?.Instance() is TileMapObject tileMapObject)
            {
                if (tileMapObjects.TryGetValue(tileUniqueId, out var tileMapObjectNodeReference))
                {
                    tileMapObjectNodeReference.node = tileMapObject;
                    tmpContainerNode.AddChild(tileMapObjectNodeReference.node);
                    tileMapObjectNodeReference.node.ZIndex = (int)tile.y * 2;
                    tileMapObjectNodeReference.node.SetPosition(worldPosition);
                }
                else
                {
                    throw new Exception("Expected already setup tileMapObjectNodeReference!");
                }
            }

//            else {
//                throw new Exception("Instance is not a tileMapObject");
//            }
        }
Exemplo n.º 2
0
        private void OnPathInvalidated()
        {
            var tilePositionNextToTree = ((TreeTileMapObject)pathfindingTileMap.tileMapManipulator.GetTileMapObjectWithTileMapCoordinates(targetPosition)).GetTilePositionNextToTree();

            if (tilePositionNextToTree != new Vector2(-1, -1))
            {
                entityMovement.MoveToPosition(pathfindingTileMap.MapToWorld(tilePositionNextToTree), isPlayer: true, paramsToReturn: new object[] { }, targetCannotBeReachedParamsToReturn: new object[] { GetOwner <Player>() });
            }
            else
            {
                GetStateMachine <PlayerStateMachine>().TransitionTo(GetStateMachine <PlayerStateMachine>().idle);
            }
        }
        private void OnPathInvalidated() {
            var tileMapObjectWithTileMapCoordinates = pathfindingTileMap.tileMapManipulator.GetTileMapObjectWithTileMapCoordinates(pathfindingTileMap.WorldToMap(targetPosition));
            if (tileMapObjectWithTileMapCoordinates is TreeTileMapObject treeTileMapObject) {
                var tilePositionNextToTree = treeTileMapObject.GetTilePositionNextToTree();
                if (tilePositionNextToTree != new Vector2(-1, -1)) {
                    entityMovement.MoveToPosition(pathfindingTileMap.MapToWorld(tilePositionNextToTree), isPlayer: false, paramsToReturn: new object[] { }, targetCannotBeReachedParamsToReturn: new object[] {GetOwner<Demon>()});
                    return;
                }
            }

            GetStateMachine<DemonStateMachine>().TransitionTo(GetStateMachine<DemonStateMachine>().idle);
            GetNode<Eventing>(Eventing.EventingNodePath).EmitSignal(nameof(Eventing.TargetCannotBeReached), GetOwner<Demon>());
        }