/// <summary> /// 建立 Scriptable Asset /// </summary> /// <returns>是否成功建立</returns> public bool CreateScriptableAssets(string scriptableScriptName, string scriptableAssetName) { _config = ClientDataBaseManager.Instance.m_config; MonoScript script = AssetDatabase.LoadAssetAtPath <MonoScript>(_config.GetScriptableScriptsPath() + scriptableScriptName); if (script == null || script.GetClass() == null) { Debug.LogError(string.Format("Scriptable Script is Null. [Path:{0}]", _config.GetScriptableScriptsPath() + scriptableScriptName)); return(false); } string path = _config.GetScriptableAssetPath() + scriptableAssetName; UtilityEditor.CreateFolder(_config.GetScriptableAssetPath()); Object _Object = ScriptableObject.CreateInstance(script.GetClass()); AssetDatabase.CreateAsset(_Object, path); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport); Debug.Log(string.Format("[Scriptable Asset] is Create.\nFile:[{0}] Path:[{1}]", scriptableAssetName, _config.GetScriptableAssetPath())); //資料讀取 ScriptableObjectBase scriptableObjectBase = AssetDatabase.LoadAssetAtPath <ScriptableObjectBase>(path); return(scriptableObjectBase.LoadGameTable(true)); }
public bool Check <T>(ScriptableObjectBase table, ICollection <T> values, string keyFieldName) where T : TableClassBase { string tableName = table.GetTableName(); // 是否有自定义策略 return(customCheckers[tableName].Check(table, values, keyFieldName)); }
public bool Validate(Type fieldType, string value) { ScriptableObjectBase t = ClientDataBaseManager.Get().LoadTable(tableName); if (t == null) { return(false); } return(t.CheckField(fieldName, value)); }
void UpdateAsset() { foreach (Object go in _objList) { ScriptableObjectBase script = (ScriptableObjectBase)go; if (script.LoadGameTable(true) == false) { continue; } } _boolStartCreate = false; }
/// <summary> /// 把csv的内容保存为asset格式的 /// </summary> /// <param name="csvFileName"></param> /// <param name="csvContent"></param> /// <returns></returns> public static ScriptableObjectBase SaveScriptableAsset(string csvFileName, string csvContent) { ScriptableObjectBase obj = CreateScriptableAsset(csvFileName); if (obj == null) { return(null); } if (!obj.LoadGameTable(csvContent)) { return(null); } EditorUtility.SetDirty(obj); AssetDatabase.SaveAssets(); return(obj); }
public void Check <T>(ScriptableObjectBase table, ICollection <T> values, string keyFieldName = null) where T : TableClassBase { if (values.Count == 0) { return; } string tableName = table.GetTableName(); foreach (var oneStrategy in strategies) { if (oneStrategy.Contains(tableName)) { oneStrategy.Check(table, values, keyFieldName); break; } } }
public static ScriptableObjectBase CreateScriptableAsset( string scriptableScriptName, string scriptableAssetName) { var config = ClientDataBaseManager.Instance.m_config; MonoScript script = AssetDatabase.LoadAssetAtPath <MonoScript>(config.GetScriptableScriptsPath() + scriptableScriptName); if (script == null || script.GetClass() == null) { Debug.LogError( string.Format( "Scriptable Script is Null. [Path:{0}]", config.GetScriptableScriptsPath() + scriptableScriptName)); return(null); } string path = config.GetScriptableAssetPath() + scriptableAssetName; CreateFolder(config.GetScriptableAssetPath()); Object obj = ScriptableObject.CreateInstance(script.GetClass()); AssetDatabase.CreateAsset(obj, path); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport); Debug.Log( string.Format( "[Scriptable Asset] is Create.\nFile:[{0}] Path:[{1}]", scriptableAssetName, config.GetScriptableAssetPath())); //資料讀取 ScriptableObjectBase scriptableObjectBase = AssetDatabase.LoadAssetAtPath <ScriptableObjectBase>(path); return(scriptableObjectBase); }
public bool Check <T>(ScriptableObjectBase table, ICollection <T> values, string keyFieldName) where T : TableClassBase { // 是否这个table的配置检测 string tableName = table.GetTableName(); var tableConfig = GetTableConfig(tableName); if (tableConfig == null) { return(true); } bool success = true; // ValidateXmlConfig已经做过提示了, 所以这里只做数据验证提示 foreach (var fieldConfig in tableConfig.FieldCheckConfigs) { string fieldName = Utility.TypeRelate.CorrectFieldName(fieldConfig.FieldName); // 是否有该字段的属性 var propertyInfo = typeof(T).GetProperty(fieldName); if (propertyInfo == null) { continue; } foreach (var fieldValidater in fieldConfig.ValidateConfigs) { // 是否存在验证node var validateNode = fieldValidater.ToValidateNode(); if (validateNode == null) { continue; } // 验证约束 if (!validateNode.Constraint(propertyInfo.PropertyType)) { continue; } bool keyExist = !string.IsNullOrEmpty(keyFieldName); int row = 1; foreach (var oneValue in values) { string val = propertyInfo.GetValue(oneValue, null).ToString(); if (!validateNode.Validate(propertyInfo.PropertyType, val)) { if (keyExist) { string keyValue = oneValue.GetPropertyValue(keyFieldName).ToString(); Debug.LogError( string.Format( "#TableCheck# 表格[{0}]主键为[{1}({2})]行[{3}]列的值[{4}]不能通过[{5}]验证 ", tableName, keyFieldName, keyValue, fieldName, val, validateNode.GetDesc())); } else { Debug.LogError( string.Format( "#TableCheck# 表格[{0}]第[{1}]行[{2}]列的值[{3}]不能通过[{4}]验证 ", tableName, row.ToString(), fieldName, val, validateNode.GetDesc())); } } row++; } success = false; } } return(success); }
public bool Check <T>(ScriptableObjectBase table, ICollection <T> values, string keyFieldName) where T : TableClassBase { return(false); }