Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void CombineDependencys()
- {
- //A while loop for all the duplicates
- while(duplicates.Count >= 1)
- {
- Object currentObject = duplicates[0] as Object;
- //S_collectDependencies runs a WHERE dependency over all assets in the asset folder
- List<Object> results = S_collectDependencies(currentObject);
- foreach (Object o in results)
- {
- string UID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(duplicates[0]));
- string[] lines = File.ReadAllLines(AssetDatabase.GetAssetPath(o));
- for (int i = 0; i < lines.Length; i++)
- {
- //Check if the current ID exists inside the object
- Regex r = new Regex(@"\b" + UID + "\b");
- bool containsmaterial = Regex.IsMatch(lines[i], @"\b" + UID + "\b");
- if (containsmaterial)
- {
- // duplicatesCompare is the object duplicates is a duplicate of.
- string newUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(duplicatesCompare[0]));
- lines[i] = r.Replace(lines[i], newUID);
- Debug.Log(i + " Replaced: " + UID + " with " + newUID + " in " + o.name);
- }
- else continue;
- if (i == lines.Length - 1)
- {
- using (StreamWriter sw = new StreamWriter(AssetDatabase.GetAssetPath(o), false))
- {
- for (int e = 0; i < lines.Length; e++)
- {
- sw.WriteLine(lines[e]);
- }
- }
- _duplicates.RemoveAt(0);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement