Advertisement
d3ullist

Untitled

Oct 1st, 2014
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.08 KB | None | 0 0
  1. public void CombineDependencys()
  2.         {
  3.             //A while loop for all the duplicates
  4.             while(duplicates.Count >= 1)
  5.             {
  6.                 Object currentObject = duplicates[0] as Object;
  7.                 //S_collectDependencies runs a WHERE dependency over all assets in the asset folder
  8.                 List<Object> results = S_collectDependencies(currentObject);
  9.    
  10.                 foreach (Object o in results)
  11.                 {
  12.                     string UID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(duplicates[0]));
  13.                     string[] lines = File.ReadAllLines(AssetDatabase.GetAssetPath(o));
  14.                     for (int i = 0; i < lines.Length; i++)
  15.                     {
  16.                         //Check if the current ID exists inside the object
  17.                         Regex r = new Regex(@"\b" + UID + "\b");
  18.                         bool containsmaterial = Regex.IsMatch(lines[i], @"\b" + UID + "\b");
  19.                         if (containsmaterial)
  20.                         {
  21.                             // duplicatesCompare is the object duplicates is a duplicate of.
  22.                             string newUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(duplicatesCompare[0]));
  23.                             lines[i] = r.Replace(lines[i], newUID);
  24.                             Debug.Log(i + " Replaced: " + UID + " with " + newUID + " in " + o.name);
  25.                         }
  26.                         else continue;
  27.    
  28.                         if (i == lines.Length - 1)
  29.                         {
  30.                             using (StreamWriter sw = new StreamWriter(AssetDatabase.GetAssetPath(o), false))
  31.                             {
  32.                                 for (int e = 0; i < lines.Length; e++)
  33.                                 {
  34.                                     sw.WriteLine(lines[e]);
  35.                                 }
  36.                             }
  37.                             _duplicates.RemoveAt(0);
  38.                         }
  39.                     }
  40.                 }
  41.             }
  42.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement