SkeletonToolWrapper.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using UnityEngine;
  3. namespace UnityEditor.U2D.Animation
  4. {
  5. internal class SkeletonToolWrapper : BaseTool
  6. {
  7. private SkeletonTool m_SkeletonTool;
  8. private SkeletonMode m_Mode;
  9. public SkeletonTool skeletonTool
  10. {
  11. get { return m_SkeletonTool; }
  12. set { m_SkeletonTool = value; }
  13. }
  14. public SkeletonMode mode
  15. {
  16. get { return m_Mode; }
  17. set { m_Mode = value; }
  18. }
  19. public bool editBindPose { get; set; }
  20. public override int defaultControlID
  21. {
  22. get
  23. {
  24. Debug.Assert(skeletonTool != null);
  25. return skeletonTool.defaultControlID;
  26. }
  27. }
  28. protected override void OnActivate()
  29. {
  30. Debug.Assert(skeletonTool != null);
  31. skeletonTool.enableBoneInspector = true;
  32. skeletonTool.Activate();
  33. }
  34. protected override void OnDeactivate()
  35. {
  36. skeletonTool.enableBoneInspector = false;
  37. skeletonTool.Deactivate();
  38. }
  39. private SkeletonMode OverrideMode()
  40. {
  41. var modeOverride = mode;
  42. //Disable SkeletonManipulation if character exists and we are in SpriteSheet mode
  43. if (skinningCache.mode == SkinningMode.SpriteSheet && skinningCache.hasCharacter && editBindPose)
  44. modeOverride = SkeletonMode.Selection;
  45. return modeOverride;
  46. }
  47. protected override void OnGUI()
  48. {
  49. Debug.Assert(skeletonTool != null);
  50. skeletonTool.mode = OverrideMode();
  51. skeletonTool.editBindPose = editBindPose;
  52. skeletonTool.DoGUI();
  53. }
  54. }
  55. }