Build() public method

public Build ( ) : void
return void
Example #1
0
    // Use this for initialization
    void Start()
    {
        normalPiece.Build();
        resultingPiece.Build();

        var renderer = normalPiece.renderData.GetComponentInChildren <Renderer>();

        renderer.material.shader = Shader.Find("Custom/BlendVertexTransparentColor");

        renderer = resultingPiece.renderData.GetComponentInChildren <Renderer>();
        renderer.material.shader = Shader.Find("Custom/BlendVertexTransparentColor");

        normalAlpha    = 0f;
        direction      = 1;
        startCrossFade = false;
        crossFading    = false;

        var normalRenderer = normalPiece.renderData.GetComponentInChildren <Renderer>();

        normalRenderer.material.color = new Color(normalRenderer.material.color.r, normalRenderer.material.color.g, normalRenderer.material.color.b, 0);
        normalPiece.renderData.transform.localScale = new Vector3(0.5f * 0.15f, 0.5f * 0.15f, 1);
        normalPiece.renderData.transform.parent     = normalPiece.transform;

        var resultingRenderer = resultingPiece.renderData.GetComponentInChildren <Renderer>();

        resultingRenderer.material.color = new Color(resultingRenderer.material.color.r, resultingRenderer.material.color.g, resultingRenderer.material.color.b, 0);
        resultingPiece.renderData.transform.localScale = new Vector3(0.5f * 0.15f, 0.5f * 0.15f, 1);
        resultingPiece.renderData.transform.parent     = resultingPiece.transform;

        gameObject.SetLayerRecursively(5);
    }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        Debug.Log(tilemap.GetTile(1, 1, 3));

        tilemap.ClearTile(1, 1, 3);
        tilemap.Build();
    }
Example #3
0
 //从一个CVS格式内容,读取数据,并根据数据生成当前tilemap
 public bool LoadTileMap(tk2dTileMap tk2dTM, int layerID, string result)
 {
     try
     {
         //清空layerID此层的所有数据,若不清空,之前拥有Prefab的tile会继续保留在场景中,所以要销毁此层所有数据
         tk2dTM.Layers[layerID].DestroyGameData(tk2dTM);
         width  = tk2dTM.width;
         height = tk2dTM.height;
         int tileID;
         //根据换行符 "\r\n" 将数据分割为数组,每行对应一个元素   ★重点应用★
         string[] resultArray = result.Split(new string[] { "\r\n" }, StringSplitOptions.None);
         //从第一行开始,读取数据,tiled中的第一行,对应的是tk2dTileMap中的 height-1-y 行
         for (int y = height - 1; y > -1; y--)
         {
             //将每行的数据分割为数组,对应为每个tile的tileID
             string[] row = resultArray[height - 1 - y].Split(new Char[] { ',' });
             //循环读取行数组的数据,并将每个tile设置为对应内容
             for (int x = 0; x < width; x++)
             {
                 tileID = Convert.ToInt16(row[x]);
                 //设置前,清除当前位置的tile
                 tk2dTM.ClearTile(x, y, layerID);
                 tk2dTM.SetTile(x, y, layerID, tileID);
             }
         }
         //对tk2dTileMap进行修改后,需要build才能生效
         tk2dTM.Build();
         return(true);
     }
     catch
     {
         //throw;
         return(false);
     }
 }
    public void Clone(Mode mode)
    {
        var layers = _tileMapTarget.Layers;

        for (int l = 0; l < layers.Length; l++)
        {
            var layer = layers[l];

            for (int w = 0; w < _tileMapTarget.width; w++)
            {
                for (int h = 0; h < _tileMapTarget.height; h++)
                {
                    var tileId = _tileMapTarget.GetTile(w, h, l);

                    if (tileId != -1)
                    {
                        var tileInfo = _tileMapTarget.GetTileInfoForTileId(tileId);

                        if (tileInfo.stringVal == "n")
                        {
                            continue;
                        }

                        var nameIndex = _targetNameIndexes[tileId];

                        var tileToChange = 0;

                        if (tileInfo.stringVal == "c")
                        {
                            tileToChange = getSpriteId("tileset/" + tileInfo.intVal);
                        }

                        if (tileInfo.stringVal == "")
                        {
                            tileToChange = getSpriteId("tileset/" + (nameIndex + _offset));
                        }

                        switch (mode)
                        {
                        case Mode.Safe:
                            cloneSafe(tileId, tileToChange, w, h, l);
                            break;

                        case Mode.Override:
                            cloneOverride(tileToChange, w, h, l);
                            break;

                        case Mode.SafeOverride:
                            cloneSafeAdd(tileId, tileToChange, w, h, l);
                            break;
                        }
                    }
                }
            }
        }

        _tileMap.Build();
    }
