UnityPlatformWin32.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #if ((UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN) || (UNITY_STANDALONE && (!UNITY_IOS) && (!UNITY_ANDROID)))
  2. using CommonUI_Unity3D.Platform;
  3. using UnityEngine;
  4. using CommonUI.Gemo;
  5. using CommonUI_Win32;
  6. using CommonLang.Concurrent;
  7. using System.IO;
  8. using CommonLang;
  9. using MPQ.Updater;
  10. using System;
  11. namespace CommonUI_Unity3D_Win32
  12. {
  13. public class UnityPlatformWin32 : IUnityPlatform
  14. {
  15. public bool IsNativeUnzip { get { return false; } }
  16. public void Assert(string msg)
  17. {
  18. Debug.LogError(msg);
  19. }
  20. public Texture2D SysFontTexture(
  21. string text, bool readable,
  22. CommonUI.Display.FontStyle style,
  23. int fontSize,
  24. uint fontColor,
  25. int borderTime,
  26. uint borderColor,
  27. CommonUI.Gemo.Size2D expectSize,
  28. out int boundW,
  29. out int boundH)
  30. {
  31. byte[] rgba = null;
  32. int txtw = 0;
  33. int txth = 0;
  34. Size2D size = SysFontWin32.SysFontTexture(
  35. text, style, fontSize, fontColor, borderTime, borderColor, expectSize,
  36. out rgba,
  37. out txtw,
  38. out txth);
  39. if (rgba != null)
  40. {
  41. Texture2D mTexture = new UnityEngine.Texture2D(
  42. txtw,
  43. txth,
  44. TextureFormat.RGBA32,
  45. false,
  46. true);
  47. mTexture.filterMode = FilterMode.Bilinear;
  48. mTexture.wrapMode = TextureWrapMode.Clamp;
  49. mTexture.anisoLevel = 0;
  50. mTexture.mipMapBias = 0;
  51. mTexture.LoadRawTextureData(rgba);
  52. mTexture.Apply(false, !readable);
  53. boundW = txtw;
  54. boundH = txth;
  55. return mTexture;
  56. }
  57. boundW = 0;
  58. boundH = 0;
  59. return null;
  60. }
  61. public bool TestTextLineBreak(string text, float size, CommonUI.Display.FontStyle style,
  62. int borderTime,
  63. float testWidth,
  64. out float realWidth,
  65. out float realHeight)
  66. {
  67. return SysFontWin32.TestTextLineBreak(text, size, style, borderTime, testWidth, out realWidth, out realHeight);
  68. }
  69. private static void InnRect(Texture2D src, ref int sx, ref int sy)
  70. {
  71. if (sx < 0) sx = 0;
  72. if (sx >= src.width) sx = src.width - 1;
  73. if (sy < 0) sy = 0;
  74. if (sy >= src.height) sy = src.height - 1;
  75. }
  76. public void CopyPixels(Texture2D src, int sx, int sy, int sw, int sh, Texture2D dst, int dx, int dy)
  77. {
  78. if (sw > 0 && sh > 0)
  79. {
  80. UnityEngine.Color[] colors = src.GetPixels(sx, sy, sw, sh);
  81. dst.SetPixels(dx, dst.height - sh - dy, sw, sh, colors);
  82. }
  83. }
  84. public long GetAvaliableSpace(string path)
  85. {
  86. try
  87. {
  88. DriveInfo drive = new DriveInfo(Directory.GetDirectoryRoot(path));
  89. return drive.AvailableFreeSpace;
  90. }
  91. catch (Exception)
  92. {
  93. return long.MaxValue;
  94. }
  95. }
  96. public long GetTotalSpace(string path)
  97. {
  98. try
  99. {
  100. DriveInfo drive = new DriveInfo(Directory.GetDirectoryRoot(path));
  101. return drive.TotalSize;
  102. }
  103. catch (Exception)
  104. {
  105. return long.MaxValue;
  106. }
  107. }
  108. public bool NativeDecompressFile(MPQUpdater updater, MPQUpdater.RemoteFileInfo zip_file, MPQUpdater.RemoteFileInfo mpq_file, AtomicLong current_unzip_bytes)
  109. {
  110. return CommonMPQ.SharpZipLib.Unzip.SharpZipLib_RunUnzipMPQ(updater, zip_file, mpq_file, current_unzip_bytes);
  111. }
  112. public bool NativeDecompressMemory(ArraySegment<byte> src, ArraySegment<byte> dst)
  113. {
  114. return CommonMPQ.SharpZipLib.Unzip.SharpZipLib_DecompressZ(src, dst);
  115. }
  116. public bool NativeGetFileMD5(string fullname, out string md5)
  117. {
  118. using (var fs = new FileStream(fullname, FileMode.Open, FileAccess.Read))
  119. {
  120. md5 = CMD5.CalculateMD5(fs);
  121. }
  122. return true;
  123. }
  124. }
  125. }
  126. #endif