mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
Compare commits
13 Commits
TEngine4.0
...
TEngine4.0
Author | SHA1 | Date | |
---|---|---|---|
![]() |
d61b1206ee | ||
![]() |
3650ba1a8b | ||
![]() |
8f14a4d2cb | ||
![]() |
dc22e595c9 | ||
![]() |
0e70f7d446 | ||
![]() |
039569b2d4 | ||
![]() |
ea38004ba2 | ||
![]() |
cc97c0583a | ||
![]() |
887094a4b1 | ||
![]() |
0d09a7e73b | ||
![]() |
d8f8514f9d | ||
![]() |
f2f6b2422f | ||
![]() |
3a9cad9397 |
@@ -1,61 +0,0 @@
|
||||
using Bright.Serialization;
|
||||
using GameBase;
|
||||
using GameConfig;
|
||||
using TEngine;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 配置加载器。
|
||||
/// </summary>
|
||||
public class ConfigSystem : Singleton<ConfigSystem>
|
||||
{
|
||||
private bool _init = false;
|
||||
|
||||
private Tables _tables;
|
||||
|
||||
public Tables Tables
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!_init)
|
||||
{
|
||||
Load();
|
||||
}
|
||||
|
||||
return _tables;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载配置。
|
||||
/// </summary>
|
||||
public void Load()
|
||||
{
|
||||
_tables = new Tables(LoadIdxByteBuf, LoadByteBuf);
|
||||
_init = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载二进制配置。
|
||||
/// </summary>
|
||||
/// <param name="file">FileName</param>
|
||||
/// <returns>ByteBuf</returns>
|
||||
private ByteBuf LoadByteBuf(string file)
|
||||
{
|
||||
var textAssets = GameModule.Resource.LoadAsset<TextAsset>(file);
|
||||
byte[] ret = textAssets.bytes;
|
||||
return new ByteBuf(ret);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载懒加载Index。
|
||||
/// </summary>
|
||||
/// <param name="file"></param>
|
||||
/// <returns></returns>
|
||||
private ByteBuf LoadIdxByteBuf(string file)
|
||||
{
|
||||
var textAssets = GameModule.Resource.LoadAsset<TextAsset>($"Idx_{file}");
|
||||
byte[] ret = textAssets.bytes;
|
||||
return new ByteBuf(ret);
|
||||
}
|
||||
}
|
@@ -1,87 +0,0 @@
|
||||
using Bright.Serialization;
|
||||
using System.Collections.Generic;
|
||||
{{
|
||||
name = x.name
|
||||
parent_def_type = x.parent_def_type
|
||||
export_fields = x.export_fields
|
||||
hierarchy_export_fields = x.hierarchy_export_fields
|
||||
}}
|
||||
|
||||
|
||||
namespace {{x.namespace_with_top_module}}
|
||||
{
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{x.cs_class_modifier}} partial class {{name}} : {{if parent_def_type}} {{x.parent}} {{else}} Bright.Config.BeanBase {{end}}
|
||||
{
|
||||
public {{name}}(ByteBuf _buf) {{if parent_def_type}} : base(_buf) {{end}}
|
||||
{
|
||||
{{~ for field in export_fields ~}}
|
||||
{{cs_deserialize '_buf' field.convention_name field.ctype}}
|
||||
{{~if field.index_field~}}
|
||||
foreach(var _v in {{field.convention_name}})
|
||||
{
|
||||
{{field.convention_name}}_Index.Add(_v.{{field.index_field.convention_name}}, _v);
|
||||
}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
PostInit();
|
||||
}
|
||||
|
||||
public static {{name}} Deserialize{{name}}(ByteBuf _buf)
|
||||
{
|
||||
{{~if x.is_abstract_type~}}
|
||||
switch (_buf.ReadInt())
|
||||
{
|
||||
{{~for child in x.hierarchy_not_abstract_children~}}
|
||||
case {{child.full_name}}.__ID__: return new {{child.full_name}}(_buf);
|
||||
{{~end~}}
|
||||
default: throw new SerializationException();
|
||||
}
|
||||
{{~else~}}
|
||||
return new {{x.full_name}}(_buf);
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{cs_define_type field.ctype}} {{field.convention_name}} { get; private set; }
|
||||
{{~if field.index_field~}}
|
||||
public readonly Dictionary<{{cs_define_type field.index_field.ctype}}, {{cs_define_type field.ctype.element_type}}> {{field.convention_name}}_Index = new Dictionary<{{cs_define_type field.index_field.ctype}}, {{cs_define_type field.ctype.element_type}}>();
|
||||
{{~end~}}
|
||||
{{~if field.gen_ref~}}
|
||||
public {{field.cs_ref_validator_define}}
|
||||
{{~end~}}
|
||||
{{~if (gen_datetime_mills field.ctype) ~}}
|
||||
public long {{field.convention_name}}_Millis => {{field.convention_name}} * 1000L;
|
||||
{{~end~}}
|
||||
{{~if field.gen_text_key~}}
|
||||
public {{cs_define_text_key_field field}} { get; }
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
{{~if !x.is_abstract_type~}}
|
||||
public const int __ID__ = {{x.id}};
|
||||
public override int GetTypeId() => __ID__;
|
||||
{{~end~}}
|
||||
public override string ToString()
|
||||
{
|
||||
return "{{full_name}}{ "
|
||||
{{~for field in hierarchy_export_fields ~}}
|
||||
+ "{{field.convention_name}}:" + {{cs_to_string field.convention_name field.ctype}} + ","
|
||||
{{~end~}}
|
||||
+ "}";
|
||||
}
|
||||
|
||||
partial void PostInit();
|
||||
}
|
||||
|
||||
}
|
@@ -1,413 +0,0 @@
|
||||
using Bright.Serialization;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace {{x.namespace_with_top_module}}
|
||||
{
|
||||
{{
|
||||
name = x.name
|
||||
key_type = x.key_ttype
|
||||
key_type1 = x.key_ttype1
|
||||
key_type2 = x.key_ttype2
|
||||
value_type = x.value_ttype
|
||||
}}
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public partial class {{name}}
|
||||
{
|
||||
public static {{name}} Instance { get; private set; }
|
||||
{{~if x.is_map_table ~}}
|
||||
private bool _readAll = false;
|
||||
private Dictionary<{{cs_define_type key_type}}, {{cs_define_type value_type}}> _dataMap;
|
||||
private List<{{cs_define_type value_type}}> _dataList;
|
||||
public Dictionary<{{cs_define_type key_type}}, {{cs_define_type value_type}}> DataMap
|
||||
{
|
||||
get
|
||||
{
|
||||
if(!_readAll)
|
||||
{
|
||||
ReadAll();
|
||||
_readAll = true;
|
||||
}
|
||||
return _dataMap;
|
||||
}
|
||||
}
|
||||
public List<{{cs_define_type value_type}}> DataList
|
||||
{
|
||||
get
|
||||
{
|
||||
if(!_readAll)
|
||||
{
|
||||
ReadAll();
|
||||
_readAll = true;
|
||||
}
|
||||
return _dataList;
|
||||
}
|
||||
}
|
||||
private Dictionary<{{cs_define_type key_type}},int> _indexMap;
|
||||
public List<{{cs_define_type key_type}}> Indexes;
|
||||
private System.Func<ByteBuf> _dataLoader;
|
||||
|
||||
private void ReadAll()
|
||||
{
|
||||
_dataList.Clear();
|
||||
foreach(var index in Indexes)
|
||||
{
|
||||
var v = Get(index);
|
||||
_dataMap[index] = v;
|
||||
_dataList.Add(v);
|
||||
}
|
||||
}
|
||||
|
||||
public {{name}}(ByteBuf _buf, string _tbName, System.Func<string, ByteBuf> _loader)
|
||||
{
|
||||
Instance = this;
|
||||
_dataMap = new Dictionary<{{cs_define_type key_type}}, {{cs_define_type value_type}}>();
|
||||
_dataList = new List<{{cs_define_type value_type}}>();
|
||||
_indexMap = new Dictionary<{{cs_define_type key_type}}, int>();
|
||||
_dataLoader = new System.Func<ByteBuf>(() => _loader(_tbName));
|
||||
|
||||
for (int n = _buf.ReadSize(); n > 0; --n)
|
||||
{
|
||||
{{cs_define_type key_type}} key;
|
||||
{{cs_deserialize '_buf' 'key' key_type}}
|
||||
int index = _buf.ReadInt();
|
||||
_indexMap[key] = index;
|
||||
}
|
||||
Indexes = _indexMap.Keys.ToList();
|
||||
PostInit();
|
||||
}
|
||||
|
||||
{{~if value_type.is_dynamic~}}
|
||||
public T GetOrDefaultAs<T>({{cs_define_type key_type}} key) where T : {{cs_define_type value_type}}
|
||||
{
|
||||
if(_indexMap.TryGetValue(key,out var _))
|
||||
{
|
||||
return (T)Get(key);
|
||||
}
|
||||
return default(T);
|
||||
}
|
||||
public T GetAs<T>({{cs_define_type key_type}} key) where T : {{cs_define_type value_type}} => (T)Get(key);
|
||||
{{~end~}}
|
||||
public {{cs_define_type value_type}} this[{{cs_define_type key_type}} key] => Get(key);
|
||||
public {{cs_define_type value_type}} Get({{cs_define_type key_type}} key)
|
||||
{
|
||||
{{cs_define_type value_type}} _v;
|
||||
if(_dataMap.TryGetValue(key, out _v))
|
||||
{
|
||||
return _v;
|
||||
}
|
||||
ResetByteBuf(_indexMap[key]);
|
||||
{{cs_deserialize '_buf' '_v' value_type}}
|
||||
_dataMap[_v.{{x.index_field.convention_name}}] = _v;
|
||||
_v.Resolve(tables);
|
||||
if(_indexMap.Count == _dataMap.Count)
|
||||
{
|
||||
_buf = null;
|
||||
}
|
||||
return _v;
|
||||
}
|
||||
public {{cs_define_type value_type}} GetOrDefault({{cs_define_type key_type}} key)
|
||||
{
|
||||
if(_indexMap.TryGetValue(key,out var _))
|
||||
{
|
||||
return Get(key);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
{{~else if x.is_list_table ~}}
|
||||
private bool _readAllList = false;
|
||||
private List<{{cs_define_type value_type}}> _dataList;
|
||||
public List<{{cs_define_type value_type}}> DataList
|
||||
{
|
||||
get
|
||||
{
|
||||
if(!_readAllList)
|
||||
{
|
||||
ReadAllList();
|
||||
_readAllList = true;
|
||||
}
|
||||
return _dataList;
|
||||
}
|
||||
}
|
||||
private System.Func<ByteBuf> _dataLoader;
|
||||
|
||||
{{~if x.is_union_index~}}
|
||||
private bool _readAll;
|
||||
private {{cs_table_union_map_type_name x}} _dataMapUnion;
|
||||
public {{cs_table_union_map_type_name x}} DataMapUnion
|
||||
{
|
||||
get
|
||||
{
|
||||
if(!_readAll)
|
||||
{
|
||||
ReadAll();
|
||||
_readAll = true;
|
||||
}
|
||||
return _dataMapUnion;
|
||||
}
|
||||
}
|
||||
private void ReadAll()
|
||||
{
|
||||
foreach(var index in Indexes)
|
||||
{
|
||||
var ({{cs_table_get_param_name_list x}}) = index;
|
||||
var v = Get({{cs_table_get_param_name_list x}});
|
||||
_dataMapUnion[({{cs_table_get_param_name_list x}})] = v;
|
||||
}
|
||||
}
|
||||
private void ReadAllList()
|
||||
{
|
||||
_dataList.Clear();
|
||||
foreach(var index in Indexes)
|
||||
{
|
||||
var ({{cs_table_get_param_name_list x}}) = index;
|
||||
var v = Get({{cs_table_get_param_name_list x}});
|
||||
_dataList.Add(v);
|
||||
}
|
||||
}
|
||||
private Dictionary<({{cs_table_get_param_def_list x}}),int> _indexMap;
|
||||
public List<({{cs_table_get_param_def_list x}})> Indexes;
|
||||
|
||||
{{~else if !x.index_list.empty?~}}
|
||||
{{~for idx in x.index_list~}}
|
||||
private bool _readAll{{idx.index_field.convention_name}} = false;
|
||||
private Dictionary<{{cs_define_type idx.type}}, {{cs_define_type value_type}}> _dataMap_{{idx.index_field.name}};
|
||||
public Dictionary<{{cs_define_type idx.type}}, {{cs_define_type value_type}}> DataMap_{{idx.index_field.name}}
|
||||
{
|
||||
get
|
||||
{
|
||||
if(!_readAll{{idx.index_field.convention_name}})
|
||||
{
|
||||
ReadAll{{idx.index_field.convention_name}}();
|
||||
_readAll{{idx.index_field.convention_name}} = true;
|
||||
}
|
||||
return _dataMap_{{idx.index_field.name}};
|
||||
}
|
||||
}
|
||||
{{~if for.first ~}}
|
||||
private void ReadAllList()
|
||||
{
|
||||
_dataList.Clear();
|
||||
foreach(var index in Indexes_{{idx.index_field.name}})
|
||||
{
|
||||
var v = GetBy{{idx.index_field.convention_name}}(index);
|
||||
_dataList.Add(v);
|
||||
}
|
||||
}
|
||||
{{~end~}}
|
||||
private void ReadAll{{idx.index_field.convention_name}}()
|
||||
{
|
||||
foreach(var index in Indexes_{{idx.index_field.name}})
|
||||
{
|
||||
var v = GetBy{{idx.index_field.convention_name}}(index);
|
||||
_dataMap_{{idx.index_field.name}}[index] = v;
|
||||
}
|
||||
}
|
||||
private Dictionary<{{cs_define_type idx.type}},int> _indexMap_{{idx.index_field.name}};
|
||||
public List<{{cs_define_type idx.type}}> Indexes_{{idx.index_field.name}};
|
||||
{{~end~}}
|
||||
{{~else~}}
|
||||
private bool _readAll = false;
|
||||
private Dictionary<int,int> _indexMap;
|
||||
public List<int> Indexes;
|
||||
private Dictionary<int, {{cs_define_type value_type}}> _dataMap;
|
||||
private Dictionary<int, {{cs_define_type value_type}}> DataMap
|
||||
{
|
||||
get
|
||||
{
|
||||
if(!_readAll)
|
||||
{
|
||||
ReadAllList();
|
||||
}
|
||||
return _dataMap;
|
||||
}
|
||||
}
|
||||
private void ReadAllList()
|
||||
{
|
||||
_dataList.Clear();
|
||||
foreach(var index in Indexes)
|
||||
{
|
||||
var v = Get(index);
|
||||
_dataList.Add(v);
|
||||
}
|
||||
}
|
||||
{{~end~}}
|
||||
public {{name}}(ByteBuf _buf, string _tbName, System.Func<string, ByteBuf> _loader)
|
||||
{
|
||||
Instance = this;
|
||||
_dataList = new List<{{cs_define_type value_type}}>();
|
||||
_dataLoader = new System.Func<ByteBuf>(()=> _loader(_tbName));
|
||||
{{~if x.is_union_index~}}
|
||||
_dataMapUnion = new {{cs_table_union_map_type_name x}}();
|
||||
_indexMap = new Dictionary<({{cs_table_get_param_def_list x}}),int>();
|
||||
{{key_value ='('}}
|
||||
for (int i = _buf.ReadSize(); i > 0; i--)
|
||||
{
|
||||
{{~for idx in x.index_list~}}
|
||||
{{field_name = 'key'+for.index}}
|
||||
{{cs_define_type idx.type}} {{field_name}};
|
||||
{{cs_deserialize '_buf' field_name idx.type}}
|
||||
{{~if for.last~}}
|
||||
{{key_value=key_value+field_name+')'}}
|
||||
{{~else~}}
|
||||
{{key_value=key_value+field_name+', '}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
_indexMap.Add({{key_value}}, _buf.ReadInt());
|
||||
}
|
||||
Indexes = _indexMap.Keys.ToList();
|
||||
{{~else if !x.index_list.empty?~}}
|
||||
{{~for idx in x.index_list~}}
|
||||
_dataMap_{{idx.index_field.name}} = new Dictionary<{{cs_define_type idx.type}}, {{cs_define_type value_type}}>();
|
||||
_indexMap_{{idx.index_field.name}} = new Dictionary<{{cs_define_type idx.type}},int>();
|
||||
{{~end~}}
|
||||
|
||||
|
||||
int size = _buf.ReadSize();
|
||||
for(int i = 0; i < size; i++)
|
||||
{
|
||||
{{~for idx in x.index_list~}}
|
||||
{{cs_define_type idx.type}} key_{{idx.index_field.name}};
|
||||
{{cs_deserialize '_buf' 'key_'+idx.index_field.name idx.type}}
|
||||
{{~end~}}
|
||||
int index = _buf.ReadInt();
|
||||
{{~for idx in x.index_list~}}
|
||||
_indexMap_{{idx.index_field.name}}.Add(key_{{idx.index_field.name}},index);
|
||||
{{~end~}}
|
||||
}
|
||||
{{~for idx in x.index_list~}}
|
||||
Indexes_{{idx.index_field.name}} = _indexMap_{{idx.index_field.name}}.Keys.ToList();
|
||||
{{~end~}}
|
||||
{{~else~}}
|
||||
_indexMap = new Dictionary<int,int>();
|
||||
_dataMap = new Dictionary<int, {{cs_define_type value_type}}>();
|
||||
int size = _buf.ReadSize();
|
||||
for(int i = 0; i < size; i++)
|
||||
{
|
||||
_indexMap.Add(i,_buf.ReadInt());
|
||||
}
|
||||
Indexes = _indexMap.Keys.ToList();
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
|
||||
|
||||
{{~if x.is_union_index~}}
|
||||
public {{cs_define_type value_type}} Get({{cs_table_get_param_def_list x}})
|
||||
{
|
||||
{{cs_define_type value_type}} __v;
|
||||
if(_dataMapUnion.TryGetValue(({{cs_table_get_param_name_list x}}), out __v))
|
||||
{
|
||||
return __v;
|
||||
}
|
||||
ResetByteBuf(_indexMap[({{cs_table_get_param_name_list x}})]);
|
||||
|
||||
{{cs_deserialize '_buf' '__v' value_type}}
|
||||
_dataList.Add(__v);
|
||||
_dataMapUnion.Add(({{cs_table_get_param_name_list x}}), __v);
|
||||
__v.Resolve(tables);
|
||||
if(_indexMap.Count == _dataMapUnion.Count)
|
||||
{
|
||||
_buf = null;
|
||||
}
|
||||
return __v;
|
||||
}
|
||||
{{~else if !x.index_list.empty? ~}}
|
||||
{{~for idx in x.index_list~}}
|
||||
public {{cs_define_type value_type}} GetBy{{idx.index_field.convention_name}}({{cs_define_type idx.type}} key)
|
||||
{
|
||||
if(_dataMap_{{idx.index_field.name}}.TryGetValue(key,out var value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
int index = _indexMap_{{idx.index_field.name}}[key];
|
||||
ResetByteBuf(index);
|
||||
{{cs_define_type value_type}} _v;
|
||||
{{cs_deserialize '_buf' '_v' value_type}}
|
||||
_dataMap_{{idx.index_field.name}}[key] = _v;
|
||||
_v.Resolve(tables);
|
||||
return _v;
|
||||
}
|
||||
{{~end~}}
|
||||
{{~else if x.index_list.empty? ~}}
|
||||
public {{cs_define_type value_type}} this[int index] => Get(index);
|
||||
public {{cs_define_type value_type}} Get(int index)
|
||||
{
|
||||
{{cs_define_type value_type}} _v;
|
||||
if(_dataMap.TryGetValue(index, out _v))
|
||||
{
|
||||
return _v;
|
||||
}
|
||||
ResetByteBuf(_indexMap[index]);
|
||||
{{cs_deserialize '_buf' '_v' value_type}}
|
||||
_dataMap[index] = _v;
|
||||
_v.Resolve(tables);
|
||||
if(_indexMap.Count == _dataMap.Count)
|
||||
{
|
||||
_buf = null;
|
||||
}
|
||||
return _v;
|
||||
}
|
||||
{{~end~}}
|
||||
{{~else~}}
|
||||
|
||||
private {{cs_define_type value_type}} _data;
|
||||
|
||||
public {{name}} (ByteBuf _buf, string _tbName, System.Func<string, ByteBuf> _loader)
|
||||
{
|
||||
Instance = this;
|
||||
ByteBuf _dataBuf = _loader(_tbName);
|
||||
int n = _buf.ReadSize();
|
||||
int m = _dataBuf.ReadSize();
|
||||
if (n != 1 || m != 1) throw new SerializationException("table mode=one, but size != 1");
|
||||
{{cs_deserialize '_dataBuf' '_data' value_type}}
|
||||
}
|
||||
|
||||
|
||||
{{~ for field in value_type.bean.hierarchy_export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{cs_define_type field.ctype}} {{field.convention_name}} => _data.{{field.convention_name}};
|
||||
{{~if field.gen_ref~}}
|
||||
public {{cs_define_type field.ref_type}} {{field.convention_name}}_Ref => _data.{{field.convention_name}}_Ref;
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
{{~end~}}
|
||||
|
||||
{{~if x.is_map_table||x.is_list_table ~}}
|
||||
private void ResetByteBuf(int readerInex = 0)
|
||||
{
|
||||
if( _buf == null)
|
||||
{
|
||||
if (_buf == null)
|
||||
{
|
||||
_buf = _dataLoader();
|
||||
}
|
||||
}
|
||||
_buf.ReaderIndex = readerInex;
|
||||
}
|
||||
{{~end~}}
|
||||
|
||||
{{~if x.mode != 'ONE'~}}
|
||||
private ByteBuf _buf = null;
|
||||
private Dictionary<string, object> tables;
|
||||
{{~end~}}
|
||||
public void CacheTables(Dictionary<string, object> _tables)
|
||||
{
|
||||
{{~if x.mode == 'ONE'~}}
|
||||
_data.Resolve(_tables);
|
||||
{{~else~}}
|
||||
tables = _tables;
|
||||
{{~end~}}
|
||||
}
|
||||
partial void PostInit();
|
||||
}
|
||||
}
|
@@ -1,40 +0,0 @@
|
||||
using Bright.Serialization;
|
||||
|
||||
{{
|
||||
name = x.name
|
||||
namespace = x.namespace
|
||||
tables = x.tables
|
||||
|
||||
}}
|
||||
namespace {{namespace}}
|
||||
{
|
||||
|
||||
public partial class {{name}}
|
||||
{
|
||||
{{~for table in tables ~}}
|
||||
{{~if table.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{table.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{table.full_name}} {{table.name}} {get; }
|
||||
{{~end~}}
|
||||
|
||||
public {{name}}(System.Func<string, ByteBuf> idxLoader,System.Func<string, ByteBuf> dataLoader)
|
||||
{
|
||||
var tables = new System.Collections.Generic.Dictionary<string, object>();
|
||||
{{~for table in tables ~}}
|
||||
{{table.name}} = new {{table.full_name}}(idxLoader("{{table.output_data_file}}"),"{{table.output_data_file}}",dataLoader);
|
||||
tables.Add("{{table.full_name}}", {{table.name}});
|
||||
{{~end~}}
|
||||
|
||||
PostInit();
|
||||
{{~for table in tables ~}}
|
||||
{{table.name}}.CacheTables(tables);
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
partial void PostInit();
|
||||
}
|
||||
|
||||
}
|
@@ -1,95 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Bright.Serialization;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using GameBase;
|
||||
using GameConfig;
|
||||
using TEngine;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 配置加载器
|
||||
/// </summary>
|
||||
public class ConfigSystem : Singleton<ConfigSystem>
|
||||
{
|
||||
private bool _init = false;
|
||||
|
||||
private Tables _tables;
|
||||
|
||||
public Tables Tables
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!_init)
|
||||
{
|
||||
#if !UNITY_WEBGL
|
||||
_init = true;
|
||||
|
||||
#endif
|
||||
Log.Error("Config not loaded. You need Take LoadAsync at first.");
|
||||
}
|
||||
return _tables;
|
||||
}
|
||||
}
|
||||
|
||||
private readonly Dictionary<string, TextAsset> _configs = new Dictionary<string, TextAsset>();
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载配置。
|
||||
/// </summary>
|
||||
public async UniTask LoadAsync()
|
||||
{
|
||||
_tables = new Tables();
|
||||
await _tables.LoadAsync(LoadByteBufAsync);
|
||||
_init = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载二进制配置。
|
||||
/// </summary>
|
||||
/// <param name="file">FileName</param>
|
||||
/// <returns>ByteBuf</returns>
|
||||
private async UniTask<ByteBuf> LoadByteBufAsync(string file)
|
||||
{
|
||||
#if false
|
||||
GameTickWatcher gameTickWatcher = new GameTickWatcher();
|
||||
#endif
|
||||
byte[] ret;
|
||||
var location = file;
|
||||
if (_configs.TryGetValue(location, out var config))
|
||||
{
|
||||
ret = config.bytes;
|
||||
}
|
||||
else
|
||||
{
|
||||
var textAssets = await GameModule.Resource.LoadAssetAsync<TextAsset>(location, CancellationToken.None);
|
||||
ret = textAssets.bytes;
|
||||
RegisterTextAssets(file, textAssets);
|
||||
}
|
||||
#if false
|
||||
Log.Warning($"LoadByteBuf {file} used time {gameTickWatcher.ElapseTime()}");
|
||||
#endif
|
||||
return new ByteBuf(ret);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 注册配置资源。
|
||||
/// </summary>
|
||||
/// <param name="key">资源Key。</param>
|
||||
/// <param name="value">资源实例。</param>
|
||||
/// <returns>注册成功。</returns>
|
||||
private bool RegisterTextAssets(string key, TextAsset value)
|
||||
{
|
||||
if (string.IsNullOrEmpty(key))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (value == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_configs[key] = value;
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -1,115 +0,0 @@
|
||||
using Bright.Serialization;
|
||||
using System.Collections.Generic;
|
||||
{{
|
||||
name = x.name
|
||||
parent_def_type = x.parent_def_type
|
||||
export_fields = x.export_fields
|
||||
hierarchy_export_fields = x.hierarchy_export_fields
|
||||
}}
|
||||
|
||||
{{cs_start_name_space_grace x.namespace_with_top_module}}
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{x.cs_class_modifier}} partial class {{name}} : {{if parent_def_type}} {{x.parent}} {{else}} Bright.Config.BeanBase {{end}}
|
||||
{
|
||||
public {{name}}(ByteBuf _buf) {{if parent_def_type}} : base(_buf) {{end}}
|
||||
{
|
||||
{{~ for field in export_fields ~}}
|
||||
{{cs_deserialize '_buf' field.convention_name field.ctype}}
|
||||
{{~if field.index_field~}}
|
||||
foreach(var _v in {{field.convention_name}})
|
||||
{
|
||||
{{field.convention_name}}_Index.Add(_v.{{field.index_field.convention_name}}, _v);
|
||||
}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
PostInit();
|
||||
}
|
||||
|
||||
public static {{name}} Deserialize{{name}}(ByteBuf _buf)
|
||||
{
|
||||
{{~if x.is_abstract_type~}}
|
||||
switch (_buf.ReadInt())
|
||||
{
|
||||
{{~for child in x.hierarchy_not_abstract_children~}}
|
||||
case {{child.full_name}}.__ID__: return new {{child.full_name}}(_buf);
|
||||
{{~end~}}
|
||||
default: throw new SerializationException();
|
||||
}
|
||||
{{~else~}}
|
||||
return new {{x.full_name}}(_buf);
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{cs_define_type field.ctype}} {{field.convention_name}} { get; private set; }
|
||||
{{~if field.index_field~}}
|
||||
public readonly Dictionary<{{cs_define_type field.index_field.ctype}}, {{cs_define_type field.ctype.element_type}}> {{field.convention_name}}_Index = new Dictionary<{{cs_define_type field.index_field.ctype}}, {{cs_define_type field.ctype.element_type}}>();
|
||||
{{~end~}}
|
||||
{{~if field.gen_ref~}}
|
||||
public {{field.cs_ref_validator_define}}
|
||||
{{~end~}}
|
||||
{{~if (gen_datetime_mills field.ctype) ~}}
|
||||
public long {{field.convention_name}}_Millis => {{field.convention_name}} * 1000L;
|
||||
{{~end~}}
|
||||
{{~if field.gen_text_key~}}
|
||||
public {{cs_define_text_key_field field}} { get; }
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
{{~if !x.is_abstract_type~}}
|
||||
public const int __ID__ = {{x.id}};
|
||||
public override int GetTypeId() => __ID__;
|
||||
{{~end~}}
|
||||
|
||||
public {{x.cs_method_modifier}} void Resolve(Dictionary<string, object> _tables)
|
||||
{
|
||||
{{~if parent_def_type~}}
|
||||
base.Resolve(_tables);
|
||||
{{~end~}}
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.gen_ref~}}
|
||||
{{cs_ref_validator_resolve field}}
|
||||
{{~else if field.has_recursive_ref~}}
|
||||
{{cs_recursive_resolve field '_tables'}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
PostResolve();
|
||||
}
|
||||
|
||||
public {{x.cs_method_modifier}} void TranslateText(System.Func<string, string, string> translator)
|
||||
{
|
||||
{{~if parent_def_type~}}
|
||||
base.TranslateText(translator);
|
||||
{{~end~}}
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.gen_text_key~}}
|
||||
{{cs_translate_text field 'translator'}}
|
||||
{{~else if field.has_recursive_text~}}
|
||||
{{cs_recursive_translate_text field 'translator'}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "{{full_name}}{ "
|
||||
{{~for field in hierarchy_export_fields ~}}
|
||||
+ "{{field.convention_name}}:" + {{cs_to_string field.convention_name field.ctype}} + ","
|
||||
{{~end~}}
|
||||
+ "}";
|
||||
}
|
||||
|
||||
partial void PostInit();
|
||||
partial void PostResolve();
|
||||
}
|
||||
|
||||
{{cs_end_name_space_grace x.namespace_with_top_module}}
|
@@ -1,173 +0,0 @@
|
||||
using Bright.Serialization;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
{{cs_start_name_space_grace x.namespace_with_top_module}}
|
||||
{{
|
||||
name = x.name
|
||||
key_type = x.key_ttype
|
||||
key_type1 = x.key_ttype1
|
||||
key_type2 = x.key_ttype2
|
||||
value_type = x.value_ttype
|
||||
}}
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public partial class {{name}}
|
||||
{
|
||||
{{~if x.is_map_table ~}}
|
||||
private readonly Dictionary<{{cs_define_type key_type}}, {{cs_define_type value_type}}> _dataMap;
|
||||
private readonly List<{{cs_define_type value_type}}> _dataList;
|
||||
|
||||
public {{name}}(ByteBuf _buf)
|
||||
{
|
||||
_dataMap = new Dictionary<{{cs_define_type key_type}}, {{cs_define_type value_type}}>();
|
||||
_dataList = new List<{{cs_define_type value_type}}>();
|
||||
|
||||
for(int n = _buf.ReadSize() ; n > 0 ; --n)
|
||||
{
|
||||
{{cs_define_type value_type}} _v;
|
||||
{{cs_deserialize '_buf' '_v' value_type}}
|
||||
_dataList.Add(_v);
|
||||
_dataMap.Add(_v.{{x.index_field.convention_name}}, _v);
|
||||
}
|
||||
PostInit();
|
||||
}
|
||||
|
||||
public Dictionary<{{cs_define_type key_type}}, {{cs_define_type value_type}}> DataMap => _dataMap;
|
||||
public List<{{cs_define_type value_type}}> DataList => _dataList;
|
||||
|
||||
{{~if value_type.is_dynamic~}}
|
||||
public T GetOrDefaultAs<T>({{cs_define_type key_type}} key) where T : {{cs_define_type value_type}} => _dataMap.TryGetValue(key, out var v) ? (T)v : null;
|
||||
public T GetAs<T>({{cs_define_type key_type}} key) where T : {{cs_define_type value_type}} => (T)_dataMap[key];
|
||||
{{~end~}}
|
||||
public {{cs_define_type value_type}} GetOrDefault({{cs_define_type key_type}} key) => _dataMap.TryGetValue(key, out var v) ? v : null;
|
||||
public {{cs_define_type value_type}} Get({{cs_define_type key_type}} key) => _dataMap[key];
|
||||
public {{cs_define_type value_type}} this[{{cs_define_type key_type}} key] => _dataMap[key];
|
||||
|
||||
public void Resolve(Dictionary<string, object> _tables)
|
||||
{
|
||||
foreach(var v in _dataList)
|
||||
{
|
||||
v.Resolve(_tables);
|
||||
}
|
||||
PostResolve();
|
||||
}
|
||||
|
||||
public void TranslateText(System.Func<string, string, string> translator)
|
||||
{
|
||||
foreach(var v in _dataList)
|
||||
{
|
||||
v.TranslateText(translator);
|
||||
}
|
||||
}
|
||||
{{~else if x.is_list_table ~}}
|
||||
private readonly List<{{cs_define_type value_type}}> _dataList;
|
||||
|
||||
{{~if x.is_union_index~}}
|
||||
private {{cs_table_union_map_type_name x}} _dataMapUnion;
|
||||
{{~else if !x.index_list.empty?~}}
|
||||
{{~for idx in x.index_list~}}
|
||||
private Dictionary<{{cs_define_type idx.type}}, {{cs_define_type value_type}}> _dataMap_{{idx.index_field.name}};
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
public {{name}}(ByteBuf _buf)
|
||||
{
|
||||
_dataList = new List<{{cs_define_type value_type}}>();
|
||||
|
||||
for(int n = _buf.ReadSize() ; n > 0 ; --n)
|
||||
{
|
||||
{{cs_define_type value_type}} _v;
|
||||
{{cs_deserialize '_buf' '_v' value_type}}
|
||||
_dataList.Add(_v);
|
||||
}
|
||||
{{~if x.is_union_index~}}
|
||||
_dataMapUnion = new {{cs_table_union_map_type_name x}}();
|
||||
foreach(var _v in _dataList)
|
||||
{
|
||||
_dataMapUnion.Add(({{cs_table_key_list x "_v"}}), _v);
|
||||
}
|
||||
{{~else if !x.index_list.empty?~}}
|
||||
{{~for idx in x.index_list~}}
|
||||
_dataMap_{{idx.index_field.name}} = new Dictionary<{{cs_define_type idx.type}}, {{cs_define_type value_type}}>();
|
||||
{{~end~}}
|
||||
foreach(var _v in _dataList)
|
||||
{
|
||||
{{~for idx in x.index_list~}}
|
||||
_dataMap_{{idx.index_field.name}}.Add(_v.{{idx.index_field.convention_name}}, _v);
|
||||
{{~end~}}
|
||||
}
|
||||
{{~end~}}
|
||||
PostInit();
|
||||
}
|
||||
|
||||
|
||||
public List<{{cs_define_type value_type}}> DataList => _dataList;
|
||||
|
||||
{{~if x.is_union_index~}}
|
||||
public {{cs_define_type value_type}} Get({{cs_table_get_param_def_list x}}) => _dataMapUnion.TryGetValue(({{cs_table_get_param_name_list x}}), out {{cs_define_type value_type}} __v) ? __v : null;
|
||||
{{~else if !x.index_list.empty? ~}}
|
||||
{{~for idx in x.index_list~}}
|
||||
public {{cs_define_type value_type}} GetBy{{idx.index_field.convention_name}}({{cs_define_type idx.type}} key) => _dataMap_{{idx.index_field.name}}.TryGetValue(key, out {{cs_define_type value_type}} __v) ? __v : null;
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
public void Resolve(Dictionary<string, object> _tables)
|
||||
{
|
||||
foreach(var v in _dataList)
|
||||
{
|
||||
v.Resolve(_tables);
|
||||
}
|
||||
PostResolve();
|
||||
}
|
||||
|
||||
public void TranslateText(System.Func<string, string, string> translator)
|
||||
{
|
||||
foreach(var v in _dataList)
|
||||
{
|
||||
v.TranslateText(translator);
|
||||
}
|
||||
}
|
||||
{{~else~}}
|
||||
|
||||
private readonly {{cs_define_type value_type}} _data;
|
||||
|
||||
public {{name}}(ByteBuf _buf)
|
||||
{
|
||||
int n = _buf.ReadSize();
|
||||
if (n != 1) throw new SerializationException("table mode=one, but size != 1");
|
||||
{{cs_deserialize '_buf' '_data' value_type}}
|
||||
PostInit();
|
||||
}
|
||||
|
||||
|
||||
{{~ for field in value_type.bean.hierarchy_export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{cs_define_type field.ctype}} {{field.convention_name}} => _data.{{field.convention_name}};
|
||||
{{~end~}}
|
||||
|
||||
public void Resolve(Dictionary<string, object> _tables)
|
||||
{
|
||||
_data.Resolve(_tables);
|
||||
PostResolve();
|
||||
}
|
||||
|
||||
public void TranslateText(System.Func<string, string, string> translator)
|
||||
{
|
||||
_data.TranslateText(translator);
|
||||
}
|
||||
|
||||
{{~end~}}
|
||||
|
||||
partial void PostInit();
|
||||
partial void PostResolve();
|
||||
}
|
||||
|
||||
{{cs_end_name_space_grace x.namespace_with_top_module}}
|
@@ -1,53 +0,0 @@
|
||||
using Bright.Serialization;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
|
||||
{{
|
||||
name = x.name
|
||||
namespace = x.namespace
|
||||
tables = x.tables
|
||||
}}
|
||||
namespace {{namespace}}
|
||||
{
|
||||
|
||||
public sealed class {{name}}
|
||||
{
|
||||
{{~for table in tables ~}}
|
||||
{{~if table.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{table.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{table.full_name}} {{table.name}} {get; private set; }
|
||||
{{~end~}}
|
||||
|
||||
public {{name}}() { }
|
||||
|
||||
public async UniTask LoadAsync(System.Func<string, UniTask<ByteBuf>> loader)
|
||||
{
|
||||
var tables = new System.Collections.Generic.Dictionary<string, object>();
|
||||
List<UniTask> list = new List<UniTask>();
|
||||
{{~for table in tables ~}}
|
||||
list.Add(UniTask.Create(async () =>
|
||||
{
|
||||
{{table.name}} = new {{table.full_name}}(await loader("{{table.output_data_file}}"));
|
||||
tables.Add("{{table.full_name}}", {{table.name}});
|
||||
}));
|
||||
{{~end~}}
|
||||
|
||||
await UniTask.WhenAll(list);
|
||||
|
||||
{{~for table in tables ~}}
|
||||
{{table.name}}.Resolve(tables);
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public void TranslateText(System.Func<string, string, string> translator)
|
||||
{
|
||||
{{~for table in tables ~}}
|
||||
{{table.name}}.TranslateText(translator);
|
||||
{{~end~}}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,115 +0,0 @@
|
||||
using Bright.Serialization;
|
||||
using System.Collections.Generic;
|
||||
{{
|
||||
name = x.name
|
||||
parent_def_type = x.parent_def_type
|
||||
export_fields = x.export_fields
|
||||
hierarchy_export_fields = x.hierarchy_export_fields
|
||||
}}
|
||||
|
||||
{{cs_start_name_space_grace x.namespace_with_top_module}}
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{x.cs_class_modifier}} partial class {{name}} : {{if parent_def_type}} {{x.parent}} {{else}} Bright.Config.BeanBase {{end}}
|
||||
{
|
||||
public {{name}}(ByteBuf _buf) {{if parent_def_type}} : base(_buf) {{end}}
|
||||
{
|
||||
{{~ for field in export_fields ~}}
|
||||
{{cs_deserialize '_buf' field.convention_name field.ctype}}
|
||||
{{~if field.index_field~}}
|
||||
foreach(var _v in {{field.convention_name}})
|
||||
{
|
||||
{{field.convention_name}}_Index.Add(_v.{{field.index_field.convention_name}}, _v);
|
||||
}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
PostInit();
|
||||
}
|
||||
|
||||
public static {{name}} Deserialize{{name}}(ByteBuf _buf)
|
||||
{
|
||||
{{~if x.is_abstract_type~}}
|
||||
switch (_buf.ReadInt())
|
||||
{
|
||||
{{~for child in x.hierarchy_not_abstract_children~}}
|
||||
case {{child.full_name}}.__ID__: return new {{child.full_name}}(_buf);
|
||||
{{~end~}}
|
||||
default: throw new SerializationException();
|
||||
}
|
||||
{{~else~}}
|
||||
return new {{x.full_name}}(_buf);
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{cs_define_type field.ctype}} {{field.convention_name}} { get; private set; }
|
||||
{{~if field.index_field~}}
|
||||
public readonly Dictionary<{{cs_define_type field.index_field.ctype}}, {{cs_define_type field.ctype.element_type}}> {{field.convention_name}}_Index = new Dictionary<{{cs_define_type field.index_field.ctype}}, {{cs_define_type field.ctype.element_type}}>();
|
||||
{{~end~}}
|
||||
{{~if field.gen_ref~}}
|
||||
public {{field.cs_ref_validator_define}}
|
||||
{{~end~}}
|
||||
{{~if (gen_datetime_mills field.ctype) ~}}
|
||||
public long {{field.convention_name}}_Millis => {{field.convention_name}} * 1000L;
|
||||
{{~end~}}
|
||||
{{~if field.gen_text_key~}}
|
||||
public {{cs_define_text_key_field field}} { get; }
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
{{~if !x.is_abstract_type~}}
|
||||
public const int __ID__ = {{x.id}};
|
||||
public override int GetTypeId() => __ID__;
|
||||
{{~end~}}
|
||||
|
||||
public {{x.cs_method_modifier}} void Resolve(Dictionary<string, object> _tables)
|
||||
{
|
||||
{{~if parent_def_type~}}
|
||||
base.Resolve(_tables);
|
||||
{{~end~}}
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.gen_ref~}}
|
||||
{{cs_ref_validator_resolve field}}
|
||||
{{~else if field.has_recursive_ref~}}
|
||||
{{cs_recursive_resolve field '_tables'}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
PostResolve();
|
||||
}
|
||||
|
||||
public {{x.cs_method_modifier}} void TranslateText(System.Func<string, string, string> translator)
|
||||
{
|
||||
{{~if parent_def_type~}}
|
||||
base.TranslateText(translator);
|
||||
{{~end~}}
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.gen_text_key~}}
|
||||
{{cs_translate_text field 'translator'}}
|
||||
{{~else if field.has_recursive_text~}}
|
||||
{{cs_recursive_translate_text field 'translator'}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "{{full_name}}{ "
|
||||
{{~for field in hierarchy_export_fields ~}}
|
||||
+ "{{field.convention_name}}:" + {{cs_to_string field.convention_name field.ctype}} + ","
|
||||
{{~end~}}
|
||||
+ "}";
|
||||
}
|
||||
|
||||
partial void PostInit();
|
||||
partial void PostResolve();
|
||||
}
|
||||
|
||||
{{cs_end_name_space_grace x.namespace_with_top_module}}
|
@@ -1,173 +0,0 @@
|
||||
using Bright.Serialization;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
{{cs_start_name_space_grace x.namespace_with_top_module}}
|
||||
{{
|
||||
name = x.name
|
||||
key_type = x.key_ttype
|
||||
key_type1 = x.key_ttype1
|
||||
key_type2 = x.key_ttype2
|
||||
value_type = x.value_ttype
|
||||
}}
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public partial class {{name}}
|
||||
{
|
||||
{{~if x.is_map_table ~}}
|
||||
private readonly Dictionary<{{cs_define_type key_type}}, {{cs_define_type value_type}}> _dataMap;
|
||||
private readonly List<{{cs_define_type value_type}}> _dataList;
|
||||
|
||||
public {{name}}(ByteBuf _buf)
|
||||
{
|
||||
_dataMap = new Dictionary<{{cs_define_type key_type}}, {{cs_define_type value_type}}>();
|
||||
_dataList = new List<{{cs_define_type value_type}}>();
|
||||
|
||||
for(int n = _buf.ReadSize() ; n > 0 ; --n)
|
||||
{
|
||||
{{cs_define_type value_type}} _v;
|
||||
{{cs_deserialize '_buf' '_v' value_type}}
|
||||
_dataList.Add(_v);
|
||||
_dataMap.Add(_v.{{x.index_field.convention_name}}, _v);
|
||||
}
|
||||
PostInit();
|
||||
}
|
||||
|
||||
public Dictionary<{{cs_define_type key_type}}, {{cs_define_type value_type}}> DataMap => _dataMap;
|
||||
public List<{{cs_define_type value_type}}> DataList => _dataList;
|
||||
|
||||
{{~if value_type.is_dynamic~}}
|
||||
public T GetOrDefaultAs<T>({{cs_define_type key_type}} key) where T : {{cs_define_type value_type}} => _dataMap.TryGetValue(key, out var v) ? (T)v : null;
|
||||
public T GetAs<T>({{cs_define_type key_type}} key) where T : {{cs_define_type value_type}} => (T)_dataMap[key];
|
||||
{{~end~}}
|
||||
public {{cs_define_type value_type}} GetOrDefault({{cs_define_type key_type}} key) => _dataMap.TryGetValue(key, out var v) ? v : null;
|
||||
public {{cs_define_type value_type}} Get({{cs_define_type key_type}} key) => _dataMap[key];
|
||||
public {{cs_define_type value_type}} this[{{cs_define_type key_type}} key] => _dataMap[key];
|
||||
|
||||
public void Resolve(Dictionary<string, object> _tables)
|
||||
{
|
||||
foreach(var v in _dataList)
|
||||
{
|
||||
v.Resolve(_tables);
|
||||
}
|
||||
PostResolve();
|
||||
}
|
||||
|
||||
public void TranslateText(System.Func<string, string, string> translator)
|
||||
{
|
||||
foreach(var v in _dataList)
|
||||
{
|
||||
v.TranslateText(translator);
|
||||
}
|
||||
}
|
||||
{{~else if x.is_list_table ~}}
|
||||
private readonly List<{{cs_define_type value_type}}> _dataList;
|
||||
|
||||
{{~if x.is_union_index~}}
|
||||
private {{cs_table_union_map_type_name x}} _dataMapUnion;
|
||||
{{~else if !x.index_list.empty?~}}
|
||||
{{~for idx in x.index_list~}}
|
||||
private Dictionary<{{cs_define_type idx.type}}, {{cs_define_type value_type}}> _dataMap_{{idx.index_field.name}};
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
public {{name}}(ByteBuf _buf)
|
||||
{
|
||||
_dataList = new List<{{cs_define_type value_type}}>();
|
||||
|
||||
for(int n = _buf.ReadSize() ; n > 0 ; --n)
|
||||
{
|
||||
{{cs_define_type value_type}} _v;
|
||||
{{cs_deserialize '_buf' '_v' value_type}}
|
||||
_dataList.Add(_v);
|
||||
}
|
||||
{{~if x.is_union_index~}}
|
||||
_dataMapUnion = new {{cs_table_union_map_type_name x}}();
|
||||
foreach(var _v in _dataList)
|
||||
{
|
||||
_dataMapUnion.Add(({{cs_table_key_list x "_v"}}), _v);
|
||||
}
|
||||
{{~else if !x.index_list.empty?~}}
|
||||
{{~for idx in x.index_list~}}
|
||||
_dataMap_{{idx.index_field.name}} = new Dictionary<{{cs_define_type idx.type}}, {{cs_define_type value_type}}>();
|
||||
{{~end~}}
|
||||
foreach(var _v in _dataList)
|
||||
{
|
||||
{{~for idx in x.index_list~}}
|
||||
_dataMap_{{idx.index_field.name}}.Add(_v.{{idx.index_field.convention_name}}, _v);
|
||||
{{~end~}}
|
||||
}
|
||||
{{~end~}}
|
||||
PostInit();
|
||||
}
|
||||
|
||||
|
||||
public List<{{cs_define_type value_type}}> DataList => _dataList;
|
||||
|
||||
{{~if x.is_union_index~}}
|
||||
public {{cs_define_type value_type}} Get({{cs_table_get_param_def_list x}}) => _dataMapUnion.TryGetValue(({{cs_table_get_param_name_list x}}), out {{cs_define_type value_type}} __v) ? __v : null;
|
||||
{{~else if !x.index_list.empty? ~}}
|
||||
{{~for idx in x.index_list~}}
|
||||
public {{cs_define_type value_type}} GetBy{{idx.index_field.convention_name}}({{cs_define_type idx.type}} key) => _dataMap_{{idx.index_field.name}}.TryGetValue(key, out {{cs_define_type value_type}} __v) ? __v : null;
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
public void Resolve(Dictionary<string, object> _tables)
|
||||
{
|
||||
foreach(var v in _dataList)
|
||||
{
|
||||
v.Resolve(_tables);
|
||||
}
|
||||
PostResolve();
|
||||
}
|
||||
|
||||
public void TranslateText(System.Func<string, string, string> translator)
|
||||
{
|
||||
foreach(var v in _dataList)
|
||||
{
|
||||
v.TranslateText(translator);
|
||||
}
|
||||
}
|
||||
{{~else~}}
|
||||
|
||||
private readonly {{cs_define_type value_type}} _data;
|
||||
|
||||
public {{name}}(ByteBuf _buf)
|
||||
{
|
||||
int n = _buf.ReadSize();
|
||||
if (n != 1) throw new SerializationException("table mode=one, but size != 1");
|
||||
{{cs_deserialize '_buf' '_data' value_type}}
|
||||
PostInit();
|
||||
}
|
||||
|
||||
|
||||
{{~ for field in value_type.bean.hierarchy_export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{cs_define_type field.ctype}} {{field.convention_name}} => _data.{{field.convention_name}};
|
||||
{{~end~}}
|
||||
|
||||
public void Resolve(Dictionary<string, object> _tables)
|
||||
{
|
||||
_data.Resolve(_tables);
|
||||
PostResolve();
|
||||
}
|
||||
|
||||
public void TranslateText(System.Func<string, string, string> translator)
|
||||
{
|
||||
_data.TranslateText(translator);
|
||||
}
|
||||
|
||||
{{~end~}}
|
||||
|
||||
partial void PostInit();
|
||||
partial void PostResolve();
|
||||
}
|
||||
|
||||
{{cs_end_name_space_grace x.namespace_with_top_module}}
|
@@ -1,46 +0,0 @@
|
||||
using Bright.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
{{
|
||||
name = x.name
|
||||
namespace = x.namespace
|
||||
tables = x.tables
|
||||
}}
|
||||
namespace {{namespace}}
|
||||
{
|
||||
|
||||
public sealed class {{name}}
|
||||
{
|
||||
{{~for table in tables ~}}
|
||||
{{~if table.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{table.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{table.full_name}} {{table.name}} {get; private set; }
|
||||
{{~end~}}
|
||||
|
||||
public {{name}}() { }
|
||||
|
||||
public async Task LoadAsync(System.Func<string, Task<ByteBuf>> loader)
|
||||
{
|
||||
var tables = new System.Collections.Generic.Dictionary<string, object>();
|
||||
{{~for table in tables ~}}
|
||||
{{table.name}} = new {{table.full_name}}(await loader("{{table.output_data_file}}"));
|
||||
tables.Add("{{table.full_name}}", {{table.name}});
|
||||
{{~end~}}
|
||||
|
||||
{{~for table in tables ~}}
|
||||
{{table.name}}.Resolve(tables);
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public void TranslateText(System.Func<string, string, string> translator)
|
||||
{
|
||||
{{~for table in tables ~}}
|
||||
{{table.name}}.TranslateText(translator);
|
||||
{{~end~}}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,36 +0,0 @@
|
||||
<module name="Battle">
|
||||
<enum name="ActorAttrDataType">
|
||||
<var name="None" alias="无效数据" value="0"/>
|
||||
<var name="MaxHp" alias="最大血量" value="1"/>
|
||||
<var name="Attack" alias="攻击力" value="2"/>
|
||||
<var name="PhyDamage" alias="物理伤害" value="3"/>
|
||||
<var name="PhyDef" alias="物理防御" value="4"/>
|
||||
<var name="MagicDamage" alias="法术伤害" value="5"/>
|
||||
<var name="MagicDef" alias="法术防御" value="6"/>
|
||||
<var name="MoveSpeed" alias="移动速度" value="7"/>
|
||||
<var name="AttackSpeed" alias="攻击速度" value="8"/>
|
||||
<var name="Hit" alias="命中率" value="9"/>
|
||||
<var name="Dodge" alias="闪避率" value="10"/>
|
||||
<var name="CriticalAtkRatio" alias="暴击率" value="11"/>
|
||||
<var name="SanValue" alias="San值(疯狂值)" value="12"/>
|
||||
<var name="MaxMp" alias="最大MP" value="13"/>
|
||||
|
||||
<var name="PhyDamageRatio" alias="物理伤害倍率" value="14"/>
|
||||
<var name="MagicDamageRatio" alias="魔法伤害倍率" value="15"/>
|
||||
<var name="CriticalRatio" alias="暴击倍率" value="16"/>
|
||||
<var name="CriticalReduce" alias="暴击减免" value="17"/>
|
||||
</enum>
|
||||
|
||||
<enum name="ActorAttrAddType">
|
||||
<var name="NONE" alias="无效数据" value="0"/>
|
||||
<var name="ABSOLUTE_VAL" alias="加法计算" value="1"/>
|
||||
<var name="SUM_PERCENT_VAL" alias="多个项结果累加,然后对加法做乘法" value="2"/>
|
||||
<var name="MUL_PERCENT_VAL" alias="每一项都是对最终结果做乘法" value="3"/>
|
||||
</enum>
|
||||
|
||||
<bean name="ResAttrImpactData" sep="," parent="">
|
||||
<var name="DataType" type="ActorAttrDataType"/>
|
||||
<var name="AddType" type="ActorAttrAddType"/>
|
||||
<var name="Value" type="float"/>
|
||||
</bean>
|
||||
</module>
|
@@ -1,68 +0,0 @@
|
||||
<module name="Battle">
|
||||
<enum name="BuffTimeType">
|
||||
<var name="BUFF_TIME_DURING" alias="指定持续时间" value="0"/>
|
||||
<var name="BUFF_TIME_INFINIT" alias="无尽时间" value="1"/>
|
||||
</enum>
|
||||
|
||||
<enum name="BuffReplaceType">
|
||||
<var name="BUFF_REPLACE_INSTEAD" alias="更新时间范围" value="0"/>
|
||||
<var name="BUFF_REPLACE_FORBIT" alias="不允许叠加" value="1"/>
|
||||
<var name="BUFF_REPLACE_ADD_TIME" alias="累加时间范围" value="2"/>
|
||||
<var name="BUFF_REPLACE_ADD_ATTR" alias="叠加数值" value="3"/>
|
||||
<var name="BUFF_REPLACE_TYPE_COUNT" alias="叠加种类" value="4"/>
|
||||
</enum>
|
||||
|
||||
<enum name="BuffStateID">
|
||||
<var name="BUFF_STATE_NONE" alias="无状态" value="0"/>
|
||||
<var name="BUFF_STATE_STUN" alias="眩晕状态" value="1"/>
|
||||
<var name="BUFF_STATE_UNDEAD" alias="无敌状态" value="2"/>
|
||||
<var name="BUFF_STATE_INVISIBLE" alias="隐身状态" value="3"/>
|
||||
<var name="BUFF_STATE_BIGGER" alias="体形变大" value="4"/>
|
||||
<var name="BUFF_STATE_NO_MOVE" alias="定身,不能移动" value="5"/>
|
||||
<var name="BUFF_STATE_NO_SKILL" alias="沉默,不能放技能" value="6"/>
|
||||
<var name="BUFF_STATE_SLEEP" alias="昏睡" value="7"/>
|
||||
<var name="BUFF_STATE_FORCE_COLLIDER" alias="强制开启阻挡" value="8"/>
|
||||
<var name="BUFF_STATE_IGNORE_COLLIDER" alias="无视阻挡" value="9"/>
|
||||
<var name="BUFF_STATE_MAX" alias="最大状态" value="10"/>
|
||||
</enum>
|
||||
|
||||
<enum name="BuffResultType">
|
||||
<var name="BUFF_RESULT_NONE" alias="无" value="0"/>
|
||||
<var name="BUFF_RESULT_PHY_ATK_UP" alias="物理攻击提升" value="1"/>
|
||||
<var name="BUFF_RESULT_PHY_ATK_DOWN" alias="物理攻击降低" value="2"/>
|
||||
<var name="BUFF_RESULT_PHY_DEF_UP" alias="物理防御提升" value="3"/>
|
||||
<var name="BUFF_RESULT_PHY_DEF_DOWN" alias="物理防御降低" value="4"/>
|
||||
<var name="BUFF_RESULT_PHY_HIT_UP" alias="物理命中提升" value="5"/>
|
||||
<var name="BUFF_RESULT_PHY_HIT_DOWN" alias="物理命中降低" value="6"/>
|
||||
<var name="BUFF_RESULT_PHY_LOSE_HP" alias="物理持续掉血" value="7"/>
|
||||
|
||||
<var name="BUFF_RESULT_MAG_ATK_UP" alias="法术攻击提升" value="8"/>
|
||||
<var name="BUFF_RESULT_MAG_ATK_DOWN" alias="法术攻击降低" value="9"/>
|
||||
<var name="BUFF_RESULT_MAG_DEF_UP" alias="法术防御提升" value="10"/>
|
||||
<var name="BUFF_RESULT_MAG_DEF_DOWN" alias="法术防御降低" value="11"/>
|
||||
<var name="BUFF_RESULT_MAG_HIT_UP" alias="法术命中提升" value="12"/>
|
||||
<var name="BUFF_RESULT_MAG_HIT_DOWN" alias="法术命中降低" value="13"/>
|
||||
<var name="BUFF_RESULT_MAG_LOSE_HP" alias="法术持续掉血" value="14"/>
|
||||
|
||||
<var name="BUFF_RESULT_CIRT_UP" alias="暴击率提升" value="15"/>
|
||||
<var name="BUFF_RESULT_CIRT_DOWN" alias="暴击率降低" value="16"/>
|
||||
<var name="BUFF_RESULT_CIRT_VALUE_UP" alias="暴击倍率提升" value="17"/>
|
||||
<var name="BUFF_RESULT_CIRT_VALUE_DOWN" alias="暴击倍率降低" value="18"/>
|
||||
|
||||
<var name="BUFF_RESULT_MOVE_SPEED_UP" alias="移速提升" value="19"/>
|
||||
<var name="BUFF_RESULT_MOVE_SPEED_DOWN" alias="移速降低" value="20"/>
|
||||
</enum>
|
||||
|
||||
<bean name="BuffTriggleState" sep="," parent="">
|
||||
<var name="StateID" type="BuffStateID"/>
|
||||
<var name="StateParam" type="float"/>
|
||||
</bean>
|
||||
|
||||
<bean name="BuffDotTickConfig" sep="," parent="">
|
||||
<!-- 触发间隔,如果为0, 则只加一次 -->
|
||||
<var name="TickTime" type="float"/>
|
||||
<!-- 1增加buff的时候立刻触发,否则等待TickTime后再触发 -->
|
||||
<var name="TickWhenAdd" type="int"/>
|
||||
</bean>
|
||||
|
||||
</module>
|
@@ -1,25 +0,0 @@
|
||||
<module name="Battle">
|
||||
<enum name="SkillMagicType"> 技能元素类型
|
||||
<var name="SKILL_TYPE_NONE" alias="无类型" value="0"/>
|
||||
<var name="SKILL_TYPE_DMG_PHY" alias="物理伤害属性" value="1"/>
|
||||
<var name="SKILL_TYPE_DMG_MAGIC" alias="魔法伤害属性" value="2"/>
|
||||
</enum>
|
||||
|
||||
<enum name="SkillAttrDamageType"> 伤害类型
|
||||
<var name="ATTR_TYPE_NONE" alias="无数值" value="0"/>
|
||||
<var name="ATTR_TYPE_DMG_WEAPON" alias="按释放者的伤害类型*X%+固定值计算,目标有防御计算" value="1"/>
|
||||
<var name="ATTR_TYPE_DMG_NO_DEFEND" alias="按释放者的伤害类型*X%+固定值计算(无视目标的防御)" value="2"/>
|
||||
<var name="ATTR_TYPE_DMG_TARGET_HP_NO_DEFEND" alias="按受击者的气血上限*X%+固定值计算(无视目标的防御)" value="3"/>
|
||||
<var name="ATTR_TYPE_HP_AS_ATK" alias="按释放者的攻击类型*X%+固定值计算,恢复当前生命" value="4"/>
|
||||
<var name="ATTR_TYPE_HP_RATIO" alias="按受击者的HP上限*X%+固定值计算,恢复当前生命" value="5"/>
|
||||
</enum>
|
||||
|
||||
<bean name="SkillAttrDamageData" sep="," parent="">
|
||||
<var name="MagicType" type="SkillMagicType"/>
|
||||
<var name="AttrType" type="SkillAttrDamageType"/>
|
||||
<var name="Param1" type="float"/>
|
||||
<var name="Param2" type="float"/>
|
||||
<var name="Param3" type="float"/>
|
||||
<var name="MaxLimit" type="float"/>
|
||||
</bean>
|
||||
</module>
|
@@ -1,23 +0,0 @@
|
||||
<root>
|
||||
|
||||
<topmodule name="GameConfig"/>
|
||||
|
||||
<externalselector name="unity"/>
|
||||
|
||||
<patch name="cn"/>
|
||||
<patch name="en"/>
|
||||
|
||||
<group name="c,client" default="1"/> client
|
||||
<group name="s,server" default="1"/> server
|
||||
<group name="e" default="1"/> editor
|
||||
|
||||
<import name="."/>
|
||||
|
||||
<importexcel name="__tables__.xlsx" type="table"/> 相对data目录
|
||||
<importexcel name="__enums__.xlsx" type="enum"/>相对data目录
|
||||
<importexcel name="__beans__.xlsx" type="bean"/>相对data目录
|
||||
|
||||
<service name="server" manager="Tables" group="s"/>
|
||||
<service name="client" manager="Tables" group="c"/>
|
||||
<service name="all" manager="Tables" group="c,s,e"/>
|
||||
</root>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,4 +1,4 @@
|
||||
using Bright.Serialization;
|
||||
using Luban;
|
||||
using GameBase;
|
||||
using GameConfig;
|
||||
using TEngine;
|
||||
@@ -21,6 +21,7 @@ public class ConfigSystem : Singleton<ConfigSystem>
|
||||
{
|
||||
Load();
|
||||
}
|
||||
|
||||
return _tables;
|
||||
}
|
||||
}
|
@@ -0,0 +1,55 @@
|
||||
using Luban;
|
||||
|
||||
{{namespace_with_grace_begin __namespace}}
|
||||
public partial class {{__name}}
|
||||
{
|
||||
#region The Tables
|
||||
|
||||
{{~for table in __tables ~}}
|
||||
{{~if table.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{escape_comment table.comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
private {{table.full_name}} m_{{table.name}};
|
||||
public {{table.full_name}} {{format_property_name __code_style table.name}}
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_{{table.name}} == null)
|
||||
{
|
||||
m_{{table.name}} = new {{table.full_name}}(defaultLoader("{{table.output_data_file}}"));
|
||||
m_{{table.name}}.ResolveRef(this);
|
||||
}
|
||||
return m_{{table.name}};
|
||||
}
|
||||
set
|
||||
{
|
||||
m_{{table.name}} = value;
|
||||
m_{{table.name}}.ResolveRef(this);
|
||||
}
|
||||
}
|
||||
{{~end~}}
|
||||
|
||||
#endregion
|
||||
|
||||
System.Func<string, ByteBuf> defaultLoader;
|
||||
|
||||
public {{__name}}(System.Func<string, ByteBuf> loader)
|
||||
{
|
||||
SetDefaultLoader(loader);
|
||||
Init();
|
||||
}
|
||||
|
||||
public void SetDefaultLoader(System.Func<string, ByteBuf> loader)
|
||||
{
|
||||
defaultLoader = null;
|
||||
defaultLoader = loader;
|
||||
}
|
||||
|
||||
//public partial void Init();
|
||||
|
||||
public void Init(){}
|
||||
}
|
||||
|
||||
{{namespace_with_grace_end __namespace}}
|
BIN
Configs/GameConfig/Datas/__beans__.xlsx
Normal file
BIN
Configs/GameConfig/Datas/__beans__.xlsx
Normal file
Binary file not shown.
BIN
Configs/GameConfig/Datas/__enums__.xlsx
Normal file
BIN
Configs/GameConfig/Datas/__enums__.xlsx
Normal file
Binary file not shown.
BIN
Configs/GameConfig/Datas/__tables__.xlsx
Normal file
BIN
Configs/GameConfig/Datas/__tables__.xlsx
Normal file
Binary file not shown.
BIN
Configs/GameConfig/Datas/item.xlsx
Normal file
BIN
Configs/GameConfig/Datas/item.xlsx
Normal file
Binary file not shown.
17
Configs/GameConfig/Defines/builtin.xml
Normal file
17
Configs/GameConfig/Defines/builtin.xml
Normal file
@@ -0,0 +1,17 @@
|
||||
<module name="">
|
||||
<bean name="vector2" valueType="1" sep=",">
|
||||
<var name="x" type="float"/>
|
||||
<var name="y" type="float"/>
|
||||
</bean>
|
||||
<bean name="vector3" valueType="1" sep=",">
|
||||
<var name="x" type="float"/>
|
||||
<var name="y" type="float"/>
|
||||
<var name="z" type="float"/>
|
||||
</bean>
|
||||
<bean name="vector4" valueType="1" sep=",">
|
||||
<var name="x" type="float"/>
|
||||
<var name="y" type="float"/>
|
||||
<var name="z" type="float"/>
|
||||
<var name="w" type="float"/>
|
||||
</bean>
|
||||
</module>
|
17
Configs/GameConfig/gen_code_bin_to_project.bat
Normal file
17
Configs/GameConfig/gen_code_bin_to_project.bat
Normal file
@@ -0,0 +1,17 @@
|
||||
set WORKSPACE=../..
|
||||
set LUBAN_DLL=%WORKSPACE%\Tools\Luban\Luban.dll
|
||||
set CONF_ROOT=.
|
||||
set DATA_OUTPATH=%WORKSPACE%/UnityProject/Assets/AssetRaw/Configs/bytes/
|
||||
set CODE_OUTPATH=%WORKSPACE%/UnityProject/Assets/GameScripts/HotFix/GameProto/GameConfig/
|
||||
|
||||
xcopy /s /e /i /y "%CONF_ROOT%\CustomTemplate\ConfigSystem.cs" "%WORKSPACE%\UnityProject\Assets\GameScripts\HotFix\GameProto\ConfigSystem.cs"
|
||||
|
||||
dotnet %LUBAN_DLL% ^
|
||||
-t client ^
|
||||
-c cs-bin ^
|
||||
-d bin^
|
||||
--conf %CONF_ROOT%\luban.conf ^
|
||||
-x outputCodeDir=%CODE_OUTPATH% ^
|
||||
-x outputDataDir=%DATA_OUTPATH%
|
||||
pause
|
||||
|
18
Configs/GameConfig/gen_code_bin_to_project_lazyload.bat
Normal file
18
Configs/GameConfig/gen_code_bin_to_project_lazyload.bat
Normal file
@@ -0,0 +1,18 @@
|
||||
set WORKSPACE=../..
|
||||
set LUBAN_DLL=%WORKSPACE%\Tools\Luban\Luban.dll
|
||||
set CONF_ROOT=.
|
||||
set DATA_OUTPATH=%WORKSPACE%/UnityProject/Assets/AssetRaw/Configs/bytes/
|
||||
set CODE_OUTPATH=%WORKSPACE%/UnityProject/Assets/GameScripts/HotFix/GameProto/GameConfig/
|
||||
|
||||
xcopy /s /e /i /y "%CONF_ROOT%\CustomTemplate\ConfigSystem.cs" "%WORKSPACE%\UnityProject\Assets\GameScripts\HotFix\GameProto\ConfigSystem.cs"
|
||||
|
||||
dotnet %LUBAN_DLL% ^
|
||||
-t client ^
|
||||
-c cs-bin ^
|
||||
-d bin^
|
||||
--conf %CONF_ROOT%\luban.conf ^
|
||||
--customTemplateDir %CONF_ROOT%\CustomTemplate\CustomTemplate_Client_LazyLoad ^
|
||||
-x outputCodeDir=%CODE_OUTPATH% ^
|
||||
-x outputDataDir=%DATA_OUTPATH%
|
||||
pause
|
||||
|
15
Configs/GameConfig/gen_code_bin_to_server.bat
Normal file
15
Configs/GameConfig/gen_code_bin_to_server.bat
Normal file
@@ -0,0 +1,15 @@
|
||||
set WORKSPACE=../../
|
||||
set LUBAN_DLL=%WORKSPACE%/Tools/Luban/Luban.dll
|
||||
set CONF_ROOT=.
|
||||
set DATA_OUTPATH=%WORKSPACE%/Server/GameConfig
|
||||
set CODE_OUTPATH=%WORKSPACE%/Server/Hotfix/Config/GameConfig
|
||||
|
||||
dotnet %LUBAN_DLL% ^
|
||||
-t server^
|
||||
-c cs-bin ^
|
||||
-d bin^
|
||||
--conf %CONF_ROOT%\luban.conf ^
|
||||
-x outputCodeDir=%CODE_OUTPATH% ^
|
||||
-x outputDataDir=%DATA_OUTPATH%
|
||||
pause
|
||||
|
22
Configs/GameConfig/luban.conf
Normal file
22
Configs/GameConfig/luban.conf
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"groups":
|
||||
[
|
||||
{"names":["c"], "default":true},
|
||||
{"names":["s"], "default":true},
|
||||
{"names":["e"], "default":true}
|
||||
],
|
||||
"schemaFiles":
|
||||
[
|
||||
{"fileName":"Defines", "type":""},
|
||||
{"fileName":"Datas/__tables__.xlsx", "type":"table"},
|
||||
{"fileName":"Datas/__beans__.xlsx", "type":"bean"},
|
||||
{"fileName":"Datas/__enums__.xlsx", "type":"enum"}
|
||||
],
|
||||
"dataDir": "Datas",
|
||||
"targets":
|
||||
[
|
||||
{"name":"server", "manager":"Tables", "groups":["s"], "topModule":"GameConfig"},
|
||||
{"name":"client", "manager":"Tables", "groups":["c"], "topModule":"GameConfig"},
|
||||
{"name":"all", "manager":"Tables", "groups":["c,s,e"], "topModule":"GameConfig"}
|
||||
]
|
||||
}
|
@@ -1,21 +0,0 @@
|
||||
cd /d %~dp0
|
||||
set WORKSPACE=..
|
||||
|
||||
set GEN_CLIENT=%WORKSPACE%\Tools\Luban.ClientServer\Luban.ClientServer.exe
|
||||
set CONF_ROOT=%WORKSPACE%\Configs
|
||||
set DATA_OUTPUT=%ROOT_PATH%..\GenerateDatas
|
||||
set CUSTOM_TEMP=%WORKSPACE%\Configs\CustomTemplate\CustomTemplate_Client
|
||||
|
||||
xcopy %CUSTOM_TEMP%\ConfigSystem.cs %WORKSPACE%\UnityProject\Assets\GameScripts\HotFix\GameProto\ConfigSystem.cs /s /e /i /y
|
||||
|
||||
%GEN_CLIENT% -j cfg --^
|
||||
-d %CONF_ROOT%\Defines\__root__.xml ^
|
||||
--input_data_dir %CONF_ROOT%\Excels^
|
||||
--output_code_dir %WORKSPACE%/UnityProject/Assets/GameScripts/HotFix/GameProto/GameConfig ^
|
||||
--output_data_dir %WORKSPACE%/UnityProject/Assets/AssetRaw/Configs/bytes/ ^
|
||||
--gen_types code_cs_unity_bin,data_bin ^
|
||||
-s client
|
||||
|
||||
echo ======== 生成配置文件结束 ========
|
||||
|
||||
pause
|
@@ -1,40 +0,0 @@
|
||||
cd /d %~dp0
|
||||
set WORKSPACE=..
|
||||
|
||||
set GEN_CLIENT=%WORKSPACE%\Tools\Luban.ClientServer\Luban.ClientServer.exe
|
||||
set CONF_ROOT=%WORKSPACE%\Configs
|
||||
set DATA_OUTPUT=%ROOT_PATH%..\GenerateDatas
|
||||
set CUSTOM_TEMP=%WORKSPACE%\Configs\CustomTemplate\CustomTemplate_Client_LazyLoad
|
||||
|
||||
xcopy %CUSTOM_TEMP%\ConfigSystem.cs %WORKSPACE%\UnityProject\Assets\GameScripts\HotFix\GameProto\ConfigSystem.cs /s /e /i /y
|
||||
|
||||
%GEN_CLIENT% --template_search_path %CONF_ROOT%\CustomTemplate\CustomTemplate_Client_LazyLoad -j cfg --^
|
||||
-d %CONF_ROOT%\Defines\__root__.xml ^
|
||||
--input_data_dir %CONF_ROOT%\Excels^
|
||||
--output_code_dir %WORKSPACE%/UnityProject/Assets/GameScripts/HotFix/GameProto/GameConfig ^
|
||||
--output_data_dir %WORKSPACE%/UnityProject/Assets/AssetRaw/Configs/bytes/ ^
|
||||
--gen_types data_bin ^
|
||||
-s client
|
||||
|
||||
%GEN_CLIENT% --template_search_path %CONF_ROOT%\CustomTemplate\CustomTemplate_Client_LazyLoad -j cfg --^
|
||||
-d %CONF_ROOT%\Defines\__root__.xml ^
|
||||
--input_data_dir %CONF_ROOT%\Excels^
|
||||
--output_code_dir %WORKSPACE%/UnityProject/Assets/GameScripts/HotFix/GameProto/GameConfig ^
|
||||
--output_data_dir ..\GenerateDatas\bidx ^
|
||||
--gen_types code_cs_unity_bin,data_bidx ^
|
||||
-s client
|
||||
|
||||
echo ======== 生成配置文件结束 ========
|
||||
set WORKSPACE=..
|
||||
|
||||
set "prefix=Idx_"
|
||||
|
||||
for %%a in (%DATA_OUTPUT%\bidx\*) do (
|
||||
ren "%%a" "Idx_%%~nxa"
|
||||
)
|
||||
|
||||
echo ======== 所有文件已添加前缀 ========
|
||||
|
||||
xcopy %DATA_OUTPUT%\bidx\ %WORKSPACE%\UnityProject\Assets\AssetRaw\Configs\bidx\ /s /e /i /y
|
||||
|
||||
pause
|
@@ -1,21 +0,0 @@
|
||||
cd /d %~dp0
|
||||
set WORKSPACE=..
|
||||
|
||||
set GEN_CLIENT=%WORKSPACE%\Tools\Luban.ClientServer\Luban.ClientServer.exe
|
||||
set CONF_ROOT=%WORKSPACE%\Configs
|
||||
set DATA_OUTPUT=%ROOT_PATH%..\GenerateDatas
|
||||
set CUSTOM_TEMP=%WORKSPACE%\Configs\CustomTemplate\CustomTemplate_Client_UniTask
|
||||
|
||||
xcopy %CUSTOM_TEMP%\ConfigSystem.cs %WORKSPACE%\UnityProject\Assets\GameScripts\HotFix\GameProto\ConfigSystem.cs /s /e /i /y
|
||||
|
||||
%GEN_CLIENT% --template_search_path %CONF_ROOT%\CustomTemplate\CustomTemplate_Client_UniTask -j cfg --^
|
||||
-d %CONF_ROOT%\Defines\__root__.xml ^
|
||||
--input_data_dir %CONF_ROOT%\Excels^
|
||||
--output_code_dir %WORKSPACE%/UnityProject/Assets/GameScripts/HotFix/GameProto/GameConfig ^
|
||||
--output_data_dir %WORKSPACE%/UnityProject/Assets/AssetRaw/Configs/bytes/ ^
|
||||
--gen_types code_cs_unity_bin,data_bin ^
|
||||
-s client
|
||||
|
||||
echo ======== 生成配置文件结束 ========
|
||||
|
||||
pause
|
@@ -1,18 +0,0 @@
|
||||
cd /d %~dp0
|
||||
set WORKSPACE=..
|
||||
|
||||
set GEN_CLIENT=%WORKSPACE%\Tools\Luban.ClientServer\Luban.ClientServer.exe
|
||||
set CONF_ROOT=%WORKSPACE%\Configs
|
||||
set DATA_OUTPUT=%ROOT_PATH%..\GenerateDatas
|
||||
|
||||
%GEN_CLIENT% --template_search_path %CONF_ROOT%\CustomTemplate\CustomTemplate_Server_Task -j cfg --^
|
||||
-d %CONF_ROOT%\Defines\__root__.xml ^
|
||||
--input_data_dir %CONF_ROOT%\Excels^
|
||||
--output_code_dir %WORKSPACE%/DotNet/Logic/src/Config/GameConfig ^
|
||||
--output_data_dir ..\DotNet\Config\GameConfig ^
|
||||
--gen_types code_cs_bin,data_bin ^
|
||||
-s server
|
||||
|
||||
echo ======== 生成配置文件结束 ========
|
||||
|
||||
pause
|
@@ -1 +0,0 @@
|
||||
目前使用luban-classic,请自行导入
|
1
Tools/Luban/about.txt
Normal file
1
Tools/Luban/about.txt
Normal file
@@ -0,0 +1 @@
|
||||
使用luban-next, 请前往Tools/build-luban编译或者自行导入
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 49afb8bbdbfbf014baadbaed2e2bebee
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
|
||||
namespace Luban
|
||||
{
|
||||
public abstract class BeanBase
|
||||
{
|
||||
public abstract int GetTypeId();
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 893ae545d065e534bbb7ec9df68e48fe
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
1568
UnityProject/Assets/GameScripts/HotFix/GameProto/LubanLib/ByteBuf.cs
Normal file
1568
UnityProject/Assets/GameScripts/HotFix/GameProto/LubanLib/ByteBuf.cs
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4e75cc385e3ba2a4a928b3beb7f69b13
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,7 @@
|
||||
namespace Luban
|
||||
{
|
||||
public interface ITypeId
|
||||
{
|
||||
int GetTypeId();
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 09af473d0f77f7f43ba793fc8c3996a0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,52 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Luban
|
||||
{
|
||||
public static class StringUtil
|
||||
{
|
||||
public static string ToStr(object o)
|
||||
{
|
||||
return ToStr(o, new StringBuilder());
|
||||
}
|
||||
|
||||
public static string ToStr(object o, StringBuilder sb)
|
||||
{
|
||||
foreach (var p in o.GetType().GetFields())
|
||||
{
|
||||
|
||||
sb.Append($"{p.Name} = {p.GetValue(o)},");
|
||||
}
|
||||
|
||||
foreach (var p in o.GetType().GetProperties())
|
||||
{
|
||||
sb.Append($"{p.Name} = {p.GetValue(o)},");
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public static string ArrayToString<T>(T[] arr)
|
||||
{
|
||||
return "[" + string.Join(",", arr) + "]";
|
||||
}
|
||||
|
||||
|
||||
public static string CollectionToString<T>(IEnumerable<T> arr)
|
||||
{
|
||||
return "[" + string.Join(",", arr) + "]";
|
||||
}
|
||||
|
||||
|
||||
public static string CollectionToString<TK, TV>(IDictionary<TK, TV> dic)
|
||||
{
|
||||
var sb = new StringBuilder('{');
|
||||
foreach (var e in dic)
|
||||
{
|
||||
sb.Append(e.Key).Append(':');
|
||||
sb.Append(e.Value).Append(',');
|
||||
}
|
||||
sb.Append('}');
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 353da197a63f6004ba2cbd8751e717bf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -123,6 +123,50 @@ NavMeshSettings:
|
||||
debug:
|
||||
m_Flags: 0
|
||||
m_NavMeshData: {fileID: 0}
|
||||
--- !u!1 &450845952
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 450845953}
|
||||
- component: {fileID: 450845954}
|
||||
m_Layer: 0
|
||||
m_Name: Scene
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &450845953
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 450845952}
|
||||
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: 10
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &450845954
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 450845952}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 86342cc6845c403da1a3f6db507fae9d, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
--- !u!1 &553327090
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -405,6 +449,7 @@ Transform:
|
||||
- {fileID: 1666908677}
|
||||
- {fileID: 1863338241}
|
||||
- {fileID: 914171638}
|
||||
- {fileID: 450845953}
|
||||
- {fileID: 1047779124}
|
||||
m_Father: {fileID: 1195690679}
|
||||
m_RootOrder: 0
|
||||
@@ -768,6 +813,7 @@ MonoBehaviour:
|
||||
milliseconds: 30
|
||||
downloadingMaxNum: 3
|
||||
failedTryAgain: 3
|
||||
adaptiveReplacementCacheCapacity: 32
|
||||
--- !u!1 &1047779123
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -798,7 +844,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 &1047779125
|
||||
MonoBehaviour:
|
||||
|
8
UnityProject/Assets/TEngine/Editor/Inspector/Asset.meta
Normal file
8
UnityProject/Assets/TEngine/Editor/Inspector/Asset.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1d6f43591dfb9c54fbbebda60c1210fa
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,52 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.IO;
|
||||
|
||||
[CanEditMultipleObjects, CustomEditor(typeof(DefaultAsset), false)]
|
||||
public class DefaultAssetInspector : Editor
|
||||
{
|
||||
private const int MaxColum = 10240;
|
||||
|
||||
private GUIStyle _textStyle;
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
base.OnInspectorGUI();
|
||||
if (_textStyle == null)
|
||||
{
|
||||
_textStyle = "ScriptText";
|
||||
}
|
||||
|
||||
bool enabled = GUI.enabled;
|
||||
GUI.enabled = true;
|
||||
string assetPath = AssetDatabase.GetAssetPath(target);
|
||||
if (assetPath.EndsWith(".lua") ||
|
||||
assetPath.EndsWith(".properties") ||
|
||||
assetPath.EndsWith(".gradle")
|
||||
)
|
||||
{
|
||||
string luaFile = File.ReadAllText(assetPath);
|
||||
string text;
|
||||
if (targets.Length > 1)
|
||||
{
|
||||
text = Path.GetFileName(assetPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
text = luaFile;
|
||||
if (text.Length > MaxColum)
|
||||
{
|
||||
text = text.Substring(0, MaxColum) + "...\n\n<...etc...>";
|
||||
}
|
||||
}
|
||||
|
||||
Rect rect = GUILayoutUtility.GetRect(new GUIContent(text), _textStyle);
|
||||
rect.x = 0f;
|
||||
rect.y -= 3f;
|
||||
rect.width = EditorGUIUtility.currentViewWidth + 1f;
|
||||
GUI.Box(rect, text, _textStyle);
|
||||
}
|
||||
|
||||
GUI.enabled = enabled;
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 83f53d2e775d0ff449616ff946f1be55
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,53 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.IO;
|
||||
|
||||
[CanEditMultipleObjects, CustomEditor(typeof(TextAsset))]
|
||||
public class TextAssetInspector : Editor
|
||||
{
|
||||
private const int MaxColum = 10240;
|
||||
|
||||
private GUIStyle _textStyle;
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
if (_textStyle == null)
|
||||
{
|
||||
_textStyle = "ScriptText";
|
||||
}
|
||||
|
||||
bool enabled = GUI.enabled;
|
||||
GUI.enabled = true;
|
||||
string assetPath = AssetDatabase.GetAssetPath(target);
|
||||
if (assetPath.EndsWith(".md")
|
||||
|| assetPath.EndsWith(".xml")
|
||||
|| assetPath.EndsWith(".txt")
|
||||
|| assetPath.EndsWith(".html")
|
||||
|| assetPath.EndsWith(".csv")
|
||||
)
|
||||
{
|
||||
string luaFile = File.ReadAllText(assetPath);
|
||||
string text;
|
||||
if (base.targets.Length > 1)
|
||||
{
|
||||
text = Path.GetFileName(assetPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
text = luaFile;
|
||||
if (text.Length > MaxColum)
|
||||
{
|
||||
text = text.Substring(0, MaxColum) + "...\n\n<...etc...>";
|
||||
}
|
||||
}
|
||||
|
||||
Rect rect = GUILayoutUtility.GetRect(new GUIContent(text), _textStyle);
|
||||
rect.x = 0f;
|
||||
rect.y -= 3f;
|
||||
rect.width = EditorGUIUtility.currentViewWidth + 1f;
|
||||
GUI.Box(rect, text, _textStyle);
|
||||
}
|
||||
|
||||
GUI.enabled = enabled;
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ad0327765273616459117746a53a35e6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
3
UnityProject/Assets/TEngine/Editor/ReleaseTools.meta
Normal file
3
UnityProject/Assets/TEngine/Editor/ReleaseTools.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: defa3b5ccfc64b0392d67db95b3c528d
|
||||
timeCreated: 1698043573
|
@@ -0,0 +1,64 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using YooAsset.Editor;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
/// <summary>
|
||||
/// 打包工具类。
|
||||
/// <remarks>通过CommandLineReader可以不前台开启Unity实现静默打包,详见CommandLineReader.cs example1</remarks>
|
||||
/// </summary>
|
||||
public static class ReleaseTools
|
||||
{
|
||||
public static void BuildPackage()
|
||||
{
|
||||
string outputRoot = CommandLineReader.GetCustomArgument("outputRoot");
|
||||
BuildTarget target = BuildTarget.StandaloneWindows64;
|
||||
BuildInternal(target,outputRoot);
|
||||
Debug.LogWarning($"Start BuildPackage BuildTarget:{target} outputPath:{outputRoot}");
|
||||
}
|
||||
|
||||
private static void BuildInternal(BuildTarget buildTarget,string outputRoot)
|
||||
{
|
||||
Debug.Log($"开始构建 : {buildTarget}");
|
||||
|
||||
// 构建参数
|
||||
BuildParameters buildParameters = new BuildParameters();
|
||||
buildParameters.StreamingAssetsRoot = AssetBundleBuilderHelper.GetDefaultStreamingAssetsRoot();
|
||||
buildParameters.BuildOutputRoot = outputRoot;//AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
|
||||
buildParameters.BuildTarget = buildTarget;
|
||||
buildParameters.BuildPipeline = EBuildPipeline.BuiltinBuildPipeline;
|
||||
buildParameters.BuildMode = EBuildMode.ForceRebuild;
|
||||
buildParameters.PackageName = "DefaultPackage";
|
||||
buildParameters.PackageVersion = "1.0";
|
||||
buildParameters.VerifyBuildingResult = true;
|
||||
buildParameters.SharedPackRule = new ZeroRedundancySharedPackRule();
|
||||
buildParameters.CompressOption = ECompressOption.LZ4;
|
||||
buildParameters.OutputNameStyle = EOutputNameStyle.HashName;
|
||||
buildParameters.CopyBuildinFileOption = ECopyBuildinFileOption.None;
|
||||
|
||||
// 执行构建
|
||||
AssetBundleBuilder builder = new AssetBundleBuilder();
|
||||
var buildResult = builder.Run(buildParameters);
|
||||
if (buildResult.Success)
|
||||
{
|
||||
Debug.Log($"构建成功 : {buildResult.OutputPackageDirectory}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"构建失败 : {buildResult.ErrorInfo}");
|
||||
}
|
||||
}
|
||||
|
||||
// 从构建命令里获取参数示例
|
||||
private static string GetBuildPackageName()
|
||||
{
|
||||
foreach (string arg in System.Environment.GetCommandLineArgs())
|
||||
{
|
||||
if (arg.StartsWith("buildPackage"))
|
||||
return arg.Split("="[0])[1];
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 336706b48f93452ea43f7272872e5451
|
||||
timeCreated: 1698043593
|
69
UnityProject/Assets/TEngine/Editor/Utility/ClassHelper.cs
Normal file
69
UnityProject/Assets/TEngine/Editor/Utility/ClassHelper.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Unity编辑器类帮助类。
|
||||
/// </summary>
|
||||
public static class ClassHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取MonoBehaviour的脚本Id。
|
||||
/// </summary>
|
||||
/// <param name="type">脚本类型。</param>
|
||||
/// <returns>脚本Id。</returns>
|
||||
public static int GetClassID(System.Type type)
|
||||
{
|
||||
GameObject gameObject = EditorUtility.CreateGameObjectWithHideFlags("Temp", HideFlags.HideAndDontSave);
|
||||
Component component = gameObject.AddComponent(type);
|
||||
SerializedObject @class = new SerializedObject(component);
|
||||
int classID = @class.FindProperty("m_Script").objectReferenceInstanceIDValue;
|
||||
Object.DestroyImmediate(gameObject);
|
||||
return classID;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取MonoBehaviour的脚本Id。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">脚本类型。</typeparam>
|
||||
/// <returns>脚本Id。</returns>
|
||||
public static int GetClassID<T>() where T : MonoBehaviour
|
||||
{
|
||||
return GetClassID(typeof(T));
|
||||
}
|
||||
|
||||
#region Method Documentation
|
||||
/************************************************************************************************************
|
||||
Example:
|
||||
[MenuItem("GameObject/UI/转化成CustomText", false, 1999)]
|
||||
public static void ConvertToCustomText(MenuCommand menuCommand)
|
||||
{
|
||||
GameObject go = menuCommand.context as GameObject;
|
||||
if (go != null)
|
||||
{
|
||||
Text text = go.GetComponent<Text>();
|
||||
if (text != null)
|
||||
{
|
||||
var ob = ClassHelper.ReplaceClass(text, typeof(CustomText));
|
||||
ob.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
************************************************************************************************************/
|
||||
#endregion
|
||||
/// <summary>
|
||||
/// 替换MonoBehaviour脚本。
|
||||
/// </summary>
|
||||
/// <param name="monoBehaviour"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
public static SerializedObject ReplaceClass(MonoBehaviour monoBehaviour, System.Type type)
|
||||
{
|
||||
int classID = GetClassID(type);
|
||||
SerializedObject @class = new SerializedObject(monoBehaviour);
|
||||
@class.Update();
|
||||
@class.FindProperty("m_Script").objectReferenceInstanceIDValue = classID;
|
||||
@class.ApplyModifiedProperties();
|
||||
@class.Update();
|
||||
return @class;
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aa5c786315234462bb549c4533d4d858
|
||||
timeCreated: 1698042158
|
120
UnityProject/Assets/TEngine/Editor/Utility/CommandLineReader.cs
Normal file
120
UnityProject/Assets/TEngine/Editor/Utility/CommandLineReader.cs
Normal file
@@ -0,0 +1,120 @@
|
||||
#region Class Documentation
|
||||
/************************************************************************************************************
|
||||
Class Name: CommandLineReader.cs
|
||||
Type: Util, Static
|
||||
Definition:
|
||||
CommandLineReader.cs give the ability to access [Custom Arguments] sent
|
||||
through the command line. Simply add your custom arguments under the
|
||||
keyword '-CustomArgs:' and seperate them by ';'.
|
||||
Example:
|
||||
C:\Program Files (x86)\Unity\Editor\Unity.exe [ProjectLocation] -executeMethod [Your entrypoint] -quit -CustomArgs:Language=en_US;Version=1.02
|
||||
|
||||
Example1:
|
||||
set WORKSPACE=.
|
||||
set UNITYEDITOR_PATH=G:/UnityEditor/2021.3.20f1c1/Editor
|
||||
set LOGFILE=./build.log
|
||||
set BUILDROOT=G:/github/TEngine/UnityProject/Bundles
|
||||
|
||||
%UNITYEDITOR_PATH%/Unity.exe %WORKSPACE%/UnityProject -logFile %LOGFILE% -executeMethod TEngine.ReleaseTools.BuildPackage -quit -batchmode -CustomArgs:Language=en_US;Version=1.02;outputRoot=%BUILDROOT%
|
||||
|
||||
@REM for /f "delims=[" %%i in (%LOGFILE%) do echo %%i
|
||||
|
||||
pause
|
||||
************************************************************************************************************/
|
||||
#endregion
|
||||
|
||||
#region Using
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using Debug = UnityEngine.Debug;
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Unity命令行拓展帮助类。
|
||||
/// <remarks>可以用来制定自己项目的打包、编辑器工作流。</remarks>
|
||||
/// </summary>
|
||||
public class CommandLineReader
|
||||
{
|
||||
//Config
|
||||
private const string CUSTOM_ARGS_PREFIX = "-CustomArgs:";
|
||||
private const char CUSTOM_ARGS_SEPARATOR = ';';
|
||||
|
||||
public static string[] GetCommandLineArgs()
|
||||
{
|
||||
return Environment.GetCommandLineArgs();
|
||||
}
|
||||
|
||||
public static string GetCommandLine()
|
||||
{
|
||||
string[] args = GetCommandLineArgs();
|
||||
|
||||
if (args.Length > 0)
|
||||
{
|
||||
return string.Join(" ", args);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("CommandLineReader.cs - GetCommandLine() - Can't find any command line arguments!");
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static Dictionary<string,string> GetCustomArguments()
|
||||
{
|
||||
Dictionary<string, string> customArgsDict = new Dictionary<string, string>();
|
||||
string[] commandLineArgs = GetCommandLineArgs();
|
||||
string[] customArgs;
|
||||
string[] customArgBuffer;
|
||||
string customArgsStr = "";
|
||||
|
||||
try
|
||||
{
|
||||
customArgsStr = commandLineArgs.Where(row => row.Contains(CUSTOM_ARGS_PREFIX)).Single();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError("CommandLineReader.cs - GetCustomArguments() - Can't retrieve any custom arguments in the command line [" + commandLineArgs + "]. Exception: " + e);
|
||||
return customArgsDict;
|
||||
}
|
||||
|
||||
customArgsStr = customArgsStr.Replace(CUSTOM_ARGS_PREFIX, "");
|
||||
customArgs = customArgsStr.Split(CUSTOM_ARGS_SEPARATOR);
|
||||
|
||||
foreach (string customArg in customArgs)
|
||||
{
|
||||
customArgBuffer = customArg.Split('=');
|
||||
if (customArgBuffer.Length == 2)
|
||||
{
|
||||
customArgsDict.Add(customArgBuffer[0], customArgBuffer[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("CommandLineReader.cs - GetCustomArguments() - The custom argument [" + customArg + "] seem to be malformed.");
|
||||
}
|
||||
}
|
||||
|
||||
return customArgsDict;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取cmd输入的自定义参数数值。
|
||||
/// </summary>
|
||||
/// <param name="argumentName">自定义参数名称。</param>
|
||||
/// <returns>自定义参数数值。</returns>
|
||||
public static string GetCustomArgument(string argumentName)
|
||||
{
|
||||
Dictionary<string, string> customArgsDict = GetCustomArguments();
|
||||
|
||||
if (customArgsDict.TryGetValue(argumentName, out var argument))
|
||||
{
|
||||
return argument;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("CommandLineReader.cs - GetCustomArgument() - Can't retrieve any custom argument named [" + argumentName + "] in the command line [" + GetCommandLine() + "].");
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9f4bc66bca9a460cb714a36a127739e7
|
||||
timeCreated: 1698041943
|
99
UnityProject/Assets/TEngine/Editor/Utility/LogRedirection.cs
Normal file
99
UnityProject/Assets/TEngine/Editor/Utility/LogRedirection.cs
Normal file
@@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Callbacks;
|
||||
using UnityEditorInternal;
|
||||
|
||||
namespace TEngine.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 日志重定向相关的实用函数。
|
||||
/// </summary>
|
||||
internal static class LogRedirection
|
||||
{
|
||||
[OnOpenAsset(0)]
|
||||
private static bool OnOpenAsset(int instanceID, int line)
|
||||
{
|
||||
if (line <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var stackTrace = GetStackTrace();
|
||||
if (!string.IsNullOrEmpty(stackTrace) && (stackTrace.Contains("[Debug]") ||
|
||||
stackTrace.Contains("[INFO]") ||
|
||||
stackTrace.Contains("[ASSERT]") ||
|
||||
stackTrace.Contains("[WARNING]") ||
|
||||
stackTrace.Contains("[ERROR]") ||
|
||||
stackTrace.Contains("[EXCEPTION]")))
|
||||
|
||||
{
|
||||
// 使用正则表达式匹配at的哪个脚本的哪一行
|
||||
var matches = Regex.Match(stackTrace, @"\(at (.+)\)",
|
||||
RegexOptions.IgnoreCase);
|
||||
while (matches.Success)
|
||||
{
|
||||
var pathLine = matches.Groups[1].Value;
|
||||
|
||||
if (!pathLine.Contains("Logger.cs") &&
|
||||
!pathLine.Contains("DefaultLogHelper.cs") &&
|
||||
!pathLine.Contains("GameFrameworkLog.cs") &&
|
||||
!pathLine.Contains("AssetsLogger.cs") &&
|
||||
!pathLine.Contains("Log.cs"))
|
||||
{
|
||||
var splitIndex = pathLine.LastIndexOf(":", StringComparison.Ordinal);
|
||||
// 脚本路径
|
||||
var path = pathLine.Substring(0, splitIndex);
|
||||
// 行号
|
||||
line = Convert.ToInt32(pathLine.Substring(splitIndex + 1));
|
||||
var fullPath = UnityEngine.Application.dataPath.Substring(0, UnityEngine.Application.dataPath.LastIndexOf("Assets", StringComparison.Ordinal));
|
||||
fullPath = $"{fullPath}{path}";
|
||||
// 跳转到目标代码的特定行
|
||||
InternalEditorUtility.OpenFileAtLineExternal(fullPath.Replace('/', '\\'), line);
|
||||
break;
|
||||
}
|
||||
|
||||
matches = matches.NextMatch();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前日志窗口选中的日志的堆栈信息。
|
||||
/// </summary>
|
||||
/// <returns>选中日志的堆栈信息实例。</returns>
|
||||
private static string GetStackTrace()
|
||||
{
|
||||
// 通过反射获取ConsoleWindow类
|
||||
var consoleWindowType = typeof(EditorWindow).Assembly.GetType("UnityEditor.ConsoleWindow");
|
||||
// 获取窗口实例
|
||||
var fieldInfo = consoleWindowType.GetField("ms_ConsoleWindow",
|
||||
BindingFlags.Static |
|
||||
BindingFlags.NonPublic);
|
||||
if (fieldInfo != null)
|
||||
{
|
||||
var consoleInstance = fieldInfo.GetValue(null);
|
||||
if (consoleInstance != null)
|
||||
if (EditorWindow.focusedWindow == (EditorWindow)consoleInstance)
|
||||
{
|
||||
// 获取m_ActiveText成员
|
||||
fieldInfo = consoleWindowType.GetField("m_ActiveText",
|
||||
BindingFlags.Instance |
|
||||
BindingFlags.NonPublic);
|
||||
// 获取m_ActiveText的值
|
||||
if (fieldInfo != null)
|
||||
{
|
||||
var activeText = fieldInfo.GetValue(consoleInstance).ToString();
|
||||
return activeText;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8e219db54fde57a4aae694a55da3e1b1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -4,6 +4,9 @@ using System.Collections.Generic;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
/// <summary>
|
||||
/// Unity编辑器主动执行cmd帮助类。
|
||||
/// </summary>
|
||||
public static class ShellHelper
|
||||
{
|
||||
public static void Run(string cmd, string workDirectory, List<string> environmentVars = null)
|
||||
|
Binary file not shown.
@@ -1,33 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 03804aac55906c846a647bfd1e0b7eca
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
- first:
|
||||
Windows Store Apps: WindowsStoreApps
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -82,6 +82,12 @@ namespace TEngine
|
||||
|
||||
private static LocalizationModule _localization;
|
||||
|
||||
/// <summary>
|
||||
/// 获取场景模块。
|
||||
/// </summary>
|
||||
public static SceneModule Scene => _scene ??= Get<SceneModule>();
|
||||
|
||||
private static SceneModule _scene;
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
|
@@ -165,9 +165,10 @@ namespace TEngine
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
T LoadAsset<T>(string location, bool needInstance) where T : Object;
|
||||
T LoadAsset<T>(string location, bool needInstance, bool needCache = false) where T : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源。
|
||||
@@ -175,18 +176,20 @@ namespace TEngine
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
T LoadAsset<T>(string location, Transform parent, bool needInstance) where T : Object;
|
||||
T LoadAsset<T>(string location, Transform parent, bool needInstance, bool needCache = false) where T : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源。
|
||||
/// </summary>
|
||||
/// <param name="handle">资源操作句柄。</param>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
T LoadAsset<T>(string location, out AssetOperationHandle handle) where T : Object;
|
||||
T LoadAsset<T>(string location, out AssetOperationHandle handle, bool needCache = false) where T : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源。
|
||||
@@ -194,25 +197,28 @@ namespace TEngine
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="handle">资源操作句柄。</param>
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
T LoadAsset<T>(string location, Transform parent, out AssetOperationHandle handle) where T : Object;
|
||||
T LoadAsset<T>(string location, Transform parent, out AssetOperationHandle handle, bool needCache = false) where T : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源并获取句柄。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>同步加载资源句柄。</returns>
|
||||
AssetOperationHandle LoadAssetGetOperation<T>(string location) where T : Object;
|
||||
AssetOperationHandle LoadAssetGetOperation<T>(string location, bool needCache = false) where T : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载资源并获取句柄。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>异步加载资源句柄。</returns>
|
||||
AssetOperationHandle LoadAssetAsyncHandle<T>(string location) where T : Object;
|
||||
AssetOperationHandle LoadAssetAsyncHandle<T>(string location, bool needCache = false) where T : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载子资源对象。
|
||||
@@ -269,17 +275,19 @@ namespace TEngine
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>异步资源实例。</returns>
|
||||
UniTask<T> LoadAssetAsync<T>(string location, CancellationToken cancellationToken = default, bool needInstance = true) where T : Object;
|
||||
UniTask<T> LoadAssetAsync<T>(string location, CancellationToken cancellationToken = default, bool needInstance = true, bool needCache = false) where T : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载游戏物体。
|
||||
/// </summary>
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <returns>异步游戏物体实例。</returns>
|
||||
UniTask<GameObject> LoadGameObjectAsync(string location, CancellationToken cancellationToken = default);
|
||||
UniTask<GameObject> LoadGameObjectAsync(string location, CancellationToken cancellationToken = default, bool needCache = false);
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载游戏物体。
|
||||
@@ -287,8 +295,9 @@ namespace TEngine
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <returns>异步游戏物体实例。</returns>
|
||||
UniTask<GameObject> LoadGameObjectAsync(string location, Transform parent, CancellationToken cancellationToken = default);
|
||||
UniTask<GameObject> LoadGameObjectAsync(string location, Transform parent, CancellationToken cancellationToken = default, bool needCache = false);
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载原生文件。
|
||||
|
@@ -103,7 +103,9 @@ namespace TEngine
|
||||
internal override void Shutdown()
|
||||
{
|
||||
ReleaseAllHandle();
|
||||
YooAssets.Destroy();
|
||||
#if !UNITY_WEBGL
|
||||
YooAssets.Destroy();
|
||||
#endif
|
||||
ResourcePool.Destroy();
|
||||
}
|
||||
|
||||
@@ -204,10 +206,15 @@ namespace TEngine
|
||||
/// 从缓存中获取同步资源句柄。
|
||||
/// </summary>
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">资源类型。</typeparam>
|
||||
/// <returns>资源句柄。</returns>
|
||||
private AssetOperationHandle GetHandleSync<T>(string location) where T : Object
|
||||
private AssetOperationHandle GetHandleSync<T>(string location, bool needCache = false) where T : Object
|
||||
{
|
||||
if (!needCache)
|
||||
{
|
||||
return YooAssets.LoadAssetSync<T>(location);
|
||||
}
|
||||
AssetOperationHandle handle = null;
|
||||
// 尝试从从ARC缓存表取出对象。
|
||||
handle = _arcCacheTable.GetCache(location);
|
||||
@@ -226,10 +233,15 @@ namespace TEngine
|
||||
/// 从缓存中获取异步资源句柄。
|
||||
/// </summary>
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">资源类型。</typeparam>
|
||||
/// <returns>资源句柄。</returns>
|
||||
private AssetOperationHandle GetHandleAsync<T>(string location) where T : Object
|
||||
private AssetOperationHandle GetHandleAsync<T>(string location, bool needCache = false) where T : Object
|
||||
{
|
||||
if (!needCache)
|
||||
{
|
||||
return YooAssets.LoadAssetAsync<T>(location);
|
||||
}
|
||||
AssetOperationHandle handle = null;
|
||||
// 尝试从从ARC缓存表取出对象。
|
||||
handle = _arcCacheTable.GetCache(location);
|
||||
@@ -499,9 +511,10 @@ namespace TEngine
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
public T LoadAsset<T>(string location, bool needInstance = true) where T : Object
|
||||
public T LoadAsset<T>(string location, bool needInstance = true, bool needCache = false) where T : Object
|
||||
{
|
||||
if (string.IsNullOrEmpty(location))
|
||||
{
|
||||
@@ -509,23 +522,27 @@ namespace TEngine
|
||||
return default;
|
||||
}
|
||||
|
||||
AssetOperationHandle handle = GetHandleSync<T>(location);
|
||||
AssetOperationHandle handle = GetHandleSync<T>(location, needCache);
|
||||
|
||||
if (typeof(T) == typeof(GameObject))
|
||||
{
|
||||
if (needInstance)
|
||||
{
|
||||
GameObject ret = handle.InstantiateSync();
|
||||
return ret as T;
|
||||
GameObject gameObject = handle.InstantiateSync();
|
||||
if (!needCache)
|
||||
{
|
||||
AssetReference.BindAssetReference(gameObject, handle, location);
|
||||
}
|
||||
return gameObject as T;
|
||||
}
|
||||
|
||||
return handle.AssetObject as T;
|
||||
}
|
||||
else
|
||||
|
||||
T ret = handle.AssetObject as T;
|
||||
if (!needCache)
|
||||
{
|
||||
T ret = handle.AssetObject as T;
|
||||
return ret;
|
||||
handle.Dispose();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -534,9 +551,10 @@ namespace TEngine
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
public T LoadAsset<T>(string location, Transform parent, bool needInstance = true) where T : Object
|
||||
public T LoadAsset<T>(string location, Transform parent, bool needInstance = true, bool needCache = false) where T : Object
|
||||
{
|
||||
if (string.IsNullOrEmpty(location))
|
||||
{
|
||||
@@ -544,23 +562,27 @@ namespace TEngine
|
||||
return default;
|
||||
}
|
||||
|
||||
AssetOperationHandle handle = GetHandleSync<T>(location);
|
||||
AssetOperationHandle handle = GetHandleSync<T>(location, needCache);
|
||||
|
||||
if (typeof(T) == typeof(GameObject))
|
||||
{
|
||||
if (needInstance)
|
||||
{
|
||||
GameObject ret = handle.InstantiateSync();
|
||||
return ret as T;
|
||||
GameObject gameObject = handle.InstantiateSync(parent);
|
||||
if (!needCache)
|
||||
{
|
||||
AssetReference.BindAssetReference(gameObject, handle, location);
|
||||
}
|
||||
return gameObject as T;
|
||||
}
|
||||
|
||||
return handle.AssetObject as T;
|
||||
}
|
||||
else
|
||||
|
||||
T ret = handle.AssetObject as T;
|
||||
if (!needCache)
|
||||
{
|
||||
T ret = handle.AssetObject as T;
|
||||
return ret;
|
||||
handle.Dispose();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -568,11 +590,12 @@ namespace TEngine
|
||||
/// </summary>
|
||||
/// <param name="handle">资源操作句柄。</param>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
public T LoadAsset<T>(string location, out AssetOperationHandle handle) where T : Object
|
||||
public T LoadAsset<T>(string location, out AssetOperationHandle handle, bool needCache = false) where T : Object
|
||||
{
|
||||
handle = GetHandleSync<T>(location);
|
||||
handle = GetHandleSync<T>(location, needCache);
|
||||
if (string.IsNullOrEmpty(location))
|
||||
{
|
||||
Log.Error("Asset name is invalid.");
|
||||
@@ -581,13 +604,20 @@ namespace TEngine
|
||||
|
||||
if (typeof(T) == typeof(GameObject))
|
||||
{
|
||||
GameObject ret = handle.InstantiateSync();
|
||||
return ret as T;
|
||||
GameObject gameObject = handle.InstantiateSync();
|
||||
if (!needCache)
|
||||
{
|
||||
AssetReference.BindAssetReference(gameObject, handle, location);
|
||||
}
|
||||
return gameObject as T;
|
||||
}
|
||||
else
|
||||
|
||||
T ret = handle.AssetObject as T;
|
||||
if (!needCache)
|
||||
{
|
||||
return handle.AssetObject as T;
|
||||
handle.Dispose();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -595,12 +625,13 @@ namespace TEngine
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="handle">资源操作句柄。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
public T LoadAsset<T>(string location, Transform parent, out AssetOperationHandle handle) where T : Object
|
||||
public T LoadAsset<T>(string location, Transform parent, out AssetOperationHandle handle, bool needCache = false) where T : Object
|
||||
{
|
||||
handle = GetHandleSync<T>(location);
|
||||
handle = GetHandleSync<T>(location, needCache);
|
||||
|
||||
if (string.IsNullOrEmpty(location))
|
||||
{
|
||||
@@ -610,35 +641,44 @@ namespace TEngine
|
||||
|
||||
if (typeof(T) == typeof(GameObject))
|
||||
{
|
||||
GameObject ret = handle.InstantiateSync(parent);
|
||||
return ret as T;
|
||||
GameObject gameObject = handle.InstantiateSync(parent);
|
||||
if (!needCache)
|
||||
{
|
||||
AssetReference.BindAssetReference(gameObject, handle, location);
|
||||
}
|
||||
return gameObject as T;
|
||||
}
|
||||
else
|
||||
|
||||
T ret = handle.AssetObject as T;
|
||||
if (!needCache)
|
||||
{
|
||||
return handle.AssetObject as T;
|
||||
handle.Dispose();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源并获取句柄。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>同步加载资源句柄。</returns>
|
||||
public AssetOperationHandle LoadAssetGetOperation<T>(string location) where T : Object
|
||||
public AssetOperationHandle LoadAssetGetOperation<T>(string location, bool needCache = false) where T : Object
|
||||
{
|
||||
return GetHandleSync<T>(location);
|
||||
return GetHandleSync<T>(location, needCache);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载资源并获取句柄。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>异步加载资源句柄。</returns>
|
||||
public AssetOperationHandle LoadAssetAsyncHandle<T>(string location) where T : Object
|
||||
public AssetOperationHandle LoadAssetAsyncHandle<T>(string location, bool needCache = false) where T : Object
|
||||
{
|
||||
return GetHandleAsync<T>(location);
|
||||
return GetHandleAsync<T>(location, needCache);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -721,10 +761,11 @@ namespace TEngine
|
||||
/// <param name="location">要加载的实例名称。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <returns>资源实实例。</returns>
|
||||
public async UniTask<T> LoadAssetAsync<T>(string location, CancellationToken cancellationToken = default, bool needInstance = true) where T : Object
|
||||
public async UniTask<T> LoadAssetAsync<T>(string location, CancellationToken cancellationToken = default, bool needInstance = true, bool needCache = false) where T : Object
|
||||
{
|
||||
AssetOperationHandle handle = LoadAssetAsyncHandle<T>(location);
|
||||
AssetOperationHandle handle = LoadAssetAsyncHandle<T>(location, needCache);
|
||||
|
||||
bool cancelOrFailed = await handle.ToUniTask().AttachExternalCancellation(cancellationToken).SuppressCancellationThrow();
|
||||
|
||||
@@ -737,16 +778,21 @@ namespace TEngine
|
||||
{
|
||||
if (needInstance)
|
||||
{
|
||||
GameObject ret = handle.InstantiateSync();
|
||||
return ret as T;
|
||||
GameObject gameObject = handle.InstantiateSync();
|
||||
if (!needCache)
|
||||
{
|
||||
AssetReference.BindAssetReference(gameObject, handle, location);
|
||||
}
|
||||
return gameObject as T;
|
||||
}
|
||||
|
||||
return handle.AssetObject as T;
|
||||
}
|
||||
else
|
||||
|
||||
T ret = handle.AssetObject as T;
|
||||
if (!needCache)
|
||||
{
|
||||
return handle.AssetObject as T;
|
||||
handle.Dispose();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -754,10 +800,11 @@ namespace TEngine
|
||||
/// </summary>
|
||||
/// <param name="location">要加载的游戏物体名称。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <returns>异步游戏物体实例。</returns>
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string location, CancellationToken cancellationToken = default)
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string location, CancellationToken cancellationToken = default, bool needCache = false)
|
||||
{
|
||||
AssetOperationHandle handle = LoadAssetAsyncHandle<GameObject>(location);
|
||||
AssetOperationHandle handle = LoadAssetAsyncHandle<GameObject>(location, needCache);
|
||||
|
||||
bool cancelOrFailed = await handle.ToUniTask().AttachExternalCancellation(cancellationToken).SuppressCancellationThrow();
|
||||
|
||||
@@ -766,9 +813,12 @@ namespace TEngine
|
||||
return null;
|
||||
}
|
||||
|
||||
GameObject ret = handle.InstantiateSync();
|
||||
|
||||
return ret;
|
||||
GameObject gameObject = handle.InstantiateSync();
|
||||
if (!needCache)
|
||||
{
|
||||
AssetReference.BindAssetReference(gameObject, handle, location);
|
||||
}
|
||||
return gameObject;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -777,10 +827,11 @@ namespace TEngine
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <returns>异步游戏物体实例。</returns>
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string location, Transform parent, CancellationToken cancellationToken = default)
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string location, Transform parent, CancellationToken cancellationToken = default, bool needCache = false)
|
||||
{
|
||||
GameObject gameObject = await LoadGameObjectAsync(location, cancellationToken);
|
||||
GameObject gameObject = await LoadGameObjectAsync(location, cancellationToken, needCache);
|
||||
if (parent != null)
|
||||
{
|
||||
gameObject.transform.SetParent(parent);
|
||||
|
@@ -449,11 +449,12 @@ namespace TEngine
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
public T LoadAsset<T>(string location, bool needInstance = true) where T : UnityEngine.Object
|
||||
public T LoadAsset<T>(string location, bool needInstance = true, bool needCache = false) where T : UnityEngine.Object
|
||||
{
|
||||
return m_ResourceManager.LoadAsset<T>(location, needInstance);
|
||||
return m_ResourceManager.LoadAsset<T>(location, needInstance, needCache);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -462,11 +463,12 @@ namespace TEngine
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
public T LoadAsset<T>(string location, Transform parent, bool needInstance = true) where T : UnityEngine.Object
|
||||
public T LoadAsset<T>(string location, Transform parent, bool needInstance = true, bool needCache = false) where T : UnityEngine.Object
|
||||
{
|
||||
return m_ResourceManager.LoadAsset<T>(location, parent, needInstance);
|
||||
return m_ResourceManager.LoadAsset<T>(location, parent, needInstance, needCache);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -474,11 +476,12 @@ namespace TEngine
|
||||
/// </summary>
|
||||
/// <param name="handle">资源操作句柄。</param>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
public T LoadAsset<T>(string location, out AssetOperationHandle handle) where T : UnityEngine.Object
|
||||
public T LoadAsset<T>(string location, out AssetOperationHandle handle, bool needCache = false) where T : UnityEngine.Object
|
||||
{
|
||||
return m_ResourceManager.LoadAsset<T>(location, out handle);
|
||||
return m_ResourceManager.LoadAsset<T>(location, out handle, needCache);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -487,11 +490,12 @@ namespace TEngine
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="handle">资源操作句柄。</param>
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
public T LoadAsset<T>(string location, Transform parent, out AssetOperationHandle handle) where T : UnityEngine.Object
|
||||
public T LoadAsset<T>(string location, Transform parent, out AssetOperationHandle handle, bool needCache = false) where T : UnityEngine.Object
|
||||
{
|
||||
return m_ResourceManager.LoadAsset<T>(location, parent, out handle);
|
||||
return m_ResourceManager.LoadAsset<T>(location, parent, out handle, needCache);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -499,10 +503,11 @@ namespace TEngine
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="callback">回调函数。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
public void LoadAssetAsync<T>(string location, Action<AssetOperationHandle> callback = null) where T : UnityEngine.Object
|
||||
public void LoadAssetAsync<T>(string location, Action<AssetOperationHandle> callback = null, bool needCache = false) where T : UnityEngine.Object
|
||||
{
|
||||
AssetOperationHandle handle = m_ResourceManager.LoadAssetAsyncHandle<T>(location);
|
||||
AssetOperationHandle handle = m_ResourceManager.LoadAssetAsyncHandle<T>(location, needCache);
|
||||
|
||||
handle.Completed += callback;
|
||||
}
|
||||
@@ -511,22 +516,24 @@ namespace TEngine
|
||||
/// 同步加载资源并获取句柄。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>同步加载资源句柄。</returns>
|
||||
public AssetOperationHandle LoadAssetGetOperation<T>(string location) where T : UnityEngine.Object
|
||||
public AssetOperationHandle LoadAssetGetOperation<T>(string location, bool needCache = false) where T : UnityEngine.Object
|
||||
{
|
||||
return m_ResourceManager.LoadAssetGetOperation<T>(location);
|
||||
return m_ResourceManager.LoadAssetGetOperation<T>(location, needCache);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载资源并获取句柄。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>异步加载资源句柄。</returns>
|
||||
public AssetOperationHandle LoadAssetAsyncHandle<T>(string location) where T : UnityEngine.Object
|
||||
public AssetOperationHandle LoadAssetAsyncHandle<T>(string location, bool needCache = false) where T : UnityEngine.Object
|
||||
{
|
||||
return m_ResourceManager.LoadAssetAsyncHandle<T>(location);
|
||||
return m_ResourceManager.LoadAssetAsyncHandle<T>(location, needCache);
|
||||
}
|
||||
|
||||
|
||||
@@ -611,11 +618,12 @@ namespace TEngine
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>异步资源实例。</returns>
|
||||
public async UniTask<T> LoadAssetAsync<T>(string location, CancellationToken cancellationToken = default, bool needInstance = true) where T : UnityEngine.Object
|
||||
public async UniTask<T> LoadAssetAsync<T>(string location, CancellationToken cancellationToken = default, bool needInstance = true, bool needCache = false) where T : UnityEngine.Object
|
||||
{
|
||||
return await m_ResourceManager.LoadAssetAsync<T>(location, cancellationToken, needInstance);
|
||||
return await m_ResourceManager.LoadAssetAsync<T>(location, cancellationToken, needInstance, needCache);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -623,10 +631,11 @@ namespace TEngine
|
||||
/// </summary>
|
||||
/// <param name="location">要加载的游戏物体名称。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <returns>异步游戏物体实例。</returns>
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string location, CancellationToken cancellationToken = default)
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string location, CancellationToken cancellationToken = default, bool needCache = false)
|
||||
{
|
||||
return await m_ResourceManager.LoadGameObjectAsync(location, cancellationToken);
|
||||
return await m_ResourceManager.LoadGameObjectAsync(location, cancellationToken, needCache);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -635,10 +644,11 @@ namespace TEngine
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <returns>异步游戏物体实例。</returns>
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string location, Transform parent, CancellationToken cancellationToken = default)
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string location, Transform parent, CancellationToken cancellationToken = default, bool needCache = false)
|
||||
{
|
||||
return await m_ResourceManager.LoadGameObjectAsync(location, parent, cancellationToken);
|
||||
return await m_ResourceManager.LoadGameObjectAsync(location, parent, cancellationToken, needCache);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2c67061fae264c5a861a5bdb257128a2
|
||||
timeCreated: 1697614501
|
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using UnityEngine.SceneManagement;
|
||||
using YooAsset;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
public interface ISceneModule
|
||||
{
|
||||
/// <summary>
|
||||
/// 当前主场景名称。
|
||||
/// </summary>
|
||||
public string CurrentMainSceneName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 加载场景。
|
||||
/// </summary>
|
||||
/// <param name="location">场景的定位地址</param>
|
||||
/// <param name="sceneMode">场景加载模式</param>
|
||||
/// <param name="suspendLoad">加载完毕时是否主动挂起</param>
|
||||
/// <param name="priority">优先级</param>
|
||||
/// <param name="callBack">加载回调。</param>
|
||||
/// <param name="gcCollect">加载主场景是否回收垃圾。</param>
|
||||
public void LoadScene(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, bool suspendLoad = false, int priority = 100,
|
||||
Action<SceneOperationHandle> callBack = null, bool gcCollect = true);
|
||||
|
||||
/// <summary>
|
||||
/// 激活场景(当同时存在多个场景时用于切换激活场景)。
|
||||
/// </summary>
|
||||
/// <param name="location">场景资源定位地址。</param>
|
||||
/// <returns>是否操作成功。</returns>
|
||||
public bool ActivateScene(string location);
|
||||
|
||||
/// <summary>
|
||||
/// 解除场景加载挂起操作。
|
||||
/// </summary>
|
||||
/// <param name="location">场景资源定位地址。</param>
|
||||
/// <returns>是否操作成功。</returns>
|
||||
public bool UnSuspend(string location);
|
||||
|
||||
/// <summary>
|
||||
/// 是否为主场景。
|
||||
/// </summary>
|
||||
/// <param name="location">场景资源定位地址。</param>
|
||||
/// <returns>是否主场景。</returns>
|
||||
public bool IsMainScene(string location);
|
||||
|
||||
/// <summary>
|
||||
/// 异步卸载子场景。
|
||||
/// </summary>
|
||||
/// <param name="location">场景资源定位地址。</param>
|
||||
/// <returns>场景卸载异步操作类。</returns>
|
||||
public UnloadSceneOperation UnloadAsync(string location);
|
||||
|
||||
/// <summary>
|
||||
/// 是否包含场景。
|
||||
/// </summary>
|
||||
/// <param name="location">场景资源定位地址。</param>
|
||||
/// <returns>是否包含场景。</returns>
|
||||
public bool IsContainScene(string location);
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f0b4f7a8db8740098bcb15904587e077
|
||||
timeCreated: 1697614518
|
@@ -0,0 +1,115 @@
|
||||
using System;
|
||||
using UnityEngine.SceneManagement;
|
||||
using YooAsset;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
/// <summary>
|
||||
/// 场景管理模块。
|
||||
/// </summary>
|
||||
public sealed class SceneModule: Module
|
||||
{
|
||||
private ISceneModule _sceneModule;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
RootModule baseComponent = ModuleSystem.GetModule<RootModule>();
|
||||
if (baseComponent == null)
|
||||
{
|
||||
Log.Fatal("Root module is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
_sceneModule = ModuleImpSystem.GetModule<SceneModuleImp>();
|
||||
if (_sceneModule == null)
|
||||
{
|
||||
Log.Fatal("SceneModule is invalid.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 当前主场景名称。
|
||||
/// </summary>
|
||||
public string CurrentMainSceneName => _sceneModule.CurrentMainSceneName;
|
||||
|
||||
/// <summary>
|
||||
/// 加载场景。
|
||||
/// </summary>
|
||||
/// <param name="location">场景的定位地址</param>
|
||||
/// <param name="sceneMode">场景加载模式</param>
|
||||
/// <param name="suspendLoad">加载完毕时是否主动挂起</param>
|
||||
/// <param name="priority">优先级</param>
|
||||
/// <param name="callBack">加载回调。</param>
|
||||
/// <param name="gcCollect">加载主场景是否回收垃圾。</param>
|
||||
public void LoadScene(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, bool suspendLoad = false, int priority = 100,
|
||||
Action<SceneOperationHandle> callBack = null, bool gcCollect = true)
|
||||
{
|
||||
_sceneModule.LoadScene(location, sceneMode, suspendLoad, priority, callBack, gcCollect);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载子场景。
|
||||
/// </summary>
|
||||
/// <param name="location">场景的定位地址</param>
|
||||
/// <param name="suspendLoad">加载完毕时是否主动挂起</param>
|
||||
/// <param name="priority">优先级</param>
|
||||
/// <param name="callBack">加载回调。</param>
|
||||
/// <param name="gcCollect">加载主场景是否回收垃圾。</param>
|
||||
public void LoadSubScene(string location, bool suspendLoad = false, int priority = 100,
|
||||
Action<SceneOperationHandle> callBack = null, bool gcCollect = true)
|
||||
{
|
||||
_sceneModule.LoadScene(location, LoadSceneMode.Additive, suspendLoad, priority, callBack, gcCollect);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 激活场景(当同时存在多个场景时用于切换激活场景)。
|
||||
/// </summary>
|
||||
/// <param name="location">场景资源定位地址。</param>
|
||||
/// <returns>是否操作成功。</returns>
|
||||
public bool ActivateScene(string location)
|
||||
{
|
||||
return _sceneModule.ActivateScene(location);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解除场景加载挂起操作。
|
||||
/// </summary>
|
||||
/// <param name="location">场景资源定位地址。</param>
|
||||
/// <returns>是否操作成功。</returns>
|
||||
public bool UnSuspend(string location)
|
||||
{
|
||||
return _sceneModule.UnSuspend(location);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否为主场景。
|
||||
/// </summary>
|
||||
/// <param name="location">场景资源定位地址。</param>
|
||||
/// <returns>是否主场景。</returns>
|
||||
public bool IsMainScene(string location)
|
||||
{
|
||||
return _sceneModule.IsMainScene(location);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步卸载子场景。
|
||||
/// </summary>
|
||||
/// <param name="location">场景资源定位地址。</param>
|
||||
/// <returns>场景卸载异步操作类。</returns>
|
||||
public UnloadSceneOperation UnloadAsync(string location)
|
||||
{
|
||||
return _sceneModule.UnloadAsync(location);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否包含场景。
|
||||
/// </summary>
|
||||
/// <param name="location">场景资源定位地址。</param>
|
||||
/// <returns>是否包含场景。</returns>
|
||||
public bool IsContainScene(string location)
|
||||
{
|
||||
return _sceneModule.IsContainScene(location);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 86342cc6845c403da1a3f6db507fae9d
|
||||
timeCreated: 1697616931
|
@@ -0,0 +1,188 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.SceneManagement;
|
||||
using YooAsset;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
/// <summary>
|
||||
/// 场景管理器。
|
||||
/// </summary>
|
||||
internal class SceneModuleImp : ModuleImp,ISceneModule
|
||||
{
|
||||
private string _currentMainSceneName = string.Empty;
|
||||
|
||||
private SceneOperationHandle _currentMainScene;
|
||||
|
||||
private readonly Dictionary<string,SceneOperationHandle> _subScenes = new Dictionary<string, SceneOperationHandle>();
|
||||
|
||||
/// <summary>
|
||||
/// 当前主场景名称。
|
||||
/// </summary>
|
||||
public string CurrentMainSceneName => _currentMainSceneName;
|
||||
|
||||
internal override void Shutdown()
|
||||
{
|
||||
var iter = _subScenes.Values.GetEnumerator();
|
||||
while (iter.MoveNext())
|
||||
{
|
||||
SceneOperationHandle subScene = iter.Current;
|
||||
if (subScene != null)
|
||||
{
|
||||
subScene.UnloadAsync();
|
||||
}
|
||||
}
|
||||
iter.Dispose();
|
||||
_subScenes.Clear();
|
||||
_currentMainSceneName = string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载场景。
|
||||
/// </summary>
|
||||
/// <param name="location">场景的定位地址</param>
|
||||
/// <param name="sceneMode">场景加载模式</param>
|
||||
/// <param name="suspendLoad">加载完毕时是否主动挂起</param>
|
||||
/// <param name="priority">优先级</param>
|
||||
/// <param name="callBack">加载回调。</param>
|
||||
/// <param name="gcCollect">加载主场景是否回收垃圾。</param>
|
||||
public void LoadScene(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, bool suspendLoad = false, int priority = 100, Action<SceneOperationHandle> callBack = null,bool gcCollect = true)
|
||||
{
|
||||
if (sceneMode == LoadSceneMode.Additive)
|
||||
{
|
||||
if (_subScenes.ContainsKey(location))
|
||||
{
|
||||
Log.Warning($"Could not load subScene while already loaded. Scene: {location}");
|
||||
return;
|
||||
}
|
||||
var subScene = GameModule.Resource.LoadSceneAsync(location, sceneMode, suspendLoad, priority);
|
||||
|
||||
if (callBack != null)
|
||||
{
|
||||
subScene.Completed += callBack;
|
||||
}
|
||||
_subScenes.Add(location, subScene);
|
||||
}
|
||||
else if(sceneMode == LoadSceneMode.Single)
|
||||
{
|
||||
_currentMainSceneName = location;
|
||||
|
||||
_currentMainScene = GameModule.Resource.LoadSceneAsync(location, sceneMode, suspendLoad, priority);
|
||||
|
||||
if (callBack != null)
|
||||
{
|
||||
_currentMainScene.Completed += callBack;
|
||||
}
|
||||
GameModule.Resource.ForceUnloadUnusedAssets(gcCollect);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 激活场景(当同时存在多个场景时用于切换激活场景)。
|
||||
/// </summary>
|
||||
/// <param name="location">场景资源定位地址。</param>
|
||||
/// <returns>是否操作成功。</returns>
|
||||
public bool ActivateScene(string location)
|
||||
{
|
||||
if (_currentMainSceneName.Equals(location))
|
||||
{
|
||||
if (_currentMainScene != null)
|
||||
{
|
||||
return _currentMainScene.ActivateScene();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
_subScenes.TryGetValue(location, out SceneOperationHandle subScene);
|
||||
if (subScene != null)
|
||||
{
|
||||
return subScene.ActivateScene();
|
||||
}
|
||||
Log.Warning($"IsMainScene invalid location:{location}");
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解除场景加载挂起操作。
|
||||
/// </summary>
|
||||
/// <param name="location">场景资源定位地址。</param>
|
||||
/// <returns>是否操作成功。</returns>
|
||||
public bool UnSuspend(string location)
|
||||
{
|
||||
if (_currentMainSceneName.Equals(location))
|
||||
{
|
||||
if (_currentMainScene != null)
|
||||
{
|
||||
return _currentMainScene.UnSuspend();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
_subScenes.TryGetValue(location, out SceneOperationHandle subScene);
|
||||
if (subScene != null)
|
||||
{
|
||||
return subScene.UnSuspend();
|
||||
}
|
||||
Log.Warning($"IsMainScene invalid location:{location}");
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否为主场景。
|
||||
/// </summary>
|
||||
/// <param name="location">场景资源定位地址。</param>
|
||||
/// <returns>是否主场景。</returns>
|
||||
public bool IsMainScene(string location)
|
||||
{
|
||||
if (_currentMainSceneName.Equals(location))
|
||||
{
|
||||
if (_currentMainScene != null)
|
||||
{
|
||||
return _currentMainScene.IsMainScene();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
_subScenes.TryGetValue(location, out SceneOperationHandle subScene);
|
||||
if (subScene != null)
|
||||
{
|
||||
return subScene.IsMainScene();
|
||||
}
|
||||
Log.Warning($"IsMainScene invalid location:{location}");
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步卸载子场景。
|
||||
/// </summary>
|
||||
/// <param name="location">场景资源定位地址。</param>
|
||||
/// <returns>场景卸载异步操作类。</returns>
|
||||
public UnloadSceneOperation UnloadAsync(string location)
|
||||
{
|
||||
_subScenes.TryGetValue(location, out SceneOperationHandle subScene);
|
||||
if (subScene != null)
|
||||
{
|
||||
if (subScene.SceneObject == default)
|
||||
{
|
||||
Log.Error($"Could not unload Scene while not loaded. Scene: {location}");
|
||||
return null;
|
||||
}
|
||||
_subScenes.Remove(location);
|
||||
return subScene.UnloadAsync();
|
||||
}
|
||||
Log.Warning($"UnloadAsync invalid location:{location}");
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否包含场景。
|
||||
/// </summary>
|
||||
/// <param name="location">场景资源定位地址。</param>
|
||||
/// <returns>是否包含场景。</returns>
|
||||
public bool IsContainScene(string location)
|
||||
{
|
||||
if (_currentMainSceneName.Equals(location))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return _subScenes.TryGetValue(location, out var _);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 67fca5b8a8634d7b9e62c640a4049d02
|
||||
timeCreated: 1697614527
|
@@ -400,7 +400,7 @@ namespace TEngine
|
||||
throw new Exception($"Window {type.FullName} not found {nameof(WindowAttribute)} attribute.");
|
||||
|
||||
string assetName = string.IsNullOrEmpty(attribute.Location) ? type.Name : attribute.Location;
|
||||
window.Init(type.FullName, attribute.WindowLayer, attribute.FullScreen, assetName, attribute.FromResources);
|
||||
window.Init(type.FullName, attribute.WindowLayer, attribute.FullScreen, assetName, attribute.FromResources, attribute.NeedCache);
|
||||
return window;
|
||||
}
|
||||
|
||||
|
@@ -66,6 +66,11 @@ namespace TEngine
|
||||
/// 是内部资源无需AB加载。
|
||||
/// </summary>
|
||||
public bool FromResources { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否需要缓存。
|
||||
/// </summary>
|
||||
public bool NeedCache { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 自定义数据。
|
||||
@@ -221,13 +226,14 @@ namespace TEngine
|
||||
|
||||
#endregion
|
||||
|
||||
public void Init(string name, int layer, bool fullScreen, string assetName, bool fromResources)
|
||||
public void Init(string name, int layer, bool fullScreen, string assetName, bool fromResources, bool needCache = false)
|
||||
{
|
||||
WindowName = name;
|
||||
WindowLayer = layer;
|
||||
FullScreen = fullScreen;
|
||||
AssetName = assetName;
|
||||
FromResources = fromResources;
|
||||
NeedCache = needCache;
|
||||
}
|
||||
|
||||
internal void TryInvoke(System.Action<UIWindow> prepareCallback, System.Object[] userDatas)
|
||||
@@ -249,7 +255,7 @@ namespace TEngine
|
||||
this.userDatas = userDatas;
|
||||
if (!FromResources)
|
||||
{
|
||||
GameModule.Resource.LoadAssetAsync<GameObject>(location, Handle_Completed);
|
||||
GameModule.Resource.LoadAssetAsync<GameObject>(location, Handle_Completed, needCache: NeedCache);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -392,6 +398,10 @@ namespace TEngine
|
||||
|
||||
// 实例化对象
|
||||
var panel = handle.InstantiateSync(UIModule.UIRootStatic);
|
||||
if (!NeedCache)
|
||||
{
|
||||
AssetReference.BindAssetReference(panel, handle, AssetName);
|
||||
}
|
||||
Handle_Completed(panel);
|
||||
}
|
||||
|
||||
|
@@ -37,31 +37,41 @@ namespace TEngine
|
||||
/// </summary>
|
||||
public readonly bool FromResources;
|
||||
|
||||
public WindowAttribute(int windowLayer, string location = "", bool fullScreen = false)
|
||||
/// <summary>
|
||||
/// 需要缓存。
|
||||
/// <remarks>关闭界面不立刻释放资源。</remarks>
|
||||
/// </summary>
|
||||
public readonly bool NeedCache;
|
||||
|
||||
public WindowAttribute(int windowLayer, string location = "", bool fullScreen = false,bool needCache = false)
|
||||
{
|
||||
WindowLayer = windowLayer;
|
||||
Location = location;
|
||||
FullScreen = fullScreen;
|
||||
NeedCache = needCache;
|
||||
}
|
||||
|
||||
public WindowAttribute(UILayer windowLayer, string location = "", bool fullScreen = false)
|
||||
public WindowAttribute(UILayer windowLayer, string location = "", bool fullScreen = false,bool needCache = false)
|
||||
{
|
||||
WindowLayer = (int)windowLayer;
|
||||
Location = location;
|
||||
FullScreen = fullScreen;
|
||||
NeedCache = needCache;
|
||||
}
|
||||
|
||||
public WindowAttribute(UILayer windowLayer, bool fromResources, bool fullScreen = false)
|
||||
public WindowAttribute(UILayer windowLayer, bool fromResources, bool fullScreen = false,bool needCache = false)
|
||||
{
|
||||
WindowLayer = (int)windowLayer;
|
||||
FromResources = fromResources;
|
||||
NeedCache = needCache;
|
||||
}
|
||||
|
||||
public WindowAttribute(UILayer windowLayer, bool fromResources, string location, bool fullScreen = false)
|
||||
public WindowAttribute(UILayer windowLayer, bool fromResources, string location, bool fullScreen = false,bool needCache = false)
|
||||
{
|
||||
WindowLayer = (int)windowLayer;
|
||||
FromResources = fromResources;
|
||||
Location = location;
|
||||
NeedCache = needCache;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user