com.elestrago.unity.package-tools 2.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/CAHNGELOG.md +130 -0
  2. package/CAHNGELOG.md.meta +7 -0
  3. package/Documentation~/Inspector.png +0 -0
  4. package/Documentation~/PackageManifestConfigIcon.png +0 -0
  5. package/Editor/CIUtils.cs +247 -0
  6. package/Editor/CIUtils.cs.meta +11 -0
  7. package/Editor/Drawers/AuthorPropertyDrawer.cs +82 -0
  8. package/Editor/Drawers/AuthorPropertyDrawer.cs.meta +11 -0
  9. package/Editor/Drawers/DependencyPropertyDrawer.cs +60 -0
  10. package/Editor/Drawers/DependencyPropertyDrawer.cs.meta +3 -0
  11. package/Editor/Drawers/SamplePropertyDrawer.cs +62 -0
  12. package/Editor/Drawers/SamplePropertyDrawer.cs.meta +3 -0
  13. package/Editor/Drawers.meta +3 -0
  14. package/Editor/EditorConstants.cs +110 -0
  15. package/Editor/EditorConstants.cs.meta +3 -0
  16. package/Editor/IconMap/PackageManifestConfigIcon.png +0 -0
  17. package/Editor/IconMap/PackageManifestConfigIcon.png.meta +127 -0
  18. package/Editor/IconMap.meta +8 -0
  19. package/Editor/Inspectors/PackageManifestConfigInspector.cs +404 -0
  20. package/Editor/Inspectors/PackageManifestConfigInspector.cs.meta +3 -0
  21. package/Editor/Inspectors.meta +3 -0
  22. package/Editor/MenuItems.cs +11 -0
  23. package/Editor/MenuItems.cs.meta +11 -0
  24. package/Editor/PackageManifestConfig.cs +194 -0
  25. package/Editor/PackageManifestConfig.cs.meta +11 -0
  26. package/Editor/Playdarium.PackageTool.Editor.asmdef +16 -0
  27. package/Editor/Playdarium.PackageTool.Editor.asmdef.meta +7 -0
  28. package/Editor/Tools/CodeGenTools.cs +145 -0
  29. package/Editor/Tools/CodeGenTools.cs.meta +11 -0
  30. package/Editor/Tools/CommandLineTools.cs +68 -0
  31. package/Editor/Tools/CommandLineTools.cs.meta +11 -0
  32. package/Editor/Tools/FileTools.cs +328 -0
  33. package/Editor/Tools/FileTools.cs.meta +3 -0
  34. package/Editor/Tools/GUILayoutTools.cs +177 -0
  35. package/Editor/Tools/GUILayoutTools.cs.meta +3 -0
  36. package/Editor/Tools/GitTools.cs +66 -0
  37. package/Editor/Tools/GitTools.cs.meta +11 -0
  38. package/Editor/Tools/PackageJsonModel.cs +149 -0
  39. package/Editor/Tools/PackageJsonModel.cs.meta +3 -0
  40. package/Editor/Tools/PackageManifestTools.cs +77 -0
  41. package/Editor/Tools/PackageManifestTools.cs.meta +3 -0
  42. package/Editor/Tools/UnityFileTools.cs +132 -0
  43. package/Editor/Tools/UnityFileTools.cs.meta +3 -0
  44. package/Editor/Tools.meta +3 -0
  45. package/Editor/Utils/PackageInitialize/PackageInitializeTemplates.cs +171 -0
  46. package/Editor/Utils/PackageInitialize/PackageInitializeTemplates.cs.meta +3 -0
  47. package/Editor/Utils/PackageInitialize/PackageInitializeUtil.cs +111 -0
  48. package/Editor/Utils/PackageInitialize/PackageInitializeUtil.cs.meta +3 -0
  49. package/Editor/Utils/PackageInitialize/PackageInitializeWindow.cs +92 -0
  50. package/Editor/Utils/PackageInitialize/PackageInitializeWindow.cs.meta +3 -0
  51. package/Editor/Utils/PackageInitialize.meta +3 -0
  52. package/Editor/Utils.meta +3 -0
  53. package/Editor.meta +3 -0
  54. package/LICENSE +21 -0
  55. package/LICENSE.meta +7 -0
  56. package/README.md +204 -0
  57. package/README.md.meta +7 -0
  58. package/package.json +41 -0
  59. package/package.json.meta +7 -0
