DesktopScreen.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class DesktopScreen : MonoBehaviour
  5. {
  6. private void Start()
  7. {
  8. this.m_nDisplayNo = GameMain.Instance.CMSystem.DesktopCaptureMonitorNo;
  9. Material sharedMaterial = base.GetComponent<Renderer>().sharedMaterial;
  10. sharedMaterial.mainTexture = Resources.Load<Texture2D>("System/Texture/unsupported");
  11. this.m_dup = base.gameObject.AddComponent<DesktopDuplication>();
  12. bool flag = this.m_dup.CreateDesktopDuplication("\\\\.\\DISPLAY" + this.m_nDisplayNo.ToString());
  13. Size<float> size;
  14. if (flag && this.m_dup.width != 0 && this.m_dup.height != 0)
  15. {
  16. Debug.Log("ディスプレイクラス生成成功:DISPLAY" + this.m_nDisplayNo.ToString());
  17. Texture2D texture2D = new Texture2D(this.m_dup.width, this.m_dup.height, TextureFormat.BGRA32, false);
  18. this.m_dup.render_texture = texture2D;
  19. sharedMaterial.mainTextureScale = new Vector2(-1f, 1f);
  20. sharedMaterial.mainTexture = texture2D;
  21. size.width = (float)this.m_dup.width;
  22. size.height = (float)this.m_dup.height;
  23. this.m_trCursor = base.transform.Find("Cursor");
  24. this.m_trCursorBack = base.transform.Find("Screen_back/CursorBack");
  25. }
  26. else
  27. {
  28. Debug.Log("ディスプレイクラス生成失敗:DISPLAY" + this.m_nDisplayNo.ToString());
  29. List<Monitor.InfoData> info_data_list = Monitor.info_data_list;
  30. if (0 < this.m_nDisplayNo && this.m_nDisplayNo <= info_data_list.Count)
  31. {
  32. Monitor.InfoData infoData = info_data_list[this.m_nDisplayNo - 1];
  33. size.width = (float)infoData.width;
  34. size.height = (float)infoData.height;
  35. }
  36. else
  37. {
  38. Debug.Log("ディスプレイ番号無し:DISPLAY" + this.m_nDisplayNo.ToString());
  39. size.width = 1600f;
  40. size.height = 900f;
  41. }
  42. }
  43. base.transform.localScale = new Vector3(this.m_fSize, 1f, size.height * this.m_fSize / size.width);
  44. }
  45. private void Update()
  46. {
  47. if (this.m_trCursor != null && this.m_dup.is_mouse_pointer_visible)
  48. {
  49. this.m_trCursor.localPosition = new Vector3((float)this.m_dup.mouse_pointer_x / (float)this.m_dup.width * 10f - 5f, 0.005f, (float)this.m_dup.mouse_pointer_y / (float)this.m_dup.height * -10f + 5f);
  50. this.m_trCursorBack.localPosition = this.m_trCursor.localPosition;
  51. }
  52. }
  53. public int m_nDisplayNo = 1;
  54. public float m_fSize = 0.3f;
  55. private DesktopDuplication m_dup;
  56. private Transform m_trCursor;
  57. private Transform m_trCursorBack;
  58. }