DrawingManager.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // /******************************************************************************
  2. // * File: DrawingManager.cs
  3. // * Copyright (c) 2023 Qualcomm Technologies, Inc. and/or its subsidiaries. All rights reserved.
  4. // *
  5. // *
  6. // ******************************************************************************/
  7. using UnityEngine;
  8. namespace QCHT.Samples.Drawing
  9. {
  10. public class DrawingManager : MonoBehaviour
  11. {
  12. public Pen Pen;
  13. #region Singleton
  14. private static DrawingManager s_instance;
  15. public static DrawingManager Instance
  16. {
  17. get
  18. {
  19. if (s_instance == null)
  20. s_instance = FindObjectOfType<DrawingManager>();
  21. return s_instance;
  22. }
  23. }
  24. #endregion
  25. /// <summary>
  26. /// Sets the new brush descriptor to the current pen tool.
  27. /// </summary>
  28. /// <param name="brush"> The new brush descriptor. </param>
  29. public void ChangeBrush(BrushDescriptor brush)
  30. {
  31. if (!Pen)
  32. return;
  33. Pen.SetBrush(brush);
  34. }
  35. /// <summary>
  36. /// Sets the new width to the current pen tool.
  37. /// </summary>
  38. /// <param name="width"> The new width. </param>
  39. public void SetWidth(float width)
  40. {
  41. if (!Pen)
  42. return;
  43. Pen.SetWidth(width);
  44. }
  45. /// <summary>
  46. /// Sets the current drawing mode.
  47. /// Converts integer to drawing.
  48. /// </summary>
  49. public void SetDrawingMode(Pen.DrawingMode drawingMode)
  50. {
  51. if (!Pen)
  52. return;
  53. Pen.SetDrawingMode(drawingMode);
  54. }
  55. /// <summary>
  56. /// Undo the current pen line.
  57. /// </summary>
  58. public void Undo()
  59. {
  60. if (!Pen)
  61. return;
  62. Pen.Undo();
  63. }
  64. /// <summary>
  65. /// Redo the last removed pen line.
  66. /// </summary>
  67. public void Redo()
  68. {
  69. if (!Pen)
  70. return;
  71. Pen.Redo();
  72. }
  73. /// <summary>
  74. /// Clears all lines done with this pen.
  75. /// </summary>
  76. public void Clear()
  77. {
  78. if (!Pen)
  79. return;
  80. Pen.Clear();
  81. }
  82. }
  83. }