Skip to content

Commit 457bd3b

Browse files
author
wanderer
committed
DataTable增加Color
1 parent 65f84f1 commit 457bd3b

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

GameFramework/Runtime/DataTable/TableData.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class TableData : IEquatable<TableData>,IEnumerable<TableData>
1717
private string _instanceString;
1818
private Vector2 _instanceVector2;
1919
private Vector3 _instanceVector3;
20+
private Color _instanceColor;
2021

2122
#endregion
2223
#region TableData Typs
@@ -126,6 +127,13 @@ internal TableData SetData(List<TableData> data)
126127
_type=TableDataType.Table_Array;
127128
return this;
128129
}
130+
131+
internal TableData SetData(Color data)
132+
{
133+
_instanceColor=data;
134+
_type=TableDataType.Table_Color;
135+
return this;
136+
}
129137
#endregion
130138

131139
#region IEnumerator
@@ -288,6 +296,12 @@ public static implicit operator TableData (Vector3 data)
288296
TableData tableData = TableDataPool.Get().SetData(data);
289297
return tableData;
290298
}
299+
300+
public static implicit operator TableData (Color data)
301+
{
302+
TableData tableData = TableDataPool.Get().SetData(data);
303+
return tableData;
304+
}
291305
#endregion
292306

293307

@@ -361,6 +375,11 @@ public static explicit operator Vector3 (TableData data)
361375
return data._instanceVector3;
362376
}
363377

378+
public static explicit operator Color32(TableData data)
379+
{
380+
return Color.white;
381+
}
382+
364383
#endregion
365384

366385
}
@@ -378,6 +397,7 @@ public enum TableDataType
378397
Table_Vector2,
379398
Table_Vector3,
380399
Table_Array,
400+
Table_Color,
381401
}
382402

383403

@@ -421,6 +441,9 @@ public static TableData Get(string type,string value)
421441
case "vector3":
422442
tableData.SetData(value.ToVector3());
423443
break;
444+
case "color":
445+
tableData.SetData(value.ToColor());
446+
break;
424447
default:
425448
tableData.SetData(value);
426449
break;

GameFramework/Runtime/Utility/StringExtensions.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,12 @@ public static Vector3 ToVector3(this string value)
6666
return result;
6767
}
6868

69-
69+
public static Color ToColor(this string value)
70+
{
71+
Color result = Color.white;
72+
UnityEngine.ColorUtility.TryParseHtmlString(value.Trim(),out result);
73+
return result;
74+
}
7075

7176
}
7277
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ DataTable为了配置修改不再动态生成或修改对应的序列化的类
1818
* 每一行前面第一列带`#`号代表忽略。前面四行是固定的
1919
* 第一行是配置表的名称;
2020
* 第二行是配置表的键值;
21-
* 第三行为当前列的数据类型,`[bool,int,long,float,double,string,Vector2,Vector3]`,`Vector2`示例`100,100`;
21+
* 第三行为当前列的数据类型,`[bool,int,long,float,double,string,Vector2,Vector3,Color]`,`Vector2`示例`100,100`,`Color`示例`#F0F`或者`#FF00FF`;
2222
* 第四行是每一列的说明。
2323
* 实际数据以第五行,第二列开始,第二列的数据一定为`int`类型的唯一识别`id`
2424
* 最后用excel导出为`Unicode 文本`格式即可。

0 commit comments

Comments
 (0)