static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { foreach (string str in importedAssets) { if (str.IndexOf("/SpawnEnemy.csv") != -1) { TextAsset data = AssetDatabase.LoadAssetAtPath <TextAsset>(str); string assetfile = str.Replace(".csv", ".asset"); SpawnEnemyExample gm = AssetDatabase.LoadAssetAtPath <SpawnEnemyExample>(assetfile); if (gm == null) { gm = ScriptableObject.CreateInstance <SpawnEnemyExample>(); AssetDatabase.CreateAsset(gm, assetfile); } gm.spawnEnemies = CSVSerializer.Deserialize <SpawnEnemyExample.SpawnEnemy>(data.text); EditorUtility.SetDirty(gm); AssetDatabase.SaveAssets(); #if DEBUG_LOG || UNITY_EDITOR Debug.Log("Reimported Asset: " + str); #endif } } }
static void Setup(string path, string fullPath, string[] importedAssets) { foreach (string str in importedAssets) { if (str.IndexOf(path) != -1) { var assetPath = str.Replace(path, fullPath); TextAsset data = AssetDatabase.LoadAssetAtPath <TextAsset>(str); string assetfile = assetPath.Replace(".csv", ".asset"); ShopGroupExample gm = AssetDatabase.LoadAssetAtPath <ShopGroupExample>(assetfile); if (gm == null) { gm = ScriptableObject.CreateInstance <ShopGroupExample>(); AssetDatabase.CreateAsset(gm, assetfile); } gm.shopGroups = CSVSerializer.Deserialize <ShopGroupExample.ShopGroup>(data.text); EditorUtility.SetDirty(gm); AssetDatabase.SaveAssets(); #if DEBUG_LOG || UNITY_EDITOR Debug.Log("Reimported Asset: " + assetPath); #endif } } }
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { foreach (string str in importedAssets) { if (str.IndexOf("/orderdata.csv") != -1) { TextAsset data = AssetDatabase.LoadAssetAtPath <TextAsset>(str); string assetfile = str.Replace(".csv", ".asset"); Orderdata gm = AssetDatabase.LoadAssetAtPath <Orderdata>(assetfile); if (gm == null) { gm = new Orderdata(); AssetDatabase.CreateAsset(gm, assetfile); } gm.allOrderType = CSVSerializer.Deserialize <Orderdata.OrderDetails>(data.text); EditorUtility.SetDirty(gm); AssetDatabase.SaveAssets(); #if DEBUG_LOG || UNITY_EDITOR Debug.Log("Reimported Asset: " + str); #endif } } }
public static void ImportCardData(string text, string assetfile) { List <string[]> rows = CSVSerializer.ParseCSV(text); if (rows != null) { CardData cardData = AssetDatabase.LoadAssetAtPath <CardData>(assetfile); if (cardData == null) { cardData = (CardData)ScriptableObject.CreateInstance(typeof(CardData)); AssetDatabase.CreateAsset(cardData, assetfile); } cardData.cards = CSVSerializer.Deserialize <Card>(rows); EditorUtility.SetDirty(cardData); AssetDatabase.SaveAssets(); } }
static void ImportRankingData(string text, string assetfile) { List <string[]> rows = CSVSerializer.ParseCSV(text); if (rows != null) { RankingData gm = AssetDatabase.LoadAssetAtPath <RankingData>(assetfile); if (gm == null) { gm = new RankingData(); AssetDatabase.CreateAsset(gm, assetfile); } gm.m_Items = CSVSerializer.Deserialize <RankingData.Item>(rows); EditorUtility.SetDirty(gm); AssetDatabase.SaveAssets(); } }
static void Main(string[] args) { if (File.Exists("export.csv")) { File.Delete("export.csv"); } string connectionString = "Data Source=localhost;Database=tutorial_db;userid=xxxx;password=xxxxx"; MinimalDataContext dataContext = new MinimalDataContext(connectionString); var mydataList = dataContext.GetUserData(); CSVSerializer serializer = new CSVSerializer(); using (StreamWriter file = new StreamWriter("export.csv")) { foreach (var item in mydataList) { file.WriteLine(serializer.Serialize(item)); } } dataContext.DeleteAll(); using (StreamReader reader = new StreamReader("export.csv")) { string line; while ((line = reader.ReadLine()) != null) { var model = serializer.Deserialize(line); dataContext.Insert(model); } } }
private void Awake() { ItemBase[] items = CSVSerializer.Deserialize <ItemBase>(csvItems.text); foreach (var item in items) { this.items.Add(item.id, item); } ItemBaseLocal[] locals = CSVSerializer.Deserialize <ItemBaseLocal>(csvItemsLocals.text); foreach (var item in locals) { if (this.items.ContainsKey(item.id)) { try { this.items[item.id].local = item; } catch (Exception ex) { Debug.Log("Couldnt load local for: " + item.id + " " + ex.ToString()); } } } }
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { foreach (string str in importedAssets) { if (str.IndexOf("/sample.csv") != -1) { TextAsset data = AssetDatabase.LoadAssetAtPath <TextAsset>(str); string assetfile = str.Replace(".csv", ".asset"); CSVImportExample gm = AssetDatabase.LoadAssetAtPath <CSVImportExample>(assetfile); if (gm == null) { gm = new CSVImportExample(); AssetDatabase.CreateAsset(gm, assetfile); } gm.m_Sample = CSVSerializer.Deserialize <CSVImportExample.Sample>(data.text); EditorUtility.SetDirty(gm); AssetDatabase.SaveAssets(); #if DEBUG_LOG || UNITY_EDITOR Debug.Log("Reimported Asset: " + str); #endif } if (str.IndexOf("/f1ranking2018.csv") != -1) { TextAsset data = AssetDatabase.LoadAssetAtPath <TextAsset>(str); string assetfile = str.Replace(".csv", ".asset"); RankingData gm = AssetDatabase.LoadAssetAtPath <RankingData>(assetfile); if (gm == null) { gm = new RankingData(); AssetDatabase.CreateAsset(gm, assetfile); } gm.m_Items = CSVSerializer.Deserialize <RankingData.Item>(data.text); EditorUtility.SetDirty(gm); AssetDatabase.SaveAssets(); #if DEBUG_LOG || UNITY_EDITOR Debug.Log("Reimported Asset: " + str); #endif } if (str.IndexOf("/lan.csv") != -1) { TextAsset data = AssetDatabase.LoadAssetAtPath <TextAsset>(str); string assetfile = str.Replace(".csv", ".asset"); LanguageStringData gm = AssetDatabase.LoadAssetAtPath <LanguageStringData>(assetfile); if (gm == null) { gm = new LanguageStringData(); AssetDatabase.CreateAsset(gm, assetfile); } gm.m_Items = CSVSerializer.Deserialize <LanguageStringData.Item>(data.text); EditorUtility.SetDirty(gm); AssetDatabase.SaveAssets(); #if DEBUG_LOG || UNITY_EDITOR Debug.Log("Reimported Asset: " + str); #endif } if (str.IndexOf("/const.csv") != -1) { TextAsset data = AssetDatabase.LoadAssetAtPath <TextAsset>(str); string assetfile = str.Replace(".csv", ".asset"); ConstData gm = AssetDatabase.LoadAssetAtPath <ConstData>(assetfile); if (gm == null) { gm = new ConstData(); AssetDatabase.CreateAsset(gm, assetfile); } ConstData readdata = CSVSerializer.DeserializeIdValue <ConstData>(data.text); EditorUtility.CopySerialized(readdata, gm); EditorUtility.SetDirty(gm); AssetDatabase.SaveAssets(); #if DEBUG_LOG || UNITY_EDITOR Debug.Log("Reimported Asset: " + str); #endif } } }
static void Main(string[] args) { var data = CSVSerializer.Deserialize <Data>("postcodes.csv"); Console.ReadLine(); }
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { foreach (string str in importedAssets) { if (str.IndexOf("/character.csv") != -1) { TextAsset data = AssetDatabase.LoadAssetAtPath <TextAsset>(str); string assetfile = str.Replace(".csv", ".asset"); CharacterText gm = AssetDatabase.LoadAssetAtPath <CharacterText>(assetfile); if (gm == null) { gm = new CharacterText(); AssetDatabase.CreateAsset(gm, assetfile); } gm.characters = CSVSerializer.Deserialize <CharacterText.Character>(data.text); EditorUtility.SetDirty(gm); AssetDatabase.SaveAssets(); #if DEBUG_LOG || UNITY_EDITOR Debug.Log("Reimported Asset: " + str); #endif } if (Regex.IsMatch(str, "L[0-9a-zA-Z]*[.]csv$")) { TextAsset data = AssetDatabase.LoadAssetAtPath <TextAsset>(str); string assetfile = str.Replace(".csv", ".asset"); LocalizableData gm = AssetDatabase.LoadAssetAtPath <LocalizableData>(assetfile); if (gm == null) { gm = new LocalizableData(); AssetDatabase.CreateAsset(gm, assetfile); } gm.datas = CSVSerializer.Deserialize <LocalizableData.Data>(data.text); EditorUtility.SetDirty(gm); AssetDatabase.SaveAssets(); #if DEBUG_LOG || UNITY_EDITOR Debug.Log("Reimported Asset: " + str); #endif } if (str.IndexOf("/CardData.csv") != -1) { TextAsset data = AssetDatabase.LoadAssetAtPath <TextAsset>(str); string assetfile = str.Replace(".csv", ".asset"); CardData gm = AssetDatabase.LoadAssetAtPath <CardData>(assetfile); if (gm == null) { gm = new CardData(); AssetDatabase.CreateAsset(gm, assetfile); } gm.Cards = CSVSerializer.Deserialize <CardData.Data>(data.text); var tempList = new List <CardSource>(); foreach (var card in gm.Cards) { var cardSource = CheckAndGetCard(card); ApplyData(card, cardSource); tempList.Add(cardSource); } foreach (var card in gm.Cards) { ApplyUpgradeList(card, tempList[0]); tempList.RemoveAt(0); } EditorUtility.SetDirty(gm); AssetDatabase.SaveAssets(); #if DEBUG_LOG || UNITY_EDITOR Debug.Log("Reimported Asset: " + str); #endif } } }
static void Setup(string path, string[] importedAssets) { Action <string, TextAsset, Type, Type> genAsset = delegate(string assetfile, TextAsset data, Type classCollection, Type classData) { var gm = AssetDatabase.LoadAssetAtPath(assetfile, classCollection); if (gm == null) { gm = ScriptableObject.CreateInstance(classCollection); AssetDatabase.CreateAsset(gm, assetfile); } Type type = classData; var field = gm.GetType().GetField("dataGroups", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); var method = gm.GetType().GetMethod("Convert"); field.SetValue(gm, CSVSerializer.Deserialize(data.text, type)); method?.Invoke(gm, null); if (field.IsPrivate) { field.SetValue(gm, null); } EditorUtility.SetDirty(gm); AssetDatabase.SaveAssets(); }; foreach (string str in importedAssets) { if (str.IndexOf(path) != -1) { Debug.Log("str: " + str); TextAsset data = AssetDatabase.LoadAssetAtPath <TextAsset>(str); var isDefineCollection = path.Equals("define_collection.csv"); var assetfile = ""; Type classCollection; Type classData; if (isDefineCollection) { assetfile = "Assets/Resources/Collection/define_collection.asset"; classCollection = Type.GetType("DefineCollection"); classData = Type.GetType("DefineData"); genAsset(assetfile, data, classCollection, classData); } else { var defineCollection = LoadResourceController.GetDefineCollection(); if (defineCollection == null) { TextAsset textAsset = AssetDatabase.LoadAssetAtPath <TextAsset>( "Assets/Csv/Collection/define_collection.csv"); Debug.Log("textAsset:" + textAsset); assetfile = "Assets/Resources/Collection/define_collection.asset"; classCollection = Type.GetType("DefineCollection"); classData = Type.GetType("DefineData"); genAsset(assetfile, textAsset, classCollection, classData); } defineCollection = LoadResourceController.GetDefineCollection(); var defineData = defineCollection.GetDefineCollectionData(path); if (defineData == null) { return; } assetfile = "Assets/Resources/" + defineData.assetPath + ".asset"; classCollection = Type.GetType(defineData.classCollection); classData = Type.GetType(defineData.classData); genAsset(assetfile, data, classCollection, classData); } #if DEBUG_LOG || UNITY_EDITOR Debug.Log("Reimported Asset: " + assetfile); #endif } } }