1
0

FullAngleScreenshotTool.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System.IO;
  5. using System.Threading.Tasks;
  6. using ToneTuneToolkit.Common;
  7. using ToneTuneToolkit.Media;
  8. namespace FordBeyond
  9. {
  10. /// <summary>
  11. /// 全角度截图工具
  12. /// </summary>
  13. public class FullAngleScreenshotTool : MonoBehaviour
  14. {
  15. public GameObject GO;
  16. public GameObject ShotCamera;
  17. public int ShotTime = 4;
  18. private string _basepath = Application.streamingAssetsPath + "/Cars/";
  19. private void Update()
  20. {
  21. if (Input.GetKeyDown(KeyCode.Q))
  22. {
  23. StartCoroutine("Begin");
  24. }
  25. }
  26. private IEnumerator Begin()
  27. {
  28. // 判断有多少文件夹在目录中
  29. DirectoryInfo di = new DirectoryInfo(_basepath);
  30. FileInfo[] files = di.GetFiles("*", SearchOption.TopDirectoryOnly);
  31. int folderIndex = files.Length + 1;
  32. string currentPath = _basepath + string.Format("{0:d4}", folderIndex) + "/";
  33. ShotCamera.transform.LookAt(GO.transform);
  34. for (int i = 0; i < ShotTime; i++)
  35. {
  36. GO.transform.rotation = Quaternion.Euler(0, 360 / ShotTime * i, 0);
  37. yield return new WaitForEndOfFrame();
  38. ScreenshotMaster.Instance.SaveRenderTexture(currentPath, string.Format("{0:d4}", i) + ".png");
  39. }
  40. yield break;
  41. }
  42. private void OnApplicationQuit()
  43. {
  44. StopAllCoroutines();
  45. }
  46. }
  47. }