MouseCursor.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using UnityEngine;
  2. using System.Collections;
  3. //-----------------------------------------------------------------------------
  4. // Copyright 2012-2017 RenderHeads Ltd. All rights reserved.
  5. //-----------------------------------------------------------------------------
  6. namespace RenderHeads.Media.AVProMovieCapture
  7. {
  8. /// <summary>
  9. /// Draws a mouse cursor on the screen using IMGUI, allowing the cursor to be captured when using CaptureFromScreen component
  10. /// </summary>
  11. [AddComponentMenu("AVPro Movie Capture/Mouse Cursor", 302)]
  12. public class MouseCursor : MonoBehaviour
  13. {
  14. [SerializeField]
  15. private Texture2D _texture;
  16. [SerializeField]
  17. private Vector2 _hotspotOffset = Vector2.zero;
  18. [SerializeField]
  19. [Range(1, 16)]
  20. private int _sizeScale = 1;
  21. [SerializeField]
  22. private int _depth = -9999;
  23. // State
  24. private GUIContent _content;
  25. void Start()
  26. {
  27. SetTexture(_texture);
  28. }
  29. public void SetTexture(Texture2D texture)
  30. {
  31. if (texture != null)
  32. {
  33. _content = new GUIContent(texture);
  34. _texture = texture;
  35. }
  36. }
  37. private void OnGUI()
  38. {
  39. if (_content != null)
  40. {
  41. GUI.depth = _depth;
  42. Vector2 p = Event.current.mousePosition;
  43. Rect rect = new Rect(p.x - _hotspotOffset.x, p.y - _hotspotOffset.y, _texture.width * _sizeScale, _texture.height * _sizeScale);
  44. GUI.Label(rect, _content);
  45. }
  46. }
  47. }
  48. }