public Sprite(ObjectReader reader) : base(reader) { m_Rect = reader.ReadRectangleF(); m_Offset = reader.ReadVector2(); if (version[0] > 4 || (version[0] == 4 && version[1] >= 5)) //4.5 and up { m_Border = reader.ReadVector4(); } m_PixelsToUnits = reader.ReadSingle(); if (version[0] > 5 || (version[0] == 5 && version[1] > 4) || (version[0] == 5 && version[1] == 4 && version[2] >= 2) || (version[0] == 5 && version[1] == 4 && version[2] == 1 && buildType.IsPatch && version[3] >= 3)) //5.4.1p3 and up { m_Pivot = reader.ReadVector2(); } m_Extrude = reader.ReadUInt32(); if (version[0] > 5 || (version[0] == 5 && version[1] >= 3)) //5.3 and up { m_IsPolygon = reader.ReadBoolean(); reader.AlignStream(); } if (version[0] >= 2017) //2017 and up { var first = new Guid(reader.ReadBytes(16)); var second = reader.ReadInt64(); m_RenderDataKey = new KeyValuePair <Guid, long>(first, second); m_AtlasTags = reader.ReadStringArray(); m_SpriteAtlas = new PPtr <SpriteAtlas>(reader); } m_RD = new SpriteRenderData(reader); if (version[0] >= 2017) //2017 and up { var m_PhysicsShapeSize = reader.ReadInt32(); m_PhysicsShape = new Vector2[m_PhysicsShapeSize][]; for (int i = 0; i < m_PhysicsShapeSize; i++) { m_PhysicsShape[i] = reader.ReadVector2Array(); } } //vector m_Bones 2018 and up }
private static Vector2[][] GetTriangles(SpriteRenderData m_RD) { if (m_RD.vertices != null) //5.6 down { var vertices = m_RD.vertices.Select(x => (Vector2)x.pos).ToArray(); var triangleCount = m_RD.indices.Length / 3; var triangles = new Vector2[triangleCount][]; for (int i = 0; i < triangleCount; i++) { var first = m_RD.indices[i * 3]; var second = m_RD.indices[i * 3 + 1]; var third = m_RD.indices[i * 3 + 2]; var triangle = new[] { vertices[first], vertices[second], vertices[third] }; triangles[i] = triangle; } return(triangles); } return(GetTriangles(m_RD.m_VertexData, m_RD.m_SubMeshes, m_RD.m_IndexBuffer)); //5.6 and up }