SToolFunction.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace SFramework
  5. {
  6. public class SToolFunction
  7. {
  8. public static int GetFileSize(string fileFullPath)
  9. {
  10. System.IO.FileInfo oneFileInfo = new System.IO.FileInfo(fileFullPath);
  11. return (int)oneFileInfo.Length;
  12. }
  13. public static string GetAssetBundleFullPath(string abFullNameWithPath)
  14. {
  15. string[] nameInfo = abFullNameWithPath.Split('/');
  16. string realABName = nameInfo[nameInfo.Length - 1];
  17. string fullPath = abFullNameWithPath.Substring(0, abFullNameWithPath.Length - realABName.Length);
  18. return fullPath;
  19. }
  20. public static string GetDownloadSpeed(float alreadyDownloadBytes, float downloadTime)
  21. {
  22. float downloadSpeed = alreadyDownloadBytes / downloadTime; // Bytes Per Second.
  23. string extName = "B/s";
  24. if (System.Math.Floor(downloadSpeed / 1024) > 0)
  25. {
  26. downloadSpeed = downloadSpeed / 1024; // KB/s
  27. extName = "KB/s";
  28. }
  29. if (System.Math.Floor(downloadSpeed / 1024) > 0)
  30. {
  31. downloadSpeed = downloadSpeed / 1024; //MB/s
  32. extName = "MB/s";
  33. }
  34. downloadSpeed = (float)System.Math.Round(downloadSpeed, 2);
  35. string finalSpeed = downloadSpeed.ToString() + " " + extName;
  36. return finalSpeed;
  37. }
  38. public static void MakeSurePathExisted(string path)
  39. {
  40. if (System.IO.Directory.Exists(path))
  41. return;
  42. System.IO.Directory.CreateDirectory(path);
  43. }
  44. public static SFileInfo CreateFileInfo(string fileName, string fileFullPathWithName)
  45. {
  46. SFileInfo fileInfo = new SFileInfo();
  47. fileInfo.fileName = fileName;
  48. fileInfo.hashInfo = fileName.GetHashCode().ToString();
  49. fileInfo.fileSize = SToolFunction.GetFileSize(fileFullPathWithName);
  50. return fileInfo;
  51. }
  52. }
  53. }