diff --git a/Assets/TEngine/Runtime/BaseComponent.cs b/Assets/TEngine/Runtime/BaseComponent.cs index f4e3b821..f14bce44 100644 --- a/Assets/TEngine/Runtime/BaseComponent.cs +++ b/Assets/TEngine/Runtime/BaseComponent.cs @@ -1,6 +1,6 @@ using System; -using TEngine.Localization; using UnityEngine; +using TEngine.Localization; namespace TEngine { diff --git a/Assets/TEngine/Runtime/GameFramework/GameTime.cs b/Assets/TEngine/Runtime/GameFramework/GameTime.cs new file mode 100644 index 00000000..25320316 --- /dev/null +++ b/Assets/TEngine/Runtime/GameFramework/GameTime.cs @@ -0,0 +1,19 @@ +namespace TEngine +{ + public class GameTime + { + public static float time; + + public static float deltaTime; + + public static float fixedDeltaTime; + + public static float unscaledTime; + + public static float unscaledDeltaTime; + + public static float fixedUnscaledDeltaTime; + + public static float realtimeSinceStartup; + } +} \ No newline at end of file diff --git a/Assets/TEngine/Runtime/GameFramework/GameTime.cs.meta b/Assets/TEngine/Runtime/GameFramework/GameTime.cs.meta new file mode 100644 index 00000000..001c12ac --- /dev/null +++ b/Assets/TEngine/Runtime/GameFramework/GameTime.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 61ebff67750c418fb48bec8f0b90c6d3 +timeCreated: 1680341218 \ No newline at end of file diff --git a/Assets/TEngine/Runtime/Resource/ResourceManager.Services.cs b/Assets/TEngine/Runtime/Resource/ResourceManager.Services.cs new file mode 100644 index 00000000..8fd567db --- /dev/null +++ b/Assets/TEngine/Runtime/Resource/ResourceManager.Services.cs @@ -0,0 +1,72 @@ +using System; +using System.IO; +using YooAsset; + +namespace TEngine +{ + internal partial class ResourceManager + { + /// + /// 资源文件解密服务类。 + /// + private class GameDecryptionServices : IDecryptionServices + { + public ulong LoadFromFileOffset(DecryptFileInfo fileInfo) + { + return 32; + } + + public byte[] LoadFromMemory(DecryptFileInfo fileInfo) + { + throw new NotImplementedException(); + } + + public Stream LoadFromStream(DecryptFileInfo fileInfo) + { + BundleStream bundleStream = new BundleStream(fileInfo.FilePath, FileMode.Open); + return bundleStream; + } + + public uint GetManagedReadBufferSize() + { + return 1024; + } + } + + /// + /// 内置文件查询服务类。 + /// + private class GameQueryServices : IQueryServices + { + public bool QueryStreamingAssets(string fileName) + { + string builtinFolderName = YooAssets.GetStreamingAssetBuildinFolderName(); + return StreamingAssetsHelper.FileExists($"{builtinFolderName}/{fileName}"); + } + } + } + + public class BundleStream : FileStream + { + public const byte KEY = 64; + + public BundleStream(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, bool useAsync) : base(path, mode, access, share, bufferSize, useAsync) + { + } + + public BundleStream(string path, FileMode mode) : base(path, mode) + { + } + + public override int Read(byte[] array, int offset, int count) + { + var index = base.Read(array, offset, count); + for (int i = 0; i < array.Length; i++) + { + array[i] ^= KEY; + } + + return index; + } + } +} \ No newline at end of file diff --git a/Assets/TEngine/Runtime/Resource/ResourceManager.Services.cs.meta b/Assets/TEngine/Runtime/Resource/ResourceManager.Services.cs.meta new file mode 100644 index 00000000..f59d3214 --- /dev/null +++ b/Assets/TEngine/Runtime/Resource/ResourceManager.Services.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 3f67ac878fa04885ad6e90c076ddd9ff +timeCreated: 1680341970 \ No newline at end of file diff --git a/Assets/TEngine/Runtime/Resource/ResourceManager.StreamingAssetsHelper.cs b/Assets/TEngine/Runtime/Resource/ResourceManager.StreamingAssetsHelper.cs new file mode 100644 index 00000000..09434636 --- /dev/null +++ b/Assets/TEngine/Runtime/Resource/ResourceManager.StreamingAssetsHelper.cs @@ -0,0 +1,158 @@ +using System.Collections.Generic; +using UnityEngine; + +namespace TEngine +{ + internal partial class ResourceManager + { + public sealed class StreamingAssetsHelper + { + private static readonly Dictionary _cacheData = new Dictionary(1000); + +#if UNITY_ANDROID && !UNITY_EDITOR + private static AndroidJavaClass _unityPlayerClass; + + public static AndroidJavaClass UnityPlayerClass + { + get + { + if (_unityPlayerClass == null) + _unityPlayerClass = new UnityEngine.AndroidJavaClass("com.unity3d.player.UnityPlayer"); + return _unityPlayerClass; + } + } + + private static AndroidJavaObject _currentActivity; + + public static AndroidJavaObject CurrentActivity + { + get + { + if (_currentActivity == null) + _currentActivity = UnityPlayerClass.GetStatic("currentActivity"); + return _currentActivity; + } + } + + private static AndroidJavaObject _assetManager; + + public static AndroidJavaObject AssetManager + { + get + { + if (_assetManager == null) + _assetManager = CurrentActivity.Call("GetAssets");; + return _assetManager; + } + } + + /// + /// 利用安卓原生接口查询内置文件是否存在 + /// + public static bool FileExists(string filePath) + { + if (_cacheData.TryGetValue(filePath, out bool result) == false) + { + result = CurrentActivity.Call("CheckAssetExist", filePath); + _cacheData.Add(filePath, result); + } + + Log.Warning($"FileExists ? :{filePath} result:{result}"); + + return result; + } +#else + public static bool FileExists(string filePath) + { + string path = string.Empty; + + if (_cacheData.TryGetValue(filePath, out bool result) == false) + { + path = System.IO.Path.Combine(Application.streamingAssetsPath, filePath); + result = System.IO.File.Exists(path); + _cacheData.Add(filePath, result); + } + + Log.Warning($"FileExists ? :{path} result:{result}"); + + return result; + } +#endif + } + } +} + + +#if UNITY_ANDROID && UNITY_EDITOR +/// +/// 为Github对开发者的友好,采用自动补充UnityPlayerActivity.java文件的通用姿势满足各个开发者 +/// +internal class AndroidPost : UnityEditor.Android.IPostGenerateGradleAndroidProject +{ + public int callbackOrder => 99; + public void OnPostGenerateGradleAndroidProject(string path) + { + path = path.Replace("\\", "/"); + string untityActivityFilePath = $"{path}/src/main/java/com/unity3d/player/UnityPlayerActivity.java"; + var readContent = System.IO.File.ReadAllLines(untityActivityFilePath); + string postContent = + " //auto-gen-function \n" + + " public boolean CheckAssetExist(String filePath) \n" + + " { \n" + + " android.content.res.AssetManager assetManager = getAssets(); \n" + + " try \n" + + " { \n" + + " java.io.InputStream inputStream = assetManager.open(filePath); \n" + + " if (null != inputStream) \n" + + " { \n" + + " inputStream.close(); \n" + + " return true; \n" + + " } \n" + + " } \n" + + " catch(java.io.IOException e) \n" + + " { \n" + + " e.printStackTrace(); \n" + + " } \n" + + " return false; \n" + + " } \n" + + "}"; + + if (CheckFunctionExist(readContent) == false) + readContent[readContent.Length - 1] = postContent; + System.IO.File.WriteAllLines(untityActivityFilePath, readContent); + } + private bool CheckFunctionExist(string[] contents) + { + for (int i = 0; i < contents.Length; i++) + { + if (contents[i].Contains("CheckAssetExist")) + { + return true; + } + } + return false; + } +} +#endif + +/* +//auto-gen-function +public boolean CheckAssetExist(String filePath) +{ + android.content.res.AssetManager assetManager = getAssets(); + try + { + java.io.InputStream inputStream = assetManager.open(filePath); + if(null != inputStream) + { + inputStream.close(); + return true; + } + } + catch(java.io.IOException e) + { + e.printStackTrace(); + } + return false; +} +*/ \ No newline at end of file diff --git a/Assets/TEngine/Runtime/Resource/ResourceManager.StreamingAssetsHelper.cs.meta b/Assets/TEngine/Runtime/Resource/ResourceManager.StreamingAssetsHelper.cs.meta new file mode 100644 index 00000000..aa53c5ac --- /dev/null +++ b/Assets/TEngine/Runtime/Resource/ResourceManager.StreamingAssetsHelper.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: fbeb482c66ed4d2ea083457f2af53be7 +timeCreated: 1680341970 \ No newline at end of file diff --git a/Assets/TEngine/Runtime/Resource/YooAsset/YooAssetsLogger.cs b/Assets/TEngine/Runtime/Resource/YooAsset/YooAssetsLogger.cs new file mode 100644 index 00000000..8a38853c --- /dev/null +++ b/Assets/TEngine/Runtime/Resource/YooAsset/YooAssetsLogger.cs @@ -0,0 +1,28 @@ +using System; +using YooAsset; + +namespace TEngine +{ + public class YooAssetsLogger:ILogger + { + public void Log(string message) + { + TEngine.Log.Info(message); + } + + public void Warning(string message) + { + TEngine.Log.Warning(message); + } + + public void Error(string message) + { + TEngine.Log.Error(message); + } + + public void Exception(Exception exception) + { + TEngine.Log.Fatal(exception.Message); + } + } +} \ No newline at end of file diff --git a/Assets/TEngine/Runtime/Resource/YooAsset/YooAssetsLogger.cs.meta b/Assets/TEngine/Runtime/Resource/YooAsset/YooAssetsLogger.cs.meta new file mode 100644 index 00000000..a6778bfa --- /dev/null +++ b/Assets/TEngine/Runtime/Resource/YooAsset/YooAssetsLogger.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ac133d55c89b41aa99f915bb4c1e972a +timeCreated: 1680341816 \ No newline at end of file