Skip to content

Commit 0d5c3d5

Browse files
Create GuidGenerator
1 parent bc5d149 commit 0d5c3d5

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

com.stansassets.plugins-dev-kit/Editor/Utility.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using UnityEngine;
5+
6+
namespace StansAssets.Plugins.Editor
7+
{
8+
public static class GuidGenerator
9+
{
10+
public static void RegenerateGuid(string assetPath)
11+
{
12+
try
13+
{
14+
var path = $"{assetPath}.meta";
15+
var metafile = File.ReadAllText(path);
16+
var startGuid = metafile.IndexOf("guid:") + 6;
17+
var endGuid = metafile.Substring(startGuid).IndexOf("\n");
18+
var oldGuid = metafile.Substring(startGuid, endGuid);
19+
metafile = metafile.Replace(oldGuid, Guid.NewGuid().ToString("N"));
20+
File.WriteAllText(path, metafile);
21+
}
22+
catch (Exception exception)
23+
{
24+
Debug.LogError(exception.Message);
25+
}
26+
}
27+
28+
public static void RegenerateGuids(IEnumerable<string> assetPaths)
29+
{
30+
foreach (var assetPath in assetPaths)
31+
{
32+
RegenerateGuid(assetPath);
33+
}
34+
35+
}
36+
}
37+
}

com.stansassets.plugins-dev-kit/Editor/Utility/GuidGenerator.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)