public void Initialize(IGoogleSpreadsheetClient client) { Reset(); _client = client; _spreadsheetData = client.SpreadsheetData; foreach (var importer in importers.Concat <ISpreadsheetTriggerAssetsHandler>(serializabledImporters)) { importer.Initialize(client); importer.ExportCommand. Where(x => x.CanExport). Do(x => ExportSheets(Export(_spreadsheetData, x))). Subscribe(). AddTo(LifeTime); importer.ImportCommand. Where(x => x.CanImport). Do(x => { if (autoReloadSpreadsheetOnImport) { _client.ReloadAll(); } }). Do(x => Import(_spreadsheetData, x)). Subscribe(). AddTo(LifeTime); } LifeTime.AddCleanUpAction(() => _client = null); LifeTime.AddCleanUpAction(() => _spreadsheetData = null); }
public bool UpdateSheetValue(object source, ISpreadsheetData data, string sheetId = "", string sheetKeyField = "") { if (source == null) { return(false); } var type = source.GetType(); var syncScheme = type.CreateSheetScheme(); var keyField = string.IsNullOrEmpty(sheetKeyField) ? syncScheme.keyField : syncScheme.GetFieldBySheetFieldName(sheetKeyField); if (keyField == null) { return(false); } var sheetValueInfo = new SheetValueInfo { Source = source, SpreadsheetData = data, SyncScheme = syncScheme, SyncFieldName = sheetKeyField, SheetName = sheetId }; return(UpdateSheetValue(sheetValueInfo)); }
public static object ApplySpreadsheetData( this object asset, ISpreadsheetData spreadsheetData, string sheetName, object keyValue = null, string sheetFieldName = "") { if (spreadsheetData.HasSheet(sheetName) == false) { return(asset); } var syncAsset = asset.CreateSheetScheme(); var sheetValueIndo = new SheetValueInfo { Source = asset, SheetName = sheetName, SpreadsheetData = spreadsheetData, SyncScheme = syncAsset, SyncFieldName = sheetFieldName, SyncFieldValue = keyValue, StartColumn = 0 }; return(DefaultProcessor.ApplyData(sheetValueIndo)); }
/// <summary> /// Sync folder assets by spreadsheet data /// </summary> /// <param name="filterType"></param> /// <param name="assets"></param> /// <param name="folder"></param> /// <param name="createMissing">if true - create missing assets</param> /// <param name="spreadsheetData"></param> /// <param name="maxItemsCount"></param> /// <param name="overrideSheetId">force override target sheet id</param> /// <returns></returns> public List <Object> SyncFolderAssets( Type filterType, string folder, ISpreadsheetData spreadsheetData, Object[] assets = null, bool createMissing = true, int maxItemsCount = -1, string overrideSheetId = "") { var result = assets != null ? new List <Object>(assets) : new List <Object>(); if (!filterType.IsScriptableObject() && !filterType.IsComponent()) { Debug.LogError($"SyncFolderAssets: BAD target type {filterType}"); return(result); } var syncScheme = filterType.CreateSheetScheme(); var sheetId = string.IsNullOrEmpty(overrideSheetId) ? syncScheme.sheetId : overrideSheetId; var sheet = spreadsheetData[sheetId]; if (sheet == null) { Debug.LogWarning($"{nameof(AssetSheetDataProcessor)} Missing Sheet with name {sheetId}"); return(result); } var keyField = syncScheme.keyField; if (keyField == null) { Debug.LogWarning($"{nameof(AssetSheetDataProcessor)} Key field missing sheet = {sheetId}"); return(result); } var keysId = keyField.sheetField; var column = sheet.GetColumn(keysId); if (column == null) { Debug.LogWarning($"{nameof(AssetSheetDataProcessor)} Keys line missing with id = {keysId}"); return(result); } var updatedItems = ApplyAssets( filterType, sheetId, folder, syncScheme, spreadsheetData, sheet.GetColumnValues(keysId).ToArray(), assets, maxItemsCount, createMissing); result.AddRange(updatedItems); return(result); }
public static List <Object> SyncFolderAssets( this Type type, string folder, bool createMissing, ISpreadsheetData spreadsheetData) { return(DefaultProcessor.SyncFolderAssets(type, folder, createMissing, spreadsheetData)); }
public override ISpreadsheetData ExportObjects(IEnumerable <object> source, ISpreadsheetData data) { foreach (var importer in source.OfType <ISpreadsheetAssetsExporter>().Where(x => x.CanExport)) { importer.Export(data); } return(data); }
public ISpreadsheetData Export(ISpreadsheetData data) { foreach (var importer in Importers.Where(x => x.CanExport)) { Export(data, importer); } return(data); }
public ISpreadsheetData ExportSheets(ISpreadsheetData data) { var sheets = data.Sheets.ToList(); foreach (var sheetData in sheets.Where(sheetData => sheetData.IsChanged)) { _client.Upload(sheetData); } return(data); }
public static List <Object> SyncFolderAssets( this Type filterType, string folder, ISpreadsheetData spreadsheetData, Object[] assets = null, bool createMissing = true, int maxItemsCount = -1, string overrideSheetId = "") { return(DefaultProcessor.SyncFolderAssets(filterType, folder, spreadsheetData, assets, createMissing, maxItemsCount, overrideSheetId)); }
public override ISpreadsheetData ExportObjects(IEnumerable <object> source, ISpreadsheetData spreadsheetData) { foreach (var item in assets) { if (item.asset == null) { continue; } item.asset.UpdateSheetValue(spreadsheetData, item.sheetId); } return(spreadsheetData); }
public IEnumerable <object> Import(ISpreadsheetData spreadsheetData) { if (autoReloadSpreadsheetOnImport) { _client.ReloadAll(); } var result = new List <object>(); foreach (var importer in Importers.Where(x => x.CanImport)) { result.AddRange(Import(spreadsheetData, importer)); } return(result); }
public object ApplyData(object source, ISpreadsheetData spreadsheetData) { var syncScheme = source.CreateSheetScheme(); var syncValue = new SheetValueInfo { Source = source, SpreadsheetData = spreadsheetData, SheetName = syncScheme.sheetId, SyncScheme = syncScheme, SyncFieldName = syncScheme.keyField.sheetField, }; var result = ApplyData(syncValue); return(result); }
public static object ApplySpreadsheetData( this object asset, Type type, ISpreadsheetData sheetData, string sheetId, object keyValue = null, string sheetFieldName = "") { var syncAsset = type.CreateSheetScheme(); var sheetValue = new SheetValueInfo { Source = asset, SheetName = sheetId, SpreadsheetData = sheetData, SyncScheme = syncAsset, SyncFieldName = sheetFieldName, SyncFieldValue = keyValue, StartColumn = 0 }; return(DefaultProcessor.ApplyData(sheetValue)); }
/// <summary> /// Sync folder assets by spreadsheet data /// </summary> /// <param name="filterType"></param> /// <param name="folder"></param> /// <param name="createMissing">if true - create missing assets</param> /// <param name="spreadsheetData"></param> /// <param name="maxItems"></param> /// <param name="overrideSheetId"></param> /// <returns></returns> public List <Object> SyncFolderAssets( Type filterType, string folder, bool createMissing, ISpreadsheetData spreadsheetData, int maxItems = -1, string overrideSheetId = "") { if (!filterType.IsScriptableObject() && !filterType.IsComponent()) { Debug.LogError($"SyncFolderAssets: BAD target type {filterType}"); return(null); } var assets = AssetEditorTools.GetAssets <Object>(filterType, folder); var result = SyncFolderAssets( filterType, folder, spreadsheetData, assets.ToArray(), createMissing, maxItems, overrideSheetId); return(result); }
public virtual ISpreadsheetData ExportObjects(IEnumerable <object> source, ISpreadsheetData spreadsheetData) => spreadsheetData;
public virtual IEnumerable <object> ImportObjects(IEnumerable <object> source, ISpreadsheetData spreadsheetData) { return(source); }
public override IEnumerable <object> ImportObjects(IEnumerable <object> source, ISpreadsheetData spreadsheetData) { var result = new List <object>(); foreach (var item in source.OfType <SheetSyncItem>()) { if (!spreadsheetData.HasSheet(item.sheetId) || item.asset == null) { continue; } var asset = item.asset. ApplySpreadsheetData(spreadsheetData, item.sheetId); result.Add(asset); } return(result); }
private ISpreadsheetData Export(ISpreadsheetData data, ISpreadsheetAssetsHandler importer) { importer.Load(); return(importer.Export(data)); }
public static object ApplySpreadsheetData(this object asset, SheetSyncScheme syncAsset, ISpreadsheetData data) { var sheetValueInfo = new SheetValueInfo { Source = asset, SyncScheme = syncAsset, SpreadsheetData = data, StartColumn = 0 }; return(DefaultProcessor.ApplyData(sheetValueInfo)); }
public abstract IEnumerable <object> Import(ISpreadsheetData spreadsheetData);
public IEnumerable <Object> ApplyAssets( Type filterType, string sheetId, string folder, SheetSyncScheme syncScheme, ISpreadsheetData spreadsheetData, object[] keys, Object[] assets = null, int count = -1, bool createMissing = true, string keyFieldName = "") { count = count < 0 ? keys.Length : count; count = Math.Min(keys.Length, count); var keyField = string.IsNullOrEmpty(keyFieldName) ? syncScheme.keyField : syncScheme.GetFieldBySheetFieldName(keyFieldName); try { for (var i = 0; i < count; i++) { var keyValue = keys[i]; var key = keyValue.TryConvert <string>(); var targetAsset = assets?.FirstOrDefault(x => string.Equals(keyField.GetValue(x).TryConvert <string>(), key, StringComparison.OrdinalIgnoreCase)); //create asset if missing if (targetAsset == null) { //skip asset creation step if (createMissing == false) { continue; } targetAsset = filterType.CreateAsset(); targetAsset.SaveAsset($"{filterType.Name}_{i + 1}", folder, false); Debug.Log($"Create Asset [{targetAsset}] for path {folder}", targetAsset); } //show assets progression AssetEditorTools.ShowProgress(new ProgressData() { IsDone = false, Progress = i / (float)count, Content = $"{i}:{count} {targetAsset.name}", Title = "Spreadsheet Importing" }); var spreadsheetValueInfo = new SheetValueInfo() { Source = targetAsset, SheetName = sheetId, SpreadsheetData = spreadsheetData, SyncScheme = syncScheme, SyncFieldName = keyField.sheetField, SyncFieldValue = keyValue, }; ApplyData(spreadsheetValueInfo); yield return(targetAsset); } } finally { AssetEditorTools.ShowProgress(new ProgressData() { IsDone = true, }); AssetDatabase.SaveAssets(); } }
public sealed override IEnumerable <object> ImportObjects(IEnumerable <object> source, ISpreadsheetData spreadsheetData) { var result = new List <object>(); foreach (var importer in OnPreImport(source.OfType <T>()).Where(x => x.CanImport)) { result.AddRange(importer.Import(spreadsheetData)); } result = OnPostImport(result).ToList(); return(result); }
public static bool UpdateSheetValue(this object source, ISpreadsheetData data, string sheetId) { return(DefaultProcessor.UpdateSheetValue(source, data, sheetId)); }
public IEnumerable <object> Import(ISpreadsheetData spreadsheetData) { var source = Load(); return(ImportObjects(source, spreadsheetData)); }
public ISpreadsheetData Export(ISpreadsheetData data) { var source = Load(); return(ExportObjects(source, data)); }
private IEnumerable <object> Import(ISpreadsheetData data, ISpreadsheetAssetsHandler importer) { importer.Load(); return(importer.Import(data)); }
public virtual ISpreadsheetData Export(ISpreadsheetData data) { return(data); }
public static object ApplySpreadsheetData(this object asset, ISpreadsheetData data) { return(DefaultProcessor.ApplyData(asset, data)); }