VRPhotoMenu.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Runtime.CompilerServices;
  6. using UnityEngine;
  7. using UnityEngine.Events;
  8. using UnityEngine.UI;
  9. public class VRPhotoMenu : MonoBehaviour
  10. {
  11. private void Update()
  12. {
  13. this.m_TotalTime += Time.deltaTime;
  14. if (this.m_RefreshTime < this.m_TotalTime)
  15. {
  16. this.m_TotalTime = 0f;
  17. if (this.m_ScreenShotCount != this.m_BeforeScreenShotCount)
  18. {
  19. this.Refresh();
  20. }
  21. this.m_BeforeScreenShotCount = this.m_ScreenShotCount;
  22. }
  23. }
  24. public static int CompareLastWriteTime(FileInfo file1, FileInfo file2)
  25. {
  26. return DateTime.Compare(file2.LastWriteTime, file1.LastWriteTime);
  27. }
  28. public void Refresh()
  29. {
  30. this.m_ScreenShotPath = Path.GetFullPath(".\\") + "ScreenShot\\VRPhotoThumb\\";
  31. string screenShotPath = this.m_ScreenShotPath;
  32. DirectoryInfo directoryInfo = new DirectoryInfo(screenShotPath);
  33. if (!directoryInfo.Exists)
  34. {
  35. this.m_ImagePhoto.gameObject.SetActive(false);
  36. this.m_ImagePhoto.sprite = null;
  37. return;
  38. }
  39. FileInfo[] files = directoryInfo.GetFiles("*", SearchOption.TopDirectoryOnly);
  40. FileInfo[] array = files;
  41. if (VRPhotoMenu.<>f__mg$cache0 == null)
  42. {
  43. VRPhotoMenu.<>f__mg$cache0 = new Comparison<FileInfo>(VRPhotoMenu.CompareLastWriteTime);
  44. }
  45. Array.Sort<FileInfo>(array, VRPhotoMenu.<>f__mg$cache0);
  46. this.m_FileInfoArray.Clear();
  47. for (int i = 0; i < files.Length; i++)
  48. {
  49. this.m_FileInfoArray.Add(files[i]);
  50. }
  51. int screenShotCount = this.m_ScreenShotCount;
  52. this.m_ScreenShotCount = files.Length;
  53. this.ButtonEvent_ChangePhoto(this.m_ScreenShotCount - screenShotCount);
  54. }
  55. public void ButtonEvent_ChangePhoto(int index)
  56. {
  57. if (this.m_FileInfoArray.Count <= 0)
  58. {
  59. this.m_ImagePhoto.sprite = null;
  60. this.m_ImagePhoto.gameObject.SetActive(false);
  61. this.m_TextPageNumber.text = "000/000";
  62. return;
  63. }
  64. this.m_ScreenShotIndex += index;
  65. this.m_ScreenShotIndex = ((this.m_ScreenShotIndex >= 0) ? this.m_ScreenShotIndex : (this.m_ScreenShotCount - 1));
  66. this.m_ScreenShotIndex = ((this.m_ScreenShotIndex < this.m_ScreenShotCount) ? this.m_ScreenShotIndex : 0);
  67. this.m_TextPageNumber.text = (this.m_ScreenShotIndex + 1).ToString("000") + " / " + this.m_ScreenShotCount.ToString("000");
  68. FileInfo fileInfo = this.m_FileInfoArray[this.m_ScreenShotIndex];
  69. base.StopAllCoroutines();
  70. base.StartCoroutine(this.Coroutine_LoadSprite("File://" + fileInfo.FullName, delegate(WWW www)
  71. {
  72. if (!string.IsNullOrEmpty(www.error))
  73. {
  74. this.m_ImagePhoto.sprite = null;
  75. this.m_ImagePhoto.gameObject.SetActive(false);
  76. return;
  77. }
  78. www.Dispose();
  79. www = null;
  80. this.m_ImagePhoto.gameObject.SetActive(true);
  81. }));
  82. }
  83. private IEnumerator Coroutine_LoadSprite(string url, UnityAction<WWW> callback)
  84. {
  85. WWW www = new WWW(url);
  86. yield return www;
  87. Texture2D tex = www.textureNonReadable;
  88. string rawFileName = Path.GetFileNameWithoutExtension(url);
  89. char[] fileNameCharArray = rawFileName.ToCharArray();
  90. char angle = fileNameCharArray[fileNameCharArray.Length - 1];
  91. RectTransform trans = this.m_ImagePhoto.GetComponent<RectTransform>();
  92. Rect rect = trans.rect;
  93. if (angle == 'd')
  94. {
  95. trans.localEulerAngles = Vector3.zero;
  96. trans.localScale = Vector3.one * 0.6f;
  97. }
  98. else if (angle == 'l')
  99. {
  100. trans.localEulerAngles = Vector3.forward * 90f;
  101. trans.localScale = Vector3.one;
  102. }
  103. else if (angle == 't')
  104. {
  105. trans.localEulerAngles = Vector3.forward * 180f;
  106. trans.localScale = Vector3.one * 0.6f;
  107. }
  108. else if (angle == 'r')
  109. {
  110. trans.localEulerAngles = Vector3.forward * 270f;
  111. trans.localScale = Vector3.one;
  112. }
  113. else
  114. {
  115. trans.localEulerAngles = Vector3.forward * 90f;
  116. trans.localScale = Vector3.one;
  117. }
  118. this.m_ImagePhoto.sprite = Sprite.Create(tex, new Rect(0f, 0f, (float)tex.width, (float)tex.height), Vector2.one * 0.5f, 1f, 0u, SpriteMeshType.FullRect);
  119. callback(www);
  120. yield break;
  121. }
  122. private void OnEnable()
  123. {
  124. this.Refresh();
  125. this.ButtonEvent_ChangePhoto(0);
  126. }
  127. private void OnDisable()
  128. {
  129. this.m_FileInfoArray.Clear();
  130. }
  131. private string m_ScreenShotPath = string.Empty;
  132. [SerializeField]
  133. private Image m_ImagePhoto;
  134. [SerializeField]
  135. private Text m_TextPageNumber;
  136. private int m_ScreenShotIndex;
  137. private int m_ScreenShotCount;
  138. private int m_BeforeScreenShotCount;
  139. private List<FileInfo> m_FileInfoArray = new List<FileInfo>();
  140. private float m_RefreshTime = 4f;
  141. private float m_TotalTime;
  142. [CompilerGenerated]
  143. private static Comparison<FileInfo> <>f__mg$cache0;
  144. }