/// <summary> /// 添加多个数据到数据表 /// </summary> private static void AddProtosToSet <T>(ProtoSet <T> protoSet, List <Proto> protos) where T : Proto { var array = protoSet.dataArray; protoSet.Init(array.Length + protos.Count); for (int i = 0; i < array.Length; i++) { protoSet.dataArray[i] = array[i]; } for (int i = 0; i < protos.Count; i++) { protoSet.dataArray[array.Length + i] = protos[i] as T; if (protos[i] is ItemProto) { Traverse.Create(protos[i]).Property("index").SetValue(array.Length + i); } if (protos[i] is RecipeProto) { RecipeProto proto = protos[i] as RecipeProto; if (proto.preTech != null) { ArrayAddItem <int>(ref proto.preTech.UnlockRecipes, proto.ID); ArrayAddItem <RecipeProto>(ref proto.preTech.unlockRecipeArray, proto); } } Debug.Log($"[LDBTool]Add {protos[i].ID} {protos[i].Name.Translate()} to {protoSet.GetType().Name}."); } var dataIndices = new Dictionary <int, int>(); for (int i = 0; i < protoSet.dataArray.Length; i++) { protoSet.dataArray[i].sid = protoSet.dataArray[i].SID; dataIndices[protoSet.dataArray[i].ID] = i; } Traverse.Create(protoSet).Field("dataIndices").SetValue(dataIndices); if (protoSet is ProtoSet <StringProto> ) { var nameIndices = Traverse.Create(protoSet).Field("nameIndices").GetValue <Dictionary <string, int> >(); for (int i = array.Length; i < protoSet.dataArray.Length; i++) { nameIndices[protoSet.dataArray[i].Name] = i; } Traverse.Create(protoSet).Field("nameIndices").SetValue(nameIndices); } }
public static void ShowSet <T>(this ProtoSet <T> protoSet) where T : Proto { if (ProtoDataUI.Skin != null) { GUI.skin = ProtoDataUI.Skin.GetSkin(); } GUILayout.BeginHorizontal(GUI.skin.box); Search = GUILayout.TextField(Search, GUILayout.Width(200)); if (needSearch) { SearchLDB(protoSet); } GUILayout.Label($"Page {selectPages[protoSet.GetType()] + 1} / {searchResultList.Count / 100 + 1}", GUILayout.Width(80)); if (GUILayout.Button("-", GUILayout.Width(20))) { selectPages[protoSet.GetType()]--; } if (GUILayout.Button("+", GUILayout.Width(20))) { selectPages[protoSet.GetType()]++; } if (selectPages[protoSet.GetType()] < 0) { selectPages[protoSet.GetType()] = searchResultList.Count / 100; } else if (selectPages[protoSet.GetType()] > searchResultList.Count / 100) { selectPages[protoSet.GetType()] = 0; } GUILayout.EndHorizontal(); GUILayout.BeginVertical(GUI.skin.box); GUILayout.BeginHorizontal(); GUILayout.Label($"index", GUILayout.Width(40)); GUILayout.Label($"ID", GUILayout.Width(40)); GUILayout.Label($"Name"); GUILayout.Label($"TranslateName"); if (SupportsHelper.SupportsRuntimeUnityEditor) { GUILayout.Label($"Show Data", GUILayout.Width(100)); } GUILayout.EndHorizontal(); sv = GUILayout.BeginScrollView(sv); for (int i = selectPages[protoSet.GetType()] * 100; i < Mathf.Min(selectPages[protoSet.GetType()] * 100 + 100, searchResultList.Count); i++) { GUILayout.BeginHorizontal(); GUILayout.Label($"{i}", GUILayout.Width(40)); if (searchResultList[i] != null) { GUILayout.Label($"{searchResultList[i].ID}", GUILayout.Width(40)); GUILayout.Label($"{searchResultList[i].Name}"); GUILayout.Label($"{searchResultList[i].name.Translate()}"); if (SupportsHelper.SupportsRuntimeUnityEditor) { if (GUILayout.Button($"Show Data", GUILayout.Width(100))) { ShowItem item = new ShowItem(searchResultList[i], $"{searchResultList[i].GetType().Name} {searchResultList[i].Name.Translate()}"); RUEHelper.ShowData(item); } } } else { GUILayout.Label("null"); } GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); GUILayout.EndVertical(); }
public static void ShowSet <T>(this ProtoSet <T> protoSet) where T : Proto { if (protoSet.dataArray.Length > 100) { GUILayout.BeginHorizontal(GUI.skin.box); GUILayout.Label($"Page {selectPages[protoSet.GetType()] + 1} / {protoSet.dataArray.Length / 100 + 1}", GUILayout.Width(80)); if (GUILayout.Button("-", GUILayout.Width(20))) { selectPages[protoSet.GetType()]--; } if (GUILayout.Button("+", GUILayout.Width(20))) { selectPages[protoSet.GetType()]++; } if (selectPages[protoSet.GetType()] < 0) { selectPages[protoSet.GetType()] = protoSet.dataArray.Length / 100; } else if (selectPages[protoSet.GetType()] > protoSet.dataArray.Length / 100) { selectPages[protoSet.GetType()] = 0; } GUILayout.EndHorizontal(); } GUILayout.BeginHorizontal(GUI.skin.box); GUILayout.Label($"index", GUILayout.Width(40)); GUILayout.Label($"ID", GUILayout.Width(40)); GUILayout.Label($"Name"); GUILayout.Label($"TranslateName"); if (SupportsHelper.SupportsRuntimeUnityEditor) { GUILayout.Label($"Show Data", GUILayout.Width(100)); } GUILayout.EndHorizontal(); sv = GUILayout.BeginScrollView(sv, GUI.skin.box); for (int i = selectPages[protoSet.GetType()] * 100; i < Mathf.Min(selectPages[protoSet.GetType()] * 100 + 100, protoSet.dataArray.Length); i++) { GUILayout.BeginHorizontal(); GUILayout.Label($"{i}", GUILayout.Width(40)); if (protoSet.dataArray[i] != null) { GUILayout.Label($"{protoSet.dataArray[i].ID}", GUILayout.Width(40)); GUILayout.Label($"{protoSet.dataArray[i].Name}"); GUILayout.Label($"{protoSet.dataArray[i].name.Translate()}"); if (SupportsHelper.SupportsRuntimeUnityEditor) { if (GUILayout.Button($"Show Data", GUILayout.Width(100))) { ShowItem item = new ShowItem(protoSet.dataArray[i], $"{protoSet.dataArray[i].GetType().Name} {protoSet.dataArray[i].name.Translate()}"); RUEHelper.ShowData(item); } } } else { GUILayout.Label("null"); } GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); }
/// <summary> /// Add list contains to ProtoSet /// </summary> private static void AddProtosToSet <T>(ProtoSet <T> protoSet, List <Proto> protos) where T : Proto { var array = protoSet.dataArray; protoSet.Init(array.Length + protos.Count); for (int i = 0; i < array.Length; i++) { protoSet.dataArray[i] = array[i]; } for (int i = 0; i < protos.Count; i++) { protoSet.dataArray[array.Length + i] = protos[i] as T; if (protos[i] is ItemProto item) { item.index = array.Length + i; } if (protos[i] is RecipeProto) { RecipeProto proto = protos[i] as RecipeProto; if (proto.preTech != null) { ArrayAddItem(ref proto.preTech.UnlockRecipes, proto.ID); ArrayAddItem(ref proto.preTech.unlockRecipeArray, proto); } } LDBToolPlugin.logger.LogInfo($"Add {protos[i].ID} {protos[i].Name.Translate()} to {protoSet.GetType().Name}."); } var dataIndices = new Dictionary <int, int>(); for (int i = 0; i < protoSet.dataArray.Length; i++) { protoSet.dataArray[i].sid = protoSet.dataArray[i].SID; dataIndices[protoSet.dataArray[i].ID] = i; } protoSet.dataIndices = dataIndices; if (protoSet is StringProtoSet stringProtoSet) { for (int i = array.Length; i < protoSet.dataArray.Length; i++) { stringProtoSet.nameIndices[protoSet.dataArray[i].Name] = i; } } }