123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- #if ((UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN) || (UNITY_STANDALONE && (!UNITY_IOS) && (!UNITY_ANDROID)))
- using CommonUI_Unity3D.Platform;
- using UnityEngine;
- using CommonUI.Gemo;
- using CommonUI_Win32;
- using CommonLang.Concurrent;
- using System.IO;
- using CommonLang;
- using MPQ.Updater;
- using System;
- namespace CommonUI_Unity3D_Win32
- {
- public class UnityPlatformWin32 : IUnityPlatform
- {
- public bool IsNativeUnzip { get { return false; } }
- public void Assert(string msg)
- {
- Debug.LogError(msg);
- }
- public Texture2D SysFontTexture(
- string text, bool readable,
- CommonUI.Display.FontStyle style,
- int fontSize,
- uint fontColor,
- int borderTime,
- uint borderColor,
- CommonUI.Gemo.Size2D expectSize,
- out int boundW,
- out int boundH)
- {
- byte[] rgba = null;
- int txtw = 0;
- int txth = 0;
- Size2D size = SysFontWin32.SysFontTexture(
- text, style, fontSize, fontColor, borderTime, borderColor, expectSize,
- out rgba,
- out txtw,
- out txth);
- if (rgba != null)
- {
- Texture2D mTexture = new UnityEngine.Texture2D(
- txtw,
- txth,
- TextureFormat.RGBA32,
- false,
- true);
- mTexture.filterMode = FilterMode.Bilinear;
- mTexture.wrapMode = TextureWrapMode.Clamp;
- mTexture.anisoLevel = 0;
- mTexture.mipMapBias = 0;
- mTexture.LoadRawTextureData(rgba);
- mTexture.Apply(false, !readable);
- boundW = txtw;
- boundH = txth;
- return mTexture;
- }
- boundW = 0;
- boundH = 0;
- return null;
- }
- public bool TestTextLineBreak(string text, float size, CommonUI.Display.FontStyle style,
- int borderTime,
- float testWidth,
- out float realWidth,
- out float realHeight)
- {
- return SysFontWin32.TestTextLineBreak(text, size, style, borderTime, testWidth, out realWidth, out realHeight);
- }
- private static void InnRect(Texture2D src, ref int sx, ref int sy)
- {
- if (sx < 0) sx = 0;
- if (sx >= src.width) sx = src.width - 1;
- if (sy < 0) sy = 0;
- if (sy >= src.height) sy = src.height - 1;
- }
- public void CopyPixels(Texture2D src, int sx, int sy, int sw, int sh, Texture2D dst, int dx, int dy)
- {
- if (sw > 0 && sh > 0)
- {
- UnityEngine.Color[] colors = src.GetPixels(sx, sy, sw, sh);
- dst.SetPixels(dx, dst.height - sh - dy, sw, sh, colors);
- }
- }
- public long GetAvaliableSpace(string path)
- {
- try
- {
- DriveInfo drive = new DriveInfo(Directory.GetDirectoryRoot(path));
- return drive.AvailableFreeSpace;
- }
- catch (Exception)
- {
- return long.MaxValue;
- }
- }
- public long GetTotalSpace(string path)
- {
- try
- {
- DriveInfo drive = new DriveInfo(Directory.GetDirectoryRoot(path));
- return drive.TotalSize;
- }
- catch (Exception)
- {
- return long.MaxValue;
- }
- }
- public bool NativeDecompressFile(MPQUpdater updater, MPQUpdater.RemoteFileInfo zip_file, MPQUpdater.RemoteFileInfo mpq_file, AtomicLong current_unzip_bytes)
- {
- return CommonMPQ.SharpZipLib.Unzip.SharpZipLib_RunUnzipMPQ(updater, zip_file, mpq_file, current_unzip_bytes);
- }
- public bool NativeDecompressMemory(ArraySegment<byte> src, ArraySegment<byte> dst)
- {
- return CommonMPQ.SharpZipLib.Unzip.SharpZipLib_DecompressZ(src, dst);
- }
- public bool NativeGetFileMD5(string fullname, out string md5)
- {
- using (var fs = new FileStream(fullname, FileMode.Open, FileAccess.Read))
- {
- md5 = CMD5.CalculateMD5(fs);
- }
- return true;
- }
- }
- }
- #endif
|