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


C# Layer.renderTriangles方法代码示例

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


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

示例1: CreateColliderMesh

    public Mesh CreateColliderMesh()
    {
        // We use the currentLayer ID to order them on the Z axis.
        // Be aware that on the collider mesh it depends on the freezeColliderLayers
        // variable, this way you can avoid having colliders on different z axis.
        int currentLayerID = 0;

        // UsedVertices is used to maintain a count of the vertices between
        // layers so when you call renderTriangles, it nows where to start.
        int usedVertices = 0;

        TileSet tileset = null;
        List<Vector3> vertices = new List<Vector3> ();
        List<int> triangles = new List<int> ();
        Mesh mesh = new Mesh ();

        XmlDocument xmldoc = new XmlDocument ();
        xmldoc.Load (new StringReader (tilemap.text));
        XmlNodeList nodelist = xmldoc.DocumentElement.ChildNodes;

        // Works the almost the same way as the createMesh method (builds the
        // tileset and layer objects, then builds the mesh with those
        // but only checks on the collision names plus it doesn't build model
        // uv since its not neccesary.
        foreach (XmlNode outerNode in nodelist) {
            switch (outerNode.Name) {
            case "tileset":
                if (outerNode.Attributes ["name"].InnerText.IndexOf ("Collision") != -1) {
                    XmlNode imageNode = outerNode.SelectSingleNode ("image");
                    int firstGID = int.Parse (outerNode.Attributes ["firstgid"].InnerText);
                    int width = int.Parse (outerNode.Attributes ["tilewidth"].InnerText);
                    int height = int.Parse (outerNode.Attributes ["tileheight"].InnerText);
                    int imageWidth = int.Parse (imageNode.Attributes ["width"].InnerText);
                    int imageheight = int.Parse (imageNode.Attributes ["height"].InnerText);
                    tileset = new TileSet (firstGID, width, height, imageWidth, imageheight);

                    // On the TMX editor, we set some attributes on our collider tiles so when parsing the
                    // tileset, we'll be adding them to our tileset object.
                    foreach (XmlNode innerNode in outerNode.ChildNodes) {
                        if (innerNode.Name == "tile") {
                            int tileID = 0;
                            if (int.TryParse (innerNode.Attributes ["id"].InnerText, out tileID)) {
                                XmlNode propertyNodes = innerNode.SelectSingleNode ("properties");
                                foreach (XmlNode propertyNode in propertyNodes) {
                                    if (propertyNode.Attributes ["name"].InnerText == "col") {
                                        tileset.AddCollision (tileID, propertyNode.Attributes ["value"].InnerText);
                                    }
                                }
                            }
                        }
                    }
                }
                break;
            case "layer":
                if (outerNode.Attributes ["name"].InnerText.IndexOf ("collision_") != -1) {
                    XmlNode dataNode = outerNode.SelectSingleNode ("data");
                    int layerWidth = int.Parse (outerNode.Attributes ["width"].InnerText);
                    int layerHeight = int.Parse (outerNode.Attributes ["height"].InnerText);
                    string csvData = dataNode.InnerText;
                    Layer currentLayer = new Layer (tileset, csvData, currentLayerID, layerWidth, layerHeight);
                    vertices.AddRange (currentLayer.renderColVertices ());
                    triangles.AddRange (currentLayer.renderTriangles (usedVertices, usedVertices + currentLayer.vertexCount));
                    usedVertices += currentLayer.vertexCount;
                    // In case we freeze the layers on collider they wont move on the z axis.
                }
                if (!freezeLayersOnCollider)
                    currentLayerID++;
                break;
            case "objectgroup":
                if (outerNode.Attributes ["name"].InnerText.IndexOf ("CollisionObjects") != -1) {
                    foreach (XmlNode objectNode in outerNode.ChildNodes) {
                        int colliderWidth = 0;
                        int colliderHeight = 0;

                        if (objectNode.Attributes.GetNamedItem ("width") != null) {
                            colliderWidth = int.Parse (objectNode.Attributes ["width"].InnerText);
                            colliderHeight = int.Parse (objectNode.Attributes ["height"].InnerText);
                        }

                        int colliderX = int.Parse (objectNode.Attributes ["x"].InnerText);
                        int colliderY = int.Parse (objectNode.Attributes ["y"].InnerText);
                        colliderX += (colliderWidth / 2 + 16);
                        colliderY = - (colliderY + colliderHeight / 2);

                        GameObject newCollider = null;

                        if (objectNode.HasChildNodes) {
                            // Can be polyline, ellipse or polygon, as boxes have no child.
                            string objectType = objectNode.FirstChild.Name;
                            Debug.Log ("Has children: " + objectType);
                            switch (objectType) {
                            case "ellipse":
                                newCollider = CreateEllipseCollider (colliderX, colliderY, colliderWidth, colliderHeight);
                                break;
                            case "polyline":
                                XmlNode polylineData = objectNode.FirstChild;
                                newCollider = CreatePolylineCollider (polylineData, colliderX, colliderY);
                                break;
                            case "polygon":
                            default:
//.........这里部分代码省略.........
开发者ID:kjellski,项目名称:TiledMapLoader,代码行数:101,代码来源:TileMap.cs

示例2: CreateMesh

    public Mesh CreateMesh()
    {
        // We use the currentLayer ID to order them on the Z axis.
        int currentLayerID = 0;

        // UsedVertices is used to maintain a count of the vertices between
        //layers so when you call renderTriangles, it nows where to start.
        int usedVertices = 0;

        TileSet tileset = null;
        List<Vector3> vertices = new List<Vector3> ();
        List<Vector2> uv = new List<Vector2> ();
        List<int> triangles = new List<int> ();
        Mesh mesh = new Mesh ();

        // What we're doing here is simple: Load the xml file from the attributes
        // And start parsing. Once it finds a tileset element it creates the tileset object
        // (it will be the first thing it encounters)
        XmlDocument xmldoc = new XmlDocument ();
        xmldoc.Load (new StringReader (tilemap.text));
        XmlNodeList nodelist = xmldoc.DocumentElement.ChildNodes;
        foreach (XmlNode outerNode in nodelist) {
            switch (outerNode.Name) {
            case "tileset":
                // Basically we just grab the data from the xml and build a Tileset object
                // To avoid problems with the collision tileset since we only store one tileset
                // we ignore anything with Collision inside.
                if (outerNode.Attributes ["name"].InnerText.IndexOf ("Collision") == -1) {
                    XmlNode imageNode = outerNode.SelectSingleNode ("image");
                    int firstGID = int.Parse (outerNode.Attributes ["firstgid"].InnerText);
                    int width = int.Parse (outerNode.Attributes ["tilewidth"].InnerText);
                    int height = int.Parse (outerNode.Attributes ["tileheight"].InnerText);
                    int imageWidth = int.Parse (imageNode.Attributes ["width"].InnerText);
                    int imageheight = int.Parse (imageNode.Attributes ["height"].InnerText);
                    int tileBorder = 0;
                    if (outerNode.Attributes ["spacing"] != null)
                        tileBorder = int.Parse (outerNode.Attributes ["spacing"].InnerText);
                    tileset = new TileSet (firstGID, width, height, imageWidth, imageheight, tileBorder);
                }
                break;
            case "layer":
                // First we build the layer object and then just call the renderVertices
                // renderUV and renderTriangles to build our textured mesh.
                // Finally we store the vertexcount and +1 to the currentLayerID.
                // like in the tileset, we avoid using the "collision_" layers since
                // they only contain collision info
                if (outerNode.Attributes ["name"].InnerText.IndexOf ("collision_") == -1) {
                    XmlNode dataNode = outerNode.SelectSingleNode ("data");
                    int layerWidth = int.Parse (outerNode.Attributes ["width"].InnerText);
                    int layerHeight = int.Parse (outerNode.Attributes ["height"].InnerText);
                    string csvData = dataNode.InnerText;
                    Layer currentLayer = new Layer (tileset, csvData, currentLayerID, layerWidth, layerHeight);
                    vertices.AddRange (currentLayer.renderVertices ());
                    uv.AddRange (currentLayer.renderUv ());
                    triangles.AddRange (currentLayer.renderTriangles (usedVertices, usedVertices+currentLayer.vertexCount));
                    usedVertices += currentLayer.vertexCount;
                }
                currentLayerID += 1;
                break;
            }
        }

        mesh.vertices = vertices.ToArray ();
        mesh.uv = uv.ToArray ();
        mesh.triangles = triangles.ToArray ();
        return mesh;
    }
开发者ID:kjellski,项目名称:TiledMapLoader,代码行数:67,代码来源:TileMap.cs


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