当前位置: 首页>>代码示例>>C#>>正文


C# World.GetTileAt方法代码示例

本文整理汇总了C#中World.GetTileAt方法的典型用法代码示例。如果您正苦于以下问题:C# World.GetTileAt方法的具体用法?C# World.GetTileAt怎么用?C# World.GetTileAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在World的用法示例。


在下文中一共展示了World.GetTileAt方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Start

    // Use this for initialization
    void Start()
    {
        GameWorld = new World ();
        _instance = this;

        //Move the camera to the center of the world
        Camera.main.transform.position = new Vector3(World.defaultWorldSize/2, World.defaultWorldSize/2, Camera.main.transform.position.z);
        Camera.main.orthographicSize = World.defaultWorldSize/2 + 1; //set so slightly more than whole world is visible

        //Create a Gameobject for each tile in order to display on screen;
        for (int x = 0; x < GameWorld.X; x++) {
            for (int y = 0; y < GameWorld.Y; y++) {
                for (int z = 0; z < GameWorld.Z; z++) {

                    Tile tile_data = GameWorld.GetTileAt (x, y, z); //get Tile data

                    GameObject tile_go = new GameObject (); //setup gameobject for scene
                    tile_go.name = "Tile_" + x + "_" + y + "_" + z; //name it
                    tile_go.transform.position = new Vector3 (tile_data.X, tile_data.Y, tile_data.Z); //make it match data
                    tile_go.transform.SetParent(this.transform, true);

                    tile_go.AddComponent<SpriteRenderer> (); //add a sprite renderer to be setup later

                    //lambda to wrap callback function
                    tile_data.RegisterTileTypeChangedCallback ( (tile) => {OnTileTypeChanged(tile,tile_go);});

                }
            }
        }
        //for testing

        Invoke ("doRandomize", 1f); //Waits 2 seconds then randomizes tiles and updates textures
    }
开发者ID:Battlespud,项目名称:ducking-octo-shame,代码行数:34,代码来源:WorldGenerator.cs

示例2: Start

    void Start()
    {
        World = new World();

        for (int x = 0; x < World.Width; x++) {
            for (int z = 0; z < World.Height; z++) {
                Tile tile_data = World.GetTileAt(x, z);
                Vector3 pos;
                if (z % 2 == 1)
                    pos = new Vector3(x * width_offset + x_offset,0,z * z_offset);
                else
                    pos = new Vector3(x * width_offset,0,z * z_offset);
                GameObject hex_current = (GameObject) Instantiate(hex_tile, pos, Quaternion.identity);
                hex_current.name = "Hex (" + x + "," + z + ")";
                hex_current.isStatic = true;
                // Add a hex component for each hex tile at run time.
                // For ease of reference relativity.
                hex_current.AddComponent<Hex> ();
                hex_current.GetComponent<Hex> ().tile_rep = tile_data;
                // Arrange in a clean hierachy, set parent of all hex tiles to the map.
                hex_current.transform.SetParent(this.transform, true);

                // Register the callback function for tiles here, using the redisplay method in Map.
                tile_data.RegisterTileRedisplayCallback((tile)=> { OnHexRedisplay(tile, hex_current); });
            }
        }
        World.SetTilesAtRandom();

        // for testing below, generate a player pawn.
        GameObject player = GameObject.Find("Pawn (0,0)");
        player.GetComponent<Character> ().Body = new Creature (World, 0, 0, 40, Creature.ArmorType.Cloth, Creature.WeaponType.Light, 8, 4, 0, 3, 3);
        GameObject o_pawn = GameObject.Find ("Hex (" + 0 + "," + 0 + ")");
        player.transform.position = o_pawn.transform.position;

        GameObject enemy = GameObject.Find("Pawn (4,4)");
        enemy.GetComponent<Character> ().Body = new Creature (World, 4, 4, 60, Creature.ArmorType.Mail, Creature.WeaponType.Piercing, 10, 1, 0, 2);
        GameObject o_pawn2 = GameObject.Find ("Hex (" + 4 + "," + 4 + ")");
        enemy.transform.position = o_pawn2.transform.position;

        GameObject structure = GameObject.Find("Pawn (8,8)");
        structure.GetComponent<Character> ().Body = new Structure (World, 8, 8, 60, 8, 5, 1, 2);
        GameObject o_pawn3 = GameObject.Find ("Hex (" + 8 + "," + 8 + ")");
        structure.transform.position = o_pawn3.transform.position;
    }
开发者ID:12xq4,项目名称:EverConquestALand,代码行数:44,代码来源:Map.cs

示例3: Path_TileGraph

    public Path_TileGraph(World world)
    {
        Debug.Log("Path_TileGraph");

        // Loop through all tiles of the world
        // For each tile, create a node
        //  Do we create nodes for non-floor tiles?  NO!
        //  Do we create nodes for tiles that are completely unwalkable (i.e. walls)?  NO!

        nodes = new Dictionary<Tile, Path_Node<Tile>>();

        for (int x = 0; x < world.Width; x++) {
            for (int y = 0; y < world.Height; y++) {

                Tile t = world.GetTileAt(x,y);

                //if(t.movementCost > 0) {	// Tiles with a move cost of 0 are unwalkable
                    Path_Node<Tile> n = new Path_Node<Tile>();
                    n.data = t;
                    nodes.Add(t, n);
                //}

            }
        }

        Debug.Log("Path_TileGraph: Created "+nodes.Count+" nodes.");

        // Now loop through all nodes again
        // Create edges for neighbours

        int edgeCount = 0;

        foreach(Tile t in nodes.Keys) {
            Path_Node<Tile> n = nodes[t];

            List<Path_Edge<Tile>> edges = new List<Path_Edge<Tile>>();

            // Get a list of neighbours for the tile
            Tile[] neighbours = t.GetNeighbours(true);	// NOTE: Some of the array spots could be null.

            // If neighbour is walkable, create an edge to the relevant node.
            for (int i = 0; i < neighbours.Length; i++) {
                if(neighbours[i] != null && neighbours[i].movementCost > 0 && IsClippingCorner( t, neighbours[i] ) == false) {
                    // This neighbour exists, is walkable, and doesn't requiring clipping a corner --> so create an edge.

                    Path_Edge<Tile> e = new Path_Edge<Tile>();
                    e.cost = neighbours[i].movementCost;
                    e.node = nodes[ neighbours[i] ];

                    // Add the edge to our temporary (and growable!) list
                    edges.Add(e);

                    edgeCount++;
                }
            }

            n.edges = edges.ToArray();
        }

        Debug.Log("Path_TileGraph: Created "+edgeCount+" edges.");
    }
开发者ID:ConorGrocock,项目名称:Project_Porcupine,代码行数:61,代码来源:Path_TileGraph.cs


注:本文中的World.GetTileAt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。