1.AB包相关配置
GF资源管理实属牛批,但要使用它,并不是全自动的,还是要配置一下
创建一个静态类,类名随意,注意里面至少要包含以下三个属性,后面的地址所指就是打AB包所必须的三个配置文件(这个地址可以自己更改,注意改变路径就行)
[AssetBundleBuilderConfigPath] public static string AssetBundleBuilderConfig =
Utility.Path.GetCombinePath(Application.dataPath, "GameMain/Configs/AssetBundleBuilder.xml");
[AssetBundleEditorConfigPath] public static string AssetBundleEditorConfig =
Utility.Path.GetCombinePath(Application.dataPath, "GameMain/Configs/AssetBundleEditor.xml");
[AssetBundleCollectionConfigPath] public static string AssetBundleCollectionConfig =
Utility.Path.GetCombinePath(Application.dataPath, "GameMain/Configs/AssetBundleCollection.xml");
其中除了AssetBundleEditor.xml,其余两个都可以在打包的时候自动升成。所以我们要指定目录创建AssetBundleEditor.xml文件,并在里面填入以下信息
其中SourceAssetRootPath是指定资源根目录位置的,自己注意视情况更改
<?xml version="1.0" encoding="UTF-8"?>
<UnityGameFramework>
<AssetBundleEditor>
<Settings>
<SourceAssetRootPath>Assets/GameMain</SourceAssetRootPath>
<SourceAssetSearchPaths>
<SourceAssetSearchPath RelativePath=""/>
</SourceAssetSearchPaths>
<SourceAssetUnionTypeFilter>t:Scene t:Prefab t:Shader t:Model t:Material t:Texture t:AudioClip
t:AnimationClip t:AnimatorController t:Font t:TextAsset t:ScriptableObject
</SourceAssetUnionTypeFilter>
<SourceAssetUnionLabelFilter>l:AssetBundleInclusive</SourceAssetUnionLabelFilter>
<SourceAssetExceptTypeFilter>t:Script</SourceAssetExceptTypeFilter>
<SourceAssetExceptLabelFilter>l:AssetBundleExclusive</SourceAssetExceptLabelFilter>
<AssetSorter>Name</AssetSorter>
</Settings>
</AssetBundleEditor>
</UnityGameFramework>
2.UI模块相关
说实话我没想到使用UI模块会出那么多变故。。。我花了半天时间才找到问题所在。。。
首先要创建并设置一个默认Canvas,因为没有Canvas的支撑,UGUI无法正确显示
再搞一个UGuiGroupHelper
//------------------------------------------------------------
// Author: 烟雨迷离半世殇
// Mail: 1778139321@qq.com
// Data: 2019年1月11日 23:35:22
//------------------------------------------------------------
using UnityEngine;
using UnityEngine.UI;
using UnityGameFramework.Runtime;
namespace GameMain.Scripts.UI
{
public class UGuiGroupHelper : UIGroupHelperBase
{
public const int DepthFactor = 1000;
private int m_Depth = 0;
private Canvas m_CachedCanvas = null;
/// <summary>
/// 设置界面组深度。
/// </summary>
/// <param name="depth">界面组深度。</param>
public override void SetDepth(int depth)
{
m_Depth = depth;
m_CachedCanvas.overrideSorting = true;
m_CachedCanvas.sortingOrder = DepthFactor * depth;
}
private void Awake()
{
m_CachedCanvas = gameObject.GetOrAddComponent<Canvas>();
gameObject.GetOrAddComponent<GraphicRaycaster>();
}
private void Start()
{
m_CachedCanvas.overrideSorting = true;
m_CachedCanvas.sortingOrder = DepthFactor * m_Depth;
RectTransform transform = GetComponent<RectTransform>();
transform.anchorMin = Vector2.zero;
transform.anchorMax = Vector2.one;
transform.anchoredPosition = Vector2.zero;
transform.sizeDelta = Vector2.zero;
}
}
}
按下图所示替换默认的辅助器
然后是UGuiForm
//------------------------------------------------------------
// Author: 烟雨迷离半世殇
// Mail: 1778139321@qq.com
// Data: 2019年1月11日 23:42:05
//------------------------------------------------------------
using UnityEngine;
using UnityEngine.UI;
using UnityGameFramework.Runtime;
namespace GameMain.Scripts.UI
{
public class UGuiForm : UIFormLogic
{
private Canvas m_CachedCanvas = null;
public const int DepthFactor = 100;
public int OriginalDepth
{
get;
private set;
}
public int Depth
{
get
{
return m_CachedCanvas.sortingOrder;
}
}
protected override void OnInit(object userData)
{
base.OnInit(userData);
m_CachedCanvas = gameObject.GetOrAddComponent<Canvas>();
m_CachedCanvas.overrideSorting = true;
OriginalDepth = m_CachedCanvas.sortingOrder;
RectTransform transform = GetComponent<RectTransform>();
transform.anchorMin = Vector2.zero;
transform.anchorMax = Vector2.one;
transform.anchoredPosition = Vector2.zero;
transform.sizeDelta = Vector2.zero;
gameObject.GetOrAddComponent<GraphicRaycaster>();
}
protected override void OnDepthChanged(int uiGroupDepth, int depthInUIGroup)
{
int oldDepth = Depth;
base.OnDepthChanged(uiGroupDepth, depthInUIGroup);
int deltaDepth = UGuiGroupHelper.DepthFactor * uiGroupDepth + DepthFactor * depthInUIGroup - oldDepth +
OriginalDepth;
Canvas[] canvases = GetComponentsInChildren<Canvas>(true);
for (int i = 0; i < canvases.Length; i++)
{
canvases[i].sortingOrder += deltaDepth;
}
}
}
}
每个UIForm都要继承这个类
至此,你做的UI效果,才是你想要的效果。。。
最后,配置表里面的被其他UI遮挡是否会暂停,只会在同一UI Group下面生效
3.配表相关
保存的时候选择-文本文件(制表符分隔)
在Unity中应当能识别其数据
没有的话,就用文本文档打开,另存为UTF-8
4:使用类自动生成工具
先在Scripts下面新建如下
(重要部分E大和我已经打上注释,请注意查看,PS:代码全部为E大所开发,本人只是将自己的理解传达给大家,文件头的Author请自动忽略)
他们依次为
DataTableCodeTemplate.txt
//------------------------------------------------------------
// Game Framework
// Copyright © 2013-2019 Jiang Yin. All rights reserved.
// Homepage: http://gameframework.cn/
// Feedback: mailto:jiangyin@gameframework.cn
//------------------------------------------------------------
// 此文件由工具自动生成,请勿直接修改。
// 生成时间:__DATA_TABLE_CREATE_TIME__
//------------------------------------------------------------
using GameFramework;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using UnityEngine;
using UnityGameFramework.Runtime;
namespace __DATA_TABLE_NAME_SPACE__
{
/// <summary>
/// __DATA_TABLE_COMMENT__
/// </summary>
public class __DATA_TABLE_CLASS_NAME__ : DataRowBase
{
private int m_Id = 0;
/// <summary>
/// __DATA_TABLE_ID_COMMENT__
/// </summary>
public override int Id
{
get
{
return m_Id;
}
}
__DATA_TABLE_PROPERTIES__
__DATA_TABLE_STRING_PARSER__
__DATA_TABLE_BYTES_PARSER__
__DATA_TABLE_STREAM_PARSER__
__DATA_TABLE_PROPERTY_ARRAY__
}
}
//------------------------------------------------------------
// Author: 烟雨迷离半世殇
// Mail: 1778139321@qq.com
// Data: 2019年2月10日
//------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using GameFramework;
using UnityEngine;
using UnityGameFramework.Editor.DataTableTools;
namespace Assets.GameMain.Scripts.DataTable.DataTableGenerator
{
public class DataTableGenerator
{
//数据表(.txt文件所在位置)
private const string DataTablePath = "Assets/GameMain/DataTables";
//生成的CSharp类所在位置
private const string CSharpCodePath = "Assets/GameMain/Scripts/DataTable";
//用于临时存读CSharp代码的txt文件所在位置(如果没有,请创建)
private const string CSharpCodeTemplateFileName = "Assets/GameMain/Configs/DataTableCodeTemplate.txt";
private static readonly Regex EndWithNumberRegex = new Regex(@"\d+$");
private static readonly Regex NameRegex = new Regex(@"^[A-Z][A-Za-z0-9_]+$");
public static DataTableProcessor CreateDataTableProcessor(string dataTableName)
{
return new DataTableProcessor(Utility.Path.GetCombinePath(DataTablePath, dataTableName + ".txt"), Encoding.Default, 1, 2, null, 3, 4, 1);
}
public static bool CheckRawData(DataTableProcessor dataTableProcessor, string dataTableName)
{
for (int i = 0; i < dataTableProcessor.RawColumnCount; i++)
{
string name = dataTableProcessor.GetName(i);
if (string.IsNullOrEmpty(name) || name == "#")
{
continue;
}
if (!NameRegex.IsMatch(name))
{
Debug.LogWarning(Utility.Text.Format("Check raw data failure. DataTableName='{0}' Name='{1}'", dataTableName, name));
return false;
}
}
return true;
}
public static void GenerateDataFile(DataTableProcessor dataTableProcessor, string dataTableName)
{
string binaryDataFileName = Utility.Path.GetCombinePath(DataTablePath, dataTableName + ".bytes");
if (!dataTableProcessor.GenerateDataFile(binaryDataFileName, Encoding.UTF8) && File.Exists(binaryDataFileName))
{
File.Delete(binaryDataFileName);
}
}
public static void GenerateCodeFile(DataTableProcessor dataTableProcessor, string dataTableName)
{
dataTableProcessor.SetCodeTemplate(CSharpCodeTemplateFileName, Encoding.UTF8);
dataTableProcessor.SetCodeGenerator(DataTableCodeGenerator);
string csharpCodeFileName = Utility.Path.GetCombinePath(CSharpCodePath, "DR" + dataTableName + ".cs");
if (!dataTableProcessor.GenerateCodeFile(csharpCodeFileName, Encoding.UTF8, dataTableName) && File.Exists(csharpCodeFileName))
{
File.Delete(csharpCodeFileName);
}
}
private static void DataTableCodeGenerator(DataTableProcessor dataTableProcessor, StringBuilder codeContent, object userData)
{
string dataTableName = (string)userData;
codeContent.Replace("__DATA_TABLE_CREATE_TIME__", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
//所生成的CSharp类的命名空间,请保证它与BinaryReaderExtension.cs和DataTableExtension.cs的命名空间一致,否则将不能正确解析
codeContent.Replace("__DATA_TABLE_NAME_SPACE__", "Assets.GameMain.Scripts.DataTable");
codeContent.Replace("__DATA_TABLE_CLASS_NAME__", "DR" + dataTableName);
codeContent.Replace("__DATA_TABLE_COMMENT__", dataTableProcessor.GetValue(0, 1) + "。");
codeContent.Replace("__DATA_TABLE_ID_COMMENT__", "获取" + dataTableProcessor.GetComment(dataTableProcessor.IdColumn) + "。");
codeContent.Replace("__DATA_TABLE_PROPERTIES__", GenerateDataTableProperties(dataTableProcessor));
codeContent.Replace("__DATA_TABLE_STRING_PARSER__", GenerateDataTableStringParser(dataTableProcessor));
codeContent.Replace("__DATA_TABLE_BYTES_PARSER__", GenerateDataTableBytesParser(dataTableProcessor));
codeContent.Replace("__DATA_TABLE_STREAM_PARSER__", GenerateDataTableStreamParser(dataTableProcessor));
codeContent.Replace("__DATA_TABLE_PROPERTY_ARRAY__", GenerateDataTablePropertyArray(dataTableProcessor));
}
private static string GenerateDataTableProperties(DataTableProcessor dataTableProcessor)
{
StringBuilder stringBuilder = new StringBuilder();
bool firstProperty = true;
for (int i = 0; i < dataTableProcessor.RawColumnCount; i++)
{
if (dataTableProcessor.IsCommentColumn(i))
{
// 注释列
continue;
}
if (dataTableProcessor.IsIdColumn(i))
{
// 编号列
continue;
}
if (firstProperty)
{
firstProperty = false;
}
else
{
stringBuilder.AppendLine().AppendLine();
}
stringBuilder
.AppendLine(" /// <summary>")
.AppendFormat(" /// 获取{0}。", dataTableProcessor.GetComment(i)).AppendLine()
.AppendLine(" /// </summary>")
.AppendFormat(" public {0} {1}", dataTableProcessor.GetLanguageKeyword(i), dataTableProcessor.GetName(i)).AppendLine()
.AppendLine(" {")
.AppendLine(" get;")
.AppendLine(" private set;")
.Append(" }");
}
return stringBuilder.ToString();
}
private static string GenerateDataTableStringParser(DataTableProcessor dataTableProcessor)
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder
.AppendLine(" public override bool ParseDataRow(GameFrameworkSegment<string> dataRowSegment)")
.AppendLine(" {")
.AppendLine(" // Star Force 示例代码,正式项目使用时请调整此处的生成代码,以处理 GCAlloc 问题!")
.AppendLine(" string[] columnTexts = dataRowSegment.Source.Substring(dataRowSegment.Offset, dataRowSegment.Length).Split(DataTableExtension.DataSplitSeparator);")
.AppendLine(" for (int i = 0; i < columnTexts.Length; i++)")
.AppendLine(" {")
.AppendLine(" columnTexts[i] = columnTexts[i].Trim(DataTableExtension.DataTrimSeparator);")
.AppendLine(" }")
.AppendLine()
.AppendLine(" int index = 0;");
for (int i = 0; i < dataTableProcessor.RawColumnCount; i++)
{
if (dataTableProcessor.IsCommentColumn(i))
{
// 注释列
stringBuilder.AppendLine(" index++;");
continue;
}
if (dataTableProcessor.IsIdColumn(i))
{
// 编号列
stringBuilder.AppendLine(" m_Id = int.Parse(columnTexts[index++]);");
continue;
}
if (dataTableProcessor.IsSystem(i))
{
string languageKeyword = dataTableProcessor.GetLanguageKeyword(i);
if (languageKeyword == "string")
{
stringBuilder.AppendFormat(" {0} = columnTexts[index++];", dataTableProcessor.GetName(i)).AppendLine();
}
else
{
stringBuilder.AppendFormat(" {0} = {1}.Parse(columnTexts[index++]);", dataTableProcessor.GetName(i), languageKeyword).AppendLine();
}
}
else
{
stringBuilder.AppendFormat(" {0} = DataTableExtension.Parse{1}(columnTexts[index++]);", dataTableProcessor.GetName(i), dataTableProcessor.GetType(i).Name).AppendLine();
}
}
stringBuilder
.AppendLine()
.AppendLine(" GeneratePropertyArray();")
.AppendLine(" return true;")
.Append(" }");
return stringBuilder.ToString();
}
private static string GenerateDataTableBytesParser(DataTableProcessor dataTableProcessor)
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder
.AppendLine(" public override bool ParseDataRow(GameFrameworkSegment<byte[]> dataRowSegment)")
.AppendLine(" {")
.AppendLine(" // Star Force 示例代码,正式项目使用时请调整此处的生成代码,以处理 GCAlloc 问题!")
.AppendLine(" string[] columnTexts = dataRowSegment.Source.Substring(dataRowSegment.Offset, dataRowSegment.Length).Split(DataTableExtension.DataSplitSeparator);")
.AppendLine(" for (int i = 0; i < columnTexts.Length; i++)")
.AppendLine(" {")
.AppendLine(" columnTexts[i] = columnTexts[i].Trim(DataTableExtension.DataTrimSeparator);")
.AppendLine(" }")
.AppendLine()
.AppendLine(" int index = 0;");
for (int i = 0; i < dataTableProcessor.RawColumnCount; i++)
{
if (dataTableProcessor.IsCommentColumn(i))
{
// 注释列
continue;
}
if (dataTableProcessor.IsIdColumn(i))
{
// 编号列
stringBuilder.AppendLine(" m_Id = binaryReader.ReadInt32();");
continue;
}
stringBuilder.AppendFormat(" {0} = binaryReader.Read{1}();", dataTableProcessor.GetName(i), dataTableProcessor.GetType(i).Name).AppendLine();
}
stringBuilder
.AppendLine(" }")
.AppendLine(" }")
.AppendLine()
.AppendLine(" GeneratePropertyArray();")
.AppendLine(" return true;")
.Append(" }");
return stringBuilder.ToString();
}
private static string GenerateDataTableStreamParser(DataTableProcessor dataTableProcessor)
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder
.AppendLine(" public override bool ParseDataRow(GameFrameworkSegment<Stream> dataRowSegment)")
.AppendLine(" {")
.AppendLine(" Log.Warning(\"Not implemented ParseDataRow(GameFrameworkSegment<Stream>)\");")
.AppendLine(" return false;")
.Append(" }");
return stringBuilder.ToString();
}
private static string GenerateDataTablePropertyArray(DataTableProcessor dataTableProcessor)
{
List<PropertyCollection> propertyCollections = new List<PropertyCollection>();
for (int i = 0; i < dataTableProcessor.RawColumnCount; i++)
{
if (dataTableProcessor.IsCommentColumn(i))
{
// 注释列
continue;
}
if (dataTableProcessor.IsIdColumn(i))
{
// 编号列
continue;
}
string name = dataTableProcessor.GetName(i);
if (!EndWithNumberRegex.IsMatch(name))
{
continue;
}
string propertyCollectionName = EndWithNumberRegex.Replace(name, string.Empty);
int id = int.Parse(EndWithNumberRegex.Match(name).Value);
PropertyCollection propertyCollection = null;
foreach (PropertyCollection pc in propertyCollections)
{
if (pc.Name == propertyCollectionName)
{
propertyCollection = pc;
break;
}
}
if (propertyCollection == null)
{
propertyCollection = new PropertyCollection(propertyCollectionName, dataTableProcessor.GetLanguageKeyword(i));
propertyCollections.Add(propertyCollection);
}
propertyCollection.AddItem(id, name);
}
StringBuilder stringBuilder = new StringBuilder();
bool firstProperty = true;
foreach (PropertyCollection propertyCollection in propertyCollections)
{
if (firstProperty)
{
firstProperty = false;
}
else
{
stringBuilder.AppendLine().AppendLine();
}
stringBuilder
.AppendFormat(" private KeyValuePair<int, {1}>[] m_{0} = null;", propertyCollection.Name, propertyCollection.LanguageKeyword).AppendLine()
.AppendLine()
.AppendFormat(" public int Get{0}(int id)", propertyCollection.Name).AppendLine()
.AppendLine(" {")
.AppendFormat(" foreach (KeyValuePair<int, {1}> i in m_{0})", propertyCollection.Name, propertyCollection.LanguageKeyword).AppendLine()
.AppendLine(" {")
.AppendLine(" if (i.Key == id)")
.AppendLine(" {")
.AppendLine(" return i.Value;")
.AppendLine(" }")
.AppendLine(" }")
.AppendLine()
.AppendFormat(" throw new GameFrameworkException(Utility.Text.Format(\"Get{0} with invalid id '{{0}}'.\", id.ToString()));", propertyCollection.Name).AppendLine()
.AppendLine(" }")
.AppendLine()
.AppendFormat(" public int Get{0}At(int index)", propertyCollection.Name).AppendLine()
.AppendLine(" {")
.AppendFormat(" if (index < 0 || index >= m_{0}.Length)", propertyCollection.Name).AppendLine()
.AppendLine(" {")
.AppendFormat(" throw new GameFrameworkException(Utility.Text.Format(\"Get{0}At with invalid index '{{0}}'.\", index.ToString()));", propertyCollection.Name).AppendLine()
.AppendLine(" }")
.AppendLine()
.AppendFormat(" return m_{0}[index].Value;", propertyCollection.Name).AppendLine()
.Append(" }");
}
if (propertyCollections.Count > 0)
{
stringBuilder.AppendLine().AppendLine();
}
stringBuilder
.AppendLine(" private void GeneratePropertyArray()")
.AppendLine(" {");
firstProperty = true;
foreach (PropertyCollection propertyCollection in propertyCollections)
{
if (firstProperty)
{
firstProperty = false;
}
else
{
stringBuilder.AppendLine().AppendLine();
}
stringBuilder
.AppendFormat(" m_{0} = new KeyValuePair<int, {1}>[]", propertyCollection.Name, propertyCollection.LanguageKeyword).AppendLine()
.AppendLine(" {");
int itemCount = propertyCollection.ItemCount;
for (int i = 0; i < itemCount; i++)
{
KeyValuePair<int, string> item = propertyCollection.GetItem(i);
stringBuilder.AppendFormat(" new KeyValuePair<int, {0}>({1}, {2}),", propertyCollection.LanguageKeyword, item.Key.ToString(), item.Value).AppendLine();
}
stringBuilder.Append(" };");
}
stringBuilder
.AppendLine()
.Append(" }");
return stringBuilder.ToString();
}
private sealed class PropertyCollection
{
private readonly string m_Name;
private readonly string m_LanguageKeyword;
private readonly List<KeyValuePair<int, string>> m_Items;
public PropertyCollection(string name, string languageKeyword)
{
m_Name = name;
m_LanguageKeyword = languageKeyword;
m_Items = new List<KeyValuePair<int, string>>();
}
public string Name
{
get
{
return m_Name;
}
}
public string LanguageKeyword
{
get
{
return m_LanguageKeyword;
}
}
public int ItemCount
{
get
{
return m_Items.Count;
}
}
public KeyValuePair<int, string> GetItem(int index)
{
if (index < 0 || index >= m_Items.Count)
{
throw new GameFrameworkException(Utility.Text.Format("GetItem with invalid index '{0}'.", index.ToString()));
}
return m_Items[index];
}
public void AddItem(int id, string propertyName)
{
m_Items.Add(new KeyValuePair<int, string>(id, propertyName));
}
}
}
}
//------------------------------------------------------------
// Author: 烟雨迷离半世殇
// Mail: 1778139321@qq.com
// Data: 2019年2月10日
//------------------------------------------------------------
using Assets.GameMain.Scripts.Procedure;
using GameFramework;
using UnityEditor;
using UnityEngine;
using UnityGameFramework.Editor.DataTableTools;
namespace Assets.GameMain.Scripts.DataTable.DataTableGenerator
{
public class DataTableGeneratorMenu
{
[MenuItem("DataTableTools/Generate DataTables")]
private static void GenerateDataTables()
{
//所要生成的CSharp类取决于ProcedurePreload.DataTableNames(自己视情况改变)
foreach (string dataTableName in ProcedurePreload.DataTableNames)
{
DataTableProcessor dataTableProcessor = DataTableGenerator.CreateDataTableProcessor(dataTableName);
if (!DataTableGenerator.CheckRawData(dataTableProcessor, dataTableName))
{
Debug.LogError(Utility.Text.Format("Check raw data failure. DataTableName='{0}'", dataTableName));
return;
}
DataTableGenerator.GenerateDataFile(dataTableProcessor, dataTableName);
DataTableGenerator.GenerateCodeFile(dataTableProcessor, dataTableName);
}
AssetDatabase.Refresh();
}
}
}
//------------------------------------------------------------
// Author: 烟雨迷离半世殇
// Mail: 1778139321@qq.com
// Data: 2019年2月10日
//------------------------------------------------------------
using System;
using UnityEngine;
using System.IO;
namespace Assets.GameMain.Scripts.DataTable
{
public static class BinaryReaderExtension
{
public static Color32 ReadColor32(this BinaryReader binaryReader)
{
return new Color32(binaryReader.ReadByte(), binaryReader.ReadByte(), binaryReader.ReadByte(), binaryReader.ReadByte());
}
public static Color ReadColor(this BinaryReader binaryReader)
{
return new Color(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
}
public static DateTime ReadDateTime(this BinaryReader binaryReader)
{
return new DateTime(binaryReader.ReadInt64());
}
public static Quaternion ReadQuaternion(this BinaryReader binaryReader)
{
return new Quaternion(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
}
public static Rect ReadRect(this BinaryReader binaryReader)
{
return new Rect(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
}
public static Vector2 ReadVector2(this BinaryReader binaryReader)
{
return new Vector2(binaryReader.ReadSingle(), binaryReader.ReadSingle());
}
public static Vector3 ReadVector3(this BinaryReader binaryReader)
{
return new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
}
public static Vector4 ReadVector4(this BinaryReader binaryReader)
{
return new Vector4(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
}
}
}
//------------------------------------------------------------
// Author: 烟雨迷离半世殇
// Mail: 1778139321@qq.com
// Data: 2019年1月12日 20:56:31
//------------------------------------------------------------
using GameFramework;
using System;
using Assets.GameMain.Scripts.Definition.Constant;
using GameMain;
using UnityEngine;
using UnityGameFramework.Runtime;
namespace Assets.GameMain.Scripts.DataTable
{
public static class DataTableExtension
{
//CSharp类的前置命名空间
private const string DataRowClassPrefixName = "Assets.GameMain.Scripts.DataTable.DR";
internal const char DataSplitSeparator = '\t';
internal const char DataTrimSeparator = '\"';
public static void LoadDataTable(this DataTableComponent dataTableComponent, string dataTableName,
LoadType loadType, object userData = null)
{
if (string.IsNullOrEmpty(dataTableName))
{
Log.Warning("Data table name is invalid.");
return;
}
string[] splitNames = dataTableName.Split('_');
if (splitNames.Length > 2)
{
Log.Warning("Data table name is invalid.");
return;
}
string dataRowClassName = DataRowClassPrefixName + splitNames[0];
Type dataRowType = Type.GetType(dataRowClassName);
if (dataRowType == null)
{
Log.Warning("Can not get data row type with class name '{0}'.", dataRowClassName);
return;
}
string dataTableNameInType = splitNames.Length > 1 ? splitNames[1] : null;
dataTableComponent.LoadDataTable(dataRowType, dataTableName, dataTableNameInType,
AssetUtility.GetDataTableAsset(dataTableName, loadType), loadType,
Constant.AssetPriority.DataTableAsset, userData);
}
public static Color32 ParseColor32(string value)
{
string[] splitValue = value.Split(',');
return new Color32(byte.Parse(splitValue[0]), byte.Parse(splitValue[1]), byte.Parse(splitValue[2]),
byte.Parse(splitValue[3]));
}
public static Color ParseColor(string value)
{
string[] splitValue = value.Split(',');
return new Color(float.Parse(splitValue[0]), float.Parse(splitValue[1]), float.Parse(splitValue[2]),
float.Parse(splitValue[3]));
}
public static Quaternion ParseQuaternion(string value)
{
string[] splitValue = value.Split(',');
return new Quaternion(float.Parse(splitValue[0]), float.Parse(splitValue[1]), float.Parse(splitValue[2]),
float.Parse(splitValue[3]));
}
public static Rect ParseRect(string value)
{
string[] splitValue = value.Split(',');
return new Rect(float.Parse(splitValue[0]), float.Parse(splitValue[1]), float.Parse(splitValue[2]),
float.Parse(splitValue[3]));
}
public static Vector2 ParseVector2(string value)
{
string[] splitValue = value.Split(',');
return new Vector2(float.Parse(splitValue[0]), float.Parse(splitValue[1]));
}
public static Vector3 ParseVector3(string value)
{
string[] splitValue = value.Split(',');
return new Vector3(float.Parse(splitValue[0]), float.Parse(splitValue[1]), float.Parse(splitValue[2]));
}
public static Vector4 ParseVector4(string value)
{
string[] splitValue = value.Split(',');
return new Vector4(float.Parse(splitValue[0]), float.Parse(splitValue[1]), float.Parse(splitValue[2]),
float.Parse(splitValue[3]));
}
}
}