/// <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)); }
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); }