No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IKManager2DEditorData.cs 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System;
  2. using System.Collections.Generic;
  3. namespace UnityEngine.U2D.IK
  4. {
  5. public partial class IKManager2D : MonoBehaviour
  6. {
  7. #if UNITY_EDITOR
  8. [Serializable]
  9. internal struct SolverEditorData
  10. {
  11. public Color color;
  12. public bool showGizmo;
  13. public static SolverEditorData defaultValue => new SolverEditorData() { color = Color.green, showGizmo = true };
  14. }
  15. [SerializeField]
  16. private List<SolverEditorData> m_SolverEditorData = new List<SolverEditorData>();
  17. void OnEditorDataValidate()
  18. {
  19. var solverDataLength = m_SolverEditorData.Count;
  20. for (var i = solverDataLength; i < m_Solvers.Count; ++i)
  21. {
  22. AddSolverEditorData();
  23. }
  24. }
  25. internal SolverEditorData GetSolverEditorData(Solver2D solver)
  26. {
  27. var index = m_Solvers.FindIndex(x => x == solver);
  28. if (index >= 0)
  29. {
  30. if (index >= m_SolverEditorData.Count)
  31. OnEditorDataValidate();
  32. return m_SolverEditorData[index];
  33. }
  34. return SolverEditorData.defaultValue;
  35. }
  36. void AddSolverEditorData()
  37. {
  38. m_SolverEditorData.Add(new SolverEditorData()
  39. {
  40. color = Color.green,
  41. showGizmo = true
  42. });
  43. }
  44. void RemoveSolverEditorData(Solver2D solver)
  45. {
  46. var index = m_Solvers.FindIndex(x => x == solver);
  47. if (index >= 0)
  48. m_SolverEditorData.RemoveAt(index);
  49. }
  50. #else
  51. void OnEditorDataValidate() { }
  52. void AddSolverEditorData() { }
  53. void RemoveSolverEditorData(Solver2D solver) { }
  54. #endif
  55. }
  56. }