Skip to content

Commit

Permalink
SKCell v0.12.1 Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Skyrim07 committed Sep 17, 2023
1 parent 2fc5201 commit e107c44
Show file tree
Hide file tree
Showing 58 changed files with 2,981 additions and 408 deletions.
1 change: 0 additions & 1 deletion Assets/SKCell/CSV/Editor/CSVParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public class CSVParser : Editor

private static Dictionary<string, List<List<string>>> _tables = new Dictionary<string, List<List<string>>>();

private static DirectoryInfo TheFolder = new DirectoryInfo("Table/");
private static Regex _tableNameRegex = new Regex(@"\(([^>])+\)");

[MenuItem("SKCell/Build CSV Files")]
Expand Down
5 changes: 1 addition & 4 deletions Assets/SKCell/CSV/SKCSVLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ protected override void Awake()

private const string CSVPATH = "CSV";

/// <summary>
/// 添加CSV表.
/// </summary>
public void LoadTable()
{
List<string> tableList = new List<string>();
Expand All @@ -34,7 +31,7 @@ public void LoadTable()
}
}
CommonUtils.EditorLogNormal("CSV Table count:" + tableList.Count);
TableAgent.instance.Add(tableList);
SKCSVReader.instance.Add(tableList);
}
}
}
2 changes: 1 addition & 1 deletion Assets/SKCell/CSV/SKCSVLoader.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

