/// <summary> /// 插入数据 /// </summary> /// <param name="tableName"></param> /// <param name="itemData"></param> public bool BaseInsertData <T>(string tableName, T itemData) { //插入数据 Dictionary <string, object> mapData = ReflexUtil.GetAllNameAndValue(itemData); List <string> listKeys = new List <string>(); List <string> listValues = new List <string>(); foreach (var item in mapData) { string itemKey = item.Key; string valueStr = Convert.ToString(item.Value); listKeys.Add(item.Key); if (item.Value == null) { listValues.Add("null"); } else if (item.Value is string) { if (valueStr.IsNull()) { listValues.Add("null"); } else { listValues.Add("'" + valueStr + "'"); } } else { listValues.Add(valueStr); } } return(SQLiteHandle.InsertValues(ProjectConfigInfo.DATA_BASE_INFO_NAME, tableName, listKeys.ToArray(), listValues.ToArray())); }
/// <summary> /// 替换规则 /// </summary> /// <param name="scripteContent"></param> /// <param name="fileName"></param> /// <returns></returns> protected static Dictionary <string, string> ReplaceRole(string className) { //这里实现自定义的一些规则 Dictionary <string, string> dicReplaceData = new Dictionary <string, string>(); dicReplaceData.Add("#ClassName#", className); Dictionary <string, Component> dicSelect = HierarchySelect.dicSelectObj; StringBuilder content = new StringBuilder(); //获取基类 GameObject objSelect = Selection.activeGameObject; BaseMonoBehaviour uiComponent = objSelect.GetComponent <BaseMonoBehaviour>(); Dictionary <string, Type> dicBaseTypes = ReflexUtil.GetAllNameAndTypeFromBase(uiComponent); foreach (var itemSelect in dicSelect) { if (itemSelect.Value == null) { continue; } Type type = itemSelect.Value.GetType(); //如果基类里面已经有了这个属性,则不再添加 if (dicBaseTypes.ContainsKey($"ui_{itemSelect.Key}")) { continue; } content.Append(" public " + type.Name + " ui_" + itemSelect.Key + ";\r\n\r\n"); } dicReplaceData.Add("#PropertyList#", content.ToString()); return(dicReplaceData); }
/// <summary> /// 处理 设置UI的值 /// </summary> public void HandleForSetUICompontData() { GameObject objSelect = Selection.activeGameObject; if (objSelect == null) { return; } BaseMonoBehaviour uiComponent = objSelect.GetComponent <BaseMonoBehaviour>(); Dictionary <string, object> dicData = ReflexUtil.GetAllNameAndValue(uiComponent); foreach (var itemData in dicData) { string itemKey = itemData.Key; object itemValue = itemData.Value; if (itemKey.Contains("ui_")) { //获取选中的控件 Dictionary <string, Component> dicSelect = HierarchySelect.dicSelectObj; //对比选中的控件和属性名字是否一样 if (dicSelect.TryGetValue(itemKey.Replace("ui_", ""), out Component itemComponent)) { ReflexUtil.SetValueByName(uiComponent, itemKey, itemComponent); } } } Undo.RecordObject(objSelect, objSelect.gameObject.name); EditorUtility.SetDirty(objSelect); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); }
private void Awake() { aiForCharacterPath = CptUtil.AddCpt <AIForCharacterPathAuto>(gameObject); characterAnim = GetComponent <CharacterAnimCpt>(); AutoLinkHandler(); ReflexUtil.AutoLinkDataForChild(this, "transform_"); }
private void Awake() { ReflexUtil.AutoLinkDataForChild(this, "tf_"); AutoLinkManager(); AutoLinkHandler(); shipAnim = gameObject.AddComponent <ShipAnimCpt>(); shipAnim.InitAnim(); }
/// <summary> /// 获取注册的方块形状 /// </summary> /// <param name="blockShapeEnum"></param> /// <returns></returns> public BlockShape GetRegisterBlockShape(BlockShapeEnum blockShapeEnum) { string blockShapeName = blockShapeEnum.GetEnumName(); //通过反射获取类 BlockShape blockShape = ReflexUtil.CreateInstance <BlockShape>($"BlockShape{blockShapeName}"); if (blockShape == null) { blockShape = new BlockShape(); } return(blockShape); }
/// <summary> /// 读取表数据 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="dbName"></param> /// <param name="mainTable"></param> /// <param name="leftTableName"></param> /// <param name="mainKey"></param> /// <param name="leftKey"></param> /// <param name="mainColNames"></param> /// <param name="mainOperations"></param> /// <param name="mainColValues"></param> /// <returns></returns> public static List <T> LoadTableData <T>(string dbName, string mainTable, string[] leftTableName, string mainKey, string[] leftKey, string[] mainColNames, string[] mainOperations, string[] mainColValues) { SQLiteHelper sql = GetSQLiteHelper(dbName); SqliteDataReader reader = null; List <T> listData = new List <T>(); try { T tempData = Activator.CreateInstance <T>(); List <String> dataNameList = ReflexUtil.getAllName(tempData); reader = sql.ReadTable(mainTable, leftTableName, mainKey, leftKey, mainColNames, mainOperations, mainColValues); while (reader.Read()) { T itemData = Activator.CreateInstance <T>(); int dataNameSize = dataNameList.Count; for (int i = 0; i < dataNameSize; i++) { string dataName = dataNameList[i]; int ordinal = reader.GetOrdinal(dataName); if (ordinal == -1) { continue; } string name = reader.GetName(ordinal); object value = reader.GetValue(ordinal); if (value != null && !value.ToString().Equals("")) { ReflexUtil.setValueByName(itemData, dataName, value); } } listData.Add(itemData); } return(listData); } catch (Exception e) { LogUtil.log("查询表失败-" + e.Message); return(null); } finally { if (sql != null) { sql.CloseConnection(); } if (reader != null) { reader.Close(); } } }
/// <summary> /// 视窗改变 /// </summary> private static void OnHierarchyChanged() { if (!EditorUtil.CheckIsPrefabMode(out var prefabStage)) { return; } dicSelectObj.Clear(); baseUIComponent = null; baseUIView = null; GameObject root = prefabStage.prefabContentsRoot; baseUIComponent = root.GetComponent <BaseUIComponent>(); baseUIView = root.GetComponent <BaseUIView>(); if (baseUIComponent == null && baseUIView == null) { return; } //设置初始化数据 Dictionary <string, Type> dicData = null; if (baseUIComponent != null) { dicData = ReflexUtil.GetAllNameAndType(baseUIComponent); } if (baseUIView != null) { dicData = ReflexUtil.GetAllNameAndType(baseUIView); } foreach (var itemData in dicData) { string itemKey = itemData.Key; Type itemValue = itemData.Value; if (itemKey.Contains("ui_")) { string componentName = itemKey.Replace("ui_", ""); if (itemValue != null) { Component[] listRootComponent = root.GetComponentsInChildren(itemValue); foreach (Component itemRootComponent in listRootComponent) { if (itemRootComponent.name.Equals(componentName)) { dicSelectObj.Add(componentName, itemRootComponent); } } } } } return; }
public void HandleForSceneInt(StoryInfoDetailsBean itemData) { try { //场景物体互动 GameObject objFind = GameObject.Find(itemData.scene_intobj_name); //参数 List <string> listparameter = StringUtil.SplitBySubstringForListStr(itemData.scene_intcomponent_parameters, ','); //通过反射调取方法 ReflexUtil.GetInvokeMethod(objFind, itemData.scene_intcomponent_name, itemData.scene_intcomponent_method, listparameter); } catch { } }
/// <summary> /// 注册所有方块 /// </summary> public void RegisterBlock() { List <BlockTypeEnum> listBlockType = EnumExtension.GetEnumValue <BlockTypeEnum>(); for (int i = 0; i < listBlockType.Count; i++) { BlockTypeEnum blockType = listBlockType[i]; //获取方块数据 BlockInfoBean blockInfo = GetBlockInfo(blockType); string blockTypeName = EnumExtension.GetEnumName(blockType); //通过反射获取类 Block block = ReflexUtil.CreateInstance <Block>($"BlockType{blockTypeName}"); if (block == null) { block = new Block(); } block.SetData(blockType); block.blockInfo = blockInfo; arrayBlockRegister[(int)blockType] = block; } }
/// <summary> /// 初始化意图 /// </summary> /// <typeparam name="I"></typeparam> public virtual void InitIntent <E>() where E : System.Enum { List <E> listIntent = EnumExtension.GetEnumValue <E>(); for (int i = 0; i < listIntent.Count; i++) { E itemIntent = listIntent[i]; string intentName = itemIntent.GetEnumName(); string classNameTitle = itemIntent.GetType().Name.Replace("Enum", ""); string className = $"{classNameTitle}{intentName}"; //首先获取类池里面是否有这个意图 if (!dicIntentPool.TryGetValue(className, out AIBaseIntent intentClass)) { intentClass = ReflexUtil.CreateInstance <AIBaseIntent>(className); } if (intentClass != null) { intentClass.InitData(itemIntent, this); AddIntent(intentClass); } } }
public WWWForm dataToWWWForm() { WWWForm form = new WWWForm(); Dictionary <string, object> listData = ReflexUtil.getAllNameAndValue(this); if (listData != null) { foreach (string key in listData.Keys) { object value = listData[key]; if (value == null) { continue; } if (value is bool) { if ((bool)value) { form.AddField(key, "1"); } else { form.AddField(key, "0"); } } else if (value is string) { form.AddField(key, (string)value); } else { string valueStr = Convert.ToString(value); form.AddField(key, valueStr); } } } return(form); }
public string dataToUrlStr() { StringBuilder urlStr = new StringBuilder("?"); Dictionary <string, object> listData = ReflexUtil.getAllNameAndValue(this); if (listData != null) { foreach (string key in listData.Keys) { object value = listData[key]; if (value == null) { continue; } if (value is bool) { if ((bool)value) { urlStr.Append(key + "=" + "1" + "&"); } else { urlStr.Append(key + "=" + "0" + "&"); } } else if (value is string) { urlStr.Append(key + "=" + (string)value + "&"); } else { string valueStr = Convert.ToString(value); urlStr.Append(key + "=" + valueStr + "&"); } } } return(urlStr.ToString()); }
/// <summary> /// 链表插入数据 /// </summary> /// <param name="itemData"></param> /// <param name="listLeftName"></param> public bool BaseInsertDataWithLeft <T>(T itemData, List <string> listLeftName) { //插入数据 Dictionary <string, object> mapData = ReflexUtil.GetAllNameAndValue(itemData); List <string> listMainKeys = new List <string>(); List <string> listMainValues = new List <string>(); List <string> listLeftKeys = new List <string>(); List <string> listLeftValues = new List <string>(); foreach (var item in mapData) { string itemKey = item.Key; if (listLeftName.Contains(itemKey)) { string valueStr = Convert.ToString(item.Value); listLeftKeys.Add(item.Key); if (item.Value == null) { listLeftValues.Add("null"); } else if (item.Value is string) { if (valueStr.IsNull()) { listLeftValues.Add("null"); } else { listLeftValues.Add("'" + valueStr + "'"); } } else if (item.Value == null) { listLeftValues.Add("null"); } else { listLeftValues.Add(valueStr); } } else { string valueStr = Convert.ToString(item.Value); listMainKeys.Add(item.Key); if (item.Value == null) { listMainValues.Add("null"); } else if (item.Value is string) { if (valueStr.IsNull()) { listMainValues.Add("null"); } else { listMainValues.Add("'" + valueStr + "'"); } } else if (item.Value == null) { listMainValues.Add("null"); } else { listMainValues.Add(valueStr); } } } bool isInsert = true; isInsert = SQLiteHandle.InsertValues(ProjectConfigInfo.DATA_BASE_INFO_NAME, tableNameForMain, listMainKeys.ToArray(), listMainValues.ToArray()); if (isInsert) { SQLiteHandle.InsertValues(ProjectConfigInfo.DATA_BASE_INFO_NAME, tableNameForLeft, listLeftKeys.ToArray(), listMainValues.ToArray()); } return(isInsert); }
private void Awake() { ReflexUtil.AutoLinkDataForChild(this, "tf_"); }