Example #5
0
    static void Create()
    {
        tk2dSpriteCollectionData sprColl = null;

        if (sprColl == null)
        {
            // try to inherit from other TileMaps in scene
            tk2dTileMap sceneTileMaps = GameObject.FindObjectOfType(typeof(tk2dTileMap)) as tk2dTileMap;
            if (sceneTileMaps)
            {
                sprColl = sceneTileMaps.Editor__SpriteCollection;
            }
        }

        if (sprColl == null)
        {
            tk2dSpriteCollectionIndex[] spriteCollections = tk2dEditorUtility.GetOrCreateIndex().GetSpriteCollectionIndex();
            foreach (var v in spriteCollections)
            {
                if (v.managedSpriteCollection)
                {
                    continue;                                            // don't wanna pick a managed one
                }
                GameObject scgo = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(v.spriteCollectionDataGUID), typeof(GameObject)) as GameObject;
                var        sc   = scgo.GetComponent <tk2dSpriteCollectionData>();
                if (sc != null && sc.spriteDefinitions != null && sc.spriteDefinitions.Length > 0 && sc.allowMultipleAtlases == false)
                {
                    sprColl = sc;
                    break;
                }
            }

            if (sprColl == null)
            {
                EditorUtility.DisplayDialog("Create TileMap", "Unable to create sprite as no SpriteCollections have been found.", "Ok");
                return;
            }
        }

        GameObject go = tk2dEditorUtility.CreateGameObjectInScene("TileMap");

        go.transform.position = Vector3.zero;
        go.transform.rotation = Quaternion.identity;
        tk2dTileMap tileMap = go.AddComponent <tk2dTileMap>();

        tileMap.Editor__SpriteCollection = sprColl;

        tileMap.Build(tk2dTileMap.BuildFlags.ForceBuild);

        Selection.activeGameObject = go;
        Undo.RegisterCreatedObjectUndo(go, "Create TileMap");
    }
    public void BuildLevel(int level)
    {
        this.level     = level;
        MainGame.Level = level;
        for (int i = 0; i < MainGame.fullMap.Width; i++)
        {
            for (int j = 0; j < MainGame.fullMap.Height; j++)
            {
                if (MainGame.fullMap.GetTile(i, j, level).Underground)
                {
                    int tile = tileMap.SpriteCollectionInst.GetSpriteIdByName("Underground-square");
                    tileMap.SetTile(i, j, 0, tile);
                }
                else
                {
                    int tile = tileMap.SpriteCollectionInst.GetSpriteIdByName(MainGame.fullMap.GetTile(i, j, level).Biome + "-square");
                    tileMap.SetTile(i, j, 0, tile);
                }
            }
        }

        tileMap.Build();
    }
Example #7
0
    // Update is called once per frame
    void Update()
    {
        if (projectileCollision != null)
        {
            int xPos;
            int yPos;

            ContactPoint2D contactpoint = projectileCollision.contacts[0];
            Vector3        tempVec      = new Vector3(contactpoint.point.x + (.5f * contactpoint.normal.x), contactpoint.point.y, 5);

            tilemap.GetTileAtPosition(tempVec, out xPos, out yPos);


            int tileId = tilemap.Layers[layerCollider].GetTile(xPos, yPos);
            if (tileId >= 0)
            {
                if (tileArray[xPos, yPos] > 0)
                {
                    tileArray[xPos, yPos] -= damage;
                    int damageTile = (int)(3 * (tileArray[xPos, yPos]) / health) + 64;
                    Debug.Log(damageTile);
                    tilemap.Layers[layerColliderDecals].SetTile(xPos, yPos, damageTile);
                }
                else
                {
                    tilemap.Layers[layerCollider].ClearTile(xPos, yPos);
                    tilemap.Layers[layerColliderDecals].ClearTile(xPos, yPos);
                    tilemap.Layers[layerColliderCorners].ClearTile(xPos, yPos);
                    tilemap.Layers[layerColliderEdges].ClearTile(xPos, yPos);
                    setNWESTiles(xPos, yPos);
                }
                tilemap.Build();
            }
        }
        projectileCollision = null;
        damage = 0;
    }
Example #8
0
    public void Refresh()
    {
        for (int i = 0; i < MAX_WIDTH; i++)
        {
            for (int j = 0; j < MAX_HEIGHT; j++)
            {
                if (Layout[i, j] > 0)
                {
                    tileMap.SetTile(i, j, 0, Layout[i, j] - 1 + Variant * Block.MAX_VALUE);
                }
                else
                {
                    tileMap.ClearTile(i, j, 0);
                }
            }
        }

        tileMap.Build();
    }
 public void Build()
 {
     map.Build();
     // MAy be able to do this before first build
     // Make marching squares
 }