This commit is contained in:
ALEXTANG
2023-04-01 17:40:10 +08:00
parent aeb1ff29f3
commit f571605b9a
9 changed files with 290 additions and 1 deletions

View File

@@ -1,6 +1,6 @@
using System; using System;
using TEngine.Localization;
using UnityEngine; using UnityEngine;
using TEngine.Localization;
namespace TEngine namespace TEngine
{ {

View File

@@ -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;
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 61ebff67750c418fb48bec8f0b90c6d3
timeCreated: 1680341218

View File

@@ -0,0 +1,72 @@
using System;
using System.IO;
using YooAsset;
namespace TEngine
{
internal partial class ResourceManager
{
/// <summary>
/// 资源文件解密服务类。
/// </summary>
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;
}
}
/// <summary>
/// 内置文件查询服务类。
/// </summary>
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;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3f67ac878fa04885ad6e90c076ddd9ff
timeCreated: 1680341970

View File

@@ -0,0 +1,158 @@
using System.Collections.Generic;
using UnityEngine;
namespace TEngine
{
internal partial class ResourceManager
{
public sealed class StreamingAssetsHelper
{
private static readonly Dictionary<string, bool> _cacheData = new Dictionary<string, bool>(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<AndroidJavaObject>("currentActivity");
return _currentActivity;
}
}
private static AndroidJavaObject _assetManager;
public static AndroidJavaObject AssetManager
{
get
{
if (_assetManager == null)
_assetManager = CurrentActivity.Call<AndroidJavaObject>("GetAssets");;
return _assetManager;
}
}
/// <summary>
/// 利用安卓原生接口查询内置文件是否存在
/// </summary>
public static bool FileExists(string filePath)
{
if (_cacheData.TryGetValue(filePath, out bool result) == false)
{
result = CurrentActivity.Call<bool>("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
/// <summary>
/// 为Github对开发者的友好采用自动补充UnityPlayerActivity.java文件的通用姿势满足各个开发者
/// </summary>
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;
}
*/

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: fbeb482c66ed4d2ea083457f2af53be7
timeCreated: 1680341970

View File

@@ -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);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ac133d55c89b41aa99f915bb4c1e972a
timeCreated: 1680341816