Page 1 of 1
Is there a way to merge a lot of databases?
Posted: Wed Oct 14, 2020 5:41 am
by shortlin
Hi Tony,Sorry to bother..
if I want to merge more than 2 databases to 1 database.Is there a way to do it quickly?I just know I could do this in Dialogue tab and only could merge one database to another.But if there are a lot of databases that I want to merge,I should use it a lot of time.I knew you said there is one way to deal the multi-database,but I think just one database is simple to me..
So If I want to merge the databases,is there a way to do it just like click one button?
Or Could I write a code to do this?
Re: Is there a way to merge a lot of databases?
Posted: Wed Oct 14, 2020 9:29 am
by Tony Li
Hi,
You could write an editor script that uses the
DatabaseMerger class. Example:
Code: Select all
DialogueDatabase mainDatabase;
DialogueDatabase[] otherDatabases;
...
foreach (var otherDatabase in otherDatabases)
{
DatabaseMerger(mainDatabase, otherDatabase, DatabaseMerger.ConflictingIDRule.AssignUniqueIDs);
}
EditorUtility.setDirty(mainDatabase);
Important:
- Back up your databases first. Make sure you have a good backup of all of your original databases.
- After merging, thoroughly check the database to make sure everything is correct.
Re: Is there a way to merge a lot of databases?
Posted: Thu Oct 15, 2020 4:23 am
by shortlin
Thank you,I let it work with addressable.
================
Just a note to write this:if there is someone has the same question.I think before merging them you must use unique ID tool to choose all databases and use DatabaseMerger.ConflictingIDRule.ReplaceConflictingIDs to replace the same title's conversation.Good thing is using the unique ID tool choose all databases do not let the same title's ID be different.If the tool let them be different,you could not use DatabaseMerger.ConflictingIDRule.ReplaceConflictingIDs to overwrite the old one.
================
So sorry that I have 3 question again:
1.Could I write a code to do the same thing just like I use unique ID tool In Unity?
2.if I would like to import a lot of CSV, Is there a way to do the same thing like merge them to a database?
3.I want the mainDatabase not use your way,I just want use initialDatabase,but when I use GetComponent<DialogueSystemController>().initialDatabase It would be error:invalidOperationException: Collection was modified; enumeration operation may not execute.
How to solve it?Or the mainDatabase only can use merge by drag the database or load outside data(such like addresable)?
Re: Is there a way to merge a lot of databases?
Posted: Thu Oct 15, 2020 8:39 am
by Tony Li
shortlin wrote: ↑Thu Oct 15, 2020 4:23 am1.Could I write a code to do the same thing just like I use unique ID tool In Unity?
Yes. Feel free to use any of the code in Unique ID Tool to do that.
shortlin wrote: ↑Thu Oct 15, 2020 4:23 am2.if I would like to import a lot of CSV, Is there a way to do the same thing like merge them to a database?
If the CSV file is in the same format created by the Dialogue Editor's Database > Export Database > CSV function, then you can import it as a database and then merge it.
If you have many CSV files, you could combine them into one CSV file and make sure that CSV has unique IDs. Then just import that one CSV into a database.
Re: Is there a way to merge a lot of databases?
Posted: Thu Oct 15, 2020 9:19 am
by shortlin
Thank you.Tony,but about the 2 questions,could you give me the direction to do what you said?(firt question is I want to know the code referrence.second question I knew I could use csv import ,but this tool just could import one csv,so I want to know how to combine all csv to one csv)
And I modified the article to add the third question ,maybe you missed that.
Re: Is there a way to merge a lot of databases?
Posted: Thu Oct 15, 2020 3:26 pm
by Tony Li
shortlin wrote: ↑Thu Oct 15, 2020 9:19 amfirst question is I want to know the code reference.
I didn't have a code reference in mind. I thought you could just look at the code in UniqueIDWindow.cs. In particular, look at the ProcessDatabases() method.
shortlin wrote: ↑Thu Oct 15, 2020 9:19 am.second question I knew I could use csv import ,but this tool just could import one csv,so I want to know how to combine all csv to one csv)
You can try to merge them in a spreadsheet program. But you must put the rows in the correct order. The combined CSV file must match the importer's
CSV File Format.
shortlin wrote: ↑Thu Oct 15, 2020 4:23 am3.I want the mainDatabase not use your way,I just want use initialDatabase,but when I use GetComponent<DialogueSystemController>().initialDatabase It would be error:invalidOperationException: Collection was modified; enumeration operation may not execute.
How to solve it?Or the mainDatabase only can use merge by drag the database or load outside data(such like addresable)?
If you want to load the database at runtime, do not assign to initialDatabase. Instead, use
DialogueManager.AddDatabase(). Example:
Code: Select all
databaseAddressableAssetReference.LoadAssetAsync();
yield return operation;
DialogueManager.AddDatabase(operation.Result);
Re: Is there a way to merge a lot of databases?
Posted: Thu Oct 15, 2020 7:34 pm
by shortlin
Thank you Tony,about sencond question,if I want to write codes to import the one csv which is combined ,do you have a function to do that(means import the csv file to database,just like use the Unity,'s tool)or just like first question,could you point out what cs file and inside method that you use?
Re: Is there a way to merge a lot of databases?
Posted: Thu Oct 15, 2020 8:29 pm
by Tony Li
Hi,
Look at CSVConverterWindow.cs.
Re: Is there a way to merge a lot of databases?
Posted: Thu Oct 15, 2020 8:43 pm
by shortlin
Thank you!!!
Sorry I have a new question...
If I want to export one database to a lot of csv by the conversation titles(means use the conversation titles be the csv files' name).Is there a way to do this?
Re: Is there a way to merge a lot of databases?
Posted: Thu Oct 15, 2020 9:10 pm
by Tony Li
Hi,
There is not a built-in way, but you could write an editor script to do it. The
CSVUtility class can help. Give it a List<List<string>>.
The outer
List<List<string>> is the list of rows.
The inner List<
List<string>> is the list of columns in each row.