CursorRendererOS.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using UnityEngine;
  2. namespace ZenFulcrum.EmbeddedBrowser {
  3. /// <summary>
  4. /// Handles rendering a browser's cursor by letting using t he OS-level mouse cursor
  5. /// (and changing it as needed).
  6. /// </summary>
  7. public class CursorRendererOS : CursorRendererBase {
  8. [Tooltip("If true, the mouse cursor should be visible when it's not on a browser.")]
  9. public bool cursorNormallyVisible = true;
  10. protected override void CursorChange() {
  11. if (!cursor.HasMouse) {
  12. //no browser, do default
  13. Cursor.visible = cursorNormallyVisible;
  14. Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
  15. } else {
  16. if (cursor.Texture != null) {
  17. //browser, show this cursor
  18. Cursor.visible = true;
  19. Cursor.SetCursor(
  20. cursor.Texture, cursor.Hotspot,
  21. #if UNITY_STANDALONE_OSX
  22. //Not sure why, but we get really ugly looking "garbled" shadows around the mouse cursor.
  23. //I hate latency, but a software cursor is probably less irritating than looking at
  24. //that ugly stuff.
  25. CursorMode.ForceSoftware
  26. #else
  27. CursorMode.Auto
  28. #endif
  29. );
  30. } else {
  31. //browser, so no cursor
  32. Cursor.visible = false;
  33. Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
  34. }
  35. }
  36. }
  37. }
  38. }