init
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
//------------------------------------------------------------
|
||||
// Game Framework
|
||||
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
|
||||
// Homepage: https://gameframework.cn/
|
||||
// Feedback: mailto:ellan@gameframework.cn
|
||||
//------------------------------------------------------------
|
||||
|
||||
using GameFramework.DataTable;
|
||||
|
||||
namespace UnityGameFramework.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// 数据表行基类。
|
||||
/// </summary>
|
||||
public abstract class DataRowBase : IDataRow
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取数据表行的编号。
|
||||
/// </summary>
|
||||
public abstract int Id
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析数据表行。
|
||||
/// </summary>
|
||||
/// <param name="dataRowString">要解析的数据表行字符串。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
/// <returns>是否解析数据表行成功。</returns>
|
||||
public virtual bool ParseDataRow(string dataRowString, object userData)
|
||||
{
|
||||
Log.Warning("Not implemented ParseDataRow(string dataRowString, object userData).");
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析数据表行。
|
||||
/// </summary>
|
||||
/// <param name="dataRowBytes">要解析的数据表行二进制流。</param>
|
||||
/// <param name="startIndex">数据表行二进制流的起始位置。</param>
|
||||
/// <param name="length">数据表行二进制流的长度。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
/// <returns>是否解析数据表行成功。</returns>
|
||||
public virtual bool ParseDataRow(byte[] dataRowBytes, int startIndex, int length, object userData)
|
||||
{
|
||||
Log.Warning("Not implemented ParseDataRow(byte[] dataRowBytes, int startIndex, int length, object userData).");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b2e51f0c2dffb5748b75e474971bbe09
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,399 @@
|
||||
//------------------------------------------------------------
|
||||
// Game Framework
|
||||
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
|
||||
// Homepage: https://gameframework.cn/
|
||||
// Feedback: mailto:ellan@gameframework.cn
|
||||
//------------------------------------------------------------
|
||||
|
||||
using GameFramework;
|
||||
using GameFramework.DataTable;
|
||||
using GameFramework.Resource;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityGameFramework.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// 数据表组件。
|
||||
/// </summary>
|
||||
[DisallowMultipleComponent]
|
||||
[AddComponentMenu("Game Framework/Data Table")]
|
||||
public sealed class DataTableComponent : GameFrameworkComponent
|
||||
{
|
||||
private const int DefaultPriority = 0;
|
||||
|
||||
private IDataTableManager m_DataTableManager = null;
|
||||
private EventComponent m_EventComponent = null;
|
||||
|
||||
[SerializeField]
|
||||
private bool m_EnableLoadDataTableUpdateEvent = false;
|
||||
|
||||
[SerializeField]
|
||||
private bool m_EnableLoadDataTableDependencyAssetEvent = false;
|
||||
|
||||
[SerializeField]
|
||||
private string m_DataTableHelperTypeName = "UnityGameFramework.Runtime.DefaultDataTableHelper";
|
||||
|
||||
[SerializeField]
|
||||
private DataTableHelperBase m_CustomDataTableHelper = null;
|
||||
|
||||
[SerializeField]
|
||||
private int m_CachedBytesSize = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 获取数据表数量。
|
||||
/// </summary>
|
||||
public int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_DataTableManager.Count;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取缓冲二进制流的大小。
|
||||
/// </summary>
|
||||
public int CachedBytesSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_DataTableManager.CachedBytesSize;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 游戏框架组件初始化。
|
||||
/// </summary>
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
|
||||
m_DataTableManager = GameFrameworkEntry.GetModule<IDataTableManager>();
|
||||
if (m_DataTableManager == null)
|
||||
{
|
||||
Log.Fatal("Data table manager is invalid.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
BaseComponent baseComponent = GameEntry.GetComponent<BaseComponent>();
|
||||
if (baseComponent == null)
|
||||
{
|
||||
Log.Fatal("Base component is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
m_EventComponent = GameEntry.GetComponent<EventComponent>();
|
||||
if (m_EventComponent == null)
|
||||
{
|
||||
Log.Fatal("Event component is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (baseComponent.EditorResourceMode)
|
||||
{
|
||||
m_DataTableManager.SetResourceManager(baseComponent.EditorResourceHelper);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_DataTableManager.SetResourceManager(GameFrameworkEntry.GetModule<IResourceManager>());
|
||||
}
|
||||
|
||||
DataTableHelperBase dataTableHelper = Helper.CreateHelper(m_DataTableHelperTypeName, m_CustomDataTableHelper);
|
||||
if (dataTableHelper == null)
|
||||
{
|
||||
Log.Error("Can not create data table helper.");
|
||||
return;
|
||||
}
|
||||
|
||||
dataTableHelper.name = "Data Table Helper";
|
||||
Transform transform = dataTableHelper.transform;
|
||||
transform.SetParent(this.transform);
|
||||
transform.localScale = Vector3.one;
|
||||
|
||||
m_DataTableManager.SetDataProviderHelper(dataTableHelper);
|
||||
m_DataTableManager.SetDataTableHelper(dataTableHelper);
|
||||
if (m_CachedBytesSize > 0)
|
||||
{
|
||||
EnsureCachedBytesSize(m_CachedBytesSize);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 确保二进制流缓存分配足够大小的内存并缓存。
|
||||
/// </summary>
|
||||
/// <param name="ensureSize">要确保二进制流缓存分配内存的大小。</param>
|
||||
public void EnsureCachedBytesSize(int ensureSize)
|
||||
{
|
||||
m_DataTableManager.EnsureCachedBytesSize(ensureSize);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放缓存的二进制流。
|
||||
/// </summary>
|
||||
public void FreeCachedBytes()
|
||||
{
|
||||
m_DataTableManager.FreeCachedBytes();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否存在数据表。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">数据表行的类型。</typeparam>
|
||||
/// <returns>是否存在数据表。</returns>
|
||||
public bool HasDataTable<T>() where T : IDataRow
|
||||
{
|
||||
return m_DataTableManager.HasDataTable<T>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否存在数据表。
|
||||
/// </summary>
|
||||
/// <param name="dataRowType">数据表行的类型。</param>
|
||||
/// <returns>是否存在数据表。</returns>
|
||||
public bool HasDataTable(Type dataRowType)
|
||||
{
|
||||
return m_DataTableManager.HasDataTable(dataRowType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否存在数据表。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">数据表行的类型。</typeparam>
|
||||
/// <param name="name">数据表名称。</param>
|
||||
/// <returns>是否存在数据表。</returns>
|
||||
public bool HasDataTable<T>(string name) where T : IDataRow
|
||||
{
|
||||
return m_DataTableManager.HasDataTable<T>(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否存在数据表。
|
||||
/// </summary>
|
||||
/// <param name="dataRowType">数据表行的类型。</param>
|
||||
/// <param name="name">数据表名称。</param>
|
||||
/// <returns>是否存在数据表。</returns>
|
||||
public bool HasDataTable(Type dataRowType, string name)
|
||||
{
|
||||
return m_DataTableManager.HasDataTable(dataRowType, name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取数据表。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">数据表行的类型。</typeparam>
|
||||
/// <returns>要获取的数据表。</returns>
|
||||
public IDataTable<T> GetDataTable<T>() where T : IDataRow
|
||||
{
|
||||
return m_DataTableManager.GetDataTable<T>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取数据表。
|
||||
/// </summary>
|
||||
/// <param name="dataRowType">数据表行的类型。</param>
|
||||
/// <returns>要获取的数据表。</returns>
|
||||
public DataTableBase GetDataTable(Type dataRowType)
|
||||
{
|
||||
return m_DataTableManager.GetDataTable(dataRowType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取数据表。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">数据表行的类型。</typeparam>
|
||||
/// <param name="name">数据表名称。</param>
|
||||
/// <returns>要获取的数据表。</returns>
|
||||
public IDataTable<T> GetDataTable<T>(string name) where T : IDataRow
|
||||
{
|
||||
return m_DataTableManager.GetDataTable<T>(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取数据表。
|
||||
/// </summary>
|
||||
/// <param name="dataRowType">数据表行的类型。</param>
|
||||
/// <param name="name">数据表名称。</param>
|
||||
/// <returns>要获取的数据表。</returns>
|
||||
public DataTableBase GetDataTable(Type dataRowType, string name)
|
||||
{
|
||||
return m_DataTableManager.GetDataTable(dataRowType, name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有数据表。
|
||||
/// </summary>
|
||||
public DataTableBase[] GetAllDataTables()
|
||||
{
|
||||
return m_DataTableManager.GetAllDataTables();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有数据表。
|
||||
/// </summary>
|
||||
/// <param name="results">所有数据表。</param>
|
||||
public void GetAllDataTables(List<DataTableBase> results)
|
||||
{
|
||||
m_DataTableManager.GetAllDataTables(results);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建数据表。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">数据表行的类型。</typeparam>
|
||||
/// <returns>要创建的数据表。</returns>
|
||||
public IDataTable<T> CreateDataTable<T>() where T : class, IDataRow, new()
|
||||
{
|
||||
return CreateDataTable<T>(null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建数据表。
|
||||
/// </summary>
|
||||
/// <param name="dataRowType">数据表行的类型。</param>
|
||||
/// <returns>要创建的数据表。</returns>
|
||||
public DataTableBase CreateDataTable(Type dataRowType)
|
||||
{
|
||||
return CreateDataTable(dataRowType, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建数据表。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">数据表行的类型。</typeparam>
|
||||
/// <param name="name">数据表名称。</param>
|
||||
/// <returns>要创建的数据表。</returns>
|
||||
public IDataTable<T> CreateDataTable<T>(string name) where T : class, IDataRow, new()
|
||||
{
|
||||
IDataTable<T> dataTable = m_DataTableManager.CreateDataTable<T>(name);
|
||||
DataTableBase dataTableBase = (DataTableBase)dataTable;
|
||||
dataTableBase.ReadDataSuccess += OnReadDataSuccess;
|
||||
dataTableBase.ReadDataFailure += OnReadDataFailure;
|
||||
|
||||
if (m_EnableLoadDataTableUpdateEvent)
|
||||
{
|
||||
dataTableBase.ReadDataUpdate += OnReadDataUpdate;
|
||||
}
|
||||
|
||||
if (m_EnableLoadDataTableDependencyAssetEvent)
|
||||
{
|
||||
dataTableBase.ReadDataDependencyAsset += OnReadDataDependencyAsset;
|
||||
}
|
||||
|
||||
return dataTable;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建数据表。
|
||||
/// </summary>
|
||||
/// <param name="dataRowType">数据表行的类型。</param>
|
||||
/// <param name="name">数据表名称。</param>
|
||||
/// <returns>要创建的数据表。</returns>
|
||||
public DataTableBase CreateDataTable(Type dataRowType, string name)
|
||||
{
|
||||
DataTableBase dataTable = m_DataTableManager.CreateDataTable(dataRowType, name);
|
||||
dataTable.ReadDataSuccess += OnReadDataSuccess;
|
||||
dataTable.ReadDataFailure += OnReadDataFailure;
|
||||
|
||||
if (m_EnableLoadDataTableUpdateEvent)
|
||||
{
|
||||
dataTable.ReadDataUpdate += OnReadDataUpdate;
|
||||
}
|
||||
|
||||
if (m_EnableLoadDataTableDependencyAssetEvent)
|
||||
{
|
||||
dataTable.ReadDataDependencyAsset += OnReadDataDependencyAsset;
|
||||
}
|
||||
|
||||
return dataTable;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 销毁数据表。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">数据表行的类型。</typeparam>
|
||||
/// <returns>是否销毁数据表成功。</returns>
|
||||
public bool DestroyDataTable<T>() where T : IDataRow, new()
|
||||
{
|
||||
return m_DataTableManager.DestroyDataTable<T>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 销毁数据表。
|
||||
/// </summary>
|
||||
/// <param name="dataRowType">数据表行的类型。</param>
|
||||
/// <returns>是否销毁数据表成功。</returns>
|
||||
public bool DestroyDataTable(Type dataRowType)
|
||||
{
|
||||
return m_DataTableManager.DestroyDataTable(dataRowType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 销毁数据表。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">数据表行的类型。</typeparam>
|
||||
/// <param name="name">数据表名称。</param>
|
||||
/// <returns>是否销毁数据表成功。</returns>
|
||||
public bool DestroyDataTable<T>(string name) where T : IDataRow
|
||||
{
|
||||
return m_DataTableManager.DestroyDataTable<T>(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 销毁数据表。
|
||||
/// </summary>
|
||||
/// <param name="dataRowType">数据表行的类型。</param>
|
||||
/// <param name="name">数据表名称。</param>
|
||||
/// <returns>是否销毁数据表成功。</returns>
|
||||
public bool DestroyDataTable(Type dataRowType, string name)
|
||||
{
|
||||
return m_DataTableManager.DestroyDataTable(dataRowType, name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 销毁数据表。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">数据表行的类型。</typeparam>
|
||||
/// <param name="dataTable">要销毁的数据表。</param>
|
||||
/// <returns>是否销毁数据表成功。</returns>
|
||||
public bool DestroyDataTable<T>(IDataTable<T> dataTable) where T : IDataRow
|
||||
{
|
||||
return m_DataTableManager.DestroyDataTable(dataTable);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 销毁数据表。
|
||||
/// </summary>
|
||||
/// <param name="dataTable">要销毁的数据表。</param>
|
||||
/// <returns>是否销毁数据表成功。</returns>
|
||||
public bool DestroyDataTable(DataTableBase dataTable)
|
||||
{
|
||||
return m_DataTableManager.DestroyDataTable(dataTable);
|
||||
}
|
||||
|
||||
private void OnReadDataSuccess(object sender, ReadDataSuccessEventArgs e)
|
||||
{
|
||||
m_EventComponent.Fire(this, LoadDataTableSuccessEventArgs.Create(e));
|
||||
}
|
||||
|
||||
private void OnReadDataFailure(object sender, ReadDataFailureEventArgs e)
|
||||
{
|
||||
Log.Warning("Load data table failure, asset name '{0}', error message '{1}'.", e.DataAssetName, e.ErrorMessage);
|
||||
m_EventComponent.Fire(this, LoadDataTableFailureEventArgs.Create(e));
|
||||
}
|
||||
|
||||
private void OnReadDataUpdate(object sender, ReadDataUpdateEventArgs e)
|
||||
{
|
||||
m_EventComponent.Fire(this, LoadDataTableUpdateEventArgs.Create(e));
|
||||
}
|
||||
|
||||
private void OnReadDataDependencyAsset(object sender, ReadDataDependencyAssetEventArgs e)
|
||||
{
|
||||
m_EventComponent.Fire(this, LoadDataTableDependencyAssetEventArgs.Create(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 54066418ab853614483ea44b531049f0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,68 @@
|
||||
//------------------------------------------------------------
|
||||
// Game Framework
|
||||
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
|
||||
// Homepage: https://gameframework.cn/
|
||||
// Feedback: mailto:ellan@gameframework.cn
|
||||
//------------------------------------------------------------
|
||||
|
||||
using GameFramework;
|
||||
using GameFramework.DataTable;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityGameFramework.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// 数据表辅助器基类。
|
||||
/// </summary>
|
||||
public abstract class DataTableHelperBase : MonoBehaviour, IDataProviderHelper<DataTableBase>, IDataTableHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 读取数据表。
|
||||
/// </summary>
|
||||
/// <param name="dataTable">数据表。</param>
|
||||
/// <param name="dataTableAssetName">数据表资源名称。</param>
|
||||
/// <param name="dataTableAsset">数据表资源。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
/// <returns>是否读取数据表成功。</returns>
|
||||
public abstract bool ReadData(DataTableBase dataTable, string dataTableAssetName, object dataTableAsset, object userData);
|
||||
|
||||
/// <summary>
|
||||
/// 读取数据表。
|
||||
/// </summary>
|
||||
/// <param name="dataTable">数据表。</param>
|
||||
/// <param name="dataTableAssetName">数据表资源名称。</param>
|
||||
/// <param name="dataTableBytes">数据表二进制流。</param>
|
||||
/// <param name="startIndex">数据表二进制流的起始位置。</param>
|
||||
/// <param name="length">数据表二进制流的长度。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
/// <returns>是否读取数据表成功。</returns>
|
||||
public abstract bool ReadData(DataTableBase dataTable, string dataTableAssetName, byte[] dataTableBytes, int startIndex, int length, object userData);
|
||||
|
||||
/// <summary>
|
||||
/// 解析数据表。
|
||||
/// </summary>
|
||||
/// <param name="dataTable">数据表。</param>
|
||||
/// <param name="dataTableString">要解析的数据表字符串。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
/// <returns>是否解析数据表成功。</returns>
|
||||
public abstract bool ParseData(DataTableBase dataTable, string dataTableString, object userData);
|
||||
|
||||
/// <summary>
|
||||
/// 解析数据表。
|
||||
/// </summary>
|
||||
/// <param name="dataTable">数据表。</param>
|
||||
/// <param name="dataTableBytes">要解析的数据表二进制流。</param>
|
||||
/// <param name="startIndex">数据表二进制流的起始位置。</param>
|
||||
/// <param name="length">数据表二进制流的长度。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
/// <returns>是否解析数据表成功。</returns>
|
||||
public abstract bool ParseData(DataTableBase dataTable, byte[] dataTableBytes, int startIndex, int length, object userData);
|
||||
|
||||
/// <summary>
|
||||
/// 释放数据表资源。
|
||||
/// </summary>
|
||||
/// <param name="dataTable">数据表。</param>
|
||||
/// <param name="dataTableAsset">要释放的数据表资源。</param>
|
||||
public abstract void ReleaseDataAsset(DataTableBase dataTable, object dataTableAsset);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0c48521d647fac4408f41cca9820ec55
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,171 @@
|
||||
//------------------------------------------------------------
|
||||
// Game Framework
|
||||
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
|
||||
// Homepage: https://gameframework.cn/
|
||||
// Feedback: mailto:ellan@gameframework.cn
|
||||
//------------------------------------------------------------
|
||||
|
||||
using GameFramework;
|
||||
using GameFramework.DataTable;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityGameFramework.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// 默认数据表辅助器。
|
||||
/// </summary>
|
||||
public class DefaultDataTableHelper : DataTableHelperBase
|
||||
{
|
||||
private static readonly string BytesAssetExtension = ".bytes";
|
||||
|
||||
private ResourceComponent m_ResourceComponent = null;
|
||||
|
||||
/// <summary>
|
||||
/// 读取数据表。
|
||||
/// </summary>
|
||||
/// <param name="dataTable">数据表。</param>
|
||||
/// <param name="dataTableAssetName">数据表资源名称。</param>
|
||||
/// <param name="dataTableAsset">数据表资源。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
/// <returns>是否读取数据表成功。</returns>
|
||||
public override bool ReadData(DataTableBase dataTable, string dataTableAssetName, object dataTableAsset, object userData)
|
||||
{
|
||||
TextAsset dataTableTextAsset = dataTableAsset as TextAsset;
|
||||
if (dataTableTextAsset != null)
|
||||
{
|
||||
if (dataTableAssetName.EndsWith(BytesAssetExtension, StringComparison.Ordinal))
|
||||
{
|
||||
return dataTable.ParseData(dataTableTextAsset.bytes, userData);
|
||||
}
|
||||
else
|
||||
{
|
||||
return dataTable.ParseData(dataTableTextAsset.text, userData);
|
||||
}
|
||||
}
|
||||
|
||||
Log.Warning("Data table asset '{0}' is invalid.", dataTableAssetName);
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取数据表。
|
||||
/// </summary>
|
||||
/// <param name="dataTable">数据表。</param>
|
||||
/// <param name="dataTableAssetName">数据表资源名称。</param>
|
||||
/// <param name="dataTableBytes">数据表二进制流。</param>
|
||||
/// <param name="startIndex">数据表二进制流的起始位置。</param>
|
||||
/// <param name="length">数据表二进制流的长度。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
/// <returns>是否读取数据表成功。</returns>
|
||||
public override bool ReadData(DataTableBase dataTable, string dataTableAssetName, byte[] dataTableBytes, int startIndex, int length, object userData)
|
||||
{
|
||||
if (dataTableAssetName.EndsWith(BytesAssetExtension, StringComparison.Ordinal))
|
||||
{
|
||||
return dataTable.ParseData(dataTableBytes, startIndex, length, userData);
|
||||
}
|
||||
else
|
||||
{
|
||||
return dataTable.ParseData(Utility.Converter.GetString(dataTableBytes, startIndex, length), userData);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析数据表。
|
||||
/// </summary>
|
||||
/// <param name="dataTable">数据表。</param>
|
||||
/// <param name="dataTableString">要解析的数据表字符串。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
/// <returns>是否解析数据表成功。</returns>
|
||||
public override bool ParseData(DataTableBase dataTable, string dataTableString, object userData)
|
||||
{
|
||||
try
|
||||
{
|
||||
int position = 0;
|
||||
string dataRowString = null;
|
||||
while ((dataRowString = dataTableString.ReadLine(ref position)) != null)
|
||||
{
|
||||
if (dataRowString[0] == '#')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!dataTable.AddDataRow(dataRowString, userData))
|
||||
{
|
||||
Log.Warning("Can not parse data row string '{0}'.", dataRowString);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Warning("Can not parse data table string with exception '{0}'.", exception);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析数据表。
|
||||
/// </summary>
|
||||
/// <param name="dataTable">数据表。</param>
|
||||
/// <param name="dataTableBytes">要解析的数据表二进制流。</param>
|
||||
/// <param name="startIndex">数据表二进制流的起始位置。</param>
|
||||
/// <param name="length">数据表二进制流的长度。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
/// <returns>是否解析数据表成功。</returns>
|
||||
public override bool ParseData(DataTableBase dataTable, byte[] dataTableBytes, int startIndex, int length, object userData)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (MemoryStream memoryStream = new MemoryStream(dataTableBytes, startIndex, length, false))
|
||||
{
|
||||
using (BinaryReader binaryReader = new BinaryReader(memoryStream, Encoding.UTF8))
|
||||
{
|
||||
while (binaryReader.BaseStream.Position < binaryReader.BaseStream.Length)
|
||||
{
|
||||
int dataRowBytesLength = binaryReader.Read7BitEncodedInt32();
|
||||
if (!dataTable.AddDataRow(dataTableBytes, (int)binaryReader.BaseStream.Position, dataRowBytesLength, userData))
|
||||
{
|
||||
Log.Warning("Can not parse data row bytes.");
|
||||
return false;
|
||||
}
|
||||
|
||||
binaryReader.BaseStream.Position += dataRowBytesLength;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Warning("Can not parse dictionary bytes with exception '{0}'.", exception);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放数据表资源。
|
||||
/// </summary>
|
||||
/// <param name="dataTable">数据表。</param>
|
||||
/// <param name="dataTableAsset">要释放的数据表资源。</param>
|
||||
public override void ReleaseDataAsset(DataTableBase dataTable, object dataTableAsset)
|
||||
{
|
||||
m_ResourceComponent.UnloadAsset(dataTableAsset);
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
m_ResourceComponent = GameEntry.GetComponent<ResourceComponent>();
|
||||
if (m_ResourceComponent == null)
|
||||
{
|
||||
Log.Fatal("Resource component is invalid.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f6a52ac548bf3654a93c12610240a67d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
//------------------------------------------------------------
|
||||
// Game Framework
|
||||
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
|
||||
// Homepage: https://gameframework.cn/
|
||||
// Feedback: mailto:ellan@gameframework.cn
|
||||
//------------------------------------------------------------
|
||||
|
||||
using GameFramework;
|
||||
using GameFramework.Event;
|
||||
|
||||
namespace UnityGameFramework.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// 加载数据表时加载依赖资源事件。
|
||||
/// </summary>
|
||||
public sealed class LoadDataTableDependencyAssetEventArgs : GameEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// 加载数据表时加载依赖资源事件编号。
|
||||
/// </summary>
|
||||
public static readonly int EventId = typeof(LoadDataTableDependencyAssetEventArgs).GetHashCode();
|
||||
|
||||
/// <summary>
|
||||
/// 初始化加载数据表时加载依赖资源事件的新实例。
|
||||
/// </summary>
|
||||
public LoadDataTableDependencyAssetEventArgs()
|
||||
{
|
||||
DataTableAssetName = null;
|
||||
DependencyAssetName = null;
|
||||
LoadedCount = 0;
|
||||
TotalCount = 0;
|
||||
UserData = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取加载数据表时加载依赖资源事件编号。
|
||||
/// </summary>
|
||||
public override int Id
|
||||
{
|
||||
get
|
||||
{
|
||||
return EventId;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取数据表资源名称。
|
||||
/// </summary>
|
||||
public string DataTableAssetName
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取被加载的依赖资源名称。
|
||||
/// </summary>
|
||||
public string DependencyAssetName
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前已加载依赖资源数量。
|
||||
/// </summary>
|
||||
public int LoadedCount
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取总共加载依赖资源数量。
|
||||
/// </summary>
|
||||
public int TotalCount
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户自定义数据。
|
||||
/// </summary>
|
||||
public object UserData
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建加载数据表时加载依赖资源事件。
|
||||
/// </summary>
|
||||
/// <param name="e">内部事件。</param>
|
||||
/// <returns>创建的加载数据表时加载依赖资源事件。</returns>
|
||||
public static LoadDataTableDependencyAssetEventArgs Create(ReadDataDependencyAssetEventArgs e)
|
||||
{
|
||||
LoadDataTableDependencyAssetEventArgs loadDataTableDependencyAssetEventArgs = ReferencePool.Acquire<LoadDataTableDependencyAssetEventArgs>();
|
||||
loadDataTableDependencyAssetEventArgs.DataTableAssetName = e.DataAssetName;
|
||||
loadDataTableDependencyAssetEventArgs.DependencyAssetName = e.DependencyAssetName;
|
||||
loadDataTableDependencyAssetEventArgs.LoadedCount = e.LoadedCount;
|
||||
loadDataTableDependencyAssetEventArgs.TotalCount = e.TotalCount;
|
||||
loadDataTableDependencyAssetEventArgs.UserData = e.UserData;
|
||||
return loadDataTableDependencyAssetEventArgs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理加载数据表时加载依赖资源事件。
|
||||
/// </summary>
|
||||
public override void Clear()
|
||||
{
|
||||
DataTableAssetName = null;
|
||||
DependencyAssetName = null;
|
||||
LoadedCount = 0;
|
||||
TotalCount = 0;
|
||||
UserData = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d55700c511451364c85eca18f23c5e9e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,95 @@
|
||||
//------------------------------------------------------------
|
||||
// Game Framework
|
||||
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
|
||||
// Homepage: https://gameframework.cn/
|
||||
// Feedback: mailto:ellan@gameframework.cn
|
||||
//------------------------------------------------------------
|
||||
|
||||
using GameFramework;
|
||||
using GameFramework.Event;
|
||||
|
||||
namespace UnityGameFramework.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// 加载数据表失败事件。
|
||||
/// </summary>
|
||||
public sealed class LoadDataTableFailureEventArgs : GameEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// 加载数据表失败事件编号。
|
||||
/// </summary>
|
||||
public static readonly int EventId = typeof(LoadDataTableFailureEventArgs).GetHashCode();
|
||||
|
||||
/// <summary>
|
||||
/// 初始化加载数据表失败事件的新实例。
|
||||
/// </summary>
|
||||
public LoadDataTableFailureEventArgs()
|
||||
{
|
||||
DataTableAssetName = null;
|
||||
ErrorMessage = null;
|
||||
UserData = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取加载数据表失败事件编号。
|
||||
/// </summary>
|
||||
public override int Id
|
||||
{
|
||||
get
|
||||
{
|
||||
return EventId;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取数据表资源名称。
|
||||
/// </summary>
|
||||
public string DataTableAssetName
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取错误信息。
|
||||
/// </summary>
|
||||
public string ErrorMessage
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户自定义数据。
|
||||
/// </summary>
|
||||
public object UserData
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建加载数据表失败事件。
|
||||
/// </summary>
|
||||
/// <param name="e">内部事件。</param>
|
||||
/// <returns>创建的加载数据表失败事件。</returns>
|
||||
public static LoadDataTableFailureEventArgs Create(ReadDataFailureEventArgs e)
|
||||
{
|
||||
LoadDataTableFailureEventArgs loadDataTableFailureEventArgs = ReferencePool.Acquire<LoadDataTableFailureEventArgs>();
|
||||
loadDataTableFailureEventArgs.DataTableAssetName = e.DataAssetName;
|
||||
loadDataTableFailureEventArgs.ErrorMessage = e.ErrorMessage;
|
||||
loadDataTableFailureEventArgs.UserData = e.UserData;
|
||||
return loadDataTableFailureEventArgs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理加载数据表失败事件。
|
||||
/// </summary>
|
||||
public override void Clear()
|
||||
{
|
||||
DataTableAssetName = null;
|
||||
ErrorMessage = null;
|
||||
UserData = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7196ee8c6ea2e0c4ebd4825fe6c9dcd1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,95 @@
|
||||
//------------------------------------------------------------
|
||||
// Game Framework
|
||||
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
|
||||
// Homepage: https://gameframework.cn/
|
||||
// Feedback: mailto:ellan@gameframework.cn
|
||||
//------------------------------------------------------------
|
||||
|
||||
using GameFramework;
|
||||
using GameFramework.Event;
|
||||
|
||||
namespace UnityGameFramework.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// 加载数据表成功事件。
|
||||
/// </summary>
|
||||
public sealed class LoadDataTableSuccessEventArgs : GameEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// 加载数据表成功事件编号。
|
||||
/// </summary>
|
||||
public static readonly int EventId = typeof(LoadDataTableSuccessEventArgs).GetHashCode();
|
||||
|
||||
/// <summary>
|
||||
/// 初始化加载数据表成功事件的新实例。
|
||||
/// </summary>
|
||||
public LoadDataTableSuccessEventArgs()
|
||||
{
|
||||
DataTableAssetName = null;
|
||||
Duration = 0f;
|
||||
UserData = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取加载数据表成功事件编号。
|
||||
/// </summary>
|
||||
public override int Id
|
||||
{
|
||||
get
|
||||
{
|
||||
return EventId;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取数据表资源名称。
|
||||
/// </summary>
|
||||
public string DataTableAssetName
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取加载持续时间。
|
||||
/// </summary>
|
||||
public float Duration
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户自定义数据。
|
||||
/// </summary>
|
||||
public object UserData
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建加载数据表成功事件。
|
||||
/// </summary>
|
||||
/// <param name="e">内部事件。</param>
|
||||
/// <returns>创建的加载数据表成功事件。</returns>
|
||||
public static LoadDataTableSuccessEventArgs Create(ReadDataSuccessEventArgs e)
|
||||
{
|
||||
LoadDataTableSuccessEventArgs loadDataTableSuccessEventArgs = ReferencePool.Acquire<LoadDataTableSuccessEventArgs>();
|
||||
loadDataTableSuccessEventArgs.DataTableAssetName = e.DataAssetName;
|
||||
loadDataTableSuccessEventArgs.Duration = e.Duration;
|
||||
loadDataTableSuccessEventArgs.UserData = e.UserData;
|
||||
return loadDataTableSuccessEventArgs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理加载数据表成功事件。
|
||||
/// </summary>
|
||||
public override void Clear()
|
||||
{
|
||||
DataTableAssetName = null;
|
||||
Duration = 0f;
|
||||
UserData = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ed41d1abe08b7754481956fece8dfba4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,95 @@
|
||||
//------------------------------------------------------------
|
||||
// Game Framework
|
||||
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
|
||||
// Homepage: https://gameframework.cn/
|
||||
// Feedback: mailto:ellan@gameframework.cn
|
||||
//------------------------------------------------------------
|
||||
|
||||
using GameFramework;
|
||||
using GameFramework.Event;
|
||||
|
||||
namespace UnityGameFramework.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// 加载数据表更新事件。
|
||||
/// </summary>
|
||||
public sealed class LoadDataTableUpdateEventArgs : GameEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// 加载数据表更新事件编号。
|
||||
/// </summary>
|
||||
public static readonly int EventId = typeof(LoadDataTableUpdateEventArgs).GetHashCode();
|
||||
|
||||
/// <summary>
|
||||
/// 初始化加载数据表更新事件的新实例。
|
||||
/// </summary>
|
||||
public LoadDataTableUpdateEventArgs()
|
||||
{
|
||||
DataTableAssetName = null;
|
||||
Progress = 0f;
|
||||
UserData = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取加载数据表更新事件编号。
|
||||
/// </summary>
|
||||
public override int Id
|
||||
{
|
||||
get
|
||||
{
|
||||
return EventId;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取数据表资源名称。
|
||||
/// </summary>
|
||||
public string DataTableAssetName
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取加载数据表进度。
|
||||
/// </summary>
|
||||
public float Progress
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户自定义数据。
|
||||
/// </summary>
|
||||
public object UserData
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建加载数据表更新事件。
|
||||
/// </summary>
|
||||
/// <param name="e">内部事件。</param>
|
||||
/// <returns>创建的加载数据表更新事件。</returns>
|
||||
public static LoadDataTableUpdateEventArgs Create(ReadDataUpdateEventArgs e)
|
||||
{
|
||||
LoadDataTableUpdateEventArgs loadDataTableUpdateEventArgs = ReferencePool.Acquire<LoadDataTableUpdateEventArgs>();
|
||||
loadDataTableUpdateEventArgs.DataTableAssetName = e.DataAssetName;
|
||||
loadDataTableUpdateEventArgs.Progress = e.Progress;
|
||||
loadDataTableUpdateEventArgs.UserData = e.UserData;
|
||||
return loadDataTableUpdateEventArgs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理加载数据表更新事件。
|
||||
/// </summary>
|
||||
public override void Clear()
|
||||
{
|
||||
DataTableAssetName = null;
|
||||
Progress = 0f;
|
||||
UserData = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 35eba4a8a9ee9954392a0e99aa8111d6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user