mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
Compare commits
66 Commits
TEngine4.0
...
TEngine4.0
Author | SHA1 | Date | |
---|---|---|---|
![]() |
90f84a2764 | ||
![]() |
6107b41770 | ||
![]() |
1423a3716a | ||
![]() |
6a87db76ee | ||
![]() |
3a6170dca6 | ||
![]() |
9d137d613a | ||
![]() |
ba77ec6b45 | ||
![]() |
b661da68f2 | ||
![]() |
e1040110bb | ||
![]() |
2d53fa1687 | ||
![]() |
c4ef07f13e | ||
![]() |
1f2d99ddc9 | ||
![]() |
edf4925a7a | ||
![]() |
5d67238c8f | ||
![]() |
6cfd352482 | ||
![]() |
40373c473d | ||
![]() |
d799f9fdf0 | ||
![]() |
15735c3d2d | ||
![]() |
818a74f437 | ||
![]() |
f248757401 | ||
![]() |
6ada0e7de7 | ||
![]() |
7ea472f97e | ||
![]() |
fb8528ff52 | ||
![]() |
e3ac92ef46 | ||
![]() |
be6a19c26a | ||
![]() |
e7f0636f30 | ||
![]() |
fb38e96e9e | ||
![]() |
dd658c7e1d | ||
![]() |
4d7cb7641d | ||
![]() |
ae075b1fad | ||
![]() |
02827ce3b8 | ||
![]() |
1a0e3f91e0 | ||
![]() |
6d376b0e07 | ||
![]() |
cb73c9a9eb | ||
![]() |
7dda73a7ac | ||
![]() |
9bcb636ed7 | ||
![]() |
bd0cfc5577 | ||
![]() |
ff613e4130 | ||
![]() |
fea1ae2278 | ||
![]() |
866c440479 | ||
![]() |
48ff839d64 | ||
![]() |
69be3cfa23 | ||
![]() |
5f2c27ecf0 | ||
![]() |
ef17cd851b | ||
![]() |
f186d6b058 | ||
![]() |
4385123976 | ||
![]() |
1334dc30f9 | ||
![]() |
af822add2c | ||
![]() |
ffb1f214ad | ||
![]() |
213aaed426 | ||
![]() |
623d301e41 | ||
![]() |
2870383afe | ||
![]() |
1ad435958a | ||
![]() |
386787c6ec | ||
![]() |
cd65dde4c3 | ||
![]() |
8321e77421 | ||
![]() |
1b6f80952e | ||
![]() |
b52e655c30 | ||
![]() |
8c0df95626 | ||
![]() |
0d1e308f1c | ||
![]() |
f8797538fd | ||
![]() |
fe4e168041 | ||
![]() |
8e9047d3a3 | ||
![]() |
04bfaeccc8 | ||
![]() |
d66c823c15 | ||
![]() |
0ec1424f0a |
@@ -1,16 +1,16 @@
|
||||
# TEngine
|
||||
|
||||
## TEngine-Runtime
|
||||
### AOT内核基于Gameframework,最简化以及商业化适配。
|
||||
### AOT内核基于Gameframework,优化、最简化以及商业化适配。
|
||||