@@ -0,0 +1,328 @@
1
+ /*
2
+ MIT License
3
+
4
+ Copyright (c) 2020 Jeff Campbell
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
23
+ */
24
+
25
+ using System;
26
+ using System.Collections.Generic;
27
+ using System.IO;
28
+ using System.Linq;
29
+ using UnityEditor;
30
+ using UnityEngine;
31
+ using UnityEngine.Networking;
32
+
33
+ namespace Playdarium.PackageTool.Tools
34
+ {
35
+ /// <summary>
36
+ /// Helper methods for dealing with files/directories
37
+ /// </summary>
38
+ internal static class FileTools
39
+ {
40
+ /// <summary>
41
+ /// Converts <paramref name="fullFilePath"/> into a relative file path from <paramref name="referencePath"/>.
42
+ /// </summary>
43
+ /// <param name="fullFilePath"></param>
44
+ /// <param name="referencePath"></param>
45
+ /// <returns></returns>
46
+ public static string ConvertToRelativePath(string fullFilePath, string referencePath)
47
+ {
48
+ var fileUri = new Uri(fullFilePath);
49
+ var referenceUri = new Uri(referencePath);
50
+ var uri = referenceUri.MakeRelativeUri(fileUri).ToString();
51
+ return UnityWebRequest.UnEscapeURL(uri);
52
+ }
53
+
54
+ /// <summary>
55
+ /// Creates or updates the existing package contents of <see cref="PackageManifestConfig"/>
56
+ /// <paramref name="packageManifest"/>.
57
+ /// </summary>
58
+ /// <param name="packageManifest"></param>
59
+ public static void CreateOrUpdatePackageSource(PackageManifestConfig packageManifest)
60
+ {
61
+ if (!Application.isBatchMode)
62
+ {
63
+ EditorUtility.DisplayProgressBar(EditorConstants.PROGRESS_BAR_TITLE, string.Empty, 0f);
64
+ }
65
+
66
+ try
67
+ {
68
+ // Created the folders up to the package json path and then create/import the package.json file.
69
+ // Its important to have the package.json in the Unity project so that it will have a meta file
70
+ // Packages without meta files cause warnings/errors when imported.
71
+ var packageManifestAssetPath = AssetDatabase.GetAssetPath(packageManifest);
72
+ var parentManifestParentFolderAssetPath = packageManifestAssetPath
73
+ .Replace(packageManifest.name, string.Empty)
74
+ .Replace(EditorConstants.ASSET_EXTENSION, string.Empty);
75
+ var generatedFolderAssetPath = Path.Combine(parentManifestParentFolderAssetPath,
76
+ EditorConstants.GENERATED_FOLDER_NAME);
77
+ var fullGeneratedFolderAssetPath = Path.GetFullPath(generatedFolderAssetPath);
78
+
79
+ if (!Directory.Exists(fullGeneratedFolderAssetPath))
80
+ {
81
+ Directory.CreateDirectory(fullGeneratedFolderAssetPath);
82
+ }
83
+
84
+ var packageJsonFolderAssetPath = Path.Combine(generatedFolderAssetPath, packageManifest.Id);
85
+ var fullPackageJsonFolderAssetPath = Path.GetFullPath(packageJsonFolderAssetPath);
86
+ if (!Directory.Exists(fullPackageJsonFolderAssetPath))
87
+ {
88
+ Directory.CreateDirectory(fullPackageJsonFolderAssetPath);
89
+ }
90
+
91
+ var packageJsonAssetPath =
92
+ Path.Combine(packageJsonFolderAssetPath, EditorConstants.PACKAGE_JSON_FILENAME);
93
+ var fullPackageJsonAssetPath = Path.GetFullPath(packageJsonAssetPath);
94
+
95
+ File.WriteAllText(fullPackageJsonAssetPath, packageManifest.GenerateJson());
96
+ AssetDatabase.ImportAsset(packageJsonAssetPath, ImportAssetOptions.ForceUpdate);
97
+
98
+ // If the directory exists, delete its contents or make the directory.
99
+ if (Directory.Exists(packageManifest.packageDestinationPath))
100
+ {
101
+ RecursivelyDeleteDirectoryContents(new DirectoryInfo(packageManifest.packageDestinationPath));
102
+ }
103
+ else
104
+ {
105
+ Directory.CreateDirectory(packageManifest.packageDestinationPath);
106
+ }
107
+
108
+ // Copy over the package json and meta file
109
+ var destinationPackageJsonPath =
110
+ Path.Combine(packageManifest.packageDestinationPath, EditorConstants.PACKAGE_JSON_FILENAME);
111
+ File.Copy(fullPackageJsonAssetPath, destinationPackageJsonPath);
112
+
113
+ var packageJsonMetaPath = string.Format(EditorConstants.META_FORMAT, fullPackageJsonAssetPath);
114
+
115
+ File.Copy(packageJsonMetaPath,
116
+ Path.Combine(packageManifest.packageDestinationPath,
117
+ string.Format(EditorConstants.META_FORMAT, EditorConstants.PACKAGE_JSON_FILENAME)));
118
+
119
+ // Copy over all directory and file content from source to destination.
120
+ var normalizedDestinationPath = Path.GetFullPath(packageManifest.packageDestinationPath);
121
+
122
+ // If its a file, copy over it and its meta file if it exists.
123
+ var normalizedSourcePath = Path.GetFullPath(packageManifest.sourcePath);
124
+
125
+ CopyDocumentationToDirectory(packageManifest);
126
+
127
+ // if (IsFile(normalizedSourcePath) && File.Exists(normalizedSourcePath))
128
+ // {
129
+ // var fileInfo = new FileInfo(normalizedSourcePath);
130
+ // if (fileInfo.Directory == null)
131
+ // return;
132
+ //
133
+ // var parentDirectoryPath = fileInfo.Directory.FullName;
134
+ // var newPath = normalizedSourcePath.Replace(parentDirectoryPath, normalizedDestinationPath);
135
+ //
136
+ // File.Copy(normalizedSourcePath, newPath);
137
+ //
138
+ // var sourceMetaPath = string.Format(EditorConstants.META_FORMAT, normalizedSourcePath);
139
+ // if (File.Exists(sourceMetaPath))
140
+ // {
141
+ // var newMetaPath = sourceMetaPath.Replace(parentDirectoryPath, normalizedDestinationPath);
142
+ // File.Copy(sourceMetaPath, newMetaPath);
143
+ // }
144
+ // }
145
+ // Otherwise if this is a folder, copy it and all the contents over to the destination folder.
146
+ // else
147
+ {
148
+ RecursivelyCopyDirectoriesAndFiles(
149
+ packageManifest,
150
+ new DirectoryInfo(normalizedSourcePath),
151
+ normalizedSourcePath,
152
+ normalizedDestinationPath);
153
+ }
154
+
155
+ Debug.LogFormat(EditorConstants.PACKAGE_UPDATE_SUCCESS_FORMAT, packageManifest.packageName);
156
+
157
+ if (!Application.isBatchMode)
158
+ {
159
+ EditorUtility.RevealInFinder(destinationPackageJsonPath);
160
+ }
161
+ }
162
+ catch (Exception ex)
163
+ {
164
+ Debug.LogErrorFormat(EditorConstants.PACKAGE_UPDATE_ERROR_FORMAT, packageManifest.packageName);
165
+ Debug.LogErrorFormat(packageManifest, ex.ToString());
166
+ }
167
+ finally
168
+ {
169
+ if (!Application.isBatchMode)
170
+ {
171
+ EditorUtility.DisplayProgressBar(EditorConstants.PROGRESS_BAR_TITLE, string.Empty, 1f);
172
+ EditorUtility.ClearProgressBar();
173
+ }
174
+ }
175
+ }
176
+
177
+ public static void CopyDocumentationToDirectory(PackageManifestConfig packageManifest)
178
+ {
179
+ var normalizedSourcePath = Path.GetFullPath(packageManifest.sourcePath);
180
+ CopyOrReplaceFileToDirectory(packageManifest.readmePath, normalizedSourcePath);
181
+ CopyOrReplaceFileToDirectory(packageManifest.changelogPath, normalizedSourcePath);
182
+ CopyOrReplaceFileToDirectory(packageManifest.licensePath, normalizedSourcePath);
183
+
184
+ var normalizedDocumentationPath = Path.GetFullPath(packageManifest.documentationPath);
185
+ var destinationPath = Path.Combine(normalizedSourcePath, "Documentation~");
186
+ if (Directory.Exists(destinationPath))
187
+ Directory.Delete(destinationPath, true);
188
+
189
+ Directory.CreateDirectory(destinationPath);
190
+
191
+ var documentationDir = new DirectoryInfo(packageManifest.documentationPath);
192
+ if (documentationDir.Exists)
193
+ RecursivelyCopyDirectoriesAndFiles(
194
+ packageManifest,
195
+ documentationDir,
196
+ normalizedDocumentationPath,
197
+ destinationPath
198
+ );
199
+
200
+ // Generate meta
201
+ AssetDatabase.Refresh();
202
+ }
203
+
204
+ private static void CopyOrReplaceFileToDirectory(string filePath, string normalizedDestinationPath)
205
+ {
206
+ var normalizedSourcePath = Path.GetFullPath(filePath);
207
+ if (!IsFile(normalizedSourcePath) || !File.Exists(normalizedSourcePath))
208
+ return;
209
+
210
+ var fileInfo = new FileInfo(normalizedSourcePath);
211
+ if (fileInfo.Directory == null)
212
+ return;
213
+
214
+ var parentDirectoryPath = fileInfo.Directory.FullName;
215
+ var destinationPath = normalizedSourcePath.Replace(parentDirectoryPath, normalizedDestinationPath);
216
+
217
+ if (File.Exists(destinationPath))
218
+ File.Delete(destinationPath);
219
+
220
+ File.Copy(normalizedSourcePath, destinationPath);
221
+ }
222
+
223
+ /// <summary>
224
+ /// Returns true if the <paramref name="path"/> is for a file, otherwise false.
225
+ /// </summary>
226
+ /// <param name="path"></param>
227
+ /// <returns></returns>
228
+ public static bool IsFile(string path)
229
+ {
230
+ var attr = File.GetAttributes(path);
231
+ return (attr & FileAttributes.Directory) != FileAttributes.Directory;
232
+ }
233
+
234
+ /// <summary>
235
+ /// Recursively copies all sub-folders and files in <see cref="DirectoryInfo"/> <paramref name="directoryInfo"/>
236
+ /// from parent folder <see cref="sourcePath"/> to <paramref name="destinationPath"/>.
237
+ /// </summary>
238
+ /// <param name="packageManifest"></param>
239
+ /// <param name="directoryInfo"></param>
240
+ /// <param name="sourcePath"></param>
241
+ /// <param name="destinationPath"></param>
242
+ private static void RecursivelyCopyDirectoriesAndFiles(
243
+ PackageManifestConfig packageManifest,
244
+ DirectoryInfo directoryInfo,
245
+ string sourcePath,
246
+ string destinationPath
247
+ )
248
+ {
249
+ var normalizedSourcePath = Path.GetFullPath(sourcePath);
250
+ var normalizedDestinationPath = Path.GetFullPath(destinationPath);
251
+ var subDirectoryInfo = directoryInfo.GetDirectories(EditorConstants.WILDCARD_FILTER);
252
+ foreach (var sdi in subDirectoryInfo)
253
+ {
254
+ // If any of the paths we're looking at match the ignore paths from the user, skip them
255
+ if (packageManifest.packageIgnorePaths.Any(x =>
256
+ sdi.FullName.Contains(Path.GetFullPath(Path.Combine(EditorConstants.ProjectPath, x)))))
257
+ {
258
+ continue;
259
+ }
260
+
261
+ Directory.CreateDirectory(sdi.FullName.Replace(normalizedSourcePath, normalizedDestinationPath));
262
+
263
+ RecursivelyCopyDirectoriesAndFiles(packageManifest, sdi, normalizedSourcePath,
264
+ normalizedDestinationPath);
265
+ }
266
+
267
+ var fileInfo = directoryInfo.GetFiles(EditorConstants.WILDCARD_FILTER);
268
+ foreach (var fi in fileInfo)
269
+ {
270
+ // If any of the paths we're looking at match the ignore paths from the user, skip them
271
+ if (packageManifest.packageIgnorePaths.Any(x =>
272
+ fi.FullName.Contains(Path.GetFullPath(Path.Combine(EditorConstants.ProjectPath, x)))))
273
+ {
274
+ continue;
275
+ }
276
+
277
+ var newPath = Path.GetFullPath(fi.FullName).Replace(normalizedSourcePath, normalizedDestinationPath);
278
+ File.Copy(fi.FullName, newPath);
279
+ }
280
+ }
281
+
282
+ /// <summary>
283
+ /// Recursively deletes all sub-folders (excluding hidden folders) and files in <see cref="DirectoryInfo"/>
284
+ /// <paramref name="directoryInfo"/>.
285
+ /// </summary>
286
+ /// <param name="directoryInfo"></param>
287
+ private static void RecursivelyDeleteDirectoryContents(DirectoryInfo directoryInfo)
288
+ {
289
+ var subDirectoryInfo = directoryInfo.GetDirectories(EditorConstants.WILDCARD_FILTER);
290
+ foreach (var sdi in subDirectoryInfo)
291
+ {
292
+ if ((sdi.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden)
293
+ {
294
+ sdi.Delete(true);
295
+ }
296
+ }
297
+
298
+ var fileInfo = directoryInfo.GetFiles(EditorConstants.WILDCARD_FILTER);
299
+ foreach (var fi in fileInfo)
300
+ {
301
+ fi.Delete();
302
+ }
303
+ }
304
+
305
+ /// <summary>
306
+ /// Recursive find all files starting at root folder at path <paramref name="folderPath"/>
307
+ /// and return a list of absolute paths to those files.
308
+ /// </summary>
309
+ /// <param name="folderPath"></param>
310
+ /// <returns></returns>
311
+ internal static IEnumerable<string> GetAllFilesRecursively(string folderPath)
312
+ {
313
+ var filePaths = new List<string>();
314
+ var fullPath = Path.GetFullPath(folderPath);
315
+ filePaths.AddRange(Directory.GetFiles(
316
+ fullPath,
317
+ EditorConstants.WILDCARD_FILTER,
318
+ SearchOption.AllDirectories));
319
+
320
+ filePaths.AddRange(Directory.GetDirectories(
321
+ folderPath,
322
+ EditorConstants.WILDCARD_FILTER,
323
+ SearchOption.AllDirectories));
324
+
325
+ return filePaths.Distinct().OrderBy(x => x);
326
+ }
327
+ }
328
+ }
@@ -0,0 +1,3 @@
1
+ fileFormatVersion: 2
2
+ guid: 97019f57d956413a94945dd0f3dbe482
3
+ timeCreated: 1554880626
@@ -0,0 +1,177 @@
1
+ /*
2
+ MIT License
3
+
4
+ Copyright (c) 2020 Jeff Campbell
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
23
+ */
24
+
25
+ using System.IO;
26
+ using UnityEditor;
27
+ using UnityEngine;
28
+
29
+ namespace Playdarium.PackageTool.Tools
30
+ {
31
+ /// <summary>
32
+ /// Helper methods for Unity Editor GUI.
33
+ /// </summary>
34
+ internal static class GUILayoutTools
35
+ {
36
+ /// <summary>
37
+ /// Draw a folder picker button in <see cref="Rect"/> <paramref name="rect"/> that allows setting a
38
+ /// relative folder path value on <see cref="SerializedProperty"/> <paramref name="property"/>.
39
+ /// </summary>
40
+ /// <param name="rect"></param>
41
+ /// <param name="property"></param>
42
+ /// <param name="title"></param>
43
+ public static void DrawFolderPicker(Rect rect, SerializedProperty property, string title)
44
+ {
45
+ if (GUI.Button(
46
+ rect,
47
+ EditorGUIUtility.IconContent(EditorConstants.EDITOR_FOLDER_ICON)))
48
+ {
49
+ var currentFolder = string.IsNullOrEmpty(property.stringValue)
50
+ ? string.Empty
51
+ : property.stringValue;
52
+
53
+ var path = EditorUtility.SaveFolderPanel(
54
+ title,
55
+ currentFolder,
56
+ string.Empty);
57
+
58
+ if (!string.IsNullOrEmpty(path))
59
+ {
60
+ var relativePath = FileTools.ConvertToRelativePath(path, Application.dataPath);
61
+ property.stringValue = relativePath;
62
+ }
63
+ }
64
+ }
65
+
66
+ public static void DrawSourceFolderPicker(Rect rect, SerializedProperty property, string title)
67
+ {
68
+ if (GUI.Button(
69
+ rect,
70
+ EditorGUIUtility.IconContent(EditorConstants.EDITOR_FOLDER_ICON)))
71
+ {
72
+ var sourcePath = $"/{property.serializedObject.FindProperty("sourcePath").stringValue}/";
73
+ var referencePath = Path.Combine(Application.dataPath, sourcePath);
74
+ var currentFolder = string.IsNullOrEmpty(property.stringValue)
75
+ ? referencePath
76
+ : property.stringValue;
77
+
78
+ var path = EditorUtility.SaveFolderPanel(
79
+ title,
80
+ currentFolder,
81
+ string.Empty);
82
+
83
+ if (!string.IsNullOrEmpty(path))
84
+ {
85
+ var relativePath = "/" + FileTools.ConvertToRelativePath(path, Application.dataPath);
86
+ relativePath = FileTools.ConvertToRelativePath(relativePath, sourcePath);
87
+ property.stringValue = relativePath;
88
+ }
89
+ }
90
+ }
91
+
92
+ /// <summary>
93
+ /// Draw a file picker button in <see cref="Rect"/> <paramref name="rect"/> that allows setting a
94
+ /// relative file path value on <see cref="SerializedProperty"/> <paramref name="property"/>.
95
+ /// </summary>
96
+ /// <param name="rect"></param>
97
+ /// <param name="property"></param>
98
+ /// <param name="title"></param>
99
+ public static void DrawFilePicker(Rect rect, SerializedProperty property, string title)
100
+ {
101
+ if (GUI.Button(
102
+ rect,
103
+ EditorGUIUtility.IconContent(EditorConstants.EDITOR_FILE_ICON)))
104
+ {
105
+ var currentFile = string.IsNullOrEmpty(property.stringValue)
106
+ ? string.Empty
107
+ : property.stringValue;
108
+
109
+ var path = EditorUtility.OpenFilePanel(
110
+ title,
111
+ currentFile,
112
+ string.Empty);
113
+
114
+ if (!string.IsNullOrEmpty(path))
115
+ {
116
+ var relativePath = FileTools.ConvertToRelativePath(path, Application.dataPath);
117
+ property.stringValue = relativePath;
118
+ }
119
+ }
120
+ }
121
+
122
+ /// <summary>
123
+ /// Draw a folder picker button using <see cref="GUILayout"/> that allows setting a
124
+ /// relative folder path value on <see cref="SerializedProperty"/> <paramref name="property"/>.
125
+ /// </summary>
126
+ /// <param name="property"></param>
127
+ /// <param name="title"></param>
128
+ public static void DrawFolderPickerLayout(SerializedProperty property, string title)
129
+ {
130
+ if (GUILayout.Button(
131
+ EditorGUIUtility.IconContent(EditorConstants.EDITOR_FOLDER_ICON),
132
+ GUILayout.Width(EditorConstants.FOLDER_PATH_PICKER_HEIGHT),
133
+ GUILayout.Height(EditorConstants.FOLDER_PATH_PICKER_HEIGHT)))
134
+ {
135
+ var currentFolder = string.IsNullOrEmpty(property.stringValue)
136
+ ? string.Empty
137
+ : property.stringValue;
138
+
139
+ var path = EditorUtility.SaveFolderPanel(
140
+ title,
141
+ currentFolder,
142
+ string.Empty);
143
+
144
+ if (!string.IsNullOrEmpty(path))
145
+ {
146
+ var relativePath = FileTools.ConvertToRelativePath(path, Application.dataPath);
147
+ property.stringValue = relativePath;
148
+ }
149
+ }
150
+ }
151
+
152
+ public static void DrawFilePickerLayout(SerializedProperty property, string title)
153
+ {
154
+ if (GUILayout.Button(
155
+ EditorGUIUtility.IconContent(EditorConstants.EDITOR_FILE_ICON),
156
+ GUILayout.Width(EditorConstants.FOLDER_PATH_PICKER_HEIGHT),
157
+ GUILayout.Height(EditorConstants.FOLDER_PATH_PICKER_HEIGHT)))
158
+ {
159
+ var currentFolder = string.IsNullOrEmpty(property.stringValue)
160
+ ? string.Empty
161
+ : property.stringValue;
162
+
163
+ var path = EditorUtility.OpenFilePanel(
164
+ title,
165
+ currentFolder,
166
+ string.Empty
167
+ );
168
+
169
+ if (!string.IsNullOrEmpty(path))
170
+ {
171
+ var relativePath = FileTools.ConvertToRelativePath(path, Application.dataPath);
172
+ property.stringValue = relativePath;
173
+ }
174
+ }
175
+ }
176
+ }
177
+ }
@@ -0,0 +1,3 @@
1
+ fileFormatVersion: 2
2
+ guid: fb22348bdc2245938ac4d553d3c884fd
3
+ timeCreated: 1555140749
@@ -0,0 +1,66 @@
1
+ /*
2
+ MIT License
3
+
4
+ Copyright (c) 2020 Jeff Campbell
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
23
+ */
24
+
25
+ using System.Diagnostics;
26
+ using UnityEngine;
27
+
28
+ namespace Playdarium.PackageTool.Tools
29
+ {
30
+ /// <summary>
31
+ /// Helper methods for retrieving git information
32
+ /// </summary>
33
+ public static class GitTools
34
+ {
35
+ private const string GIT_APPLICATION = "git";
36
+
37
+ public static string Run(string cmd)
38
+ {
39
+ // NOTE: This currently expects that you have git included in your PATH.
40
+ var p = new Process();
41
+ p.StartInfo.FileName = GIT_APPLICATION;
42
+ p.StartInfo.Arguments = cmd;
43
+ p.StartInfo.WorkingDirectory = Application.dataPath;
44
+ p.StartInfo.CreateNoWindow = true;
45
+ p.StartInfo.RedirectStandardOutput = true;
46
+ p.StartInfo.UseShellExecute = false;
47
+ p.Start();
48
+
49
+ var output = p.StandardOutput.ReadToEnd().Trim();
50
+
51
+ p.WaitForExit();
52
+
53
+ return output;
54
+ }
55
+
56
+ public static string GetBranch()
57
+ {
58
+ return Run("rev-parse --abbrev-ref HEAD");
59
+ }
60
+
61
+ public static string GetLongHeadHash()
62
+ {
63
+ return Run("rev-parse HEAD");
64
+ }
65
+ }
66
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 0834c7a5524d1a146b9c0d8f8bfbf3e2
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant: