SpriteMeshData.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace UnityEditor.U2D.Animation
  5. {
  6. [Serializable]
  7. internal class SpriteBoneData
  8. {
  9. public string name;
  10. public int parentId = -1;
  11. public Vector2 localPosition;
  12. public Quaternion localRotation = Quaternion.identity;
  13. public Vector2 position;
  14. public Vector2 endPosition;
  15. public float depth;
  16. public float length;
  17. }
  18. internal interface ISpriteMeshData
  19. {
  20. Rect frame { get; set; }
  21. List<int> indices { get; set; }
  22. List<Edge> edges { get; set; }
  23. int vertexCount { get; }
  24. int boneCount { get; }
  25. Vector2 GetPosition(int index);
  26. void SetPosition(int index, Vector2 position);
  27. EditableBoneWeight GetWeight(int index);
  28. void SetWeight(int index, EditableBoneWeight weight);
  29. void AddVertex(Vector2 position, BoneWeight weight);
  30. void RemoveVertex(int index);
  31. SpriteBoneData GetBoneData(int index);
  32. float GetBoneDepth(int index);
  33. void Clear();
  34. }
  35. [Serializable]
  36. internal class SpriteMeshData : ISpriteMeshData
  37. {
  38. public GUID spriteID = new GUID();
  39. [SerializeField]
  40. private Rect m_Frame;
  41. public Vector2 pivot = Vector2.zero;
  42. [SerializeField]
  43. private List<Vertex2D> m_Vertices = new List<Vertex2D>();
  44. [SerializeField]
  45. private List<int> m_Indices = new List<int>();
  46. [SerializeField]
  47. public List<SpriteBoneData> m_Bones = new List<SpriteBoneData>();
  48. [SerializeField]
  49. private List<Edge> m_Edges = new List<Edge>();
  50. public Rect frame
  51. {
  52. get { return m_Frame; }
  53. set { m_Frame = value; }
  54. }
  55. public List<Vertex2D> vertices
  56. {
  57. get { return m_Vertices; }
  58. set { m_Vertices = value; }
  59. }
  60. public List<int> indices
  61. {
  62. get { return m_Indices; }
  63. set { m_Indices = value; }
  64. }
  65. public List<Edge> edges
  66. {
  67. get { return m_Edges; }
  68. set { m_Edges = value; }
  69. }
  70. public List<SpriteBoneData> bones
  71. {
  72. get { return m_Bones; }
  73. set { m_Bones = value; }
  74. }
  75. public int vertexCount { get { return m_Vertices.Count; } }
  76. public int boneCount { get { return m_Bones.Count; } }
  77. public Vector2 GetPosition(int index)
  78. {
  79. return m_Vertices[index].position;
  80. }
  81. public void SetPosition(int index, Vector2 position)
  82. {
  83. m_Vertices[index].position = position;
  84. }
  85. public EditableBoneWeight GetWeight(int index)
  86. {
  87. return m_Vertices[index].editableBoneWeight;
  88. }
  89. public void SetWeight(int index, EditableBoneWeight weight)
  90. {
  91. m_Vertices[index].editableBoneWeight = weight;
  92. }
  93. public void AddVertex(Vector2 position, BoneWeight weight)
  94. {
  95. m_Vertices.Add(new Vertex2D(position, weight));
  96. }
  97. public void RemoveVertex(int index)
  98. {
  99. m_Vertices.RemoveAt(index);
  100. }
  101. public SpriteBoneData GetBoneData(int index)
  102. {
  103. return m_Bones[index];
  104. }
  105. public float GetBoneDepth(int index)
  106. {
  107. return m_Bones[index].depth;
  108. }
  109. public void Clear()
  110. {
  111. m_Vertices.Clear();
  112. m_Indices.Clear();
  113. m_Edges.Clear();
  114. }
  115. }
  116. }