|
||||
|
||||
## AOT游戏框架模块基类。
|
||||
#### 框架思路为面向接口编程,如Resource资源模块,开发白皮书为先定义IResourceManager的接口规范,然后编写ResourceManager继承框架具体实现(GameFrameworkModule)以及实现接口。最后实现调用层GameFrameworkModuleBase,调用层可以拓展编辑器供开发者自定义模块参数。
|
||||
#### 框架思路为面向接口编程,如Resource资源模块,开发白皮书为先定义IResourceManager的接口规范,然后编写ResourceManager继承框架具体实现(ModuleImp)以及实现接口。最后实现调用层Module,调用层可以拓展编辑器供开发者自定义模块参数。
|
||||
``` csharp
|
||||
/// <summary>
|
||||
/// 游戏框架模块抽象类。GameFrameworkModule为具体框架模块实现。
|
||||
/// 游戏框架模块抽象类。ModuleImp为具体框架模块实现。
|
||||
/// </summary>
|
||||
internal abstract class GameFrameworkModule
|
||||
internal abstract class ModuleImp
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取游戏框架模块优先级。
|
||||
@@ -34,16 +34,16 @@ internal abstract class GameFrameworkModule
|
||||
//=====================================================================//
|
||||
|
||||
/// <summary>
|
||||
/// 游戏框架模块抽象类。GameFrameworkModuleBase 为Mono调用层。
|
||||
/// 游戏框架模块抽象类。Module 为Mono调用层。
|
||||
/// </summary>
|
||||
public abstract class GameFrameworkModuleBase : MonoBehaviour
|
||||
public abstract class Module : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// 游戏框架模块初始化。
|
||||
/// </summary>
|
||||
protected virtual void Awake()
|
||||
{
|
||||
GameEntry.RegisterModule(this);
|
||||
ModuleSystem.RegisterModule(this);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
16
Books/Donate.md
Normal file
16
Books/Donate.md
Normal file
@@ -0,0 +1,16 @@
|
||||
## <strong>Buy me a coffee.
|
||||
|
||||
您的赞助会让我们做得更快更好,如果觉得TEngine对您有帮助,不妨赞助我买杯咖啡吧~
|
||||
|
||||
|
||||
<p align="center">
|
||||
|
||||
<img src="src/Donate-微信.jpg" alt="logo" width="384" height="562">
|
||||
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
|
||||
<img src="src/Donate-支付宝.jpg" alt="logo" width="384" height="562">
|
||||
|
||||
</p>
|
BIN
Books/src/Donate-微信.jpg
Normal file
BIN
Books/src/Donate-微信.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 113 KiB |
BIN
Books/src/Donate-支付宝.jpg
Normal file
BIN
Books/src/Donate-支付宝.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 214 KiB |
9
BuildCLI/build_android.bat
Normal file
9
BuildCLI/build_android.bat
Normal file
@@ -0,0 +1,9 @@
|
||||
cd /d %~dp0
|
||||
|
||||
call path_define.bat
|
||||
|
||||
%UNITYEDITOR_PATH%/Unity.exe %WORKSPACE% -logFile %BUILD_LOGFILE% -executeMethod TEngine.ReleaseTools.AutomationBuildAndroid -quit -batchmode -CustomArgs:Language=en_US; %WORKSPACE%
|
||||
|
||||
@REM for /f "delims=[" %%i in (%BUILD_LOGFILE%) do echo %%i
|
||||
|
||||
pause
|
6
BuildCLI/path_define.bat
Normal file
6
BuildCLI/path_define.bat
Normal file
@@ -0,0 +1,6 @@
|
||||
cd /d %~dp0
|
||||
|
||||
set WORKSPACE=G:/github/TEngine/UnityProject
|
||||
set UNITYEDITOR_PATH=G:/UnityEditor/2021.3.20f1c1/Editor
|
||||
set BUILD_DLL_LOGFILE=./build_dll.log
|
||||
set BUILD_LOGFILE=./build.log
|
@@ -42,8 +42,16 @@ public class ConfigSystem : Singleton<ConfigSystem>
|
||||
/// <returns>ByteBuf</returns>
|
||||
private ByteBuf LoadByteBuf(string file)
|
||||
{
|
||||
var textAssets = GameModule.Resource.LoadAsset<TextAsset>(file);
|
||||
byte[] ret = textAssets.bytes;
|
||||
return new ByteBuf(ret);
|
||||
TextAsset textAsset = null;
|
||||
textAsset = GameModule.Resource.GetPreLoadAsset<TextAsset>(file);
|
||||
if (textAsset != null)
|
||||
{
|
||||
return new ByteBuf(textAsset.bytes);
|
||||
}
|
||||
else
|
||||
{
|
||||
textAsset = GameModule.Resource.LoadAsset<TextAsset>(file);
|
||||
return new ByteBuf(textAsset.bytes);
|
||||
}
|
||||
}
|
||||
}
|
11
README.md
11
README.md
@@ -46,6 +46,7 @@
|
||||
* [06_对象池模块](Books/3-4-%E5%AF%B9%E8%B1%A1%E6%B1%A0%E6%A8%A1%E5%9D%97.md): 展示对象池模块概览。
|
||||
* [07_配置表模块](Books/3-6-%E9%85%8D%E7%BD%AE%E8%A1%A8%E6%A8%A1%E5%9D%97.md): 展示配置表模块概览。
|
||||
* [08_流程模块](Books/3-7-%E6%B5%81%E7%A8%8B%E6%A8%A1%E5%9D%97.md): 展示商业化流程模块。
|
||||
* [09_UI模块](Books/3-5-UI模块.md): 展示商业化UI模块。
|
||||
|
||||
|
||||
## <strong>为什么要使用TEngine
|
||||
@@ -85,6 +86,11 @@ Assets
|
||||
└── GameLogic // 游戏业务逻辑程序集 [Dll]
|
||||
├── GameApp.cs // 热更主入口
|
||||
└── GameApp_RegisterSystem.cs // 热更主入口注册系统
|
||||
|
||||
|
||||
TEngine
|
||||
├── Editor // TEngine编辑器核心代码
|
||||
└── Runtime // TEngine运行时核心代码
|
||||
```
|
||||
|
||||
- 必要:项目使用了以下第三方插件,请自行购买导入:
|
||||
@@ -103,3 +109,8 @@ Assets
|
||||
|
||||
## <strong>交流群
|
||||
### <a href="http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=MzOcQIzGVLQ5AC5LHaqqA3h_F6lZ_DX4&authKey=LctqAWGHkJ7voQvuj1oaSe5tsGrc1XmQG3U4QniieGUlxY3lC7FtDIpEvPOX0vT8&noverify=0&group_code=862987645">群 号:862987645 </strong></a>
|
||||
|
||||
|
||||
## <strong>Buy me a coffee.
|
||||
|
||||
[您的赞助会让我们做得更快更好,如果觉得TEngine对您有帮助,不妨赞助我买杯咖啡吧~](Books/Donate.md)
|
||||
|
16
UnityProject/Assets/AssetRaw/Configs/need_cache_list.json
Normal file
16
UnityProject/Assets/AssetRaw/Configs/need_cache_list.json
Normal file
@@ -0,0 +1,16 @@
|
||||
[
|
||||
{
|
||||
"ResPath": "Assets/AssetRaw/Effects",
|
||||
"CacheTime": 300,
|
||||
"MaxPoolCnt": 30,
|
||||
"PoolGoFreeTime": 300,
|
||||
"MinPoolCnt": 0
|
||||
},
|
||||
{
|
||||
"ResPath": "Assets/AssetRaw/PoolObjects/",
|
||||
"CacheTime": 300,
|
||||
"MaxPoolCnt": 30,
|
||||
"PoolGoFreeTime": 300,
|
||||
"MinPoolCnt": 0
|
||||
}
|
||||
]
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c9f7d9280641e9a4b87697ace96a4315
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 40a878a415f34e7a855fc4916bbb8e6b
|
||||
timeCreated: 1702479104
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1dcaa491f139438dbd963d8bbf0dba85
|
||||
timeCreated: 1702385397
|
@@ -0,0 +1,9 @@
|
||||
using System;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class BaseAttribute: Attribute
|
||||
{
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 819c4eaddddd4646a100da2e3f19c3c7
|
||||
timeCreated: 1702385397
|
@@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
public class CodeTypes
|
||||
{
|
||||
private static CodeTypes _instance;
|
||||
public static CodeTypes Instance => _instance ??= new CodeTypes();
|
||||
|
||||
private readonly Dictionary<string, Type> _allTypes = new();
|
||||
private readonly UnOrderMultiMapSet<Type, Type> _types = new();
|
||||
|
||||
public void Init(Assembly[] assemblies)
|
||||
{
|
||||
Dictionary<string, Type> addTypes = GetAssemblyTypes(assemblies);
|
||||
foreach ((string fullName, Type type) in addTypes)
|
||||
{
|
||||
_allTypes[fullName] = type;
|
||||
|
||||
if (type.IsAbstract)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// 记录所有的有BaseAttribute标记的的类型
|
||||
object[] objects = type.GetCustomAttributes(typeof(BaseAttribute), true);
|
||||
|
||||
foreach (object o in objects)
|
||||
{
|
||||
_types.Add(o.GetType(), type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public HashSet<Type> GetTypes(Type systemAttributeType)
|
||||
{
|
||||
if (!_types.ContainsKey(systemAttributeType))
|
||||
{
|
||||
return new HashSet<Type>();
|
||||
}
|
||||
|
||||
return _types[systemAttributeType];
|
||||
}
|
||||
|
||||
public Dictionary<string, Type> GetTypes()
|
||||
{
|
||||
return _allTypes;
|
||||
}
|
||||
|
||||
public Type GetType(string typeName)
|
||||
{
|
||||
return _allTypes[typeName];
|
||||
}
|
||||
|
||||
public static Dictionary<string, Type> GetAssemblyTypes(params Assembly[] args)
|
||||
{
|
||||
Dictionary<string, Type> types = new Dictionary<string, Type>();
|
||||
|
||||
foreach (Assembly ass in args)
|
||||
{
|
||||
foreach (Type type in ass.GetTypes())
|
||||
{
|
||||
if (type.FullName != null)
|
||||
{
|
||||
types[type.FullName] = type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return types;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 01fdfc4515314c579523ac3716005210
|
||||
timeCreated: 1702385429
|
@@ -0,0 +1,80 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
public class UnOrderMultiMapSet<TKey, TValue>: Dictionary<TKey, HashSet<TValue>>
|
||||
{
|
||||
public new HashSet<TValue> this[TKey t]
|
||||
{
|
||||
get
|
||||
{
|
||||
HashSet<TValue> set;
|
||||
if (!TryGetValue(t, out set))
|
||||
{
|
||||
set = new HashSet<TValue>();
|
||||
}
|
||||
return set;
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<TKey, HashSet<TValue>> GetDictionary()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
public void Add(TKey t, TValue k)
|
||||
{
|
||||
HashSet<TValue> set;
|
||||
TryGetValue(t, out set);
|
||||
if (set == null)
|
||||
{
|
||||
set = new HashSet<TValue>();
|
||||
base[t] = set;
|
||||
}
|
||||
set.Add(k);
|
||||
}
|
||||
|
||||
public bool Remove(TKey t, TValue k)
|
||||
{
|
||||
HashSet<TValue> set;
|
||||
TryGetValue(t, out set);
|
||||
if (set == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!set.Remove(k))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (set.Count == 0)
|
||||
{
|
||||
Remove(t);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Contains(TKey t, TValue k)
|
||||
{
|
||||
HashSet<TValue> set;
|
||||
TryGetValue(t, out set);
|
||||
if (set == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return set.Contains(k);
|
||||
}
|
||||
|
||||
public new int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
int count = 0;
|
||||
foreach (KeyValuePair<TKey,HashSet<TValue>> kv in this)
|
||||
{
|
||||
count += kv.Value.Count;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b798f0c1317c4caf9ace168f07b51d4f
|
||||
timeCreated: 1702385485
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 123e7155051957847883c574bf957c7f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,49 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
/// <summary>
|
||||
/// 封装一个角色可能用到的各种shader场景。
|
||||
/// </summary>
|
||||
class ActorShaderGroup
|
||||
{
|
||||
private readonly TShader[] _allShader = new TShader[(int)ActorShaderEnvType.EnvTypeMax];
|
||||
|
||||
/// <summary>
|
||||
/// 增加Shader到角色Shader分组。
|
||||
/// </summary>
|
||||
/// <param name="shaderType">当前环境类型。</param>
|
||||
/// <param name="shader">TShader。</param>
|
||||
public void AddShader(ActorShaderEnvType shaderType, TShader shader)
|
||||
{
|
||||
_allShader[(int)shaderType] = shader;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据当前环境获取Shader。
|
||||
/// </summary>
|
||||
/// <param name="type">当前环境类型。</param>
|
||||
/// <returns>TShader。</returns>
|
||||
public TShader GetShader(ActorShaderEnvType type)
|
||||
{
|
||||
return _allShader[(int)type];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断是否符合shader集合。
|
||||
/// </summary>
|
||||
/// <param name="shader">Shader实例。</param>
|
||||
/// <returns>是否符合。</returns>
|
||||
public bool IsMatch(Shader shader)
|
||||
{
|
||||
foreach (var dodShader in _allShader)
|
||||
{
|
||||
if (dodShader != null && dodShader.Shader == shader)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 79b6e5be73e14c929b6a3b4a980976ac
|
||||
timeCreated: 1701916950
|
@@ -0,0 +1,117 @@
|
||||
using GameBase;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
enum ActorShaderGroupType
|
||||
{
|
||||
/// <summary>
|
||||
/// 通用的角色shader
|
||||
/// </summary>
|
||||
Brdf = 0,
|
||||
|
||||
/// <summary>
|
||||
/// 眼睛
|
||||
/// </summary>
|
||||
BrdfEye,
|
||||
|
||||
///可能后面扩展,比如特效的特殊角色材质
|
||||
GroupMax,
|
||||
}
|
||||
|
||||
enum ActorShaderEnvType
|
||||
{
|
||||
/// <summary>
|
||||
/// 游戏内场景默认模型,不带阴影,不带xray,不透明效果
|
||||
/// </summary>
|
||||
EnvNormal = 0,
|
||||
|
||||
/// <summary>
|
||||
/// 展示场景
|
||||
/// </summary>
|
||||
EnvShow,
|
||||
|
||||
/// <summary>
|
||||
/// 带阴影
|
||||
/// </summary>
|
||||
EnvShadow,
|
||||
|
||||
/// <summary>
|
||||
/// 带xray,默认也带Shadow
|
||||
/// </summary>
|
||||
EnvXRay,
|
||||
|
||||
/// <summary>
|
||||
/// 透明渐隐效果
|
||||
/// </summary>
|
||||
EnvAlphaFade,
|
||||
|
||||
/// <summary>
|
||||
/// 展示场景没shadow
|
||||
/// </summary>
|
||||
EnvShow_NoShadow,
|
||||
|
||||
EnvTypeMax
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 角色Shader管理器。
|
||||
/// </summary>
|
||||
class ActorShaderMgr : Singleton<ActorShaderMgr>
|
||||
{
|
||||
private readonly ActorShaderGroup[] _allShaderGroup = new ActorShaderGroup[(int)ActorShaderGroupType.GroupMax];
|
||||
|
||||
public ActorShaderMgr()
|
||||
{
|
||||
CreateBrdfShader();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据当前Render查找角色的Shader分组。
|
||||
/// </summary>
|
||||
/// <param name="render">Render。</param>
|
||||
/// <returns>角色的Shader分组。</returns>
|
||||
public ActorShaderGroup FindShaderGroup(Renderer render)
|
||||
{
|
||||
var sharedMat = render.sharedMaterial;
|
||||
if (sharedMat == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var shader = sharedMat.shader;
|
||||
foreach (var group in _allShaderGroup)
|
||||
{
|
||||
if (group != null && group.IsMatch(shader))
|
||||
{
|
||||
return group;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void CreateBrdfShader()
|
||||
{
|
||||
//通用的效果
|
||||
var actorShader = new ActorShaderGroup();
|
||||
actorShader.AddShader(ActorShaderEnvType.EnvNormal, new TShader("TEngine/Actor/ActorBrdf",shaderLocation:"ActorBrdf"));
|
||||
actorShader.AddShader(ActorShaderEnvType.EnvShow, new TShader("TEngine/Actor/Show/ActorBrdf",shaderLocation:"ActorBrdf_Show"));
|
||||
actorShader.AddShader(ActorShaderEnvType.EnvShow_NoShadow, new TShader("TEngine/Actor/Show/ActorBrdf_NoShadow",shaderLocation:"ActorBrdf_NoShadow"));
|
||||
actorShader.AddShader(ActorShaderEnvType.EnvShadow, new TShader("TEngine/Actor/ActorBrdf",shaderLocation:"ActorBrdf_Normal"));
|
||||
actorShader.AddShader(ActorShaderEnvType.EnvXRay, new TShader("TEngine/Actor/X-Ray",shaderLocation:"X-Ray"));
|
||||
actorShader.AddShader(ActorShaderEnvType.EnvAlphaFade, new TShader("TEngine/Actor/Fade/ActorBrdf",shaderLocation:"ActorBrdf_Fade"));
|
||||
_allShaderGroup[(int)ActorShaderGroupType.Brdf] = actorShader;
|
||||
|
||||
|
||||
//眼睛效果
|
||||
actorShader = new ActorShaderGroup();
|
||||
actorShader.AddShader(ActorShaderEnvType.EnvNormal, new TShader("TEngine/Actor/ActorEye",shaderLocation:"ActorEye"));
|
||||
actorShader.AddShader(ActorShaderEnvType.EnvShow, new TShader("TEngine/Actor/Show/ActorEye",shaderLocation:"ActorEye_Show", "MRT_DISABLE", "MRT_ENABLE"));
|
||||
actorShader.AddShader(ActorShaderEnvType.EnvShadow, new TShader("TEngine/Actor/ActorEye",shaderLocation:"ActorEye"));
|
||||
actorShader.AddShader(ActorShaderEnvType.EnvXRay, new TShader("TEngine/Actor/ActorEye",shaderLocation:"ActorEye"));
|
||||
actorShader.AddShader(ActorShaderEnvType.EnvAlphaFade, new TShader("TEngine/Actor/Fade/ActorEye",shaderLocation:"ActorEye_Fade"));
|
||||
|
||||
_allShaderGroup[(int)ActorShaderGroupType.BrdfEye] = actorShader;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5a38b9b4bee84fabb1ef8db5292a6db6
|
||||
timeCreated: 1701916853
|
@@ -0,0 +1,154 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
/// <summary>
|
||||
/// TShader scripts used for all rendering.
|
||||
/// <remarks>统一封装对shader的管理。</remarks>
|
||||
/// </summary>
|
||||
public class TShader
|
||||
{
|
||||
private bool _loaded;
|
||||
private Shader _shader;
|
||||
private readonly string _shaderName;
|
||||
private readonly string _shaderLocation;
|
||||
private readonly List<string> _keywordOn = new List<string>();
|
||||
private readonly List<string> _keywordOff = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
/// Shader scripts used for all rendering.
|
||||
/// </summary>
|
||||
public Shader Shader
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!_loaded)
|
||||
{
|
||||
_loaded = true;
|
||||
_shader = FindShader(_shaderLocation,_shaderName);
|
||||
|
||||
if (_shader == null)
|
||||
{
|
||||
Log.Error($"invalid shader path: {_shaderLocation}, shader name {_shaderName}");
|
||||
}
|
||||
}
|
||||
|
||||
return _shader;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找Shader。
|
||||
/// </summary>
|
||||
/// <param name="shaderLocation">Shader定位地址。</param>
|
||||
/// <param name="shaderName">Shader名称。</param>
|
||||
/// <returns>Shader实例。</returns>
|
||||
public static Shader FindShader(string shaderLocation,string shaderName)
|
||||
{
|
||||
Shader shader = GameModule.Resource.LoadAsset<Shader>(shaderLocation);
|
||||
if (shader != null)
|
||||
{
|
||||
return shader;
|
||||
}
|
||||
return Shader.Find(shaderName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// TShader构造函数。
|
||||
/// </summary>
|
||||
/// <param name="shaderName">shader名称。</param>
|
||||
/// <param name="shaderLocation">shader路径。</param>
|
||||
public TShader(string shaderName, string shaderLocation)
|
||||
{
|
||||
_shaderName = shaderName;
|
||||
_shaderLocation = shaderLocation;
|
||||
_shader = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// TShader构造函数。
|
||||
/// </summary>
|
||||
/// <param name="shaderName">shader名称。</param>
|
||||
/// <param name="shaderLocation">shader路径。</param>
|
||||
/// <param name="keywordOn">开启选项。</param>
|
||||
/// <param name="keywordOff">关闭选项。</param>
|
||||
public TShader(string shaderName, string shaderLocation, string keywordOn, string keywordOff)
|
||||
{
|
||||
_shaderName = shaderName;
|
||||
_shaderLocation = shaderLocation;
|
||||
_shader = null;
|
||||
_keywordOn.Add(keywordOn);
|
||||
_keywordOff.Add(keywordOff);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// TShader构造函数。
|
||||
/// </summary>
|
||||
/// <param name="shaderName">shader名称。</param>
|
||||
/// <param name="shaderLocation">shader路径。</param>
|
||||
/// <param name="keywordOn">开启选项。</param>
|
||||
/// <param name="keywordOff">关闭选项。</param>
|
||||
public TShader(string shaderName, string shaderLocation, string[] keywordOn, string[] keywordOff)
|
||||
{
|
||||
_shaderName = shaderName;
|
||||
_shaderLocation = shaderLocation;
|
||||
_shader = null;
|
||||
_keywordOn.AddRange(keywordOn);
|
||||
_keywordOff.AddRange(keywordOff);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置Shader效果。
|
||||
/// </summary>
|
||||
/// <param name="render">渲染对象。</param>
|
||||
public void ApplyRender(Renderer render)
|
||||
{
|
||||
var sharedMat = render.sharedMaterial;
|
||||
if (sharedMat != null)
|
||||
{
|
||||
//copy一份材质
|
||||
sharedMat = render.material;
|
||||
sharedMat.shader = Shader;
|
||||
|
||||
foreach (var keyword in _keywordOff)
|
||||
{
|
||||
sharedMat.DisableKeyword(keyword);
|
||||
}
|
||||
|
||||
foreach (var keyword in _keywordOn)
|
||||
{
|
||||
sharedMat.EnableKeyword(keyword);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清除shader。
|
||||
/// </summary>
|
||||
/// <param name="render">渲染对象。</param>
|
||||
public void ClearRender(Renderer render)
|
||||
{
|
||||
if (_keywordOff.Count <= 0 && _keywordOn.Count <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var sharedMat = render.sharedMaterial;
|
||||
if (sharedMat != null)
|
||||
{
|
||||
//copy一份材质。
|
||||
sharedMat = render.material;
|
||||
for (int k = 0; k < _keywordOn.Count; k++)
|
||||
{
|
||||
sharedMat.DisableKeyword(_keywordOn[k]);
|
||||
}
|
||||
|
||||
for (int k = 0; k < _keywordOff.Count; k++)
|
||||
{
|
||||
sharedMat.EnableKeyword(_keywordOff[k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e219233984c14f7d97bc744c07fe13d0
|
||||
timeCreated: 1698115491
|
@@ -9,10 +9,10 @@ namespace GameLogic
|
||||
/// <summary>
|
||||
/// UI列表Item
|
||||
/// </summary>
|
||||
/// <typeparam name="DataT"></typeparam>
|
||||
public interface IListDataItem<in DataT>
|
||||
/// <typeparam name="TData"></typeparam>
|
||||
public interface IListDataItem<in TData>
|
||||
{
|
||||
void SetItemData(DataT d);
|
||||
void SetItemData(TData d);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -180,8 +180,7 @@ namespace GameLogic
|
||||
/// <param name="n"></param>
|
||||
public void SetDatas(List<DataT> dataList, int n = -1)
|
||||
{
|
||||
AdjustItemNum(Mathf.Max(0, n >= 0 ? n : (dataList == null ? 0 : (dataList.Count - dataStartOffset))),
|
||||
dataList);
|
||||
AdjustItemNum(Mathf.Max(0, n >= 0 ? n : (dataList == null ? 0 : (dataList.Count - dataStartOffset))), dataList);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -215,8 +214,7 @@ namespace GameLogic
|
||||
return;
|
||||
}
|
||||
|
||||
var listDataItem = item as IListDataItem<DataT>;
|
||||
if (listDataItem != null)
|
||||
if (item is IListDataItem<DataT> listDataItem)
|
||||
{
|
||||
listDataItem.SetItemData(GetData(i));
|
||||
}
|
||||
@@ -271,8 +269,7 @@ namespace GameLogic
|
||||
|
||||
var preIndex = selectIndex;
|
||||
m_selectIndex = i;
|
||||
var item = GetItem(preIndex) as IListSelectItem;
|
||||
if (item != null)
|
||||
if (GetItem(preIndex) is IListSelectItem item)
|
||||
{
|
||||
item.SetSelected(false);
|
||||
}
|
||||
@@ -282,12 +279,19 @@ namespace GameLogic
|
||||
{
|
||||
item.SetSelected(true);
|
||||
}
|
||||
|
||||
UpdateSnapTargetItem();
|
||||
if (triggerEvt && funcOnSelectChange != null)
|
||||
{
|
||||
funcOnSelectChange.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 刷新Snap
|
||||
/// </summary>
|
||||
protected virtual void UpdateSnapTargetItem()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前选中的数据
|
||||
@@ -318,6 +322,11 @@ namespace GameLogic
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 点击选择
|
||||
/// </summary>
|
||||
public bool SelectByClick = true;
|
||||
|
||||
/// <summary>
|
||||
/// item被点击
|
||||
@@ -331,7 +340,10 @@ namespace GameLogic
|
||||
funcOnItemClick.Invoke(i);
|
||||
}
|
||||
|
||||
selectIndex = i;
|
||||
if (SelectByClick)
|
||||
{
|
||||
selectIndex = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TEngine;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// 普通UI列表。
|
||||
/// </summary>
|
||||
public class UIListWidget<TItem, TData> : UIListBase<TItem, TData> where TItem : UIWidget, new()
|
||||
{
|
||||
/// <summary>
|
||||
/// item列表。
|
||||
/// </summary>
|
||||
protected List<TItem> m_items = new List<TItem>();
|
||||
|
||||
/// <summary>
|
||||
/// item列表。
|
||||
/// </summary>
|
||||
public List<TItem> items => m_items;
|
||||
|
||||
/// <summary>
|
||||
/// 设置显示数据。
|
||||
/// </summary>
|
||||
/// <param name="n"></param>
|
||||
/// <param name="datas"></param>
|
||||
/// <param name="funcItem"></param>
|
||||
protected override void AdjustItemNum(int n, List<TData> datas = null, Action<TItem, int> funcItem = null)
|
||||
{
|
||||
base.AdjustItemNum(n, datas, funcItem);
|
||||
AdjustIconNum(m_items, n, gameObject.transform, itemBase);
|
||||
UpdateList(funcItem);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 刷新列表。
|
||||
/// </summary>
|
||||
/// <param name="funcItem"></param>
|
||||
protected void UpdateList(Action<TItem, int> funcItem = null)
|
||||
{
|
||||
for (var i = 0; i < m_items.Count; i++)
|
||||
{
|
||||
UpdateListItem(m_items[i], i, funcItem);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取item
|
||||
/// </summary>
|
||||
/// <param name="i"></param>
|
||||
/// <returns></returns>
|
||||
public override TItem GetItem(int i)
|
||||
{
|
||||
return i >= 0 && i < m_items.Count ? m_items[i] : null;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 96f732d895e94fbc99c904d66ca844ca
|
||||
timeCreated: 1701844130
|
@@ -66,6 +66,7 @@ namespace GameLogic
|
||||
LoopRectView.SetListItemCount(n);
|
||||
LoopRectView.RefreshAllShownItem();
|
||||
m_tpFuncItem = null;
|
||||
UpdateAllItemSelect();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -148,11 +149,20 @@ namespace GameLogic
|
||||
/// <summary>
|
||||
/// 获取item
|
||||
/// </summary>
|
||||
/// <param name="i"></param>
|
||||
/// <param name="index"></param>
|
||||
/// <returns></returns>
|
||||
public override TItem GetItem(int i)
|
||||
public override TItem GetItem(int index)
|
||||
{
|
||||
return i >= 0 && i < m_items.Count ? m_items[i] : null;
|
||||
for (var i = 0; i < m_itemCache.Count; i++)
|
||||
{
|
||||
|
||||
var item = m_itemCache.GetValueByIndex(i);
|
||||
if (item.GetItemIndex() == index)
|
||||
{
|
||||
return item;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -178,5 +188,21 @@ namespace GameLogic
|
||||
{
|
||||
return m_itemCache.GetValueByIndex(index);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 刷新所有item选中状态
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public void UpdateAllItemSelect()
|
||||
{
|
||||
var index = selectIndex;
|
||||
for (var i = 0; i < m_itemCache.Count; i++)
|
||||
{
|
||||
if (m_itemCache.GetValueByIndex(i) is IListSelectItem item)
|
||||
{
|
||||
item.SetSelected(item.GetItemIndex() == index);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -67,6 +67,7 @@ namespace GameLogic
|
||||
LoopRectView.SetListItemCount(n);
|
||||
LoopRectView.RefreshAllShownItem();
|
||||
m_tpFuncItem = null;
|
||||
UpdateAllItemSelect();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -147,11 +148,20 @@ namespace GameLogic
|
||||
/// <summary>
|
||||
/// 获取item
|
||||
/// </summary>
|
||||
/// <param name="i"></param>
|
||||
/// <param name="index"></param>
|
||||
/// <returns></returns>
|
||||
public override TItem GetItem(int i)
|
||||
public override TItem GetItem(int index)
|
||||
{
|
||||
return i >= 0 && i < m_items.Count ? m_items[i] : null;
|
||||
for (var i = 0; i < m_itemCache.Count; i++)
|
||||
{
|
||||
|
||||
var item = m_itemCache.GetValueByIndex(i);
|
||||
if (item.GetItemIndex() == index)
|
||||
{
|
||||
return item;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -186,5 +196,30 @@ namespace GameLogic
|
||||
{
|
||||
return m_itemCache.GetValueByIndex(index);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 刷新所有item选中状态
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public void UpdateAllItemSelect()
|
||||
{
|
||||
var index = selectIndex;
|
||||
for (var i = 0; i < m_itemCache.Count; i++)
|
||||
{
|
||||
if (m_itemCache.GetValueByIndex(i) is IListSelectItem item)
|
||||
{
|
||||
item.SetSelected(item.GetItemIndex() == index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void UpdateSnapTargetItem()
|
||||
{
|
||||
base.UpdateSnapTargetItem();
|
||||
if (LoopRectView != null && LoopRectView.ItemSnapEnable)
|
||||
{
|
||||
LoopRectView.SetSnapTargetItemIndex(selectIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d1f693ff76ae490fbe194855d94e8266
|
||||
timeCreated: 1702479172
|
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using TEngine;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// 事件接口帮助类。
|
||||
/// </summary>
|
||||
internal class EventInterfaceHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 初始化。
|
||||
/// </summary>
|
||||
public static void Init()
|
||||
{
|
||||
RegisterEventInterface_Logic.Register(GameEvent.EventMgr);
|
||||
RegisterEventInterface_UI.Register(GameEvent.EventMgr);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9afaf331ee7249adb5cc0953dfd3413c
|
||||
timeCreated: 1702379658
|
@@ -0,0 +1,16 @@
|
||||
using TEngine;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
[System.AttributeUsage(System.AttributeTargets.Class)]
|
||||
internal class EventInterfaceImpAttribute : BaseAttribute
|
||||
{
|
||||
private EEventGroup _eGroup;
|
||||
public EEventGroup EventGroup => _eGroup;
|
||||
|
||||
public EventInterfaceImpAttribute(EEventGroup group)
|
||||
{
|
||||
_eGroup = group;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8bbf40942b0e4470bb8d8a82577f713c
|
||||
timeCreated: 1702479403
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de49bf2e9f0a4fac85851a582e2fb4ed
|
||||
timeCreated: 1702379835
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bff68b49afffbe54b9d5ff4e4cad4f23
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,70 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by autoBindTool.
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TEngine;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
public partial class IActorLogicEvent_Event
|
||||
{
|
||||
public static readonly int OnMainPlayerDataChange = RuntimeId.ToRuntimeId("IActorLogicEvent_Event.OnMainPlayerDataChange");
|
||||
public static readonly int OnMainPlayerLevelChange = RuntimeId.ToRuntimeId("IActorLogicEvent_Event.OnMainPlayerLevelChange");
|
||||
public static readonly int OnMainPlayerGoldChange = RuntimeId.ToRuntimeId("IActorLogicEvent_Event.OnMainPlayerGoldChange");
|
||||
public static readonly int OnMainPlayerDiamondChange = RuntimeId.ToRuntimeId("IActorLogicEvent_Event.OnMainPlayerDiamondChange");
|
||||
public static readonly int OnMainPlayerBindDiamondChange = RuntimeId.ToRuntimeId("IActorLogicEvent_Event.OnMainPlayerBindDiamondChange");
|
||||
public static readonly int OnMainPlayerCurrencyChange = RuntimeId.ToRuntimeId("IActorLogicEvent_Event.OnMainPlayerCurrencyChange");
|
||||
public static readonly int OnMainPlayerExpChange = RuntimeId.ToRuntimeId("IActorLogicEvent_Event.OnMainPlayerExpChange");
|
||||
}
|
||||
|
||||
[EventInterfaceImp(EEventGroup.GroupLogic)]
|
||||
public partial class IActorLogicEvent_Gen : IActorLogicEvent
|
||||
{
|
||||
private EventDispatcher _dispatcher;
|
||||
public IActorLogicEvent_Gen(EventDispatcher dispatcher)
|
||||
{
|
||||
_dispatcher = dispatcher;
|
||||
}
|
||||
|
||||
public void OnMainPlayerDataChange()
|
||||
{
|
||||
_dispatcher.Send(IActorLogicEvent_Event.OnMainPlayerDataChange);
|
||||
}
|
||||
|
||||
public void OnMainPlayerLevelChange()
|
||||
{
|
||||
_dispatcher.Send(IActorLogicEvent_Event.OnMainPlayerLevelChange);
|
||||
}
|
||||
|
||||
public void OnMainPlayerGoldChange(System.UInt32 oldVal,System.UInt32 newVal)
|
||||
{
|
||||
_dispatcher.Send(IActorLogicEvent_Event.OnMainPlayerGoldChange,oldVal,newVal);
|
||||
}
|
||||
|
||||
public void OnMainPlayerDiamondChange(System.UInt32 oldVal,System.UInt32 newVal)
|
||||
{
|
||||
_dispatcher.Send(IActorLogicEvent_Event.OnMainPlayerDiamondChange,oldVal,newVal);
|
||||
}
|
||||
|
||||
public void OnMainPlayerBindDiamondChange(System.UInt32 oldVal,System.UInt32 newVal)
|
||||
{
|
||||
_dispatcher.Send(IActorLogicEvent_Event.OnMainPlayerBindDiamondChange,oldVal,newVal);
|
||||
}
|
||||
|
||||
public void OnMainPlayerCurrencyChange(GameLogic.CurrencyType type,System.UInt32 oldVal,System.UInt32 newVal)
|
||||
{
|
||||
_dispatcher.Send(IActorLogicEvent_Event.OnMainPlayerCurrencyChange,type,oldVal,newVal);
|
||||
}
|
||||
|
||||
public void OnMainPlayerExpChange(System.UInt64 oldVal,System.UInt64 newVal)
|
||||
{
|
||||
_dispatcher.Send(IActorLogicEvent_Event.OnMainPlayerExpChange,oldVal,newVal);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 12d7d4edd7d06bc4286ea4af153380c6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 615ca01c7a524654c91935631f39f570
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,40 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by autoBindTool.
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TEngine;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
public partial class ILoginUI_Event
|
||||
{
|
||||
public static readonly int OnRoleLogin = RuntimeId.ToRuntimeId("ILoginUI_Event.OnRoleLogin");
|
||||
public static readonly int OnRoleLoginOut = RuntimeId.ToRuntimeId("ILoginUI_Event.OnRoleLoginOut");
|
||||
}
|
||||
|
||||
[EventInterfaceImp(EEventGroup.GroupUI)]
|
||||
public partial class ILoginUI_Gen : ILoginUI
|
||||
{
|
||||
private EventDispatcher _dispatcher;
|
||||
public ILoginUI_Gen(EventDispatcher dispatcher)
|
||||
{
|
||||
_dispatcher = dispatcher;
|
||||
}
|
||||
|
||||
public void OnRoleLogin(System.Boolean isReconnect)
|
||||
{
|
||||
_dispatcher.Send(ILoginUI_Event.OnRoleLogin,isReconnect);
|
||||
}
|
||||
|
||||
public void OnRoleLoginOut()
|
||||
{
|
||||
_dispatcher.Send(ILoginUI_Event.OnRoleLoginOut);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bde7ed0ea10cf29448370b39ecd69a97
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7cf3381dedbf4daeb53e710a5c544204
|
||||
timeCreated: 1702433587
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 610229edeca4417685ffd07f18b2b9f1
|
||||
timeCreated: 1702379817
|
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using TEngine;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// 示例货币枚举。
|
||||
/// </summary>
|
||||
public enum CurrencyType
|
||||
{
|
||||
None,
|
||||
Gold,
|
||||
Diamond,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 示意逻辑层事件。
|
||||
/// <remarks> 优化抛出事件,通过接口约束事件参数。</remarks>
|
||||
/// <remarks> example: GameEvent.Get<IActorLogicEvent>().OnMainPlayerCurrencyChange(CurrencyType.Gold,oldVal,newVal); </remarks>
|
||||
/// </summary>
|
||||
[EventInterface(EEventGroup.GroupLogic)]
|
||||
interface IActorLogicEvent
|
||||
{
|
||||
void OnMainPlayerDataChange();
|
||||
|
||||
void OnMainPlayerLevelChange();
|
||||
|
||||
void OnMainPlayerGoldChange(uint oldVal, uint newVal);
|
||||
|
||||
void OnMainPlayerDiamondChange(uint oldVal, uint newVal);
|
||||
|
||||
void OnMainPlayerBindDiamondChange(uint oldVal, uint newVal);
|
||||
|
||||
void OnMainPlayerCurrencyChange(CurrencyType type, uint oldVal, uint newVal);
|
||||
|
||||
void OnMainPlayerExpChange(ulong oldVal, ulong newVal);
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8d4558cb74e8462a86f0ee3461f6b7c9
|
||||
timeCreated: 1702383645
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 90e13cc92c5d42f28b4f5fab599f472a
|
||||
timeCreated: 1702379805
|
@@ -0,0 +1,17 @@
|
||||
using TEngine;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// 示意UI层事件。
|
||||
/// <remarks> 优化抛出事件,通过接口约束事件参数。</remarks>
|
||||
/// <remarks> example: GameEvent.Get<ILoginUI>().OnRoleLogin(isReconnect); </remarks>
|
||||
/// </summary>
|
||||
[EventInterface(EEventGroup.GroupUI)]
|
||||
public interface ILoginUI
|
||||
{
|
||||
public void OnRoleLogin(bool isReconnect);
|
||||
|
||||
public void OnRoleLoginOut();
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 33b45e62bd3447498acfe874017b9a35
|
||||
timeCreated: 1702433755
|
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TEngine;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// 逻辑层事件接口。
|
||||
/// </summary>
|
||||
internal class RegisterEventInterface_Logic
|
||||
{
|
||||
/// <summary>
|
||||
/// 注册逻辑层事件接口。
|
||||
/// </summary>
|
||||
/// <param name="mgr">事件管理器。</param>
|
||||
public static void Register(EventMgr mgr)
|
||||
{
|
||||
HashSet<Type> types = CodeTypes.Instance.GetTypes(typeof(EventInterfaceImpAttribute));
|
||||
|
||||
foreach (Type type in types)
|
||||
{
|
||||
object[] attrs = type.GetCustomAttributes(typeof(EventInterfaceImpAttribute), false);
|
||||
if (attrs.Length == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
EventInterfaceImpAttribute httpHandlerAttribute = (EventInterfaceImpAttribute)attrs[0];
|
||||
|
||||
if (httpHandlerAttribute.EventGroup != EEventGroup.GroupLogic)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
object obj = Activator.CreateInstance(type, mgr.Dispatcher);
|
||||
|
||||
mgr.RegWrapInterface(obj.GetType().GetInterfaces()[0]?.FullName, obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b8bdf6c139b44758aa16db2e1837f5d9
|
||||
timeCreated: 1702379518
|
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TEngine;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// UI层事件接口。
|
||||
/// </summary>
|
||||
internal class RegisterEventInterface_UI
|
||||
{
|
||||
/// <summary>
|
||||
/// 注册UI层事件接口。
|
||||
/// </summary>
|
||||
/// <param name="mgr">事件管理器。</param>
|
||||
public static void Register(EventMgr mgr)
|
||||
{
|
||||
HashSet<Type> types = CodeTypes.Instance.GetTypes(typeof(EventInterfaceImpAttribute));
|
||||
|
||||
foreach (Type type in types)
|
||||
{
|
||||
object[] attrs = type.GetCustomAttributes(typeof(EventInterfaceImpAttribute), false);
|
||||
if (attrs.Length == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
EventInterfaceImpAttribute httpHandlerAttribute = (EventInterfaceImpAttribute)attrs[0];
|
||||
|
||||
if (httpHandlerAttribute.EventGroup != EEventGroup.GroupUI)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
object obj = Activator.CreateInstance(type, mgr.Dispatcher);
|
||||
|
||||
mgr.RegWrapInterface(obj.GetType().GetInterfaces()[0]?.FullName, obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f53b67f2cfbe4912bffee9593cd60970
|
||||
timeCreated: 1702379505
|
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using GameLogic;
|
||||
using TEngine;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -8,6 +9,8 @@ public partial class GameApp
|
||||
|
||||
private void Init()
|
||||
{
|
||||
CodeTypes.Instance.Init(_hotfixAssembly.ToArray());
|
||||
EventInterfaceHelper.Init();
|
||||
_listLogicMgr = new List<ILogicSys>();
|
||||
RegisterAllSystem();
|
||||
InitSystemSetting();
|
||||
|
@@ -38,10 +38,15 @@ namespace GameMain
|
||||
m_btnClear.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
public override void RegisterEvent()
|
||||
{
|
||||
base.RegisterEvent();
|
||||
AddUIEvent(RuntimeId.ToRuntimeId("RefreshVersion"),RefreshVersion);
|
||||
}
|
||||
|
||||
public override void OnRefresh()
|
||||
{
|
||||
base.OnRefresh();
|
||||
RefreshVersion();
|
||||
}
|
||||
|
||||
#region 事件
|
||||
|
@@ -13,9 +13,18 @@ namespace GameMain
|
||||
|
||||
private ProcedureOwner _procedureOwner;
|
||||
|
||||
private float CurrentSpeed =>
|
||||
(GameModule.Resource.Downloader.TotalDownloadBytes -
|
||||
GameModule.Resource.Downloader.CurrentDownloadBytes) / GameTime.time;
|
||||
private float _lastUpdateDownloadedSize;
|
||||
private float CurrentSpeed
|
||||
{
|
||||
get
|
||||
{
|
||||
float interval = GameTime.deltaTime;
|
||||
var sizeDiff = GameModule.Resource.Downloader.CurrentDownloadBytes - _lastUpdateDownloadedSize;
|
||||
_lastUpdateDownloadedSize = GameModule.Resource.Downloader.CurrentDownloadBytes;
|
||||
var speed = (float)Math.Floor(sizeDiff / interval);
|
||||
return speed;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnEnter(ProcedureOwner procedureOwner)
|
||||
{
|
||||
@@ -63,7 +72,7 @@ namespace GameMain
|
||||
Utility.File.GetByteLengthString(currentDownloadBytes),
|
||||
Utility.File.GetByteLengthString(totalDownloadBytes),
|
||||
GameModule.Resource.Downloader.Progress,
|
||||
Utility.File.GetByteLengthString((int)CurrentSpeed));
|
||||
Utility.File.GetLengthString((int)CurrentSpeed));
|
||||
LoadUpdateLogic.Instance.DownProgressAction?.Invoke(GameModule.Resource.Downloader.Progress);
|
||||
UILoadMgr.Show(UIDefine.UILoadUpdate,descriptionText);
|
||||
|
||||
|
@@ -29,7 +29,8 @@ namespace GameMain
|
||||
|
||||
private async UniTaskVoid InitPackage(ProcedureOwner procedureOwner)
|
||||
{
|
||||
if (GameModule.Resource.PlayMode == EPlayMode.HostPlayMode)
|
||||
if (GameModule.Resource.PlayMode == EPlayMode.HostPlayMode ||
|
||||
GameModule.Resource.PlayMode == EPlayMode.WebPlayMode)
|
||||
{
|
||||
if (SettingsUtils.EnableUpdateData())
|
||||
{
|
||||
@@ -44,7 +45,8 @@ namespace GameMain
|
||||
|
||||
if (!string.IsNullOrEmpty(updateData.FallbackHostServerURL))
|
||||
{
|
||||
SettingsUtils.FrameworkGlobalSettings.FallbackHostServerURL = updateData.FallbackHostServerURL;
|
||||
SettingsUtils.FrameworkGlobalSettings.FallbackHostServerURL =
|
||||
updateData.FallbackHostServerURL;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -60,9 +62,9 @@ namespace GameMain
|
||||
{
|
||||
//热更新阶段文本初始化
|
||||
LoadText.Instance.InitConfigData(null);
|
||||
//热更新UI初始化
|
||||
UILoadMgr.Initialize();
|
||||
|
||||
|
||||
GameEvent.Send(RuntimeId.ToRuntimeId("RefreshVersion"));
|
||||
|
||||
EPlayMode playMode = GameModule.Resource.PlayMode;
|
||||
|
||||
// 编辑器模式。
|
||||
@@ -107,7 +109,9 @@ namespace GameMain
|
||||
// 打开启动UI。
|
||||
UILoadMgr.Show(UIDefine.UILoadUpdate, $"资源初始化失败!");
|
||||
|
||||
UILoadTip.ShowMessageBox($"资源初始化失败!点击确认重试 \n \n <color=#FF0000>原因{initializationOperation.Error}</color>", MessageShowType.TwoButton,
|
||||
UILoadTip.ShowMessageBox(
|
||||
$"资源初始化失败!点击确认重试 \n \n <color=#FF0000>原因{initializationOperation.Error}</color>",
|
||||
MessageShowType.TwoButton,
|
||||
LoadStyle.StyleEnum.Style_Retry
|
||||
, () => { Retry(procedureOwner); }, UnityEngine.Application.Quit);
|
||||
}
|
||||
|
@@ -14,6 +14,9 @@ namespace GameMain
|
||||
protected override void OnEnter(ProcedureOwner procedureOwner)
|
||||
{
|
||||
base.OnEnter(procedureOwner);
|
||||
|
||||
//热更新UI初始化
|
||||
UILoadMgr.Initialize();
|
||||
|
||||
// 语言配置:设置当前使用的语言,如果不设置,则默认使用操作系统语言
|
||||
InitLanguageSettings();
|
||||
|
@@ -116,8 +116,7 @@ namespace GameMain
|
||||
{
|
||||
ChangeState<ProcedureStartGame>(m_procedureOwner);
|
||||
#if UNITY_EDITOR
|
||||
m_MainLogicAssembly = AppDomain.CurrentDomain.GetAssemblies().
|
||||
First(assembly => $"{assembly.GetName().Name}.dll" == SettingsUtils.HybridCLRCustomGlobalSettings.LogicMainDllName);
|
||||
m_MainLogicAssembly = GetMainLogicAssembly();
|
||||
#endif
|
||||
if (m_MainLogicAssembly == null)
|
||||
{
|
||||
|
@@ -16,23 +16,23 @@ namespace GameMain
|
||||
{
|
||||
private float _progress = 0f;
|
||||
|
||||
private Dictionary<string, bool> m_LoadedFlag = new Dictionary<string, bool>();
|
||||
private readonly Dictionary<string, bool> _loadedFlag = new Dictionary<string, bool>();
|
||||
|
||||
public override bool UseNativeDialog => true;
|
||||
|
||||
private bool m_needProLoadConfig = false;
|
||||
private readonly bool _needProLoadConfig = true;
|
||||
|
||||
private bool m_InitConfigXml = false;
|
||||
private bool _hadInitConfigXml = false;
|
||||
|
||||
protected override void OnEnter(ProcedureOwner procedureOwner)
|
||||
{
|
||||
base.OnEnter(procedureOwner);
|
||||
|
||||
m_LoadedFlag.Clear();
|
||||
_loadedFlag.Clear();
|
||||
|
||||
if (GameModule.Resource.PlayMode == EPlayMode.EditorSimulateMode)
|
||||
{
|
||||
m_InitConfigXml = true;
|
||||
_hadInitConfigXml = true;
|
||||
}
|
||||
|
||||
UILoadMgr.Show(UIDefine.UILoadUpdate, Utility.Text.Format(LoadText.Instance.Label_Load_Load_Progress, 0));
|
||||
@@ -46,11 +46,11 @@ namespace GameMain
|
||||
{
|
||||
base.OnUpdate(procedureOwner, elapseSeconds, realElapseSeconds);
|
||||
|
||||
var totalCount = m_LoadedFlag.Count <= 0 ? 1 : m_LoadedFlag.Count;
|
||||
var totalCount = _loadedFlag.Count <= 0 ? 1 : _loadedFlag.Count;
|
||||
|
||||
var loadCount = m_LoadedFlag.Count <= 0 ? 1 : 0;
|
||||
var loadCount = _loadedFlag.Count <= 0 ? 1 : 0;
|
||||
|
||||
foreach (KeyValuePair<string, bool> loadedFlag in m_LoadedFlag)
|
||||
foreach (KeyValuePair<string, bool> loadedFlag in _loadedFlag)
|
||||
{
|
||||
if (!loadedFlag.Value)
|
||||
{
|
||||
@@ -62,7 +62,7 @@ namespace GameMain
|
||||
}
|
||||
}
|
||||
|
||||
if (m_LoadedFlag.Count != 0)
|
||||
if (_loadedFlag.Count != 0)
|
||||
{
|
||||
UILoadMgr.Show(UIDefine.UILoadUpdate, Utility.Text.Format(LoadText.Instance.Label_Load_Load_Progress, (float)loadCount / totalCount * 100));
|
||||
}
|
||||
@@ -87,7 +87,7 @@ namespace GameMain
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_InitConfigXml == false)
|
||||
if (_hadInitConfigXml == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -116,13 +116,13 @@ namespace GameMain
|
||||
|
||||
await UniTask.Delay(TimeSpan.FromSeconds(2.5f));
|
||||
|
||||
if (m_needProLoadConfig)
|
||||
if (_needProLoadConfig)
|
||||
{
|
||||
LoadAllConfig();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_InitConfigXml = true;
|
||||
_hadInitConfigXml = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,14 +130,27 @@ namespace GameMain
|
||||
{
|
||||
if (GameModule.Resource.PlayMode == EPlayMode.EditorSimulateMode)
|
||||
{
|
||||
m_InitConfigXml = true;
|
||||
_hadInitConfigXml = true;
|
||||
return;
|
||||
}
|
||||
AssetInfo[] assetInfos = GameModule.Resource.GetAssetInfos("PRELOAD");
|
||||
foreach (var assetInfo in assetInfos)
|
||||
{
|
||||
LoadConfig(assetInfo.Address);
|
||||
}
|
||||
#if UNITY_WEBGL
|
||||
AssetInfo[] webAssetInfos = GameModule.Resource.GetAssetInfos("WEBGL_PRELOAD");
|
||||
foreach (var assetInfo in webAssetInfos)
|
||||
{
|
||||
LoadConfig(assetInfo.Address);
|
||||
}
|
||||
#endif
|
||||
_hadInitConfigXml = true;
|
||||
}
|
||||
|
||||
private void LoadConfig(string configName)
|
||||
{
|
||||
m_LoadedFlag.Add(configName, false);
|
||||
_loadedFlag.Add(configName, false);
|
||||
GameModule.Resource.LoadAssetAsync<TextAsset>(configName, OnLoadSuccess);
|
||||
}
|
||||
|
||||
@@ -147,10 +160,11 @@ namespace GameMain
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var name = assetOperationHandle.GetAssetInfo().Address;
|
||||
m_LoadedFlag[name] = true;
|
||||
Log.Info("Load config '{0}' OK.", name);
|
||||
var location = assetOperationHandle.GetAssetInfo().Address;
|
||||
_loadedFlag[location] = true;
|
||||
GameModule.Resource.PushPreLoadAsset(location, assetOperationHandle.AssetObject);
|
||||
Log.Info("Load config '{0}' OK.", location);
|
||||
assetOperationHandle.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
@@ -15,14 +15,14 @@ namespace GameMain
|
||||
public override bool UseNativeDialog => true;
|
||||
|
||||
private ProcedureOwner _procedureOwner;
|
||||
|
||||
|
||||
protected override void OnEnter(ProcedureOwner procedureOwner)
|
||||
{
|
||||
_procedureOwner = procedureOwner;
|
||||
|
||||
|
||||
base.OnEnter(procedureOwner);
|
||||
|
||||
UILoadMgr.Show(UIDefine.UILoadUpdate,$"更新静态版本文件...");
|
||||
|
||||
UILoadMgr.Show(UIDefine.UILoadUpdate, $"更新静态版本文件...");
|
||||
|
||||
//检查设备是否能够访问互联网
|
||||
if (Application.internetReachability == NetworkReachability.NotReachable)
|
||||
@@ -34,6 +34,7 @@ namespace GameMain
|
||||
GetStaticVersion().Forget,
|
||||
() => { ChangeState<ProcedureInitResources>(procedureOwner); });
|
||||
}
|
||||
|
||||
UILoadMgr.Show(UIDefine.UILoadUpdate, LoadText.Instance.Label_RequestVersionIng);
|
||||
|
||||
// 用户尝试更新静态版本。
|
||||
@@ -49,23 +50,35 @@ namespace GameMain
|
||||
|
||||
var operation = GameModule.Resource.UpdatePackageVersionAsync();
|
||||
|
||||
await operation.ToUniTask();
|
||||
try
|
||||
{
|
||||
await operation.ToUniTask();
|
||||
|
||||
if (operation.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
//线上最新版本operation.PackageVersion
|
||||
GameModule.Resource.PackageVersion = operation.PackageVersion;
|
||||
Log.Debug($"Updated package Version : from {GameModule.Resource.GetPackageVersion()} to {operation.PackageVersion}");
|
||||
ChangeState<ProcedureUpdateManifest>(_procedureOwner);
|
||||
if (operation.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
//线上最新版本operation.PackageVersion
|
||||
GameModule.Resource.PackageVersion = operation.PackageVersion;
|
||||
Log.Debug($"Updated package Version : from {GameModule.Resource.GetPackageVersion()} to {operation.PackageVersion}");
|
||||
ChangeState<ProcedureUpdateManifest>(_procedureOwner);
|
||||
}
|
||||
else
|
||||
{
|
||||
OnGetStaticVersionError(operation.Error);
|
||||
}
|
||||
}
|
||||
else
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(operation.Error);
|
||||
|
||||
UILoadTip.ShowMessageBox($"用户尝试更新静态版本失败!点击确认重试 \n \n <color=#FF0000>原因{operation.Error}</color>", MessageShowType.TwoButton,
|
||||
LoadStyle.StyleEnum.Style_Retry
|
||||
, () => { ChangeState<ProcedureUpdateVersion>(_procedureOwner); }, UnityEngine.Application.Quit);
|
||||
OnGetStaticVersionError(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnGetStaticVersionError(string error)
|
||||
{
|
||||
Log.Error(error);
|
||||
|
||||
UILoadTip.ShowMessageBox($"用户尝试更新静态版本失败!点击确认重试 \n \n <color=#FF0000>原因{error}</color>", MessageShowType.TwoButton,
|
||||
LoadStyle.StyleEnum.Style_Retry
|
||||
, () => { ChangeState<ProcedureUpdateVersion>(_procedureOwner); }, UnityEngine.Application.Quit);
|
||||
}
|
||||
}
|
||||
}
|
@@ -153,7 +153,7 @@ Transform:
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 709048975}
|
||||
m_RootOrder: 10
|
||||
m_RootOrder: 11
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &450845954
|
||||
MonoBehaviour:
|
||||
@@ -381,7 +381,7 @@ Transform:
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 709048975}
|
||||
m_RootOrder: 6
|
||||
m_RootOrder: 7
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &683825228
|
||||
MonoBehaviour:
|
||||
@@ -441,6 +441,7 @@ Transform:
|
||||
m_Children:
|
||||
- {fileID: 964133197}
|
||||
- {fileID: 1751957488}
|
||||
- {fileID: 1029867562}
|
||||
- {fileID: 877336934}
|
||||
- {fileID: 803382966}
|
||||
- {fileID: 790894654}
|
||||
@@ -505,7 +506,7 @@ Transform:
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 709048975}
|
||||
m_RootOrder: 4
|
||||
m_RootOrder: 5
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &790894655
|
||||
MonoBehaviour:
|
||||
@@ -571,7 +572,7 @@ Transform:
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 709048975}
|
||||
m_RootOrder: 3
|
||||
m_RootOrder: 4
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &803382967
|
||||
MonoBehaviour:
|
||||
@@ -617,7 +618,7 @@ Transform:
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 709048975}
|
||||
m_RootOrder: 2
|
||||
m_RootOrder: 3
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &877336935
|
||||
MonoBehaviour:
|
||||
@@ -696,7 +697,7 @@ Transform:
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 709048975}
|
||||
m_RootOrder: 9
|
||||
m_RootOrder: 10
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &914171639
|
||||
MonoBehaviour:
|
||||
@@ -790,7 +791,7 @@ Transform:
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 709048975}
|
||||
m_RootOrder: 5
|
||||
m_RootOrder: 6
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &965975542
|
||||
MonoBehaviour:
|
||||
@@ -814,6 +815,50 @@ MonoBehaviour:
|
||||
downloadingMaxNum: 3
|
||||
failedTryAgain: 3
|
||||
adaptiveReplacementCacheCapacity: 32
|
||||
--- !u!1 &1029867561
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 1029867562}
|
||||
- component: {fileID: 1029867563}
|
||||
m_Layer: 0
|
||||
m_Name: Timer
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &1029867562
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1029867561}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 709048975}
|
||||
m_RootOrder: 2
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &1029867563
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1029867561}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 5e79c115d5054209810f42dc6e25cf94, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
--- !u!1 &1047779123
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -844,7 +889,7 @@ Transform:
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 709048975}
|
||||
m_RootOrder: 11
|
||||
m_RootOrder: 12
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &1047779125
|
||||
MonoBehaviour:
|
||||
@@ -967,7 +1012,7 @@ Transform:
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 709048975}
|
||||
m_RootOrder: 7
|
||||
m_RootOrder: 8
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &1666908678
|
||||
MonoBehaviour:
|
||||
@@ -1055,7 +1100,7 @@ Transform:
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 709048975}
|
||||
m_RootOrder: 8
|
||||
m_RootOrder: 9
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &1863338242
|
||||
MonoBehaviour:
|
||||
|
@@ -14,6 +14,8 @@ MonoBehaviour:
|
||||
m_EditorClassIdentifier:
|
||||
ShowPackageView: 0
|
||||
EnableAddressable: 1
|
||||
LocationToLower: 0
|
||||
IncludeAssetGUID: 0
|
||||
UniqueBundleName: 0
|
||||
ShowEditorAlias: 0
|
||||
Packages:
|
||||
@@ -78,7 +80,7 @@ MonoBehaviour:
|
||||
AddressRuleName: AddressByFileName
|
||||
PackRuleName: PackDirectory
|
||||
FilterRuleName: CollectAll
|
||||
AssetTags:
|
||||
AssetTags: WEBGL_PRELOAD
|
||||
UserData:
|
||||
- GroupName: DLL
|
||||
GroupDesc: "\u4EE3\u7801"
|
||||
|
8
UnityProject/Assets/TEngine/Editor/EventInterface.meta
Normal file
8
UnityProject/Assets/TEngine/Editor/EventInterface.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 86094b7c7ca31ab4da174cc7eae14a3c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,227 @@
|
||||
#region Class Documentation
|
||||
/************************************************************************************************************
|
||||
Class Name: EventInterfaceGenerate.cs
|
||||
Type: Editor, Generator, Util, Static
|
||||
Definition:
|
||||
用法,在目录"Assets/GameScripts/HotFix/GameLogic/Event/Interface/"下分组照示例声明Interface 模块待抛出事件的接口。编译后自动生成接口实现抛出的脚本。
|
||||
Example:
|
||||
|
||||
旧版抛出事件方式: GameEvent.Send(RuntimeId.ToRuntimeId("OnMainPlayerCurrencyChange"),CurrencyType.Gold,oldVal,newVal);
|
||||
|
||||
新版抛出事件方式 : GameEvent.Get<IActorLogicEvent>().OnMainPlayerCurrencyChange(CurrencyType.Gold,oldVal,newVal);
|
||||
|
||||
************************************************************************************************************/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using TEngine;
|
||||
using Unity.EditorCoroutines.Editor;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
[InitializeOnLoad]
|
||||
public static class EventInterfaceGenerate
|
||||
{
|
||||
public static string NameSpace = @"GameLogic";
|
||||
|
||||
|
||||
public const string EventInterfacePath = "Assets/GameScripts/HotFix/GameLogic/Event/Interface/";
|
||||
|
||||
public static bool BOpenAutoGenerate = false;
|
||||
|
||||
static EventInterfaceGenerate()
|
||||
{
|
||||
BOpenAutoGenerate = EditorPrefs.GetBool("EventInterfaceGenerate.BOpenAutoGenerate", true);
|
||||
if (BOpenAutoGenerate)
|
||||
{
|
||||
Generate();
|
||||
}
|
||||
}
|
||||
|
||||
[MenuItem("TEngine/EventInterface/OpenAutoGenerate", false, 300)]
|
||||
public static void OpenAutoGenerate()
|
||||
{
|
||||
EditorPrefs.SetBool("EventInterfaceGenerate.BOpenAutoGenerate", true);
|
||||
Debug.Log("OpenAutoGenerate");
|
||||
}
|
||||
|
||||
[MenuItem("TEngine/EventInterface/CloseAutoGenerate", false, 301)]
|
||||
public static void CloseAutoGenerate()
|
||||
{
|
||||
EditorPrefs.SetBool("EventInterfaceGenerate.BOpenAutoGenerate", false);
|
||||
Debug.Log("CloseAutoGenerate");
|
||||
}
|
||||
|
||||
[MenuItem("TEngine/EventInterface/Generate EventInterface", false, 302)]
|
||||
public static void Generate()
|
||||
{
|
||||
if (EventInterfaceGenerateTag.HadGenerate)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
EventInterfaceGenerateTag.HadGenerate = true;
|
||||
|
||||
// 加载程序集
|
||||
Assembly assembly = typeof(GameApp).Assembly;
|
||||
|
||||
// 获取程序集中的所有类型
|
||||
Type[] types = assembly.GetTypes();
|
||||
|
||||
// 遍历每个类型
|
||||
foreach (Type type in types)
|
||||
{
|
||||
// 检查类型是否是接口
|
||||
if (!type.IsInterface)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var attribute = type.GetCustomAttributes(typeof(EventInterfaceAttribute), false).FirstOrDefault();
|
||||
|
||||
if (attribute != null)
|
||||
{
|
||||
EventInterfaceAttribute eventInterfaceAttribute = attribute as EventInterfaceAttribute;
|
||||
|
||||
GenAutoBindCode(type, eventInterfaceAttribute);
|
||||
}
|
||||
}
|
||||
|
||||
AssetDatabase.Refresh();
|
||||
Debug.Log("Generate EventInterface Complete");
|
||||
// EditorUtility.DisplayDialog("提示", "代码生成完毕", "OK");
|
||||
|
||||
EditorCoroutineUtility.StartCoroutine(EventInterfaceGenerateTag.Reset(), null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成自动绑定代码
|
||||
/// </summary>
|
||||
private static void GenAutoBindCode(Type interfaceType, EventInterfaceAttribute eventInterfaceAttribute)
|
||||
{
|
||||
string interfaceName = interfaceType.Name;
|
||||
string className = $"{interfaceName}_Gen";
|
||||
string codePath = $"{Application.dataPath}/GameScripts/HotFix/GameLogic/Event/Gen/{eventInterfaceAttribute.EventGroup}";
|
||||
|
||||
if (!Directory.Exists(codePath))
|
||||
{
|
||||
Directory.CreateDirectory(codePath);
|
||||
}
|
||||
|
||||
using (StreamWriter sw = new StreamWriter($"{codePath}/{className}.cs"))
|
||||
{
|
||||
sw.WriteLine(
|
||||
$"//------------------------------------------------------------------------------\n//\t<auto-generated>\n//\t\tThis code was generated by autoBindTool.\n//\t\tChanges to this file may cause incorrect behavior and will be lost if\n//\t\tthe code is regenerated.\n//\t</auto-generated>\n//------------------------------------------------------------------------------");
|
||||
sw.WriteLine("using UnityEngine;");
|
||||
sw.WriteLine("using UnityEngine.UI;");
|
||||
sw.WriteLine("using TEngine;");
|
||||
sw.WriteLine("");
|
||||
|
||||
if (!string.IsNullOrEmpty(NameSpace))
|
||||
{
|
||||
//命名空间
|
||||
sw.WriteLine("namespace " + NameSpace);
|
||||
sw.WriteLine("{");
|
||||
}
|
||||
|
||||
#region EventId生成
|
||||
|
||||
sw.WriteLine($"\tpublic partial class {interfaceName}_Event");
|
||||
sw.WriteLine("\t{");
|
||||
|
||||
// 获取接口中的所有方法
|
||||
MethodInfo[] methods = interfaceType.GetMethods();
|
||||
|
||||
HashSet<string> hadGenerate = new HashSet<string>();
|
||||
|
||||
//组件字段
|
||||
foreach (MethodInfo method in methods)
|
||||
{
|
||||
if (hadGenerate.Contains(method.Name))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
sw.WriteLine($"\t\tpublic static readonly int {method.Name} = RuntimeId.ToRuntimeId(\"{interfaceName}_Event.{method.Name}\");");
|
||||
hadGenerate.Add(method.Name);
|
||||
}
|
||||
|
||||
sw.WriteLine("\t}");
|
||||
sw.WriteLine("");
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
//类名
|
||||
sw.WriteLine($"\t[EventInterfaceImp(EEventGroup.{eventInterfaceAttribute.EventGroup})]");
|
||||
sw.WriteLine($"\tpublic partial class {className} : {interfaceName}");
|
||||
sw.WriteLine("\t{");
|
||||
|
||||
sw.WriteLine("\t\tprivate EventDispatcher _dispatcher;");
|
||||
sw.WriteLine($"\t\tpublic {className}(EventDispatcher dispatcher)");
|
||||
sw.WriteLine("\t\t{");
|
||||
sw.WriteLine($"\t\t\t_dispatcher = dispatcher;");
|
||||
sw.WriteLine("\t\t}");
|
||||
sw.WriteLine("");
|
||||
|
||||
//组件字段
|
||||
foreach (MethodInfo methodInfo in methods)
|
||||
{
|
||||
ParameterInfo[] parameterInfos = methodInfo.GetParameters(); //得到指定方法的参数列表
|
||||
if (parameterInfos.Length <= 0)
|
||||
{
|
||||
sw.WriteLine(
|
||||
$" public void {methodInfo.Name}()\n {{\n _dispatcher.Send({interfaceName}_Event.{methodInfo.Name});\n }}");
|
||||
}
|
||||
else
|
||||
{
|
||||
string paramStr = "";
|
||||
string paramStr2 = "";
|
||||
for (int i = 0; i < parameterInfos.Length; i++)
|
||||
{
|
||||
var parameterInfo = parameterInfos[i];
|
||||
Type type = parameterInfo.ParameterType;
|
||||
string paramName = parameterInfo.Name;
|
||||
if (i == parameterInfos.Length - 1)
|
||||
{
|
||||
paramStr += $"{type.FullName} {paramName}";
|
||||
paramStr2 += $"{paramName}";
|
||||
}
|
||||
else
|
||||
{
|
||||
paramStr += $"{type.FullName} {paramName},";
|
||||
paramStr2 += $"{paramName},";
|
||||
}
|
||||
}
|
||||
|
||||
sw.WriteLine(
|
||||
$" public void {methodInfo.Name}({paramStr})\n {{\n _dispatcher.Send({interfaceName}_Event.{methodInfo.Name},{paramStr2});\n }}");
|
||||
}
|
||||
|
||||
sw.WriteLine("");
|
||||
}
|
||||
|
||||
sw.WriteLine("\t}");
|
||||
|
||||
if (!string.IsNullOrEmpty(NameSpace))
|
||||
{
|
||||
sw.WriteLine("}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class EventInterfaceGenerateTag
|
||||
{
|
||||
public static bool HadGenerate = false;
|
||||
|
||||
public static IEnumerator Reset()
|
||||
{
|
||||
yield return new WaitForSeconds(10f);
|
||||
HadGenerate = false;
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3e3af172e88343e4cb49c9e870518ede
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -4,7 +4,7 @@ using TEngine.Editor;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
public static class BuildAssetsCommand
|
||||
public static class BuildDLLCommand
|
||||
{
|
||||
private const string EnableHybridClrScriptingDefineSymbol = "ENABLE_HYBRIDCLR";
|
||||
|
||||
@@ -35,6 +35,12 @@ public static class BuildAssetsCommand
|
||||
CopyAOTHotUpdateDlls(target);
|
||||
}
|
||||
|
||||
public static void BuildAndCopyDlls(BuildTarget target)
|
||||
{
|
||||
CompileDllCommand.CompileDll(target);
|
||||
CopyAOTHotUpdateDlls(target);
|
||||
}
|
||||
|
||||
public static void CopyAOTHotUpdateDlls(BuildTarget target)
|
||||
{
|
||||
CopyAOTAssembliesToAssetPath();
|
@@ -4,6 +4,7 @@ using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEditor.U2D;
|
||||
using UnityEngine;
|
||||
using UnityEngine.U2D;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
/// <summary>
|
||||
@@ -55,6 +56,33 @@ public static class EditorSpriteSaveInfo
|
||||
}
|
||||
|
||||
EditorApplication.update += CheckDirty;
|
||||
|
||||
//读取所有图集信息
|
||||
string[] findAssets = AssetDatabase.FindAssets("t:SpriteAtlas", new[] { NormalAtlasDir });
|
||||
foreach (var findAsset in findAssets)
|
||||
{
|
||||
var path = AssetDatabase.GUIDToAssetPath(findAsset);
|
||||
SpriteAtlas sa = AssetDatabase.LoadAssetAtPath(path, typeof(SpriteAtlas)) as SpriteAtlas;
|
||||
if (sa == null)
|
||||
{
|
||||
Debug.LogError($"加载图集数据{path}失败");
|
||||
continue;
|
||||
}
|
||||
|
||||
string atlasName = Path.GetFileNameWithoutExtension(path);
|
||||
var objects = sa.GetPackables();
|
||||
foreach (var o in objects)
|
||||
{
|
||||
if (!m_allASprites.TryGetValue(atlasName, out var list))
|
||||
{
|
||||
list = new List<string>();
|
||||
m_allASprites.Add(atlasName, list);
|
||||
}
|
||||
list.Add(AssetDatabase.GetAssetPath(o));
|
||||
}
|
||||
}
|
||||
|
||||
m_inited = true;
|
||||
}
|
||||
|
||||
public static void CheckDirty()
|
||||
|
@@ -1,42 +1,119 @@
|
||||
using UnityEditor;
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Build.Reporting;
|
||||
using UnityEngine;
|
||||
using YooAsset.Editor;
|
||||
using BuildResult = UnityEditor.Build.Reporting.BuildResult;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
/// <summary>
|
||||
/// 打包工具类。
|
||||
/// <remarks>通过CommandLineReader可以不前台开启Unity实现静默打包,详见CommandLineReader.cs example1</remarks>
|
||||
/// <remarks>通过CommandLineReader可以不前台开启Unity实现静默打包以及CLI工作流,详见CommandLineReader.cs example1</remarks>
|
||||
/// </summary>
|
||||
public static class ReleaseTools
|
||||
{
|
||||
public static void BuildPackage()
|
||||
public static void BuildDll()
|
||||
{
|
||||
string platform = CommandLineReader.GetCustomArgument("platform");
|
||||
if (string.IsNullOrEmpty(platform))
|
||||
{
|
||||
Debug.LogError($"Build Asset Bundle Error!platform is null");
|
||||
return;
|
||||
}
|
||||
|
||||
BuildTarget target = GetBuildTarget(platform);
|
||||
BuildDLLCommand.BuildAndCopyDlls(target);
|
||||
}
|
||||
|
||||
public static void BuildAssetBundle()
|
||||
{
|
||||
string outputRoot = CommandLineReader.GetCustomArgument("outputRoot");
|
||||
BuildTarget target = BuildTarget.StandaloneWindows64;
|
||||
BuildInternal(target,outputRoot);
|
||||
if (string.IsNullOrEmpty(outputRoot))
|
||||
{
|
||||
Debug.LogError($"Build Asset Bundle Error!outputRoot is null");
|
||||
return;
|
||||
}
|
||||
|
||||
string packageVersion = CommandLineReader.GetCustomArgument("packageVersion");
|
||||
if (string.IsNullOrEmpty(packageVersion))
|
||||
{
|
||||
Debug.LogError($"Build Asset Bundle Error!packageVersion is null");
|
||||
return;
|
||||
}
|
||||
|
||||
string platform = CommandLineReader.GetCustomArgument("platform");
|
||||
if (string.IsNullOrEmpty(platform))
|
||||
{
|
||||
Debug.LogError($"Build Asset Bundle Error!platform is null");
|
||||
return;
|
||||
}
|
||||
|
||||
BuildTarget target = GetBuildTarget(platform);
|
||||
BuildInternal(target, outputRoot);
|
||||
Debug.LogWarning($"Start BuildPackage BuildTarget:{target} outputPath:{outputRoot}");
|
||||
}
|
||||
|
||||
private static void BuildInternal(BuildTarget buildTarget,string outputRoot)
|
||||
|
||||
private static BuildTarget GetBuildTarget(string platform)
|
||||
{
|
||||
BuildTarget target = BuildTarget.NoTarget;
|
||||
switch (platform)
|
||||
{
|
||||
case "Android":
|
||||
target = BuildTarget.Android;
|
||||
break;
|
||||
case "IOS":
|
||||
target = BuildTarget.iOS;
|
||||
break;
|
||||
case "Windows":
|
||||
target = BuildTarget.StandaloneWindows64;
|
||||
break;
|
||||
case "MacOS":
|
||||
target = BuildTarget.StandaloneOSX;
|
||||
break;
|
||||
case "Linux":
|
||||
target = BuildTarget.StandaloneLinux64;
|
||||
break;
|
||||
case "WebGL":
|
||||
target = BuildTarget.WebGL;
|
||||
break;
|
||||
case "Switch":
|
||||
target = BuildTarget.Switch;
|
||||
break;
|
||||
case "PS4":
|
||||
target = BuildTarget.PS4;
|
||||
break;
|
||||
case "PS5":
|
||||
target = BuildTarget.PS5;
|
||||
break;
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
private static void BuildInternal(BuildTarget buildTarget, string outputRoot, string packageVersion = "1.0")
|
||||
{
|
||||
Debug.Log($"开始构建 : {buildTarget}");
|
||||
|
||||
BuildParameters.SBPBuildParameters sbpBuildParameters = new BuildParameters.SBPBuildParameters();
|
||||
sbpBuildParameters.WriteLinkXML = true;
|
||||
|
||||
// 构建参数
|
||||
BuildParameters buildParameters = new BuildParameters();
|
||||
buildParameters.StreamingAssetsRoot = AssetBundleBuilderHelper.GetDefaultStreamingAssetsRoot();
|
||||
buildParameters.BuildOutputRoot = outputRoot;//AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
|
||||
buildParameters.BuildOutputRoot = outputRoot; //AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
|
||||
buildParameters.BuildTarget = buildTarget;
|
||||
buildParameters.BuildPipeline = EBuildPipeline.BuiltinBuildPipeline;
|
||||
buildParameters.BuildMode = EBuildMode.ForceRebuild;
|
||||
buildParameters.BuildPipeline = EBuildPipeline.ScriptableBuildPipeline;
|
||||
buildParameters.BuildMode = EBuildMode.IncrementalBuild;
|
||||
buildParameters.PackageName = "DefaultPackage";
|
||||
buildParameters.PackageVersion = "1.0";
|
||||
buildParameters.PackageVersion = packageVersion;
|
||||
buildParameters.VerifyBuildingResult = true;
|
||||
buildParameters.SharedPackRule = new ZeroRedundancySharedPackRule();
|
||||
buildParameters.CompressOption = ECompressOption.LZ4;
|
||||
buildParameters.CompressOption = ECompressOption.LZMA;
|
||||
buildParameters.OutputNameStyle = EOutputNameStyle.HashName;
|
||||
buildParameters.CopyBuildinFileOption = ECopyBuildinFileOption.None;
|
||||
|
||||
buildParameters.CopyBuildinFileOption = ECopyBuildinFileOption.ClearAndCopyAll;
|
||||
buildParameters.SBPParameters = sbpBuildParameters;
|
||||
|
||||
// 执行构建
|
||||
AssetBundleBuilder builder = new AssetBundleBuilder();
|
||||
var buildResult = builder.Run(buildParameters);
|
||||
@@ -50,15 +127,66 @@ namespace TEngine
|
||||
}
|
||||
}
|
||||
|
||||
// 从构建命令里获取参数示例
|
||||
private static string GetBuildPackageName()
|
||||
[MenuItem("TEngine/Build/一键打包Windows", false, 30)]
|
||||
public static void AutomationBuild()
|
||||
{
|
||||
foreach (string arg in System.Environment.GetCommandLineArgs())
|
||||
BuildDLLCommand.BuildAndCopyDlls(BuildTarget.StandaloneWindows64);
|
||||
AssetDatabase.Refresh();
|
||||
BuildInternal(BuildTarget.StandaloneWindows64, Application.dataPath + "/../Builds/Windows", "1.0");
|
||||
AssetDatabase.Refresh();
|
||||
BuildImp(BuildTargetGroup.Standalone, BuildTarget.StandaloneWindows64, $"{Application.dataPath}/../Builds/Windows/{GetBuildPackageVersion()}Windows.exe");
|
||||
}
|
||||
|
||||
// 构建版本相关
|
||||
private static string GetBuildPackageVersion()
|
||||
{
|
||||
int totalMinutes = DateTime.Now.Hour * 60 + DateTime.Now.Minute;
|
||||
return DateTime.Now.ToString("yyyy-MM-dd") + "-" + totalMinutes;
|
||||
}
|
||||
|
||||
[MenuItem("TEngine/Build/一键打包Android", false, 30)]
|
||||
public static void AutomationBuildAndroid()
|
||||
{
|
||||
BuildDLLCommand.BuildAndCopyDlls(BuildTarget.Android);
|
||||
AssetDatabase.Refresh();
|
||||
BuildInternal(BuildTarget.Android, outputRoot:Application.dataPath + "/../Bundles",packageVersion: GetBuildPackageVersion());
|
||||
AssetDatabase.Refresh();
|
||||
BuildImp(BuildTargetGroup.Android, BuildTarget.Android, $"{Application.dataPath}/../Build/Android/{GetBuildPackageVersion()}Android.apk");
|
||||
}
|
||||
|
||||
[MenuItem("TEngine/Build/一键打包IOS", false, 30)]
|
||||
public static void AutomationBuildIOS()
|
||||
{
|
||||
BuildDLLCommand.BuildAndCopyDlls(BuildTarget.iOS);
|
||||
AssetDatabase.Refresh();
|
||||
BuildInternal(BuildTarget.iOS, outputRoot:Application.dataPath + "/../Bundles",packageVersion: GetBuildPackageVersion());
|
||||
AssetDatabase.Refresh();
|
||||
BuildImp(BuildTargetGroup.iOS, BuildTarget.iOS, $"{Application.dataPath}/../Build/IOS/XCode_Project");
|
||||
}
|
||||
|
||||
public static void BuildImp(BuildTargetGroup buildTargetGroup, BuildTarget buildTarget, string locationPathName)
|
||||
{
|
||||
EditorUserBuildSettings.SwitchActiveBuildTarget(buildTargetGroup, BuildTarget.StandaloneWindows64);
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions
|
||||
{
|
||||
if (arg.StartsWith("buildPackage"))
|
||||
return arg.Split("="[0])[1];
|
||||
scenes = new[] { "Assets/Scenes/main.unity" },
|
||||
locationPathName = locationPathName,
|
||||
targetGroup = buildTargetGroup,
|
||||
target = buildTarget,
|
||||
options = BuildOptions.None
|
||||
};
|
||||
var report = BuildPipeline.BuildPlayer(buildPlayerOptions);
|
||||
BuildSummary summary = report.summary;
|
||||
if (summary.result == BuildResult.Succeeded)
|
||||
{
|
||||
Debug.Log($"Build success: {summary.totalSize / 1024 / 1024} MB");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"Build Failed" + summary.result);
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
@@ -5,7 +5,9 @@
|
||||
"GUID:24c092aee38482f4e80715eaa8148782",
|
||||
"GUID:e34a5702dd353724aa315fb8011f08c3",
|
||||
"GUID:4d1926c9df5b052469a1c63448b7609a",
|
||||
"GUID:2373f786d14518f44b0f475db77ba4de"
|
||||
"GUID:2373f786d14518f44b0f475db77ba4de",
|
||||
"GUID:6e76b07590314a543b982daed6af2509",
|
||||
"GUID:478a2357cc57436488a56e564b08d223"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
|
@@ -19,6 +19,21 @@ namespace TEngine.Editor
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// 获取资源路径
|
||||
string assetPath = AssetDatabase.GetAssetPath(instanceID);
|
||||
|
||||
// 判断资源类型
|
||||
if (!assetPath.EndsWith(".cs"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool autoFirstMatch = assetPath.Contains("Logger.cs") ||
|
||||
assetPath.Contains("DefaultLogHelper.cs") ||
|
||||
assetPath.Contains("GameFrameworkLog.cs") ||
|
||||
assetPath.Contains("AssetsLogger.cs") ||
|
||||
assetPath.Contains("Log.cs");
|
||||
|
||||
var stackTrace = GetStackTrace();
|
||||
if (!string.IsNullOrEmpty(stackTrace) && (stackTrace.Contains("[Debug]") ||
|
||||
stackTrace.Contains("[INFO]") ||
|
||||
@@ -28,6 +43,15 @@ namespace TEngine.Editor
|
||||
stackTrace.Contains("[EXCEPTION]")))
|
||||
|
||||
{
|
||||
if (!autoFirstMatch)
|
||||
{
|
||||
var fullPath = UnityEngine.Application.dataPath.Substring(0, UnityEngine.Application.dataPath.LastIndexOf("Assets", StringComparison.Ordinal));
|
||||
fullPath = $"{fullPath}{assetPath}";
|
||||
// 跳转到目标代码的特定行
|
||||
InternalEditorUtility.OpenFileAtLineExternal(fullPath.Replace('/', '\\'), line);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 使用正则表达式匹配at的哪个脚本的哪一行
|
||||
var matches = Regex.Match(stackTrace, @"\(at (.+)\)",
|
||||
RegexOptions.IgnoreCase);
|
||||
|
@@ -60,6 +60,11 @@ namespace TEngine
|
||||
while (itr.MoveNext())
|
||||
{
|
||||
var kv = itr.Current;
|
||||
List<EventRegInfo> list = kv.Value;
|
||||
foreach (var eventRegInfo in list)
|
||||
{
|
||||
EventRegInfo.Release(eventRegInfo);
|
||||
}
|
||||
kv.Value.Clear();
|
||||
}
|
||||
|
||||
@@ -97,6 +102,7 @@ namespace TEngine
|
||||
{
|
||||
Log.Info("remove delay delete eventId[{0}]", eventId);
|
||||
listListener[i] = listListener[^1];
|
||||
EventRegInfo.Release(listListener[i]);
|
||||
listListener.RemoveAt(listListener.Count - 1);
|
||||
i--;
|
||||
}
|
||||
@@ -437,7 +443,7 @@ namespace TEngine
|
||||
return;
|
||||
}
|
||||
|
||||
listListener.Add(new EventRegInfo(listener, owner));
|
||||
listListener.Add(EventRegInfo.Alloc(listener, owner));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -469,6 +475,7 @@ namespace TEngine
|
||||
else
|
||||
{
|
||||
list[i] = list[^1];
|
||||
EventRegInfo.Release(list[i]);
|
||||
list.RemoveAt(list.Count - 1);
|
||||
i--;
|
||||
}
|
||||
@@ -587,17 +594,17 @@ namespace TEngine
|
||||
/// <summary>
|
||||
/// 事件注册信息。
|
||||
/// </summary>
|
||||
public class EventRegInfo
|
||||
public class EventRegInfo : IMemory
|
||||
{
|
||||
/// <summary>
|
||||
/// 事件回调。
|
||||
/// </summary>
|
||||
public readonly Delegate Callback;
|
||||
public Delegate Callback;
|
||||
|
||||
/// <summary>
|
||||
/// 事件持有者。
|
||||
/// </summary>
|
||||
public readonly object Owner;
|
||||
public object Owner;
|
||||
|
||||
/// <summary>
|
||||
/// 事件是否删除。
|
||||
@@ -610,5 +617,28 @@ namespace TEngine
|
||||
Owner = owner;
|
||||
IsDeleted = false;
|
||||
}
|
||||
|
||||
public EventRegInfo() { }
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
Callback = null;
|
||||
Owner = null;
|
||||
IsDeleted = false;
|
||||
}
|
||||
|
||||
public static EventRegInfo Alloc(Delegate callback, object owner)
|
||||
{
|
||||
EventRegInfo ret = MemoryPool.Acquire<EventRegInfo>();
|
||||
ret.Callback = callback;
|
||||
ret.Owner = owner;
|
||||
ret.IsDeleted = false;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static void Release(EventRegInfo eventRegInfo)
|
||||
{
|
||||
MemoryPool.Release(eventRegInfo);
|
||||
}
|
||||
}
|
||||
}
|
@@ -19,10 +19,11 @@ namespace TEngine
|
||||
}
|
||||
|
||||
[System.AttributeUsage(System.AttributeTargets.Interface)]
|
||||
public class EventInterface : Attribute
|
||||
public class EventInterfaceAttribute : Attribute
|
||||
{
|
||||
private EEventGroup _eGroup;
|
||||
public EventInterface(EEventGroup group)
|
||||
public EEventGroup EventGroup => _eGroup;
|
||||
public EventInterfaceAttribute(EEventGroup group)
|
||||
{
|
||||
_eGroup = group;
|
||||
}
|
||||
|
@@ -50,6 +50,21 @@ namespace TEngine
|
||||
_eventEntryMap.Add(typeName, entry);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 注册wrap的函数。
|
||||
/// </summary>
|
||||
/// <param name="typeName">类型名称。</param>
|
||||
/// <param name="callerWrap">调用接口名。</param>
|
||||
public void RegWrapInterface(string typeName,object callerWrap)
|
||||
{
|
||||
var entry = new EventEntryData();
|
||||
entry.InterfaceWrap = callerWrap;
|
||||
if (typeName != null)
|
||||
{
|
||||
_eventEntryMap.Add(typeName, entry);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分发注册器。
|
||||
|
@@ -12,6 +12,7 @@ namespace TEngine
|
||||
/// </summary>
|
||||
private static readonly EventMgr _eventMgr = new EventMgr();
|
||||
|
||||
public static EventMgr EventMgr => _eventMgr;
|
||||
#region 细分的注册接口
|
||||
|
||||
/// <summary>
|
||||
|
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
/// <summary>
|
||||
/// 内存池对象基类。
|
||||
/// </summary>
|
||||
public abstract class MemoryObject : IMemory
|
||||
{
|
||||
/// <summary>
|
||||
/// 清理内存对象回收入池。
|
||||
/// </summary>
|
||||
public virtual void Clear()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从内存池中初始化。
|
||||
/// </summary>
|
||||
public abstract void InitFromPool();
|
||||
|
||||
/// <summary>
|
||||
/// 回收到内存池。
|
||||
/// </summary>
|
||||
public abstract void RecycleToPool();
|
||||
}
|
||||
|
||||
public static partial class MemoryPool
|
||||
{
|
||||
/// <summary>
|
||||
/// 从内存池获取内存对象。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">内存对象类型。</typeparam>
|
||||
/// <returns>内存对象。</returns>
|
||||
public static T Alloc<T>() where T : MemoryObject, new()
|
||||
{
|
||||
T memory = Acquire<T>();
|
||||
memory.InitFromPool();
|
||||
return memory;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将内存对象归还内存池。
|
||||
/// </summary>
|
||||
/// <param name="memory">内存对象。</param>
|
||||
public static void Dealloc(MemoryObject memory)
|
||||
{
|
||||
if (memory == null)
|
||||
{
|
||||
throw new Exception("Memory is invalid.");
|
||||
}
|
||||
|
||||
memory.RecycleToPool();
|
||||
Release(memory);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ad13ef73c22340058c4420733a22b580
|
||||
timeCreated: 1701273442
|
@@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
using UnityEngine;
|
||||
|
||||
namespace TEngine
|
||||
|
@@ -92,7 +92,6 @@ namespace TEngine
|
||||
{
|
||||
Log.Warning($"HttpPost {unityWebRequest.url} be canceled!");
|
||||
unityWebRequest.Dispose();
|
||||
cts.Dispose();
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -102,14 +101,12 @@ namespace TEngine
|
||||
{
|
||||
Log.Warning("HttpPost Timeout");
|
||||
unityWebRequest.Dispose();
|
||||
cts.Dispose();
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
string ret = unityWebRequest.downloadHandler.text;
|
||||
unityWebRequest.Dispose();
|
||||
cts.Dispose();
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using System.Collections;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.Internal;
|
||||
@@ -108,6 +109,12 @@ namespace TEngine
|
||||
public static void AddUpdateListener(UnityAction fun)
|
||||
{
|
||||
_MakeEntity();
|
||||
AddUpdateListenerImp(fun).Forget();
|
||||
}
|
||||
|
||||
private static async UniTaskVoid AddUpdateListenerImp(UnityAction fun)
|
||||
{
|
||||
await UniTask.Yield(/*PlayerLoopTiming.LastPreUpdate*/);
|
||||
_behaviour.AddUpdateListener(fun);
|
||||
}
|
||||
|
||||
@@ -118,6 +125,12 @@ namespace TEngine
|
||||
public static void AddFixedUpdateListener(UnityAction fun)
|
||||
{
|
||||
_MakeEntity();
|
||||
AddFixedUpdateListenerImp(fun).Forget();
|
||||
}
|
||||
|
||||
private static async UniTaskVoid AddFixedUpdateListenerImp(UnityAction fun)
|
||||
{
|
||||
await UniTask.Yield(PlayerLoopTiming.LastEarlyUpdate);
|
||||
_behaviour.AddFixedUpdateListener(fun);
|
||||
}
|
||||
|
||||
@@ -128,6 +141,12 @@ namespace TEngine
|
||||
public static void AddLateUpdateListener(UnityAction fun)
|
||||
{
|
||||
_MakeEntity();
|
||||
AddLateUpdateListenerImp(fun).Forget();
|
||||
}
|
||||
|
||||
private static async UniTaskVoid AddLateUpdateListenerImp(UnityAction fun)
|
||||
{
|
||||
await UniTask.Yield(/*PlayerLoopTiming.LastPreLateUpdate*/);
|
||||
_behaviour.AddLateUpdateListener(fun);
|
||||
}
|
||||
|
||||
@@ -232,20 +251,10 @@ namespace TEngine
|
||||
return;
|
||||
}
|
||||
|
||||
_entity = new GameObject("[Unity.Utility]")
|
||||
{
|
||||
// hideFlags = HideFlags.HideAndDontSave
|
||||
};
|
||||
_entity = new GameObject("[Unity.Utility]");
|
||||
_entity.SetActive(true);
|
||||
_entity.transform.SetParent(GameModule.Base.transform);
|
||||
|
||||
#if UNITY_EDITOR
|
||||
if (Application.isPlaying)
|
||||
#endif
|
||||
{
|
||||
Object.DontDestroyOnLoad(_entity);
|
||||
}
|
||||
|
||||
UnityEngine.Assertions.Assert.IsFalse(_behaviour);
|
||||
_behaviour = _entity.AddComponent<MainBehaviour>();
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngineInternal;
|
||||
|
||||
@@ -132,7 +133,10 @@ namespace TEngine
|
||||
/// <param name="spriteName">图片名称。</param>
|
||||
/// <param name="isSetNativeSize">是否使用原生分辨率。</param>
|
||||
/// <param name="isAsync">是否使用异步加载。</param>
|
||||
public static void SetSprite(this UnityEngine.UI.Image image, string spriteName, bool isSetNativeSize = false, bool isAsync = false)
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <param name="assetReference">指定资源引用组。</param>
|
||||
public static void SetSprite(this UnityEngine.UI.Image image, string spriteName, bool isSetNativeSize = false,
|
||||
bool isAsync = false, string customPackageName = "",AssetReference assetReference = null)
|
||||
{
|
||||
if (image == null)
|
||||
{
|
||||
@@ -147,11 +151,21 @@ namespace TEngine
|
||||
{
|
||||
if (!isAsync)
|
||||
{
|
||||
image.sprite = GameModule.Resource.LoadAsset<Sprite>(spriteName);
|
||||
var operation = GameModule.Resource.LoadAssetGetOperation<Sprite>(spriteName, customPackageName: customPackageName);
|
||||
image.sprite = operation.AssetObject as Sprite;
|
||||
if (isSetNativeSize)
|
||||
{
|
||||
image.SetNativeSize();
|
||||
}
|
||||
|
||||
if (assetReference != null)
|
||||
{
|
||||
assetReference.Reference(operation, spriteName);
|
||||
}
|
||||
else
|
||||
{
|
||||
image.gameObject.GetOrAddComponent<AssetReference>().Reference(operation, spriteName);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -159,6 +173,8 @@ namespace TEngine
|
||||
{
|
||||
if (image == null)
|
||||
{
|
||||
operation.Dispose();
|
||||
operation = null;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -167,7 +183,17 @@ namespace TEngine
|
||||
{
|
||||
image.SetNativeSize();
|
||||
}
|
||||
});
|
||||
|
||||
image.sprite = operation.AssetObject as Sprite;
|
||||
if (assetReference != null)
|
||||
{
|
||||
assetReference.Reference(operation, spriteName);
|
||||
}
|
||||
else
|
||||
{
|
||||
image.gameObject.GetOrAddComponent<AssetReference>().Reference(operation, spriteName);
|
||||
}
|
||||
}, customPackageName: customPackageName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -178,7 +204,10 @@ namespace TEngine
|
||||
/// <param name="spriteRenderer">Image组件。</param>
|
||||
/// <param name="spriteName">图片名称。</param>
|
||||
/// <param name="isAsync">是否使用异步加载。</param>
|
||||
public static void SetSprite(this SpriteRenderer spriteRenderer, string spriteName, bool isAsync = false)
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <param name="assetReference">指定资源引用组。</param>
|
||||
public static void SetSprite(this SpriteRenderer spriteRenderer, string spriteName, bool isAsync = false,
|
||||
string customPackageName = "",AssetReference assetReference = null)
|
||||
{
|
||||
if (spriteRenderer == null)
|
||||
{
|
||||
@@ -193,7 +222,17 @@ namespace TEngine
|
||||
{
|
||||
if (!isAsync)
|
||||
{
|
||||
spriteRenderer.sprite = GameModule.Resource.LoadAsset<Sprite>(spriteName);
|
||||
var operation = GameModule.Resource.LoadAssetGetOperation<Sprite>(spriteName, customPackageName: customPackageName);
|
||||
spriteRenderer.sprite = operation.AssetObject as Sprite;
|
||||
|
||||
if (assetReference != null)
|
||||
{
|
||||
assetReference.Reference(operation, spriteName);
|
||||
}
|
||||
else
|
||||
{
|
||||
spriteRenderer.gameObject.GetOrAddComponent<AssetReference>().Reference(operation, spriteName);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -201,15 +240,25 @@ namespace TEngine
|
||||
{
|
||||
if (spriteRenderer == null)
|
||||
{
|
||||
operation.Dispose();
|
||||
operation = null;
|
||||
return;
|
||||
}
|
||||
|
||||
spriteRenderer.sprite = operation.AssetObject as Sprite;
|
||||
});
|
||||
if (assetReference != null)
|
||||
{
|
||||
assetReference.Reference(operation, spriteName);
|
||||
}
|
||||
else
|
||||
{
|
||||
spriteRenderer.gameObject.GetOrAddComponent<AssetReference>().Reference(operation, spriteName);
|
||||
}
|
||||
}, customPackageName: customPackageName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 查找子节点。
|
||||
/// </summary>
|
||||
@@ -221,7 +270,7 @@ namespace TEngine
|
||||
var findTrans = transform.Find(path);
|
||||
return findTrans != null ? findTrans : null;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 根据名字找到子节点,主要用于dummy接口。
|
||||
/// </summary>
|
||||
@@ -252,7 +301,7 @@ namespace TEngine
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
[TypeInferenceRule(TypeInferenceRules.TypeReferencedByFirstArgument)]
|
||||
public static Component FindChildComponent(this Type type, Transform transform, string path)
|
||||
{
|
||||
@@ -264,7 +313,7 @@ namespace TEngine
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static T FindChildComponent<T>(this Transform transform, string path) where T : Component
|
||||
{
|
||||
var findTrans = transform.Find(path);
|
||||
@@ -275,5 +324,72 @@ namespace TEngine
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static AssetReference GetAssetReference(this GameObject gameObject)
|
||||
{
|
||||
if (gameObject == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return gameObject.GetComponent<AssetReference>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载资源并绑定资源引用到GameObject上。
|
||||
/// </summary>
|
||||
/// <param name="gameObject">GameObject。</param>
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="callBack">加载完成回调。</param>
|
||||
/// <param name="customPackageName">自定义包。</param>
|
||||
/// <typeparam name="T">资源实例类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
public static T LoadAsset<T>(this GameObject gameObject, string location, Action<T> callBack = null,
|
||||
string customPackageName = "") where T : UnityEngine.Object
|
||||
{
|
||||
if (gameObject == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var operation = GameModule.Resource.LoadAssetGetOperation<T>(location, customPackageName: customPackageName);
|
||||
var asset = operation.AssetObject as T;
|
||||
gameObject.GetOrAddComponent<AssetReference>().Reference(operation, location);
|
||||
callBack?.Invoke(asset);
|
||||
return asset;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载资源并绑定资源引用到GameObject上。
|
||||
/// </summary>
|
||||
/// <param name="gameObject">GameObject。</param>
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="callBack">加载完成回调。</param>
|
||||
/// <param name="customPackageName">自定义包。</param>
|
||||
/// <typeparam name="T">资源实例类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
public static async UniTask<T> LoadAssetAsync<T>(this GameObject gameObject, string location, Action<T> callBack = null,
|
||||
string customPackageName = "") where T : UnityEngine.Object
|
||||
{
|
||||
if (gameObject == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var operation = GameModule.Resource.LoadAssetAsyncHandle<T>(location, customPackageName: customPackageName);
|
||||
|
||||
bool cancelOrFailed = await operation.ToUniTask().AttachExternalCancellation(gameObject.GetCancellationTokenOnDestroy())
|
||||
.SuppressCancellationThrow();
|
||||
|
||||
if (cancelOrFailed)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
gameObject.GetOrAddComponent<AssetReference>().Reference(operation, location);
|
||||
var asset = operation.AssetObject as T;
|
||||
callBack?.Invoke(asset);
|
||||
return asset;
|
||||
}
|
||||
}
|
||||
}
|
@@ -4,6 +4,46 @@ using YooAsset;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
public class AudioData : MemoryObject
|
||||
{
|
||||
public AssetOperationHandle AssetOperationHandle { private set; get; }
|
||||
|
||||
public bool InPool { private set; get; } = false;
|
||||
|
||||
public override void InitFromPool()
|
||||
{
|
||||
}
|
||||
|
||||
public override void RecycleToPool()
|
||||
{
|
||||
if (!InPool)
|
||||
{
|
||||
AssetOperationHandle.Dispose();
|
||||
}
|
||||
|
||||
InPool = false;
|
||||
AssetOperationHandle = null;
|
||||
}
|
||||
|
||||
internal static AudioData Alloc(AssetOperationHandle assetOperationHandle, bool inPool)
|
||||
{
|
||||
AudioData ret = MemoryPool.Acquire<AudioData>();
|
||||
ret.AssetOperationHandle = assetOperationHandle;
|
||||
ret.InPool = inPool;
|
||||
ret.InitFromPool();
|
||||
return ret;
|
||||
}
|
||||
|
||||
internal static void DeAlloc(AudioData audioData)
|
||||
{
|
||||
if (audioData != null)
|
||||
{
|
||||
MemoryPool.Release(audioData);
|
||||
audioData.RecycleToPool();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 音频代理辅助器。
|
||||
/// </summary>
|
||||
@@ -11,7 +51,7 @@ namespace TEngine
|
||||
{
|
||||
private int _instanceId;
|
||||
private AudioSource _source;
|
||||
private AssetOperationHandle _assetOperationHandle;
|
||||
private AudioData _audioData;
|
||||
private AudioModuleImp _audioModuleImp;
|
||||
private Transform _transform;
|
||||
float _volume = 1.0f;
|
||||
@@ -32,6 +72,7 @@ namespace TEngine
|
||||
{
|
||||
public string Path;
|
||||
public bool BAsync;
|
||||
public bool BInPool;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -47,7 +88,7 @@ namespace TEngine
|
||||
/// <summary>
|
||||
/// 资源操作句柄。
|
||||
/// </summary>
|
||||
public AssetOperationHandle AssetOperationHandle => _assetOperationHandle;
|
||||
public AudioData AudioData => _audioData;
|
||||
|
||||
/// <summary>
|
||||
/// 音频代理辅助器音频大小。
|
||||
@@ -196,7 +237,8 @@ namespace TEngine
|
||||
_source = host.AddComponent<AudioSource>();
|
||||
_source.playOnAwake = false;
|
||||
AudioMixerGroup[] audioMixerGroups =
|
||||
audioCategory.AudioMixer.FindMatchingGroups(Utility.Text.Format("Master/{0}/{1}", audioCategory.AudioMixerGroup.name, index));
|
||||
audioCategory.AudioMixer.FindMatchingGroups(Utility.Text.Format("Master/{0}/{1}", audioCategory.AudioMixerGroup.name,
|
||||
$"{audioCategory.AudioMixerGroup.name} - {index}"));
|
||||
_source.outputAudioMixerGroup = audioMixerGroups.Length > 0 ? audioMixerGroups[0] : audioCategory.AudioMixerGroup;
|
||||
_source.rolloffMode = audioCategory.AudioGroupConfig.audioRolloffMode;
|
||||
_source.minDistance = audioCategory.AudioGroupConfig.minDistance;
|
||||
@@ -218,7 +260,7 @@ namespace TEngine
|
||||
_duration = 0;
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
if (_audioModuleImp.AudioClipPool.TryGetValue(path, out var operationHandle))
|
||||
if (bInPool && _audioModuleImp.AudioClipPool.TryGetValue(path, out var operationHandle))
|
||||
{
|
||||
OnAssetLoadComplete(operationHandle);
|
||||
return;
|
||||
@@ -239,7 +281,7 @@ namespace TEngine
|
||||
}
|
||||
else
|
||||
{
|
||||
_pendingLoad = new LoadRequest { Path = path, BAsync = bAsync };
|
||||
_pendingLoad = new LoadRequest { Path = path, BAsync = bAsync, BInPool = bInPool };
|
||||
|
||||
if (_audioAgentRuntimeState == AudioAgentRuntimeState.Playing)
|
||||
{
|
||||
@@ -249,7 +291,7 @@ namespace TEngine
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 暂停音频代理辅助器。
|
||||
/// 停止播放音频代理辅助器。
|
||||
/// </summary>
|
||||
/// <param name="fadeout">是否渐出。</param>
|
||||
public void Stop(bool fadeout = false)
|
||||
@@ -268,6 +310,28 @@ namespace TEngine
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 暂停音频代理辅助器。
|
||||
/// </summary>
|
||||
public void Pause()
|
||||
{
|
||||
if (_source != null)
|
||||
{
|
||||
_source.Pause();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取消暂停音频代理辅助器。
|
||||
/// </summary>
|
||||
public void UnPause()
|
||||
{
|
||||
if (_source != null)
|
||||
{
|
||||
_source.UnPause();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 资源加载完成。
|
||||
@@ -277,16 +341,15 @@ namespace TEngine
|
||||
{
|
||||
if (handle != null)
|
||||
{
|
||||
handle.Completed -= OnAssetLoadComplete;
|
||||
if (_inPool)
|
||||
{
|
||||
_audioModuleImp.AudioClipPool.TryAdd(handle.GetAssetInfo().AssetPath, handle);
|
||||
_audioModuleImp.AudioClipPool.TryAdd(handle.GetAssetInfo().Address, handle);
|
||||
}
|
||||
}
|
||||
|
||||
if (_pendingLoad != null)
|
||||
{
|
||||
if (handle != null)
|
||||
if (!_inPool && handle != null)
|
||||
{
|
||||
handle.Dispose();
|
||||
}
|
||||
@@ -294,19 +357,21 @@ namespace TEngine
|
||||
_audioAgentRuntimeState = AudioAgentRuntimeState.End;
|
||||
string path = _pendingLoad.Path;
|
||||
bool bAsync = _pendingLoad.BAsync;
|
||||
bool bInPool = _pendingLoad.BInPool;
|
||||
_pendingLoad = null;
|
||||
Load(path, bAsync);
|
||||
Load(path, bAsync, bInPool);
|
||||
}
|
||||
else if (handle != null)
|
||||
{
|
||||
if (_assetOperationHandle != null)
|
||||
if (_audioData != null)
|
||||
{
|
||||
_assetOperationHandle.Dispose();
|
||||
AudioData.DeAlloc(_audioData);
|
||||
_audioData = null;
|
||||
}
|
||||
|
||||
_assetOperationHandle = handle;
|
||||
_audioData = AudioData.Alloc(handle, _inPool);
|
||||
|
||||
_source.clip = _assetOperationHandle.AssetObject as AudioClip;
|
||||
_source.clip = handle.AssetObject as AudioClip;
|
||||
if (_source.clip != null)
|
||||
{
|
||||
_source.Play();
|
||||
@@ -350,8 +415,9 @@ namespace TEngine
|
||||
{
|
||||
string path = _pendingLoad.Path;
|
||||
bool bAsync = _pendingLoad.BAsync;
|
||||
bool bInPool = _pendingLoad.BInPool;
|
||||
_pendingLoad = null;
|
||||
Load(path, bAsync);
|
||||
Load(path, bAsync, bInPool);
|
||||
}
|
||||
|
||||
_source.volume = _volume;
|
||||
@@ -371,9 +437,9 @@ namespace TEngine
|
||||
Object.Destroy(_transform.gameObject);
|
||||
}
|
||||
|
||||
if (_assetOperationHandle != null)
|
||||
if (_audioData != null)
|
||||
{
|
||||
_assetOperationHandle.Dispose();
|
||||
AudioData.DeAlloc(_audioData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -127,7 +127,7 @@ namespace TEngine
|
||||
|
||||
for (int i = 0; i < AudioAgents.Count; i++)
|
||||
{
|
||||
if (AudioAgents[i].AssetOperationHandle == null || AudioAgents[i].IsFree)
|
||||
if (AudioAgents[i].AudioData?.AssetOperationHandle == null || AudioAgents[i].IsFree)
|
||||
{
|
||||
freeChannel = i;
|
||||
break;
|
||||
|
@@ -48,7 +48,7 @@ AudioMixerGroupController:
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: 2
|
||||
m_Name: Sound - 2
|
||||
m_AudioMixer: {fileID: 24100000}
|
||||
m_GroupID: 039cd795affa7134a8d5f5d43d3b659d
|
||||
m_Children: []
|
||||
@@ -67,7 +67,7 @@ AudioMixerGroupController:
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: 1
|
||||
m_Name: Sound - 1
|
||||
m_AudioMixer: {fileID: 24100000}
|
||||
m_GroupID: c0d40106c2ffb1a44bd48f50b210ee20
|
||||
m_Children: []
|
||||
@@ -100,7 +100,7 @@ AudioMixerGroupController:
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: 3
|
||||
m_Name: Sound - 3
|
||||
m_AudioMixer: {fileID: 24100000}
|
||||
m_GroupID: 5f20d1b8f9ac1914dac8beae718e7d40
|
||||
m_Children: []
|
||||
@@ -153,7 +153,7 @@ AudioMixerGroupController:
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: 1
|
||||
m_Name: UISound - 1
|
||||
m_AudioMixer: {fileID: 24100000}
|
||||
m_GroupID: e012b6d2e0501df43a88eb6beff8ae07
|
||||
m_Children: []
|
||||
@@ -192,7 +192,7 @@ AudioMixerGroupController:
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: 0
|
||||
m_Name: Sound - 0
|
||||
m_AudioMixer: {fileID: 24100000}
|
||||
m_GroupID: 71c50c6b966d1f548a63193919ebfbad
|
||||
m_Children: []
|
||||
@@ -225,7 +225,7 @@ AudioMixerGroupController:
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: 0
|
||||
m_Name: Voice - 0
|
||||
m_AudioMixer: {fileID: 24100000}
|
||||
m_GroupID: f46651e8ad3c6034b8764fd635dda3fd
|
||||
m_Children: []
|
||||
@@ -313,25 +313,25 @@ AudioMixerController:
|
||||
m_UpdateMode: 0
|
||||
m_ExposedParameters:
|
||||
- guid: 7835f2c4248cb3e43a1a773bab1f8b9d
|
||||
name: UISoundVolume
|
||||
name: SoundVolume0
|
||||
- guid: 41591fd4a32f4034f880ecbc14ee69f1
|
||||
name: MusicVolume
|
||||
name: MusicVolume0
|
||||
- guid: 6e0d1a5935a802d41b27d9e2fad3ba2f
|
||||
name: UISoundVolume
|
||||
name: UISoundVolume0
|
||||
- guid: 0bc64c1c6cebbeb40ba2f724fdcaa257
|
||||
name: VoiceVolume
|
||||
name: VoiceVolume0
|
||||
- guid: f62a8b3fe89df00409532af739ee4e02
|
||||
name: SoundVolume
|
||||
name: SoundVolume1
|
||||
- guid: 265eaf7c8910ab842a845c7bb5e570c4
|
||||
name: UISoundVolume
|
||||
name: UISoundVolume1
|
||||
- guid: 2a8ce0f3383c3f0468a04fa3fc5e317d
|
||||
name: SoundVolume
|
||||
name: SoundVolume2
|
||||
- guid: e83be6d6c4ae85142a51f584159c4ff6
|
||||
name: UISoundVolume
|
||||
name: UISoundVolume2
|
||||
- guid: e54edf7c1bf7ee44297e65adce5b10b7
|
||||
name: SoundVolume
|
||||
name: SoundVolume3
|
||||
- guid: 2dd26f9dadf160f4bbd77f307c3f4f2e
|
||||
name: UISoundVolume
|
||||
name: UISoundVolume3
|
||||
- guid: ba83e724007d7e9459f157db3a54a741
|
||||
name: MasterVolume
|
||||
- guid: 6d4c2b8bc0ef38d44b2fbff2b3298ab4
|
||||
@@ -409,10 +409,14 @@ AudioMixerSnapshotController:
|
||||
m_AudioMixer: {fileID: 24100000}
|
||||
m_SnapshotID: 91dee90f8902c804c9da7728ea355157
|
||||
m_FloatValues:
|
||||
b47f0c73299cd9b4fba9896e70683903: 1
|
||||
ba83e724007d7e9459f157db3a54a741: 0
|
||||
fe15a1b40c14ea646a13dacb15b6a73b: 0
|
||||
77212647508232a458ac7d48fb55d037: 1
|
||||
3bbd22597ed32714eb271cf06b098c63: 0
|
||||
30975daa872456b41bc18e0277e301e6: 1
|
||||
6d4c2b8bc0ef38d44b2fbff2b3298ab4: -0.03
|
||||
8542b6bfd7b7bfc4d9b961ba97edf0d2: 1
|
||||
m_TransitionOverrides: {}
|
||||
--- !u!244 &246003612463095956
|
||||
AudioMixerEffectController:
|
||||
@@ -464,7 +468,7 @@ AudioMixerGroupController:
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: 0
|
||||
m_Name: Music - 0
|
||||
m_AudioMixer: {fileID: 24100000}
|
||||
m_GroupID: 1cf576bd46399874d9494863d6502d94
|
||||
m_Children: []
|
||||
@@ -483,7 +487,7 @@ AudioMixerGroupController:
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: 3
|
||||
m_Name: UISound - 3
|
||||
m_AudioMixer: {fileID: 24100000}
|
||||
m_GroupID: 98657376d4096a947953ee04d82830c1
|
||||
m_Children: []
|
||||
@@ -516,7 +520,7 @@ AudioMixerGroupController:
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: 2
|
||||
m_Name: UISound - 2
|
||||
m_AudioMixer: {fileID: 24100000}
|
||||
m_GroupID: e84c25a476798ea43a2f6de217af7dba
|
||||
m_Children: []
|
||||
@@ -629,7 +633,7 @@ AudioMixerGroupController:
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: 0
|
||||
m_Name: UISound - 0
|
||||
m_AudioMixer: {fileID: 24100000}
|
||||
m_GroupID: 29257697b1e6be546aa0558e342a15a6
|
||||
m_Children: []
|
||||
|
@@ -99,6 +99,13 @@ namespace TEngine
|
||||
public static SceneModule Scene => _scene ??= Get<SceneModule>();
|
||||
|
||||
private static SceneModule _scene;
|
||||
|
||||
/// <summary>
|
||||
/// 获取计时器模块。
|
||||
/// </summary>
|
||||
public static TimerModule Timer => _timer ??= Get<TimerModule>();
|
||||
|
||||
private static TimerModule _timer;
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
@@ -153,6 +160,7 @@ namespace TEngine
|
||||
_ui = null;
|
||||
_localization = null;
|
||||
_scene = null;
|
||||
_timer = null;
|
||||
}
|
||||
}
|
||||
}
|
@@ -22,7 +22,8 @@ namespace TEngine
|
||||
public AssetOperationHandle Handle => _handle;
|
||||
|
||||
/// <summary>
|
||||
/// 标签。
|
||||
/// 自定义资源标签。
|
||||
/// <remarks>不同于AssetTag。</remarks>
|
||||
/// </summary>
|
||||
public string Tag { private set; get; }
|
||||
|
||||
@@ -31,7 +32,7 @@ namespace TEngine
|
||||
/// </summary>
|
||||
public void Clear()
|
||||
{
|
||||
if (_handle != null)
|
||||
if (_handle is { IsValid: true })
|
||||
{
|
||||
_handle.Dispose();
|
||||
}
|
||||
@@ -78,7 +79,8 @@ namespace TEngine
|
||||
public class AssetGroup : IMemory
|
||||
{
|
||||
private readonly Dictionary<string,AssetHandleData> _assetHandleDataMap = new Dictionary<string,AssetHandleData>();
|
||||
|
||||
|
||||
#region 引用资源数据
|
||||
/// <summary>
|
||||
/// 引用资源数据到资源组内。
|
||||
/// </summary>
|
||||
@@ -105,32 +107,38 @@ namespace TEngine
|
||||
_assetHandleDataMap[address] = handleData;
|
||||
return true;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 释放资源数据
|
||||
private readonly List<AssetHandleData> _tempResult = new List<AssetHandleData>();
|
||||
|
||||
/// <summary>
|
||||
/// 从资源组内释放资源数据。
|
||||
/// </summary>
|
||||
/// <param name="assetTag">资源标签。</param>
|
||||
/// <param name="tag">自定义资源标签。</param>
|
||||
/// <returns>是否释放成功。</returns>
|
||||
public bool ReleaseByTag(string assetTag)
|
||||
public bool ReleaseByTag(string tag)
|
||||
{
|
||||
AssetHandleData founded = null;
|
||||
_tempResult.Clear();
|
||||
foreach (var assetHandleData in _assetHandleDataMap.Values)
|
||||
{
|
||||
if (assetHandleData.Tag == assetTag)
|
||||
if (assetHandleData.Tag == tag)
|
||||
{
|
||||
founded = assetHandleData;
|
||||
break;
|
||||
_tempResult.Add(assetHandleData);
|
||||
}
|
||||
}
|
||||
|
||||
if (founded != null)
|
||||
if (_tempResult.Count > 0)
|
||||
{
|
||||
_assetHandleDataMap.Remove(founded.Handle.GetAssetInfo().Address);
|
||||
AssetHandleData.Release(founded);
|
||||
foreach (var founded in _tempResult)
|
||||
{
|
||||
_assetHandleDataMap.Remove(founded.Handle.GetAssetInfo().Address);
|
||||
AssetHandleData.Release(founded);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Log.Warning($"Release AssetHandleData Tag:{assetTag} Failed");
|
||||
Log.Warning($"Release AssetHandleData Tag:{tag} Failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -178,20 +186,9 @@ namespace TEngine
|
||||
Log.Warning($"Release AssetHandleData Handle:{handle} Failed");
|
||||
return false;
|
||||
}
|
||||
#endregion
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
var etr = _assetHandleDataMap.GetEnumerator();
|
||||
while (etr.MoveNext())
|
||||
{
|
||||
AssetHandleData assetHandleData = etr.Current.Value;
|
||||
AssetHandleData.Release(assetHandleData);
|
||||
}
|
||||
|
||||
etr.Dispose();
|
||||
_assetHandleDataMap.Clear();
|
||||
}
|
||||
|
||||
#region 内存池接口
|
||||
/// <summary>
|
||||
/// 从内存池中获取资源分组数据。
|
||||
/// </summary>
|
||||
@@ -216,25 +213,41 @@ namespace TEngine
|
||||
|
||||
MemoryPool.Release(assetGroup);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
var etr = _assetHandleDataMap.GetEnumerator();
|
||||
while (etr.MoveNext())
|
||||
{
|
||||
AssetHandleData assetHandleData = etr.Current.Value;
|
||||
AssetHandleData.Release(assetHandleData);
|
||||
}
|
||||
|
||||
etr.Dispose();
|
||||
_assetHandleDataMap.Clear();
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源。
|
||||
/// </summary>
|
||||
/// <param name="assetName">要加载资源的名称。</param>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
public T LoadAsset<T>(string assetName, Transform parent = null) where T : Object
|
||||
public T LoadAsset<T>(string location, bool needInstance = true,string packageName = "",Transform parent = null) where T : Object
|
||||
{
|
||||
if (string.IsNullOrEmpty(assetName))
|
||||
if (string.IsNullOrEmpty(location))
|
||||
{
|
||||
Log.Error("Asset name is invalid.");
|
||||
return default;
|
||||
}
|
||||
|
||||
if (_assetHandleDataMap.TryGetValue(assetName,out var assetHandleData))
|
||||
if (_assetHandleDataMap.TryGetValue(location,out var assetHandleData))
|
||||
{
|
||||
if (typeof(T) == typeof(GameObject))
|
||||
if (typeof(T) == typeof(GameObject) && needInstance)
|
||||
{
|
||||
GameObject ret = assetHandleData.Handle.InstantiateSync(parent);
|
||||
return ret as T;
|
||||
@@ -245,11 +258,20 @@ namespace TEngine
|
||||
}
|
||||
}
|
||||
|
||||
AssetOperationHandle handle = YooAssets.LoadAssetSync<T>(assetName);
|
||||
AssetOperationHandle handle;
|
||||
if (string.IsNullOrEmpty(packageName))
|
||||
{
|
||||
handle = YooAssets.LoadAssetSync<T>(location);
|
||||
}
|
||||
else
|
||||
{
|
||||
var package = YooAssets.GetPackage(packageName);
|
||||
handle = package.LoadAssetSync<T>(location);
|
||||
}
|
||||
|
||||
Reference(handle);
|
||||
|
||||
if (typeof(T) == typeof(GameObject))
|
||||
if (typeof(T) == typeof(GameObject) && needInstance)
|
||||
{
|
||||
GameObject ret = handle.InstantiateSync(parent);
|
||||
return ret as T;
|
||||
@@ -259,115 +281,29 @@ namespace TEngine
|
||||
return handle.AssetObject as T;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源。
|
||||
/// 异步加载资源。
|
||||
/// </summary>
|
||||
/// <param name="assetName">要加载资源的名称。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <param name="assetOperationHandle">资源操作句柄。</param>
|
||||
/// <returns>资源实例。</returns>
|
||||
public T LoadAsset<T>(string assetName,out AssetOperationHandle assetOperationHandle) where T : Object
|
||||
{
|
||||
assetOperationHandle = null;
|
||||
if (string.IsNullOrEmpty(assetName))
|
||||
{
|
||||
Log.Error("Asset name is invalid.");
|
||||
return default;
|
||||
}
|
||||
|
||||
if (_assetHandleDataMap.TryGetValue(assetName,out var assetHandleData))
|
||||
{
|
||||
if (typeof(T) == typeof(GameObject))
|
||||
{
|
||||
GameObject ret = assetHandleData.Handle.InstantiateSync();
|
||||
return ret as T;
|
||||
}
|
||||
else
|
||||
{
|
||||
return assetHandleData.Handle.AssetObject as T;
|
||||
}
|
||||
}
|
||||
|
||||
assetOperationHandle = YooAssets.LoadAssetSync<T>(assetName);
|
||||
|
||||
Reference(assetOperationHandle);
|
||||
|
||||
if (typeof(T) == typeof(GameObject))
|
||||
{
|
||||
GameObject ret = assetOperationHandle.InstantiateSync();
|
||||
return ret as T;
|
||||
}
|
||||
else
|
||||
{
|
||||
return assetOperationHandle.AssetObject as T;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源。
|
||||
/// </summary>
|
||||
/// <param name="assetName">要加载资源的名称。</param>
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <param name="assetOperationHandle">资源操作句柄。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
public T LoadAsset<T>(string assetName, Transform parent,out AssetOperationHandle assetOperationHandle) where T : Object
|
||||
{
|
||||
assetOperationHandle = null;
|
||||
if (string.IsNullOrEmpty(assetName))
|
||||
{
|
||||
Log.Error("Asset name is invalid.");
|
||||
return default;
|
||||
}
|
||||
|
||||
if (_assetHandleDataMap.TryGetValue(assetName,out var assetHandleData))
|
||||
{
|
||||
if (typeof(T) == typeof(GameObject))
|
||||
{
|
||||
GameObject ret = assetHandleData.Handle.InstantiateSync(parent);
|
||||
return ret as T;
|
||||
}
|
||||
else
|
||||
{
|
||||
return assetHandleData.Handle.AssetObject as T;
|
||||
}
|
||||
}
|
||||
|
||||
assetOperationHandle = YooAssets.LoadAssetSync<T>(assetName);
|
||||
|
||||
Reference(assetOperationHandle);
|
||||
|
||||
if (typeof(T) == typeof(GameObject))
|
||||
{
|
||||
GameObject ret = assetOperationHandle.InstantiateSync(parent);
|
||||
return ret as T;
|
||||
}
|
||||
else
|
||||
{
|
||||
return assetOperationHandle.AssetObject as T;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载资源实例。
|
||||
/// </summary>
|
||||
/// <param name="assetName">要加载的实例名称。</param>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <returns>资源实实例。</returns>
|
||||
// ReSharper disable once UnusedParameter.Global
|
||||
// ReSharper disable once RedundantAssignment
|
||||
public async UniTask<T> LoadAssetAsync<T>(string assetName, CancellationToken cancellationToken = default) where T : Object
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包。</param>
|
||||
/// <param name="parent">资源实例父节点。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>异步资源实例。</returns>
|
||||
public async UniTask<T> LoadAssetAsync<T>(string location, CancellationToken cancellationToken = default,
|
||||
bool needInstance = true, string packageName = "", Transform parent = null) where T : Object
|
||||
{
|
||||
if (string.IsNullOrEmpty(assetName))
|
||||
if (string.IsNullOrEmpty(location))
|
||||
{
|
||||
Log.Error("Asset name is invalid.");
|
||||
return default;
|
||||
}
|
||||
|
||||
if (_assetHandleDataMap.TryGetValue(assetName,out var assetHandleData))
|
||||
if (_assetHandleDataMap.TryGetValue(location,out var assetHandleData))
|
||||
{
|
||||
if (typeof(T) == typeof(GameObject))
|
||||
if (typeof(T) == typeof(GameObject) && needInstance)
|
||||
{
|
||||
GameObject ret = assetHandleData.Handle.InstantiateSync();
|
||||
return ret as T;
|
||||
@@ -378,7 +314,16 @@ namespace TEngine
|
||||
}
|
||||
}
|
||||
|
||||
AssetOperationHandle handle = YooAssets.LoadAssetAsync<T>(assetName);
|
||||
AssetOperationHandle handle;
|
||||
if (string.IsNullOrEmpty(packageName))
|
||||
{
|
||||
handle = YooAssets.LoadAssetSync<T>(location);
|
||||
}
|
||||
else
|
||||
{
|
||||
var package = YooAssets.GetPackage(packageName);
|
||||
handle = package.LoadAssetSync<T>(location);
|
||||
}
|
||||
|
||||
Reference(handle);
|
||||
|
||||
@@ -391,9 +336,9 @@ namespace TEngine
|
||||
return null;
|
||||
}
|
||||
|
||||
if (typeof(T) == typeof(GameObject))
|
||||
if (typeof(T) == typeof(GameObject) && needInstance)
|
||||
{
|
||||
GameObject ret = handle.InstantiateSync();
|
||||
GameObject ret = handle.InstantiateSync(parent);
|
||||
return ret as T;
|
||||
}
|
||||
else
|
||||
@@ -401,16 +346,5 @@ namespace TEngine
|
||||
return handle.AssetObject as T;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载游戏物体。
|
||||
/// </summary>
|
||||
/// <param name="assetName">要加载的游戏物体名称。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <returns>异步游戏物体实例。</returns>
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string assetName, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await LoadAssetAsync<GameObject>(assetName,cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
@@ -14,6 +14,7 @@ namespace TEngine
|
||||
{
|
||||
private int _instanceID = 0;
|
||||
private string _assetLocation;
|
||||
private string _packageName;
|
||||
private AssetGroup _assetGroup;
|
||||
private AssetOperationHandle _operationHandle;
|
||||
|
||||
@@ -32,6 +33,11 @@ namespace TEngine
|
||||
/// </summary>
|
||||
public string AssetLocation => _assetLocation;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包名称。
|
||||
/// </summary>
|
||||
public string PackageName => _packageName;
|
||||
|
||||
/// <summary>
|
||||
/// 脏初始化资源分组。
|
||||
/// </summary>
|
||||
@@ -49,10 +55,19 @@ namespace TEngine
|
||||
/// <param name="operation">资源操作句柄。</param>
|
||||
/// <param name="assetLocation">资源定位地址。</param>
|
||||
/// <param name="parent">父级资源引用。(NullAble)</param>
|
||||
public void Bind(AssetOperationHandle operation, string assetLocation, AssetReference parent = null)
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
public void Bind(AssetOperationHandle operation, string assetLocation, AssetReference parent = null,
|
||||
string packageName = "")
|
||||
{
|
||||
if (_operationHandle is { IsValid: true })
|
||||
{
|
||||
Log.Warning($"rebind AssetReference gameObject.name:{gameObject.name} assetLocation:{assetLocation}");
|
||||
_operationHandle.Dispose();
|
||||
_operationHandle = null;
|
||||
}
|
||||
_operationHandle = operation;
|
||||
this._assetLocation = assetLocation;
|
||||
this._packageName = packageName;
|
||||
_instanceID = gameObject.GetInstanceID();
|
||||
if (parent != null)
|
||||
{
|
||||
@@ -138,79 +153,49 @@ namespace TEngine
|
||||
/// <summary>
|
||||
/// 同步加载资源。
|
||||
/// </summary>
|
||||
/// <param name="assetName">要加载资源的名称。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
public T LoadAsset<T>(string assetName) where T : Object
|
||||
{
|
||||
DirtyInitAssetGroup();
|
||||
return _assetGroup.LoadAsset<T>(assetName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源。
|
||||
/// </summary>
|
||||
/// <param name="assetName">要加载资源的名称。</param>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
public T LoadAsset<T>(string assetName, Transform parent) where T : Object
|
||||
public T LoadAsset<T>(string location, bool needInstance = true,string packageName = "",Transform parent = null) where T : Object
|
||||
{
|
||||
DirtyInitAssetGroup();
|
||||
return _assetGroup.LoadAsset<T>(assetName, parent);
|
||||
return _assetGroup.LoadAsset<T>(location, needInstance, packageName, parent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源。
|
||||
/// 异步加载资源。
|
||||
/// </summary>
|
||||
/// <param name="assetName">要加载资源的名称。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <param name="assetOperationHandle">资源操作句柄。</param>
|
||||
/// <returns>资源实例。</returns>
|
||||
// ReSharper disable once ParameterHidesMember
|
||||
public T LoadAsset<T>(string assetName, out AssetOperationHandle assetOperationHandle) where T : Object
|
||||
{
|
||||
DirtyInitAssetGroup();
|
||||
return _assetGroup.LoadAsset<T>(assetName, out assetOperationHandle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源。
|
||||
/// </summary>
|
||||
/// <param name="assetName">要加载资源的名称。</param>
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <param name="assetOperationHandle">资源操作句柄。</param>
|
||||
/// <returns>资源实例。</returns>
|
||||
// ReSharper disable once ParameterHidesMember
|
||||
public T LoadAsset<T>(string assetName, Transform parent, out AssetOperationHandle assetOperationHandle) where T : Object
|
||||
{
|
||||
DirtyInitAssetGroup();
|
||||
return _assetGroup.LoadAsset<T>(assetName, parent, out assetOperationHandle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载资源实例。
|
||||
/// </summary>
|
||||
/// <param name="assetName">要加载的实例名称。</param>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <returns>资源实实例。</returns>
|
||||
public async UniTask<T> LoadAssetAsync<T>(string assetName, CancellationToken cancellationToken = default) where T : Object
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包。</param>
|
||||
/// <param name="parent">资源实例父节点。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>异步资源实例。</returns>
|
||||
public async UniTask<T> LoadAssetAsync<T>(string location, CancellationToken cancellationToken = default,
|
||||
bool needInstance = true, string packageName = "", Transform parent = null) where T : Object
|
||||
{
|
||||
DirtyInitAssetGroup();
|
||||
return await _assetGroup.LoadAssetAsync<T>(assetName, cancellationToken);
|
||||
return await _assetGroup.LoadAssetAsync<T>(location, cancellationToken, needInstance, packageName, parent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载游戏物体。
|
||||
/// </summary>
|
||||
/// <param name="assetName">要加载的游戏物体名称。</param>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <returns>异步游戏物体实例。</returns>
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string assetName, CancellationToken cancellationToken = default)
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包。</param>
|
||||
/// <param name="parent">资源实例父节点。</param>
|
||||
/// <returns>异步资源实例。</returns>
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string location, CancellationToken cancellationToken = default,
|
||||
bool needInstance = true, string packageName = "", Transform parent = null)
|
||||
{
|
||||
DirtyInitAssetGroup();
|
||||
return await _assetGroup.LoadGameObjectAsync(assetName, cancellationToken);
|
||||
return await LoadAssetAsync<GameObject>(location, cancellationToken, needInstance, packageName, parent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -220,9 +205,11 @@ namespace TEngine
|
||||
/// <param name="handle">资源句柄。</param>
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="parent">父级引用。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns>资源引用组件。</returns>
|
||||
/// <exception cref="GameFrameworkException">捕获异常。</exception>
|
||||
public static AssetReference BindAssetReference(GameObject go, AssetOperationHandle handle, string location = "", AssetReference parent = null)
|
||||
public static AssetReference BindAssetReference(GameObject go, AssetOperationHandle handle,
|
||||
string location = "", AssetReference parent = null, string packageName = "")
|
||||
{
|
||||
if (go == null)
|
||||
{
|
||||
@@ -236,7 +223,7 @@ namespace TEngine
|
||||
|
||||
var ret = go.GetOrAddComponent<AssetReference>();
|
||||
|
||||
ret.Bind(operation: handle, assetLocation: location, parent: parent);
|
||||
ret.Bind(operation: handle, assetLocation: location, parent: parent, packageName: packageName);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -247,9 +234,11 @@ namespace TEngine
|
||||
/// <param name="go">游戏物体实例。</param>
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="parent">父级引用。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns>资源引用组件。</returns>
|
||||
/// <exception cref="GameFrameworkException">捕获异常。</exception>
|
||||
public static AssetReference BindAssetReference(GameObject go, string location = "", AssetReference parent = null)
|
||||
public static AssetReference BindAssetReference(GameObject go, string location = "",
|
||||
AssetReference parent = null, string packageName = "")
|
||||
{
|
||||
if (go == null)
|
||||
{
|
||||
@@ -258,7 +247,7 @@ namespace TEngine
|
||||
|
||||
var ret = go.GetOrAddComponent<AssetReference>();
|
||||
|
||||
ret.Bind(operation: null, assetLocation: location, parent: parent);
|
||||
ret.Bind(operation: null, assetLocation: location, parent: parent, packageName: packageName);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@@ -10,18 +10,6 @@ namespace TEngine
|
||||
public const string RootFolderName = "yoo";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 内置文件查询服务类。
|
||||
/// </summary>
|
||||
public class BuiltinQueryServices : IBuildinQueryServices
|
||||
{
|
||||
public bool QueryStreamingAssets(string packageName, string fileName)
|
||||
{
|
||||
// 注意:fileName包含文件格式
|
||||
return BuiltinQueryMgr.FileExists(packageName, fileName);
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
/// <summary>
|
||||
/// 内置资源资源查询帮助类。
|
||||
|
@@ -2,7 +2,6 @@
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using YooAsset;
|
||||
|
||||
namespace TEngine
|
||||
@@ -87,14 +86,23 @@ namespace TEngine
|
||||
/// <summary>
|
||||
/// 初始化操作。
|
||||
/// </summary>
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns></returns>
|
||||
InitializationOperation InitPackage();
|
||||
InitializationOperation InitPackage(string customPackageName = "");
|
||||
|
||||
/// <summary>
|
||||
/// 卸载资源。
|
||||
/// </summary>
|
||||
/// <param name="asset">要卸载的资源。</param>
|
||||
void UnloadAsset(object asset);
|
||||
|
||||
/// <summary>
|
||||
/// 释放游戏物体。
|
||||
/// </summary>
|
||||
/// <param name="gameObject">游戏物体。</param>
|
||||
/// <param name="forceNoPool">强制不入回收池。</param>
|
||||
/// <param name="delayTime">延迟时间。</param>
|
||||
void FreeGameObject(GameObject gameObject, bool forceNoPool = false, float delayTime = 0f);
|
||||
|
||||
/// <summary>
|
||||
/// 资源回收(卸载引用计数为零的资源)
|
||||
@@ -110,8 +118,9 @@ namespace TEngine
|
||||
/// 检查资源是否存在。
|
||||
/// </summary>
|
||||
/// <param name="location">要检查资源的名称。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns>检查资源是否存在的结果。</returns>
|
||||
HasAssetResult HasAsset(string location);
|
||||
HasAssetResult HasAsset(string location, string packageName = "");
|
||||
|
||||
/// <summary>
|
||||
/// 设置默认资源包。
|
||||
@@ -123,42 +132,48 @@ namespace TEngine
|
||||
/// 是否需要从远端更新下载。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns>是否需要从远端下载。</returns>
|
||||
bool IsNeedDownloadFromRemote(string location);
|
||||
bool IsNeedDownloadFromRemote(string location, string packageName = "");
|
||||
|
||||
/// <summary>
|
||||
/// 是否需要从远端更新下载。
|
||||
/// </summary>
|
||||
/// <param name="assetInfo">资源信息。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns>是否需要从远端下载。</returns>
|
||||
bool IsNeedDownloadFromRemote(AssetInfo assetInfo);
|
||||
bool IsNeedDownloadFromRemote(AssetInfo assetInfo, string packageName = "");
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源信息列表。
|
||||
/// </summary>
|
||||
/// <param name="tag">资源标签。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns>资源信息列表。</returns>
|
||||
AssetInfo[] GetAssetInfos(string tag);
|
||||
AssetInfo[] GetAssetInfos(string tag, string packageName = "");
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源信息列表。
|
||||
/// </summary>
|
||||
/// <param name="tags">资源标签列表。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns>资源信息列表。</returns>
|
||||
AssetInfo[] GetAssetInfos(string[] tags);
|
||||
AssetInfo[] GetAssetInfos(string[] tags, string packageName = "");
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源信息。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns>资源信息。</returns>
|
||||
AssetInfo GetAssetInfo(string location);
|
||||
AssetInfo GetAssetInfo(string location, string packageName = "");
|
||||
|
||||
/// <summary>
|
||||
/// 检查资源定位地址是否有效。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
bool CheckLocationValid(string location);
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
bool CheckLocationValid(string location, string packageName = "");
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源。
|
||||
@@ -166,9 +181,11 @@ namespace TEngine
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
T LoadAsset<T>(string location, bool needInstance, bool needCache = false) where T : Object;
|
||||
T LoadAsset<T>(string location, bool needInstance, bool needCache = false, string packageName = "")
|
||||
where T : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源。
|
||||
@@ -177,9 +194,11 @@ namespace TEngine
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
T LoadAsset<T>(string location, Transform parent, bool needInstance, bool needCache = false) where T : Object;
|
||||
T LoadAsset<T>(string location, Transform parent, bool needInstance, bool needCache = false,
|
||||
string packageName = "") where T : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源。
|
||||
@@ -187,9 +206,11 @@ namespace TEngine
|
||||
/// <param name="handle">资源操作句柄。</param>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
T LoadAsset<T>(string location, out AssetOperationHandle handle, bool needCache = false) where T : Object;
|
||||
T LoadAsset<T>(string location, out AssetOperationHandle handle, bool needCache = false,
|
||||
string packageName = "") where T : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源。
|
||||
@@ -198,55 +219,68 @@ namespace TEngine
|
||||
/// <param name="handle">资源操作句柄。</param>
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
T LoadAsset<T>(string location, Transform parent, out AssetOperationHandle handle, bool needCache = false) where T : Object;
|
||||
T LoadAsset<T>(string location, Transform parent, out AssetOperationHandle handle, bool needCache = false,
|
||||
string packageName = "")
|
||||
where T : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源并获取句柄。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>同步加载资源句柄。</returns>
|
||||
AssetOperationHandle LoadAssetGetOperation<T>(string location, bool needCache = false) where T : Object;
|
||||
AssetOperationHandle LoadAssetGetOperation<T>(string location, bool needCache = false, string packageName = "")
|
||||
where T : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载资源并获取句柄。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>异步加载资源句柄。</returns>
|
||||
AssetOperationHandle LoadAssetAsyncHandle<T>(string location, bool needCache = false) where T : Object;
|
||||
AssetOperationHandle LoadAssetAsyncHandle<T>(string location, bool needCache = false, string packageName = "")
|
||||
where T : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载子资源对象。
|
||||
/// </summary>
|
||||
/// <typeparam name="TObject">资源类型。</typeparam>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
public SubAssetsOperationHandle LoadSubAssetsSync<TObject>(string location) where TObject : Object;
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
public SubAssetsOperationHandle LoadSubAssetsSync<TObject>(string location, string packageName = "")
|
||||
where TObject : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载子资源对象
|
||||
/// </summary>
|
||||
/// <typeparam name="TObject">资源类型。</typeparam>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
public SubAssetsOperationHandle LoadSubAssetsAsync<TObject>(string location) where TObject : Object;
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
public SubAssetsOperationHandle LoadSubAssetsAsync<TObject>(string location, string packageName = "")
|
||||
where TObject : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载子资源对象。
|
||||
/// </summary>
|
||||
/// <param name="assetInfo">资源信息。</param>
|
||||
public SubAssetsOperationHandle LoadSubAssetsSync(AssetInfo assetInfo);
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
public SubAssetsOperationHandle LoadSubAssetsSync(AssetInfo assetInfo, string packageName = "");
|
||||
|
||||
/// <summary>
|
||||
/// 通过Tag加载资源对象集合。
|
||||
/// </summary>
|
||||
/// <param name="assetTag">资源标识。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <typeparam name="T">资源类型。</typeparam>
|
||||
/// <returns>资源对象集合。</returns>
|
||||
UniTask<List<T>> LoadAssetsByTagAsync<T>(string assetTag) where T : UnityEngine.Object;
|
||||
UniTask<LoadAssetsByTagOperation<T>> LoadAssetsByTagAsync<T>(string assetTag, string packageName = "") where T : UnityEngine.Object;
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载资源。
|
||||
@@ -255,9 +289,12 @@ namespace TEngine
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <param name="parent">资源实例父节点。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>异步资源实例。</returns>
|
||||
UniTask<T> LoadAssetAsync<T>(string location, CancellationToken cancellationToken = default, bool needInstance = true, bool needCache = false) where T : Object;
|
||||
UniTask<T> LoadAssetAsync<T>(string location, CancellationToken cancellationToken = default,
|
||||
bool needInstance = true, bool needCache = false, string packageName = "", Transform parent = null) where T : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载游戏物体。
|
||||
@@ -265,8 +302,10 @@ namespace TEngine
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns>异步游戏物体实例。</returns>
|
||||
UniTask<GameObject> LoadGameObjectAsync(string location, CancellationToken cancellationToken = default, bool needCache = false);
|
||||
UniTask<GameObject> LoadGameObjectAsync(string location, CancellationToken cancellationToken = default,
|
||||
bool needCache = false, string packageName = "");
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载游戏物体。
|
||||
@@ -275,16 +314,20 @@ namespace TEngine
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns>异步游戏物体实例。</returns>
|
||||
UniTask<GameObject> LoadGameObjectAsync(string location, Transform parent, CancellationToken cancellationToken = default, bool needCache = false);
|
||||
UniTask<GameObject> LoadGameObjectAsync(string location, Transform parent,
|
||||
CancellationToken cancellationToken = default, bool needCache = false, string packageName = "");
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载原生文件。
|
||||
/// </summary>
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns>原生文件资源实例。</returns>
|
||||
UniTask<RawFileOperationHandle> LoadRawAssetAsync(string location, CancellationToken cancellationToken = default);
|
||||
UniTask<RawFileOperationHandle> LoadRawAssetAsync(string location,
|
||||
CancellationToken cancellationToken = default, string packageName = "");
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载子文件。
|
||||
@@ -292,17 +335,38 @@ namespace TEngine
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="assetName">子资源名称。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <typeparam name="T">资源实例类型。</typeparam>
|
||||
/// <returns>原生文件资源实例。</returns>
|
||||
UniTask<T> LoadSubAssetAsync<T>(string location, string assetName, CancellationToken cancellationToken = default) where T : Object;
|
||||
UniTask<T> LoadSubAssetAsync<T>(string location, string assetName,
|
||||
CancellationToken cancellationToken = default, string packageName = "") where T : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载所有子文件。
|
||||
/// </summary>
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <typeparam name="T">资源实例类型。</typeparam>
|
||||
/// <returns>原生文件资源实例。</returns>
|
||||
UniTask<T[]> LoadAllSubAssetAsync<T>(string location, CancellationToken cancellationToken = default) where T : Object;
|
||||
UniTask<T[]> LoadAllSubAssetAsync<T>(string location, CancellationToken cancellationToken = default,
|
||||
string packageName = "") where T : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 放入预加载对象。
|
||||
/// </summary>
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="assetObject">预加载对象。</param>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
public void PushPreLoadAsset(string location, Object assetObject, string packageName = "");
|
||||
|
||||
/// <summary>
|
||||
/// 获取预加载的实例对象。
|
||||
/// </summary>
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <typeparam name="T">资源实例类型。</typeparam>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns>预加载对象。</returns>
|
||||
public T GetPreLoadAsset<T>(string location, string packageName = "") where T : Object;
|
||||
}
|
||||
}
|
@@ -19,6 +19,7 @@ namespace TEngine
|
||||
}
|
||||
|
||||
private readonly string _tag;
|
||||
private readonly string _packageName; // 指定资源包的名称
|
||||
private ESteps _steps = ESteps.None;
|
||||
private List<AssetOperationHandle> _handles;
|
||||
|
||||
@@ -28,9 +29,10 @@ namespace TEngine
|
||||
public List<TObject> AssetObjects { private set; get; }
|
||||
|
||||
|
||||
public LoadAssetsByTagOperation(string tag)
|
||||
public LoadAssetsByTagOperation(string tag, string packageName)
|
||||
{
|
||||
_tag = tag;
|
||||
_packageName = packageName;
|
||||
}
|
||||
|
||||
protected override void OnStart()
|
||||
@@ -45,11 +47,32 @@ namespace TEngine
|
||||
|
||||
if (_steps == ESteps.LoadAssets)
|
||||
{
|
||||
AssetInfo[] assetInfos = YooAssets.GetAssetInfos(_tag);
|
||||
AssetInfo[] assetInfos;
|
||||
if (string.IsNullOrEmpty(_packageName))
|
||||
{
|
||||
assetInfos = YooAssets.GetAssetInfos(_tag);
|
||||
}
|
||||
else
|
||||
{
|
||||
var package = YooAssets.GetPackage(_packageName);
|
||||
assetInfos = package.GetAssetInfos(_tag);
|
||||
}
|
||||
|
||||
_handles = new List<AssetOperationHandle>(assetInfos.Length);
|
||||
|
||||
foreach (var assetInfo in assetInfos)
|
||||
{
|
||||
var handle = YooAssets.LoadAssetAsync(assetInfo);
|
||||
AssetOperationHandle handle;
|
||||
if (string.IsNullOrEmpty(_packageName))
|
||||
{
|
||||
handle = YooAssets.LoadAssetAsync(assetInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
var package = YooAssets.GetPackage(_packageName);
|
||||
handle = package.LoadAssetAsync(assetInfo);
|
||||
}
|
||||
|
||||
_handles.Add(handle);
|
||||
}
|
||||
|
||||
@@ -101,7 +124,7 @@ namespace TEngine
|
||||
SetFinish(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void SetFinish(bool succeed, string error = "")
|
||||
{
|
||||
Error = error;
|
||||
|
@@ -1,70 +0,0 @@
|
||||
using YooAsset;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
public class CreatePoolOperation : GameAsyncOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
Waiting,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly AssetOperationHandle _handle;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
internal CreatePoolOperation(AssetOperationHandle handle)
|
||||
{
|
||||
_handle = handle;
|
||||
}
|
||||
protected override void OnStart()
|
||||
{
|
||||
_steps = ESteps.Waiting;
|
||||
}
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.Waiting)
|
||||
{
|
||||
if (_handle.IsValid == false)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"{nameof(AssetOperationHandle)} is invalid.";
|
||||
return;
|
||||
}
|
||||
|
||||
if (_handle.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_handle.AssetObject == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"{nameof(AssetOperationHandle.AssetObject)} is null.";
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 等待异步实例化结束。
|
||||
/// </summary>
|
||||
public void WaitForAsyncComplete()
|
||||
{
|
||||
if (_handle != null)
|
||||
{
|
||||
if (_steps == ESteps.Done)
|
||||
return;
|
||||
_handle.WaitForAsyncComplete();
|
||||
OnUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4e1853e7ff624c639fba990079beeee5
|
||||
timeCreated: 1693831296
|
@@ -0,0 +1,12 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
internal class DelayDestroyGo
|
||||
{
|
||||
public GoProperty Property;
|
||||
public GameObject Asset;
|
||||
public int HashId;
|
||||
public float DestroyTime;
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7e03aac69e9233b488725725586c612d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,234 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
/// <summary>
|
||||
/// 游戏物体对象池。
|
||||
/// </summary>
|
||||
internal class GameObjectPool
|
||||
{
|
||||
private readonly GameObject _root;
|
||||
private readonly Queue<InstantiateOperation> _cacheOperations;
|
||||
private readonly bool _dontDestroy;
|
||||
private readonly int _initCapacity;
|
||||
private readonly int _maxCapacity;
|
||||
private readonly float _destroyTime;
|
||||
private float _lastRestoreRealTime = -1f;
|
||||
|
||||
/// <summary>
|
||||
/// 资源句柄。
|
||||
/// </summary>
|
||||
public AssetOperationHandle AssetHandle { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源定位地址。
|
||||
/// </summary>
|
||||
public string Location { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 内部缓存总数。
|
||||
/// </summary>
|
||||
public int CacheCount => _cacheOperations.Count;
|
||||
|
||||
/// <summary>
|
||||
/// 外部使用总数。
|
||||
/// </summary>
|
||||
public int SpawnCount { private set; get; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 是否常驻不销毁。
|
||||
/// </summary>
|
||||
public bool DontDestroy => _dontDestroy;
|
||||
|
||||
/// <summary>
|
||||
/// 游戏物体对象池。
|
||||
/// </summary>
|
||||
/// <param name="poolingRoot">对象池根节点。</param>
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="dontDestroy">是否常驻不销毁。</param>
|
||||
/// <param name="initCapacity">初始容量。</param>
|
||||
/// <param name="maxCapacity">最大容量。</param>
|
||||
/// <param name="destroyTime">对象池销毁时间。</param>
|
||||
public GameObjectPool(GameObject poolingRoot, string location, bool dontDestroy, int initCapacity, int maxCapacity, float destroyTime)
|
||||
{
|
||||
_root = new GameObject(location);
|
||||
_root.transform.parent = poolingRoot.transform;
|
||||
Location = location;
|
||||
|
||||
_dontDestroy = dontDestroy;
|
||||
_initCapacity = initCapacity;
|
||||
_maxCapacity = maxCapacity;
|
||||
_destroyTime = destroyTime;
|
||||
|
||||
// 创建缓存池
|
||||
_cacheOperations = new Queue<InstantiateOperation>(initCapacity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建对象池。
|
||||
/// </summary>
|
||||
/// <param name="package">资源包。</param>
|
||||
public void CreatePool(ResourcePackage package)
|
||||
{
|
||||
// 加载游戏对象
|
||||
AssetHandle = package.LoadAssetAsync<GameObject>(Location);
|
||||
|
||||
// 创建初始对象
|
||||
for (int i = 0; i < _initCapacity; i++)
|
||||
{
|
||||
var operation = AssetHandle.InstantiateAsync(_root.transform);
|
||||
operation.Completed += Operation_Completed;
|
||||
_cacheOperations.Enqueue(operation);
|
||||
}
|
||||
}
|
||||
private void Operation_Completed(AsyncOperationBase obj)
|
||||
{
|
||||
if (obj.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
var op = obj as InstantiateOperation;
|
||||
if (op.Result != null)
|
||||
op.Result.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 销毁游戏对象池。
|
||||
/// </summary>
|
||||
public void DestroyPool()
|
||||
{
|
||||
// 卸载资源对象
|
||||
AssetHandle.Release();
|
||||
AssetHandle = null;
|
||||
|
||||
// 销毁游戏对象
|
||||
Object.Destroy(_root);
|
||||
_cacheOperations.Clear();
|
||||
|
||||
SpawnCount = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询静默时间内是否可以销毁。
|
||||
/// </summary>
|
||||
public bool CanAutoDestroy()
|
||||
{
|
||||
if (_dontDestroy)
|
||||
return false;
|
||||
if (_destroyTime < 0)
|
||||
return false;
|
||||
|
||||
if (_lastRestoreRealTime > 0 && SpawnCount <= 0)
|
||||
return (Time.realtimeSinceStartup - _lastRestoreRealTime) > _destroyTime;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 游戏对象池是否已经销毁。
|
||||
/// </summary>
|
||||
public bool IsDestroyed()
|
||||
{
|
||||
return AssetHandle == null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 回收操作。
|
||||
/// </summary>
|
||||
/// <param name="operation">资源实例化操作句柄。</param>
|
||||
public void Restore(InstantiateOperation operation)
|
||||
{
|
||||
if (IsDestroyed())
|
||||
{
|
||||
DestroyInstantiateOperation(operation);
|
||||
return;
|
||||
}
|
||||
|
||||
SpawnCount--;
|
||||
if (SpawnCount <= 0)
|
||||
_lastRestoreRealTime = Time.realtimeSinceStartup;
|
||||
|
||||
// 如果外部逻辑销毁了游戏对象
|
||||
if (operation.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
if (operation.Result == null)
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果缓存池还未满员
|
||||
if (_cacheOperations.Count < _maxCapacity)
|
||||
{
|
||||
SetRestoreGameObject(operation.Result);
|
||||
_cacheOperations.Enqueue(operation);
|
||||
}
|
||||
else
|
||||
{
|
||||
DestroyInstantiateOperation(operation);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 丢弃操作。
|
||||
/// </summary>
|
||||
/// <param name="operation">资源实例化操作句柄。</param>
|
||||
public void Discard(InstantiateOperation operation)
|
||||
{
|
||||
if (IsDestroyed())
|
||||
{
|
||||
DestroyInstantiateOperation(operation);
|
||||
return;
|
||||
}
|
||||
|
||||
SpawnCount--;
|
||||
if (SpawnCount <= 0)
|
||||
_lastRestoreRealTime = Time.realtimeSinceStartup;
|
||||
|
||||
DestroyInstantiateOperation(operation);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取一个游戏对象。
|
||||
/// </summary>
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <param name="position">位置。</param>
|
||||
/// <param name="rotation">旋转。</param>
|
||||
/// <param name="forceClone">是否强制克隆。</param>
|
||||
/// <param name="userDatas">用户自定义数据。</param>
|
||||
/// <returns>Spawn操作句柄。</returns>
|
||||
public SpawnHandle Spawn(Transform parent, Vector3 position, Quaternion rotation, bool forceClone, params System.Object[] userDatas)
|
||||
{
|
||||
InstantiateOperation operation;
|
||||
if (forceClone == false && _cacheOperations.Count > 0)
|
||||
operation = _cacheOperations.Dequeue();
|
||||
else
|
||||
operation = AssetHandle.InstantiateAsync();
|
||||
|
||||
SpawnCount++;
|
||||
SpawnHandle handle = new SpawnHandle(this, operation, parent, position, rotation, userDatas);
|
||||
YooAssets.StartOperation(handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
private void DestroyInstantiateOperation(InstantiateOperation operation)
|
||||
{
|
||||
// 取消异步操作
|
||||
operation.Cancel();
|
||||
|
||||
// 销毁游戏对象
|
||||
if (operation.Result != null)
|
||||
{
|
||||
Object.Destroy(operation.Result);
|
||||
}
|
||||
}
|
||||
private void SetRestoreGameObject(GameObject gameObj)
|
||||
{
|
||||
if (gameObj != null)
|
||||
{
|
||||
gameObj.SetActive(false);
|
||||
gameObj.transform.SetParent(_root.transform);
|
||||
gameObj.transform.SetPositionAndRotation(Vector3.zero, Quaternion.identity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3f0c9bab3d1243fda94ec9a08844ceee
|
||||
timeCreated: 1693831296
|
@@ -0,0 +1,25 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
internal class GoPoolNode
|
||||
{
|
||||
public readonly List<GameObject> ListGameObjects = new List<GameObject>();
|
||||
public int MaxCacheCnt = 10;
|
||||
public int GoRefCnt;
|
||||
public int MinCacheCnt;
|
||||
public int CacheFreeTime;
|
||||
public float PoolGoRefreshTime;
|
||||
|
||||
public bool AddCacheGo(GameObject go)
|
||||
{
|
||||
if (ListGameObjects.Count >= MaxCacheCnt)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
ListGameObjects.Add(go);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4e42a95f042081047b9105a70252b9f0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,13 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
internal struct GoProperty
|
||||
{
|
||||
public string ResPath;
|
||||
public int Layer;
|
||||
public uint FrameID;
|
||||
public float FrameTime;
|
||||
public Vector3 InitScale;
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user