103 changes: 57 additions & 46 deletions Assets/SKCell/CSV/TableAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,12 @@
using UnityEngine;
namespace SKCell
{
/// <summary>
/// 配置表代理
/// </summary>
public class TableAgent : Singleton<TableAgent>
public class SKCSVReader : Singleton<SKCSVReader>
{
private Dictionary<string, Dictionary<TableKey, string>> _tableAgent;

private Dictionary<string, List<string>> _keys;

/// <summary>
/// 加载多个CSV文件
/// </summary>
/// <param name="tables">The tables.</param>
public void Add(List<string> tables)
{
if (_tableAgent == null)
Expand All @@ -43,14 +36,6 @@ public void Add(List<string> tables)
}
}

/// <summary>
/// 添加单个条目
/// </summary>
/// <typeparam name="T">添加的值类型</typeparam>
/// <param name="name">表名称.</param>
/// <param name="key1">键1.</param>
/// <param name="key2">键2</param>
/// <param name="value">值</param>
public void Add<T>(string name, string key1, string key2, T value)
{
if (_tableAgent == null)
Expand All @@ -74,11 +59,11 @@ public void Add<T>(string name, string key1, string key2, T value)
}

/// <summary>
/// 获取字符串值
/// Get a string value from csv file
/// </summary>
/// <param name="name">The index.</param>
/// <param name="key1">The horizontal key.</param>
/// <param name="key2">The vertical key.</param>
/// <param name="name">The index. (upper-left corner)</param>
/// <param name="key1">The row key.</param>
/// <param name="key2">The column key.</param>
/// <returns></returns>
public string GetString(string name, string key1, string key2)
{
Expand All @@ -93,23 +78,40 @@ public string GetString(string name, string key1, string key2)
}

/// <summary>
/// 获取浮点值
/// Get a float value from csv file
/// </summary>
/// <param name="name">The index.</param>
/// <param name="key1">The horizontal key.</param>
/// <param name="key2">The vertical key.</param>
/// <param name="name">The index. (upper-left corner)</param>
/// <param name="key1">The row key.</param>
/// <param name="key2">The column key.</param>
/// <returns></returns>
public float GetFloat(string name, string key1, string key2)
{
return float.Parse(_tableAgent[name][new TableKey(key1, key2)]);
}
/// <summary>
/// Get floats separated by '|'
/// </summary>
/// <param name="name">The index. (upper-left corner)</param>
/// <param name="key1">The row key.</param>
/// <param name="key2">The column key.</param>
/// <returns></returns>
public float[] GetFloats(string name, string key1, string key2)
{
string[] strs = _tableAgent[name][new TableKey(key1, key2)].Split('|');
float[] result = new float[strs.Length];
for (int i = 0; i < strs.Length; i++)
{
result[i] = float.Parse(strs[i]);
}
return result;
}

/// <summary>
/// 获取整数值
/// Get a int value from csv file
/// </summary>
/// <param name="name">The index.</param>
/// <param name="key1">The key1.</param>
/// <param name="key2">The key2.</param>
/// <param name="name">The index. (upper-left corner)</param>
/// <param name="key1">The row key.</param>
/// <param name="key2">The column key.</param>
/// <returns></returns>
public int GetInt(string name, string key1, string key2)
{
Expand All @@ -128,21 +130,39 @@ public int GetInt(string name, string key1, string key2)
}

/// <summary>
/// 获取分隔字符串
/// Get ints separated by '|'
/// </summary>
/// <param name="name">The index.</param>
/// <param name="key1">The key1.</param>
/// <param name="key2">The key2.</param>
/// <param name="name">The index. (upper-left corner)</param>
/// <param name="key1">The row key.</param>
/// <param name="key2">The column key.</param>
/// <returns></returns>
public int[] GetInts(string name, string key1, string key2)
{
string[] strs = _tableAgent[name][new TableKey(key1, key2)].Split('|');
int[] result = new int[strs.Length];
for (int i = 0; i < strs.Length; i++)
{
result[i] = int.Parse(strs[i]);
}
return result;
}

/// <summary>
/// Get string values splitted by '|' from csv file
/// </summary>
/// <param name="name">The index. (upper-left corner)</param>
/// <param name="key1">The row key.</param>
/// <param name="key2">The column key.</param>
/// <returns></returns>
public string[] GetStrings(string name, string key1, string key2)
{
return (_tableAgent[name][new TableKey(key1, key2)]).Split('|');
}

/// <summary>
/// 获取所有Key1值
/// Get all row keys from csv file
/// </summary>
/// <param name="name">The name.</param>
/// <param name="name">The index. (upper-left corner)</param>
/// <returns></returns>
public List<string> CollectKey1(string name)
{
Expand All @@ -159,14 +179,11 @@ public List<string> CollectKey1(string name)
/// <returns>转换后的字符串</returns>
public static string TransformString(string des, Func<string, string> trs)
{
//第一个不是<<>>
List<string> secList = SecStrings(des);
if (secList == null)
{
return des;
}

//替换所有下标为单数的.
for (int i = 1; i < secList.Count; i += 2)
{
secList[i] = trs(secList[i]);
Expand Down Expand Up @@ -195,9 +212,9 @@ private static List<string> SecStrings(string des)
return null;
}

string str1 = des.Substring(0, match.Index); //第一段.
string str3 = des.Substring(match.Index + match.Length); //第三段
string str2 = des.Substring(match.Index + 2, match.Length - 4); //第二段
string str1 = des.Substring(0, match.Index);
string str3 = des.Substring(match.Index + match.Length);
string str2 = des.Substring(match.Index + 2, match.Length - 4);
secList.Add(str1);
secList.Add(str2);
List<string> subList = SecStrings(str3);
Expand All @@ -219,18 +236,12 @@ private static List<string> SecStrings(string des)
return secList;
}

/// <summary>
/// 清除操作,用于测试
/// </summary>
public void Clear()
{
_tableAgent.Clear();
}
}

/// <summary>
/// 表格键值对结构
/// </summary>
public struct TableKey
{
public string Key1;
Expand Down
66 changes: 48 additions & 18 deletions Assets/SKCell/Common/CommonUtils.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//------------------------------------------------------------
// SKCell - Unity Framework & Utilitiies
// Copyright © 2019-2022 Pincun (Alex) Liu. All rights reserved.
// Copyright © 2019-2023 Pincun (Alex) Liu. All rights reserved.
//------------------------------------------------------------

using System;
Expand Down Expand Up @@ -1071,7 +1071,7 @@ public static double GetSecondsSince(DateTime since, DateTime now)

#region CoroutineUtils
/// <summary>
/// Invokes an action after time seconds, then repeatedly every repeatInterval seconds, stopping at repeatCount times.
/// Invokes an action after time seconds, then repeatedly every repeatInterval seconds, stopping at repeatCount times. Using unscaled time.
/// </summary>
/// <param name="seconds"></param>
/// <param name="callback"></param>
Expand Down Expand Up @@ -1165,7 +1165,22 @@ public static Coroutine StartProcedure(SKCurve curve, float time, Action<float>
}
return cr;
}

/// <summary>
/// Starts a continuous procedure where a variable changes from 0 to 1 over time. Tweening.
/// </summary>
/// <param name="curve">Curve of the procedure.</param>
/// <param name="action">Action called per frame.</param>
/// <param name="onFinish">Action called at the end of the procedure.</param>
/// <param name="id"></param>
public static Coroutine StartProcedureUnscaled(SKCurve curve, float time, Action<float> action, Action<float> onFinish = null, string id = "")
{
Coroutine cr = StartCoroutine(ProcedureCRUnscaled(curve, 0, 1, time, action, onFinish), true);
if (id.Length > 0)
{
InsertOrUpdateKeyValueInDictionary(procedureDict, id, cr);
}
return cr;
}
/// <summary>
/// [Legacy] Starts a continuous procedure where a variable changes over time. Tweening.
/// </summary>
Expand Down Expand Up @@ -1230,26 +1245,41 @@ private static IEnumerator ProcedureCR(ProcedureType type, float startValue, flo
if (onFinish != null)
onFinish.Invoke(variable);
}

static WaitForFixedUpdate waitFixedUpdate = new WaitForFixedUpdate();
private static IEnumerator ProcedureCR(SKCurve curve, float startValue, float endValue, float timeParam, Action<float> action, Action<float> onFinish)
{
float step = timeParam / Time.fixedDeltaTime;
float diff = endValue - startValue;
float variable;
for (int i = 0; i <= step; i++)
for (int i = 0; i < step; i++)
{
variable = startValue + (SKCurveSampler.SampleCurve(curve, i / step)) * diff;
if (action != null)
action.Invoke(variable);
action?.Invoke(variable);

yield return new WaitForFixedUpdate();
yield return waitFixedUpdate;
}
variable = curve.curveDir==CurveDir.In? endValue:startValue;
if (action != null)
action.Invoke(variable);
if (onFinish != null)
onFinish.Invoke(variable);
variable = curve.curveDir == CurveDir.In ? endValue : startValue;
action?.Invoke(variable);
onFinish?.Invoke(variable);
}
static WaitForSecondsRealtime waitTick = new WaitForSecondsRealtime(0.015f);
private static IEnumerator ProcedureCRUnscaled(SKCurve curve, float startValue, float endValue, float timeParam, Action<float> action, Action<float> onFinish)
{
float step = timeParam / 0.015f;
float diff = endValue - startValue;
float variable;
for (int i = 0; i < step; i++)
{
variable = startValue + (SKCurveSampler.SampleCurve(curve, i / step)) * diff;
action?.Invoke(variable);

yield return new WaitForSecondsRealtime(0.015f); ;
}
variable = curve.curveDir == CurveDir.In ? endValue : startValue;
action?.Invoke(variable);
onFinish?.Invoke(variable);
}
/// <summary>
/// Starts a coroutine.
/// </summary>
Expand All @@ -1267,8 +1297,8 @@ public static Coroutine StartCoroutine(IEnumerator cr, bool allowMultipleInstanc
}
InsertOrUpdateKeyValueInDictionary(crDict, nameof(cr), cr);
}
if(id.Length>0)
InsertOrUpdateKeyValueInDictionary(crDict, id, cr);
if (id.Length > 0)
InsertOrUpdateKeyValueInDictionary(crDict, id, cr);
return SKCommonTimer.instance.StartCoroutine(cr);
}

