CodeSmile AssetDatabase 1.9
Unity's AssetDatabase in enjoyable, consistent, concise, convenient, comprehensible, safe, documented form.
Loading...
Searching...
No Matches
Asset.VersionControl.cs
1// Copyright (C) 2021-2023 Steffen Itterheim
2// Refer to included LICENSE file for terms and conditions.
3
4using System;
5using System.Collections.Generic;
6using System.Diagnostics.CodeAnalysis;
7using UnityEditor;
8using Object = UnityEngine.Object;
9
10namespace CodeSmileEditor
11{
12 public sealed partial class Asset
13 {
17 public static class VersionControl
18 {
19 private const StatusQueryOptions DefaultStatusQueryOption = StatusQueryOptions.UseCachedIfPossible;
20
39 public static Boolean CanMakeEditable([NotNull] Path path, StatusQueryOptions options = DefaultStatusQueryOption)
40 {
41 var canOpen = AssetDatabase.CanOpenForEdit(path, out var message, options);
42 if (canOpen == false)
43 SetLastErrorMessage(message);
44
45 return canOpen;
46 }
47
66 public static Boolean CanMakeEditable([NotNull] Object asset, StatusQueryOptions options = DefaultStatusQueryOption)
67 {
68 ThrowIf.ArgumentIsNull(asset, nameof(asset));
69
70 return CanMakeEditable(Path.Get(asset), options);
71 }
72
90 public static void CanMakeEditable([NotNull] Path[] paths, out List<String> notEditablePaths,
91 StatusQueryOptions options = DefaultStatusQueryOption) =>
92 CanMakeEditable(Path.ToStrings(paths), out notEditablePaths, options);
93
111 public static void CanMakeEditable([NotNull] String[] paths, out List<String> notEditablePaths,
112 StatusQueryOptions options = DefaultStatusQueryOption)
113 {
114 notEditablePaths = new List<String>();
115 AssetDatabase.CanOpenForEdit(paths, notEditablePaths, options);
116 }
117
135 public static void CanMakeEditable([NotNull] Object[] assets, out List<String> notEditablePaths,
136 StatusQueryOptions options = DefaultStatusQueryOption) =>
137 CanMakeEditable(Path.Get(assets), out notEditablePaths, options);
138
156 public static Boolean IsMetaEditable([NotNull] Object asset, StatusQueryOptions options = DefaultStatusQueryOption)
157 {
158 var isOpen = AssetDatabase.IsMetaFileOpenForEdit(asset, out var message, options);
159 if (isOpen == false)
160 SetLastErrorMessage(message);
161
162 return isOpen;
163 }
164
182 public static Boolean IsEditable([NotNull] Object asset, StatusQueryOptions options = DefaultStatusQueryOption)
183 {
184 var isOpen = AssetDatabase.IsOpenForEdit(asset, out var message, options);
185 if (isOpen == false)
186 SetLastErrorMessage(message);
187
188 return isOpen;
189 }
190
205 public static void IsEditable([NotNull] Path[] paths, out List<String> notEditablePaths,
206 StatusQueryOptions options = DefaultStatusQueryOption) =>
207 IsEditable(Path.ToStrings(paths), out notEditablePaths, options);
208
223 public static void IsEditable([NotNull] String[] paths, out List<String> notEditablePaths,
224 StatusQueryOptions options = DefaultStatusQueryOption)
225 {
226 notEditablePaths = new List<String>();
227 AssetDatabase.IsOpenForEdit(paths, notEditablePaths, options);
228 }
229
244 public static void IsEditable([NotNull] Object[] assets, out List<String> notEditablePaths,
245 StatusQueryOptions options = DefaultStatusQueryOption) =>
246 IsEditable(Path.Get(assets), out notEditablePaths, options);
247
261 public static Boolean MakeEditable([NotNull] Path path) => AssetDatabase.MakeEditable(path);
262
277 public static Boolean MakeEditable([NotNull] Path[] paths, out List<String> notEditablePaths) =>
278 MakeMultipleEditable(Path.ToStrings(paths), out notEditablePaths);
279
294 public static Boolean MakeEditable([NotNull] String[] paths, out List<String> notEditablePaths) =>
295 MakeMultipleEditable(paths, out notEditablePaths);
296
313 public static Boolean MakeEditableInteractive([NotNull] Path[] paths, out List<String> notEditablePaths,
314 String prompt = null) => MakeMultipleEditable(Path.ToStrings(paths), out notEditablePaths,
315 prompt != null ? prompt : "Open for Edit?");
316
333 public static Boolean MakeEditableInteractive([NotNull] String[] paths, out List<String> notEditablePaths,
334 String prompt = null) => MakeMultipleEditable(paths, out notEditablePaths,
335 prompt != null ? prompt : "Open for Edit?");
336
337 private static Boolean MakeMultipleEditable([NotNull] String[] paths, out List<String> notEditablePaths,
338 String prompt = null)
339 {
340 notEditablePaths = new List<String>();
341 return AssetDatabase.MakeEditable(paths, prompt, notEditablePaths);
342 }
343 }
344 }
345}
static String[] ToStrings([NotNull] IEnumerable< Path > paths)
Converts an IEnumerable collection of Path instances to a string array.
static Path Get([NotNull] Object asset)
Gets the relative path of an asset.
Represents a relative path to an asset file or folder, typically under 'Assets' or 'Packages'.
Definition Asset.Path.cs:25
static void IsEditable([NotNull] Path[] paths, out List< String > notEditablePaths, StatusQueryOptions options=DefaultStatusQueryOption)
Tests if the assets can be opened for editing in the version control system.
static Boolean MakeEditable([NotNull] String[] paths, out List< String > notEditablePaths)
Tries to open multiple paths for editing in the version control system.
static Boolean IsEditable([NotNull] Object asset, StatusQueryOptions options=DefaultStatusQueryOption)
Returns true if the asset file is open for editing in the version control system.
static void CanMakeEditable([NotNull] Object[] assets, out List< String > notEditablePaths, StatusQueryOptions options=DefaultStatusQueryOption)
Tests which assets can be made editable and provides a list of paths that cannot be opened for editin...
static Boolean MakeEditable([NotNull] Path path)
Tries to open the path for editing in the version control system.
static Boolean CanMakeEditable([NotNull] Path path, StatusQueryOptions options=DefaultStatusQueryOption)
Returns true if the asset can be opened for editing in the version control system.
static Boolean CanMakeEditable([NotNull] Object asset, StatusQueryOptions options=DefaultStatusQueryOption)
Returns true if the asset can be opened for editing in the version control system.
static void CanMakeEditable([NotNull] Path[] paths, out List< String > notEditablePaths, StatusQueryOptions options=DefaultStatusQueryOption)
Tests which assets can be made editable and provides a list of paths that cannot be opened for editin...
static Boolean MakeEditableInteractive([NotNull] String[] paths, out List< String > notEditablePaths, String prompt=null)
Tries to open multiple paths for editing in the version control system. Shows a prompt to the user un...
static Boolean IsMetaEditable([NotNull] Object asset, StatusQueryOptions options=DefaultStatusQueryOption)
Returns true if the meta file is open for editing in the version control system.
static Boolean MakeEditable([NotNull] Path[] paths, out List< String > notEditablePaths)
Tries to open multiple paths for editing in the version control system.
static void CanMakeEditable([NotNull] String[] paths, out List< String > notEditablePaths, StatusQueryOptions options=DefaultStatusQueryOption)
Tests which assets can be made editable and provides a list of paths that cannot be opened for editin...
static Boolean MakeEditableInteractive([NotNull] Path[] paths, out List< String > notEditablePaths, String prompt=null)
Tries to open multiple paths for editing in the version control system. Shows a prompt to the user un...
static void IsEditable([NotNull] String[] paths, out List< String > notEditablePaths, StatusQueryOptions options=DefaultStatusQueryOption)
Tests if the assets can be opened for editing in the version control system.
static void IsEditable([NotNull] Object[] assets, out List< String > notEditablePaths, StatusQueryOptions options=DefaultStatusQueryOption)
Tests if the assets can be opened for editing in the version control system.
Groups version control related functionality.