├── Package
├── uguid.dll
└── uguid.runtimeconfig.json
├── ReadMeImages
└── AccessGUID.jpg
├── UnityGuidMapper
├── UnityGuidMapper.csproj
├── ListCommand.cs
├── FileSearch.cs
├── ProgramCommand.cs
├── Program.cs
├── ReplaceCommand.cs
├── ShowCommand.cs
└── GuidMapper.cs
├── README.md
├── LICENSE
├── UnityGuidMapper.sln
└── .gitignore
/Package/uguid.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ibrahimpenekli/unity-guid-mapper/HEAD/Package/uguid.dll
--------------------------------------------------------------------------------
/ReadMeImages/AccessGUID.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ibrahimpenekli/unity-guid-mapper/HEAD/ReadMeImages/AccessGUID.jpg
--------------------------------------------------------------------------------
/Package/uguid.runtimeconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "runtimeOptions": {
3 | "tfm": "netcoreapp2.0",
4 | "framework": {
5 | "name": "Microsoft.NETCore.App",
6 | "version": "2.0.0"
7 | }
8 | }
9 | }
--------------------------------------------------------------------------------
/UnityGuidMapper/UnityGuidMapper.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.0
6 | uguid
7 | UnityGuidMapper.Program
8 | H. Ibrahim Penekli
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Unity GUID Mapper
2 | Show/List/Replace assets with specified GUID for Unity 3D.
3 |
4 | ## Usage
5 | * `dotnet uguid.dll -show ` Show the GUID for the asset file.
6 | * `dotnet uguid.dll -list ` Lists assets that uses given GUID asset.
7 | * `dotnet uguid.dll -replace ` Replaces assets that uses given GUID with the new one.
8 |
9 | ## How to know GUID of an asset?
10 | You can access GUID of an asset by its .meta file:
11 |
12 | 
13 |
--------------------------------------------------------------------------------
/UnityGuidMapper/ListCommand.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace UnityGuidMapper
4 | {
5 | public class ListCommand : ProgramCommand
6 | {
7 | public string AssetsDirectory => Args[0];
8 | public string Guid => Args[1];
9 | public override string Usage => $"{Name} <{nameof(AssetsDirectory)}> <{nameof(Guid)}>";
10 | public override string Description => "Lists assets that uses given GUID asset.";
11 |
12 | public ListCommand() : base("-list", 2)
13 | {
14 | }
15 |
16 | public override void Run()
17 | {
18 | Console.WriteLine();
19 | Console.WriteLine($"Assets Directory : {AssetsDirectory}");
20 | Console.WriteLine($"GUID : {Guid}");
21 |
22 | var guidMapper = new GuidMapper(AssetsDirectory);
23 | guidMapper.FilterBy(Guid);
24 | guidMapper.Print();
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/UnityGuidMapper/FileSearch.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 |
5 | namespace UnityGuidMapper
6 | {
7 | public class FileSearch
8 | {
9 | public static List FindFiles(string path, Predicate predicate)
10 | {
11 | var files = new List();
12 | FindFilesRecursively(path, files, predicate);
13 | return files;
14 | }
15 |
16 | private static void FindFilesRecursively(string path, List files, Predicate predicate)
17 | {
18 | foreach (var d in Directory.GetDirectories(path))
19 | {
20 | foreach (var f in Directory.GetFiles(d))
21 | {
22 | if (predicate.Invoke(f))
23 | {
24 | files.Add(f);
25 | }
26 | }
27 | FindFilesRecursively(d, files, predicate);
28 | }
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 H. Ibrahim Penekli
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/UnityGuidMapper/ProgramCommand.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace UnityGuidMapper
4 | {
5 | public abstract class ProgramCommand
6 | {
7 | public string Name { get; set; }
8 | public int ArgsCount { get; set; }
9 | public string[] Args { get; private set; }
10 |
11 | public ProgramCommand(string name, int argsCount)
12 | {
13 | Name = name;
14 | ArgsCount = argsCount;
15 | Args = new string[argsCount];
16 | }
17 |
18 | public virtual bool TryParse(string[] args)
19 | {
20 | if (args.Length == 0)
21 | {
22 | return false;
23 | }
24 |
25 | if (Name != args[0])
26 | {
27 | return false;
28 | }
29 |
30 | if (args.Length != ArgsCount + 1)
31 | {
32 | return false;
33 | }
34 |
35 | Array.Copy(args, 1, Args, 0, Args.Length);
36 | return true;
37 | }
38 |
39 | public abstract void Run();
40 | public abstract string Usage { get; }
41 | public abstract string Description { get; }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/UnityGuidMapper.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.27130.2003
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnityGuidMapper", "UnityGuidMapper\UnityGuidMapper.csproj", "{7A88335A-71F8-4B29-9699-27208CEFAF31}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {7A88335A-71F8-4B29-9699-27208CEFAF31}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {7A88335A-71F8-4B29-9699-27208CEFAF31}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {7A88335A-71F8-4B29-9699-27208CEFAF31}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {7A88335A-71F8-4B29-9699-27208CEFAF31}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | GlobalSection(ExtensibilityGlobals) = postSolution
23 | SolutionGuid = {31CADF40-B59B-4C2F-A175-C1048911D2ED}
24 | EndGlobalSection
25 | EndGlobal
26 |
--------------------------------------------------------------------------------
/UnityGuidMapper/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 |
4 | namespace UnityGuidMapper
5 | {
6 | class Program
7 | {
8 | private static readonly ProgramCommand[] Commands = new ProgramCommand[]
9 | {
10 | new ShowCommand(),
11 | new ListCommand(),
12 | new ReplaceCommand()
13 | };
14 |
15 | static void Main(string[] args)
16 | {
17 | var command = Commands.FirstOrDefault(c => c.TryParse(args));
18 | if (command == null)
19 | {
20 | PrintUsage();
21 | return;
22 | }
23 |
24 | command.Run();
25 | #if DEBUG
26 | Console.WriteLine("Done! Press enter to exit...");
27 | Console.ReadLine();
28 | #endif
29 | }
30 |
31 | private static void PrintUsage()
32 | {
33 | Console.WriteLine();
34 | Console.WriteLine("Usage:");
35 | foreach (var command in Commands)
36 | {
37 | Console.WriteLine($"dotnet uguid.dll {command.Usage}");
38 | Console.WriteLine($"\t{command.Description}");
39 | Console.WriteLine();
40 | }
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/UnityGuidMapper/ReplaceCommand.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace UnityGuidMapper
4 | {
5 | public class ReplaceCommand : ProgramCommand
6 | {
7 | public string AssetsDirectory => Args[0];
8 | public string OldGuid => Args[1];
9 | public string NewGuid => Args[2];
10 | public override string Usage => $"{Name} <{nameof(AssetsDirectory)}> <{nameof(OldGuid)}> <{nameof(NewGuid)}> ";
11 | public override string Description => "Replaces assets that uses given GUID with the new one.";
12 |
13 | public ReplaceCommand() : base("-replace", 3)
14 | {
15 | }
16 |
17 | public override void Run()
18 | {
19 | Console.WriteLine();
20 | Console.WriteLine($"Assets Directory : {AssetsDirectory}");
21 | Console.WriteLine($"GUID (old) : {OldGuid}");
22 | Console.WriteLine($"GUID (new) : {NewGuid}");
23 |
24 | var guidMapper = new GuidMapper(AssetsDirectory);
25 | guidMapper.FilterBy(OldGuid);
26 | guidMapper.Print();
27 |
28 | if (ConfirmByUser())
29 | {
30 | guidMapper.ReplaceWith(NewGuid);
31 | }
32 | }
33 |
34 | private static bool ConfirmByUser()
35 | {
36 | Console.Write($"Continue to replace? (Y) : ");
37 | return Console.ReadLine().ToUpper() == "Y";
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/UnityGuidMapper/ShowCommand.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | namespace UnityGuidMapper
5 | {
6 | public class ShowCommand : ProgramCommand
7 | {
8 | private const string GuidKey = "guid:";
9 |
10 | public string AssetFile => Args[0];
11 | public override string Usage => $"{Name} <{nameof(AssetFile)}>";
12 | public override string Description => "Show the GUID for the asset file.";
13 |
14 | public ShowCommand() : base("-show", 1)
15 | {
16 | }
17 |
18 | public override void Run()
19 | {
20 | Console.WriteLine();
21 | Console.WriteLine($"Assets file : {AssetFile}");
22 |
23 | var metaFilePath = AssetFile + ".meta";
24 | if (File.Exists(metaFilePath))
25 | {
26 | try
27 | {
28 | var metaText = File.ReadAllText(metaFilePath);
29 | var startIdx = metaText.IndexOf(GuidKey) + GuidKey.Length;
30 | var endIdx = metaText.IndexOf("\r\n", startIdx);
31 | var guid = metaText.Substring(startIdx, endIdx - startIdx).Trim();
32 | Console.WriteLine($"Asset GUID: {guid}");
33 | }
34 | catch (Exception)
35 | {
36 | Console.WriteLine($"error: Meta file is not valid.");
37 | }
38 | }
39 | else
40 | {
41 | Console.WriteLine($"error: Meta file not exist for the file.");
42 | }
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/UnityGuidMapper/GuidMapper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 |
5 | namespace UnityGuidMapper
6 | {
7 | public class GuidMapper
8 | {
9 | public string AssetsDirectory { get; private set; }
10 | public string TargetGuid { get; private set; }
11 | public string NewGuid { get; private set; }
12 |
13 | private List m_Files;
14 | private List m_FilteredFiles = new List();
15 |
16 | public GuidMapper(string assetsDirectory)
17 | {
18 | AssetsDirectory = assetsDirectory;
19 | m_Files = FindYamlFiles(AssetsDirectory);
20 | }
21 |
22 | public void FilterBy(string guid)
23 | {
24 | // Find files that contains given GUID.
25 | TargetGuid = "";
26 | m_FilteredFiles.Clear();
27 |
28 | // Just clear filter.
29 | if (string.IsNullOrEmpty(guid))
30 | {
31 | return;
32 | }
33 |
34 | // Filter by guid.
35 | TargetGuid = guid;
36 | foreach (var file in m_Files)
37 | {
38 | var fileText = File.ReadAllText(file);
39 | if (fileText.Contains(GetGuidExpression(TargetGuid)))
40 | {
41 | m_FilteredFiles.Add(file);
42 | }
43 | }
44 | }
45 |
46 | public void ReplaceWith(string guid)
47 | {
48 | // Replace old GUID with the new GUID given.
49 | foreach (var file in m_FilteredFiles)
50 | {
51 | var fileText = File.ReadAllText(file);
52 | fileText = fileText.Replace(GetGuidExpression(TargetGuid), GetGuidExpression(guid));
53 | File.WriteAllText(file, fileText);
54 | }
55 | }
56 |
57 | public void Print()
58 | {
59 | Console.WriteLine();
60 | Console.WriteLine($"Total {m_FilteredFiles.Count} assets found:");
61 | foreach (var file in m_FilteredFiles)
62 | {
63 | Console.WriteLine("\t" + Path.GetFileName(file));
64 | }
65 | }
66 |
67 | private static List FindYamlFiles(string path)
68 | {
69 | return FileSearch.FindFiles(path, (file) =>
70 | {
71 | using (var readingFile = new StreamReader(file))
72 | {
73 | var firstLine = readingFile.ReadLine();
74 | return firstLine.Contains("%YAML");
75 | }
76 | });
77 | }
78 |
79 | private static string GetGuidExpression(string guid)
80 | {
81 | return $"guid: {guid}";
82 | }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.suo
8 | *.user
9 | *.userosscache
10 | *.sln.docstates
11 |
12 | # User-specific files (MonoDevelop/Xamarin Studio)
13 | *.userprefs
14 |
15 | # Build results
16 | [Dd]ebug/
17 | [Dd]ebugPublic/
18 | [Rr]elease/
19 | [Rr]eleases/
20 | x64/
21 | x86/
22 | bld/
23 | [Bb]in/
24 | [Oo]bj/
25 | [Ll]og/
26 |
27 | # Visual Studio 2015 cache/options directory
28 | .vs/
29 | # Uncomment if you have tasks that create the project's static files in wwwroot
30 | #wwwroot/
31 |
32 | # MSTest test Results
33 | [Tt]est[Rr]esult*/
34 | [Bb]uild[Ll]og.*
35 |
36 | # NUNIT
37 | *.VisualState.xml
38 | TestResult.xml
39 |
40 | # Build Results of an ATL Project
41 | [Dd]ebugPS/
42 | [Rr]eleasePS/
43 | dlldata.c
44 |
45 | # .NET Core
46 | project.lock.json
47 | project.fragment.lock.json
48 | artifacts/
49 | **/Properties/launchSettings.json
50 |
51 | *_i.c
52 | *_p.c
53 | *_i.h
54 | *.ilk
55 | *.meta
56 | *.obj
57 | *.pch
58 | *.pdb
59 | *.pgc
60 | *.pgd
61 | *.rsp
62 | *.sbr
63 | *.tlb
64 | *.tli
65 | *.tlh
66 | *.tmp
67 | *.tmp_proj
68 | *.log
69 | *.vspscc
70 | *.vssscc
71 | .builds
72 | *.pidb
73 | *.svclog
74 | *.scc
75 |
76 | # Chutzpah Test files
77 | _Chutzpah*
78 |
79 | # Visual C++ cache files
80 | ipch/
81 | *.aps
82 | *.ncb
83 | *.opendb
84 | *.opensdf
85 | *.sdf
86 | *.cachefile
87 | *.VC.db
88 | *.VC.VC.opendb
89 |
90 | # Visual Studio profiler
91 | *.psess
92 | *.vsp
93 | *.vspx
94 | *.sap
95 |
96 | # TFS 2012 Local Workspace
97 | $tf/
98 |
99 | # Guidance Automation Toolkit
100 | *.gpState
101 |
102 | # ReSharper is a .NET coding add-in
103 | _ReSharper*/
104 | *.[Rr]e[Ss]harper
105 | *.DotSettings.user
106 |
107 | # JustCode is a .NET coding add-in
108 | .JustCode
109 |
110 | # TeamCity is a build add-in
111 | _TeamCity*
112 |
113 | # DotCover is a Code Coverage Tool
114 | *.dotCover
115 |
116 | # Visual Studio code coverage results
117 | *.coverage
118 | *.coveragexml
119 |
120 | # NCrunch
121 | _NCrunch_*
122 | .*crunch*.local.xml
123 | nCrunchTemp_*
124 |
125 | # MightyMoose
126 | *.mm.*
127 | AutoTest.Net/
128 |
129 | # Web workbench (sass)
130 | .sass-cache/
131 |
132 | # Installshield output folder
133 | [Ee]xpress/
134 |
135 | # DocProject is a documentation generator add-in
136 | DocProject/buildhelp/
137 | DocProject/Help/*.HxT
138 | DocProject/Help/*.HxC
139 | DocProject/Help/*.hhc
140 | DocProject/Help/*.hhk
141 | DocProject/Help/*.hhp
142 | DocProject/Help/Html2
143 | DocProject/Help/html
144 |
145 | # Click-Once directory
146 | publish/
147 |
148 | # Publish Web Output
149 | *.[Pp]ublish.xml
150 | *.azurePubxml
151 | # TODO: Comment the next line if you want to checkin your web deploy settings
152 | # but database connection strings (with potential passwords) will be unencrypted
153 | *.pubxml
154 | *.publishproj
155 |
156 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
157 | # checkin your Azure Web App publish settings, but sensitive information contained
158 | # in these scripts will be unencrypted
159 | PublishScripts/
160 |
161 | # NuGet Packages
162 | *.nupkg
163 | # The packages folder can be ignored because of Package Restore
164 | **/packages/*
165 | # except build/, which is used as an MSBuild target.
166 | !**/packages/build/
167 | # Uncomment if necessary however generally it will be regenerated when needed
168 | #!**/packages/repositories.config
169 | # NuGet v3's project.json files produces more ignorable files
170 | *.nuget.props
171 | *.nuget.targets
172 |
173 | # Microsoft Azure Build Output
174 | csx/
175 | *.build.csdef
176 |
177 | # Microsoft Azure Emulator
178 | ecf/
179 | rcf/
180 |
181 | # Windows Store app package directories and files
182 | AppPackages/
183 | BundleArtifacts/
184 | Package.StoreAssociation.xml
185 | _pkginfo.txt
186 |
187 | # Visual Studio cache files
188 | # files ending in .cache can be ignored
189 | *.[Cc]ache
190 | # but keep track of directories ending in .cache
191 | !*.[Cc]ache/
192 |
193 | # Others
194 | ClientBin/
195 | ~$*
196 | *~
197 | *.dbmdl
198 | *.dbproj.schemaview
199 | *.jfm
200 | *.pfx
201 | *.publishsettings
202 | orleans.codegen.cs
203 |
204 | # Since there are multiple workflows, uncomment next line to ignore bower_components
205 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
206 | #bower_components/
207 |
208 | # RIA/Silverlight projects
209 | Generated_Code/
210 |
211 | # Backup & report files from converting an old project file
212 | # to a newer Visual Studio version. Backup files are not needed,
213 | # because we have git ;-)
214 | _UpgradeReport_Files/
215 | Backup*/
216 | UpgradeLog*.XML
217 | UpgradeLog*.htm
218 |
219 | # SQL Server files
220 | *.mdf
221 | *.ldf
222 | *.ndf
223 |
224 | # Business Intelligence projects
225 | *.rdl.data
226 | *.bim.layout
227 | *.bim_*.settings
228 |
229 | # Microsoft Fakes
230 | FakesAssemblies/
231 |
232 | # GhostDoc plugin setting file
233 | *.GhostDoc.xml
234 |
235 | # Node.js Tools for Visual Studio
236 | .ntvs_analysis.dat
237 | node_modules/
238 |
239 | # Typescript v1 declaration files
240 | typings/
241 |
242 | # Visual Studio 6 build log
243 | *.plg
244 |
245 | # Visual Studio 6 workspace options file
246 | *.opt
247 |
248 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
249 | *.vbw
250 |
251 | # Visual Studio LightSwitch build output
252 | **/*.HTMLClient/GeneratedArtifacts
253 | **/*.DesktopClient/GeneratedArtifacts
254 | **/*.DesktopClient/ModelManifest.xml
255 | **/*.Server/GeneratedArtifacts
256 | **/*.Server/ModelManifest.xml
257 | _Pvt_Extensions
258 |
259 | # Paket dependency manager
260 | .paket/paket.exe
261 | paket-files/
262 |
263 | # FAKE - F# Make
264 | .fake/
265 |
266 | # JetBrains Rider
267 | .idea/
268 | *.sln.iml
269 |
270 | # CodeRush
271 | .cr/
272 |
273 | # Python Tools for Visual Studio (PTVS)
274 | __pycache__/
275 | *.pyc
276 |
277 | # Cake - Uncomment if you are using it
278 | # tools/**
279 | # !tools/packages.config
280 |
281 | # Telerik's JustMock configuration file
282 | *.jmconfig
283 |
284 | # BizTalk build output
285 | *.btp.cs
286 | *.btm.cs
287 | *.odx.cs
288 | *.xsd.cs
289 |
--------------------------------------------------------------------------------