Brak opisu
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.

SkeletonToolView.cs 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using UnityEditor.U2D.Layout;
  3. using UnityEngine;
  4. namespace UnityEditor.U2D.Animation
  5. {
  6. internal class SkeletonToolView
  7. {
  8. private BoneInspectorPanel m_BoneInspectorPanel;
  9. public event Action<BoneCache, string> onBoneNameChanged = (b, s) => {};
  10. public event Action<BoneCache, int> onBoneDepthChanged = (b, i) => {};
  11. public event Action<BoneCache, float> onBoneRotationChanged = (b, i) => {};
  12. public event Action<BoneCache, Vector2> onBonePositionChanged = (b, i) => {};
  13. public event Action<BoneCache, Color32> onBoneColorChanged = (b, i) => {};
  14. public SkeletonToolView()
  15. {
  16. m_BoneInspectorPanel = BoneInspectorPanel.GenerateFromUXML();
  17. m_BoneInspectorPanel.onBoneNameChanged += (b, n) => onBoneNameChanged(b, n);
  18. m_BoneInspectorPanel.onBoneDepthChanged += (b, d) => onBoneDepthChanged(b, d);
  19. m_BoneInspectorPanel.onBoneRotationChanged += (b, n) => onBoneRotationChanged(b, n);
  20. m_BoneInspectorPanel.onBonePositionChanged += (b, d) => onBonePositionChanged(b, d);
  21. m_BoneInspectorPanel.onBoneColorChanged += (b, d) => onBoneColorChanged(b, d);
  22. Hide();
  23. }
  24. public void Initialize(LayoutOverlay layout)
  25. {
  26. layout.rightOverlay.Add(m_BoneInspectorPanel);
  27. }
  28. public void Show(BoneCache target, bool isReadOnly)
  29. {
  30. m_BoneInspectorPanel.target = target;
  31. m_BoneInspectorPanel.SetHiddenFromLayout(false);
  32. var readOnlyProperty = BoneInspectorPanel.PropertyReadOnly.None;
  33. if (isReadOnly)
  34. readOnlyProperty = BoneInspectorPanel.PropertyReadOnly.Name |
  35. BoneInspectorPanel.PropertyReadOnly.Depth |
  36. BoneInspectorPanel.PropertyReadOnly.Color;
  37. m_BoneInspectorPanel.SetReadOnly(readOnlyProperty);
  38. }
  39. public BoneCache target => m_BoneInspectorPanel.target;
  40. public void Hide()
  41. {
  42. m_BoneInspectorPanel.HidePanel();
  43. m_BoneInspectorPanel.target = null;
  44. }
  45. public void Update(string name, int depth, Vector2 position, float rotation, Color32 color)
  46. {
  47. m_BoneInspectorPanel.boneName = name;
  48. m_BoneInspectorPanel.boneDepth = depth;
  49. m_BoneInspectorPanel.bonePosition = position;
  50. m_BoneInspectorPanel.boneRotation = rotation;
  51. m_BoneInspectorPanel.boneColor = color;
  52. }
  53. }
  54. }