Expand Down Expand Up @@ -1341,7 +1371,7 @@ public static void RefreshSelection(GameObject toSelect)
/// <returns></returns>
public static T[] Serialize2DArray<T>(T[,] arr)
{

int length1 = arr.GetLength(0);
int length2 = arr.GetLength(1);
T[] res = new T[length1 * length2];
Expand Down Expand Up @@ -1393,7 +1423,7 @@ public static T[] ModifyArray<T>(T[] arr, int length)
}
return res;
}

/// <summary>
/// Modify the length of an array. Existing data will be preserved.
/// </summary>
Expand Down Expand Up @@ -1981,7 +2011,7 @@ public static void BubbleSort(IList<int> list)
{
if (list[j] > list[j + 1])
{
SwapValueInArray(list, j, j+1);
SwapValueInArray(list, j, j + 1);
flag = false;
}
}
Expand Down Expand Up @@ -2911,7 +2941,7 @@ public static float ColorLuminance(Color c)
{
return c.r * 0.2125f + c.g * 0.7154f + c.b * 0.0721f;
}

#endregion
}

Expand Down
10 changes: 6 additions & 4 deletions Assets/SKCell/Common/SKAssetLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,16 @@ public static SKFontAsset FontAsset
{
get
{
//if (fontAsset == null)
fontAsset = Resources.Load<SKFontAsset>("SKCell/SKFontAsset");
if(fontAsset!=null)
return fontAsset;
#if UNITY_EDITOR
if (fontAsset == null)
fontAsset = AssetDatabase.LoadAssetAtPath<SKFontAsset>(FONT_ASSET_PATH);
#endif

if (fontAsset == null)
fontAsset = Resources.Load<SKFontAsset>(FONT_ASSET_PATH.Substring(FONT_ASSET_PATH.IndexOf("SKCell")));
return fontAsset;
#endif
return null;
}
}
private static Font defaultFont;
Expand Down
Loading

0 comments on commit e107c44

Please sign in to comment.