DebugLogItemCopyWebGL.cs 897 B

123456789101112131415161718192021222324252627282930313233343536
  1. #if !UNITY_EDITOR && UNITY_WEBGL
  2. using System.Runtime.InteropServices;
  3. using UnityEngine;
  4. using UnityEngine.EventSystems;
  5. namespace IngameDebugConsole
  6. {
  7. public class DebugLogItemCopyWebGL : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
  8. {
  9. [DllImport( "__Internal" )]
  10. private static extern void IngameDebugConsoleStartCopy( string textToCopy );
  11. [DllImport( "__Internal" )]
  12. private static extern void IngameDebugConsoleCancelCopy();
  13. private DebugLogItem logItem;
  14. public void Initialize( DebugLogItem logItem )
  15. {
  16. this.logItem = logItem;
  17. }
  18. public void OnPointerDown( PointerEventData eventData )
  19. {
  20. string log = logItem.GetCopyContent();
  21. if( !string.IsNullOrEmpty( log ) )
  22. IngameDebugConsoleStartCopy( log );
  23. }
  24. public void OnPointerUp( PointerEventData eventData )
  25. {
  26. if( eventData.dragging )
  27. IngameDebugConsoleCancelCopy();
  28. }
  29. }
  30. }
  31. #endif