Esempio n. 1
0
    private static GameObject MakeVisual(int id, SpriteLayer.Layers layer, LevelData leveldata)
    {
        if (id < 0)
        {
            return(null);
        }
        GameObject newVisual = new GameObject("visual " + id);

        newVisual.AddComponent <SpriteRenderer>().sprite = Resources.LoadAll <Sprite>("Fore&Background/ForeBackgroundObject")[id];
        newVisual.AddComponent <SpriteLayer>().layer     = layer;
        if (leveldata.ColorId != 0)
        {
            newVisual.AddComponent <SpriteColor>().palette = (SpriteColor.Palette)(leveldata.ColorId - 1);
        }
        return(newVisual);
    }
Esempio n. 2
0
    private static GameObject MakeTile(int id, SpriteLayer.Layers layer, LevelData leveldata)
    {
        if (id < 0)
        {
            return(null);
        }

        GameObject newTile = null;

        switch (id)
        {
        default:
            break;

        case 1:
            newTile = GameObject.Instantiate(Resources.Load <GameObject>("Prefabs/Block"));
            Sprite blockSprite = null;
            switch (leveldata.ThemeId)
            {
            case 0:
                blockSprite = Resources.LoadAll <Sprite>("Blocks/Castle")[0];
                break;

            case 1:
                blockSprite = Resources.LoadAll <Sprite>("Blocks/Cave")[0];
                break;
            }

            newTile.GetComponentInChildren <SpriteRenderer>().sprite = blockSprite;
            break;

        case 2:
            newTile = GameObject.Instantiate(Resources.Load <GameObject>("Prefabs/PassThroughBlock"));
            break;

        case 4:
            newTile = GameObject.Instantiate(Resources.Load <GameObject>("Prefabs/SwitchBlock"));
            break;
        }
        if (newTile != null)
        {
            newTile.AddComponent <SpriteLayer>().layer = layer;
        }

        return(newTile);
    }
Esempio n. 3
0
    GameObject PlaceTile(int x, int y, out TileObject tileObject, int extraData = -1)
    {
        GameObject tile       = new GameObject("tile" + _tileSelector.currentLayer);
        Sprite     tileSprite = null;

        if (_tileSelector.currentLayer != 1)
        {
            tileSprite = Tile.ForeBackground[_tileSelector.SelectedTile];
        }
        else
        {
            if (_tileSelector.SelectedTile == 1)
            {
                tile.tag = "BasicBlock";
                if (extraData != -1)
                {
                    tileSprite = tileSet[extraData];
                }
            }
            else
            {
                Tile.TileMap.TryGetValue(_tileSelector.SelectedTile, out tileSprite);
            }
        }
        tile.AddComponent <SpriteRenderer>().sprite = tileSprite;
        tile.transform.position = new Vector2(x * Tile.TILE_SIZE, y * Tile.TILE_SIZE);
        SpriteLayer.Layers newLayer = SpriteLayer.Layers.Block1;
        if (_tileSelector.currentLayer == 0)
        {
            newLayer = SpriteLayer.Layers.Foreground1;
        }
        if (_tileSelector.currentLayer == 2)
        {
            newLayer = SpriteLayer.Layers.Background2;
        }
        tile.AddComponent <SpriteLayer>().layer = newLayer;
        tileObject        = new TileObject();
        tileObject.tileId = _tileSelector.SelectedTile;
        return(tile);
    }
Esempio n. 4
0
 private static void MakeLayer(int[] layerData, LevelData leveldata, bool isVisual = false, SpriteLayer.Layers layer = SpriteLayer.Layers.Block1)
 {
     for (int i = 0; i < layerData.Length; i++)
     {
         int        currentTile = layerData[i];
         GameObject newTile     = isVisual? MakeVisual(currentTile, layer, leveldata) : MakeTile(currentTile, layer, leveldata);
         if (newTile != null)
         {
             newTile.transform.parent        = leveldata.Parent.transform;
             newTile.transform.localPosition = new Vector2(i % leveldata.Width * (LevelData.TILE_SIZE * 0.01f), ((layerData.Length / leveldata.Width) * 0.01f) - (i / leveldata.Width * (LevelData.TILE_SIZE * 0.01f)));
         }
     }
 }