forked from MattRix/UnityDecompiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssetModificationHook.cs
More file actions
87 lines (87 loc) · 2.79 KB
/
Copy pathAssetModificationHook.cs
File metadata and controls
87 lines (87 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
using UnityEditor;
using UnityEditor.VersionControl;
using UnityEngine;
namespace UnityEditorInternal.VersionControl
{
public class AssetModificationHook
{
private static Asset GetStatusCachedIfPossible(string from)
{
Asset asset = Provider.CacheStatus(from);
if (asset == null || asset.IsState(Asset.States.Updating))
{
Task task = Provider.Status(from, false);
task.Wait();
asset = Provider.CacheStatus(from);
}
return asset;
}
public static AssetMoveResult OnWillMoveAsset(string from, string to)
{
if (!Provider.enabled)
{
return AssetMoveResult.DidNotMove;
}
Asset statusCachedIfPossible = AssetModificationHook.GetStatusCachedIfPossible(from);
if (statusCachedIfPossible == null || !statusCachedIfPossible.IsUnderVersionControl)
{
return AssetMoveResult.DidNotMove;
}
if (statusCachedIfPossible.IsState(Asset.States.OutOfSync))
{
Debug.LogError("Cannot move version controlled file that is not up to date. Please get latest changes from server");
return AssetMoveResult.FailedMove;
}
if (statusCachedIfPossible.IsState(Asset.States.DeletedRemote))
{
Debug.LogError("Cannot move version controlled file that is deleted on server. Please get latest changes from server");
return AssetMoveResult.FailedMove;
}
if (statusCachedIfPossible.IsState(Asset.States.CheckedOutRemote))
{
Debug.LogError("Cannot move version controlled file that is checked out on server. Please get latest changes from server");
return AssetMoveResult.FailedMove;
}
if (statusCachedIfPossible.IsState(Asset.States.LockedRemote))
{
Debug.LogError("Cannot move version controlled file that is locked on server. Please get latest changes from server");
return AssetMoveResult.FailedMove;
}
Task task = Provider.Move(from, to);
task.Wait();
return (AssetMoveResult)((!task.success) ? 1 : task.resultCode);
}
public static AssetDeleteResult OnWillDeleteAsset(string assetPath, RemoveAssetOptions option)
{
if (!Provider.enabled)
{
return AssetDeleteResult.DidNotDelete;
}
Task task = Provider.Delete(assetPath);
task.SetCompletionAction(CompletionAction.UpdatePendingWindow);
task.Wait();
return (!task.success) ? AssetDeleteResult.FailedDelete : AssetDeleteResult.DidNotDelete;
}
public static bool IsOpenForEdit(string assetPath, out string message)
{
message = string.Empty;
if (!Provider.enabled)
{
return true;
}
if (string.IsNullOrEmpty(assetPath))
{
return true;
}
Asset asset = Provider.GetAssetByPath(assetPath);
if (asset == null)
{
Task task = Provider.Status(assetPath, false);
task.Wait();
asset = ((task.assetList.Count <= 0) ? null : task.assetList[0]);
}
return asset != null && Provider.IsOpenForEdit(asset);
}
}
}