VRPhotoMenu.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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.Combine(GameMain.Instance.SerializeStorageManager.StoreDirectoryPath, "ScreenShot");
  31. this.m_ScreenShotPath = Path.Combine(this.m_ScreenShotPath, "VRPhotoThumb\\");
  32. string screenShotPath = this.m_ScreenShotPath;
  33. DirectoryInfo directoryInfo = new DirectoryInfo(screenShotPath);
  34. if (!directoryInfo.Exists)
  35. {
  36. this.m_ImagePhoto.gameObject.SetActive(false);
  37. this.m_ImagePhoto.sprite = null;
  38. return;
  39. }
  40. FileInfo[] files = directoryInfo.GetFiles("*", SearchOption.TopDirectoryOnly);
  41. FileInfo[] array = files;
  42. if (VRPhotoMenu.<>f__mg$cache0 == null)
  43. {
  44. VRPhotoMenu.<>f__mg$cache0 = new Comparison<FileInfo>(VRPhotoMenu.CompareLastWriteTime);
  45. }
  46. Array.Sort<FileInfo>(array, VRPhotoMenu.<>f__mg$cache0);
  47. this.m_FileInfoArray.Clear();
  48. for (int i = 0; i < files.Length; i++)
  49. {
  50. this.m_FileInfoArray.Add(files[i]);
  51. }
  52. int screenShotCount = this.m_ScreenShotCount;
  53. this.m_ScreenShotCount = files.Length;
  54. this.ButtonEvent_ChangePhoto(this.m_ScreenShotCount - screenShotCount);
  55. }
  56. public void ButtonEvent_ChangePhoto(int index)
  57. {
  58. if (this.m_FileInfoArray.Count <= 0)
  59. {
  60. this.m_ImagePhoto.sprite = null;
  61. this.m_ImagePhoto.gameObject.SetActive(false);
  62. this.m_TextPageNumber.text = "000/000";
  63. return;
  64. }
  65. this.m_ScreenShotIndex += index;
  66. this.m_ScreenShotIndex = ((this.m_ScreenShotIndex >= 0) ? this.m_ScreenShotIndex : (this.m_ScreenShotCount - 1));
  67. this.m_ScreenShotIndex = ((this.m_ScreenShotIndex < this.m_ScreenShotCount) ? this.m_ScreenShotIndex : 0);
  68. this.m_TextPageNumber.text = (this.m_ScreenShotIndex + 1).ToString("000") + " / " + this.m_ScreenShotCount.ToString("000");
  69. FileInfo fileInfo = this.m_FileInfoArray[this.m_ScreenShotIndex];
  70. base.StopAllCoroutines();
  71. base.StartCoroutine(this.Coroutine_LoadSprite("File://" + fileInfo.FullName, delegate(WWW www)
  72. {
  73. if (!string.IsNullOrEmpty(www.error))
  74. {
  75. this.m_ImagePhoto.sprite = null;
  76. this.m_ImagePhoto.gameObject.SetActive(false);
  77. return;
  78. }
  79. www.Dispose();
  80. www = null;
  81. this.m_ImagePhoto.gameObject.SetActive(true);
  82. }));
  83. }
  84. private IEnumerator Coroutine_LoadSprite(string url, UnityAction<WWW> callback)
  85. {
  86. WWW www = new WWW(url);
  87. yield return www;
  88. Texture2D tex = www.textureNonReadable;
  89. string rawFileName = Path.GetFileNameWithoutExtension(url);
  90. char[] fileNameCharArray = rawFileName.ToCharArray();
  91. char angle = fileNameCharArray[fileNameCharArray.Length - 1];
  92. RectTransform trans = this.m_ImagePhoto.GetComponent<RectTransform>();
  93. Rect rect = trans.rect;
  94. if (angle == 'd')
  95. {
  96. trans.localEulerAngles = Vector3.zero;
  97. trans.localScale = Vector3.one * 0.6f;
  98. }
  99. else if (angle == 'l')
  100. {
  101. trans.localEulerAngles = Vector3.forward * 90f;
  102. trans.localScale = Vector3.one;
  103. }
  104. else if (angle == 't')
  105. {
  106. trans.localEulerAngles = Vector3.forward * 180f;
  107. trans.localScale = Vector3.one * 0.6f;
  108. }
  109. else if (angle == 'r')
  110. {
  111. trans.localEulerAngles = Vector3.forward * 270f;
  112. trans.localScale = Vector3.one;
  113. }
  114. else
  115. {
  116. trans.localEulerAngles = Vector3.forward * 90f;
  117. trans.localScale = Vector3.one;
  118. }
  119. 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);
  120. callback(www);
  121. yield break;
  122. }
  123. private void OnEnable()
  124. {
  125. this.Refresh();
  126. this.ButtonEvent_ChangePhoto(0);
  127. }
  128. private void OnDisable()
  129. {
  130. this.m_FileInfoArray.Clear();
  131. }
  132. private string m_ScreenShotPath = string.Empty;
  133. [SerializeField]
  134. private Image m_ImagePhoto;
  135. [SerializeField]
  136. private Text m_TextPageNumber;
  137. private int m_ScreenShotIndex;
  138. private int m_ScreenShotCount;
  139. private int m_BeforeScreenShotCount;
  140. private List<FileInfo> m_FileInfoArray = new List<FileInfo>();
  141. private float m_RefreshTime = 4f;
  142. private float m_TotalTime;
  143. [CompilerGenerated]
  144. private static Comparison<FileInfo> <>f__mg$cache0;
  145. }