SkinningCachePersistentState.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace UnityEditor.U2D.Animation
  5. {
  6. internal interface ISkinningCachePersistentState
  7. {
  8. String lastSpriteId
  9. {
  10. get;
  11. set;
  12. }
  13. Tools lastUsedTool
  14. {
  15. get;
  16. set;
  17. }
  18. List<int> lastBoneSelectionIds
  19. {
  20. get;
  21. }
  22. Texture2D lastTexture
  23. {
  24. get;
  25. set;
  26. }
  27. SerializableDictionary<int, BonePose> lastPreviewPose
  28. {
  29. get;
  30. }
  31. SerializableDictionary<int, bool> lastBoneVisibility
  32. {
  33. get;
  34. }
  35. SerializableDictionary<int, bool> lastBoneExpansion
  36. {
  37. get;
  38. }
  39. SerializableDictionary<string, bool> lastSpriteVisibility
  40. {
  41. get;
  42. }
  43. SerializableDictionary<int, bool> lastGroupVisibility
  44. {
  45. get;
  46. }
  47. SkinningMode lastMode
  48. {
  49. get;
  50. set;
  51. }
  52. bool lastVisibilityToolActive
  53. {
  54. get;
  55. set;
  56. }
  57. int lastVisibilityToolIndex
  58. {
  59. get;
  60. set;
  61. }
  62. IndexedSelection lastVertexSelection
  63. {
  64. get;
  65. }
  66. float lastBrushSize
  67. {
  68. get;
  69. set;
  70. }
  71. float lastBrushHardness
  72. {
  73. get;
  74. set;
  75. }
  76. float lastBrushStep
  77. {
  78. get;
  79. set;
  80. }
  81. }
  82. [Serializable]
  83. internal class SkinningCachePersistentState
  84. : ScriptableSingleton<SkinningCachePersistentState>
  85. , ISkinningCachePersistentState
  86. {
  87. [SerializeField] private Tools m_LastUsedTool = Tools.EditPose;
  88. [SerializeField] private SkinningMode m_LastMode = SkinningMode.Character;
  89. [SerializeField] private string m_LastSpriteId = String.Empty;
  90. [SerializeField] private List<int> m_LastBoneSelectionIds = new List<int>();
  91. [SerializeField] private Texture2D m_LastTexture;
  92. [SerializeField]
  93. private SerializableDictionary<int, BonePose> m_SkeletonPreviewPose =
  94. new SerializableDictionary<int, BonePose>();
  95. [SerializeField]
  96. private SerializableDictionary<int, bool> m_BoneVisibility =
  97. new SerializableDictionary<int, bool>();
  98. [SerializeField]
  99. private SerializableDictionary<int, bool> m_BoneExpansion =
  100. new SerializableDictionary<int, bool>();
  101. [SerializeField]
  102. private SerializableDictionary<string, bool> m_SpriteVisibility =
  103. new SerializableDictionary<string, bool>();
  104. [SerializeField]
  105. private SerializableDictionary<int, bool> m_GroupVisibility =
  106. new SerializableDictionary<int, bool>();
  107. [SerializeField] private IndexedSelection m_VertexSelection;
  108. [SerializeField] private bool m_VisibilityToolActive;
  109. [SerializeField] private int m_VisibilityToolIndex = -1;
  110. [SerializeField] private float m_LastBrushSize = 25f;
  111. [SerializeField] private float m_LastBrushHardness = 1f;
  112. [SerializeField] private float m_LastBrushStep = 20f;
  113. public SkinningCachePersistentState()
  114. {
  115. m_VertexSelection = new IndexedSelection();
  116. }
  117. public void SetDefault()
  118. {
  119. m_LastUsedTool = Tools.EditPose;
  120. m_LastMode = SkinningMode.Character;
  121. m_LastSpriteId = String.Empty;
  122. m_LastBoneSelectionIds.Clear();
  123. m_LastTexture = null;
  124. m_VertexSelection.Clear();
  125. m_SkeletonPreviewPose.Clear();
  126. m_BoneVisibility.Clear();
  127. m_BoneExpansion.Clear();
  128. m_SpriteVisibility.Clear();
  129. m_GroupVisibility.Clear();
  130. m_VisibilityToolActive = false;
  131. m_VisibilityToolIndex = -1;
  132. }
  133. public string lastSpriteId
  134. {
  135. get { return m_LastSpriteId; }
  136. set { m_LastSpriteId = value; }
  137. }
  138. public Tools lastUsedTool
  139. {
  140. get { return m_LastUsedTool; }
  141. set { m_LastUsedTool = value; }
  142. }
  143. public List<int> lastBoneSelectionIds
  144. {
  145. get { return m_LastBoneSelectionIds; }
  146. }
  147. public Texture2D lastTexture
  148. {
  149. get { return m_LastTexture; }
  150. set
  151. {
  152. if (value != m_LastTexture)
  153. {
  154. m_LastMode = SkinningMode.Character;
  155. m_LastSpriteId = String.Empty;
  156. m_LastBoneSelectionIds.Clear();
  157. m_VertexSelection.Clear();
  158. m_SkeletonPreviewPose.Clear();
  159. m_BoneVisibility.Clear();
  160. m_BoneExpansion.Clear();
  161. m_SpriteVisibility.Clear();
  162. m_GroupVisibility.Clear();
  163. }
  164. m_LastTexture = value;
  165. }
  166. }
  167. public SerializableDictionary<int, BonePose> lastPreviewPose
  168. {
  169. get { return m_SkeletonPreviewPose; }
  170. }
  171. public SerializableDictionary<int, bool> lastBoneVisibility
  172. {
  173. get { return m_BoneVisibility; }
  174. }
  175. public SerializableDictionary<int, bool> lastBoneExpansion
  176. {
  177. get { return m_BoneExpansion; }
  178. }
  179. public SerializableDictionary<string, bool> lastSpriteVisibility
  180. {
  181. get { return m_SpriteVisibility; }
  182. }
  183. public SerializableDictionary<int, bool> lastGroupVisibility
  184. {
  185. get { return m_GroupVisibility; }
  186. }
  187. public SkinningMode lastMode
  188. {
  189. get { return m_LastMode; }
  190. set { m_LastMode = value; }
  191. }
  192. public bool lastVisibilityToolActive
  193. {
  194. get { return m_VisibilityToolActive; }
  195. set { m_VisibilityToolActive = value; }
  196. }
  197. public int lastVisibilityToolIndex
  198. {
  199. get { return m_VisibilityToolIndex; }
  200. set { m_VisibilityToolIndex = value; }
  201. }
  202. public IndexedSelection lastVertexSelection
  203. {
  204. get { return m_VertexSelection; }
  205. }
  206. public float lastBrushSize
  207. {
  208. get { return m_LastBrushSize; }
  209. set { m_LastBrushSize = value; }
  210. }
  211. public float lastBrushHardness
  212. {
  213. get { return m_LastBrushHardness; }
  214. set { m_LastBrushHardness = value; }
  215. }
  216. public float lastBrushStep
  217. {
  218. get { return m_LastBrushStep; }
  219. set { m_LastBrushStep = value; }
  220. }
  221. }
  222. }