Version: 2020.3

Provider

class in UnityEditor.VersionControl

切换到手册

描述

此类提供对版本控制 API 的访问。

请注意,版本控制窗口会在每个版本控制操作之后刷新。这意味着,在多个资源中循环并对每个资源执行单独操作(例如签出)的速度慢于传递包含所有资源的 AssetList 并对它执行一次版本控制操作。

using System.Collections.Generic;
using UnityEditor;
using UnityEditor.VersionControl;
using UnityEngine;

public class EditorScript : MonoBehaviour { [MenuItem("VC/Checkout")] public static void TestCheckout() { AssetList assets = new AssetList(); assets.Add(new Asset("Assets/"));

Task t = Provider.Checkout(assets, CheckoutMode.Both); t.Wait(); } }

另请注意,提供程序操作仅执行 VCS 命令,而不自动刷新版本控制窗口。若要更新此窗口,请使用 Task.SetCompletionAction

using System.Collections.Generic;
using UnityEditor;
using UnityEditor.VersionControl;
using UnityEngine;

public class EditorScript : MonoBehaviour { [MenuItem("VC/ChangeSetMove")] static void ChangeSetMove() { AssetList assets = new AssetList(); assets.Add(Provider.GetAssetByPath("Assets/testMaterial.mat")); Task task = Provider.ChangeSetMove(assets, "ChangeSetID"); task.SetCompletionAction(CompletionAction.UpdatePendingWindow); } }

静态变量

activeTask获取当前正在执行的任务。
enabled如果已启用版本控制提供程序并找到有效的 Unity Pro 许可证,则返回 true。
hasCheckoutSupportThis is true if the currently selected version control plugin supports the Checkout method.
hasLockingSupportThis is true if the currently selected version control plugin supports the Lock and Unlock methods.
isActive如果已正确选择和配置版本控制插件,则返回 true。
offlineReason返回版本控制提供程序的离线原因(如果离线)。
onlineState返回版本控制提供程序的在线状态。
preCheckoutCallback在版本控制签出操作之前要调用的用户提供的回调。
preSubmitCallback在版本控制提交操作之前要调用的用户提供的回调。
requiresNetwork如果当前选择的版本控制插件执行任何操作时需要网络连接,则为 true。

静态函数

AddAllows you to add files to version control via script.
AddIsValidGiven a list of assets this function returns true if Provider.Add is a valid task to perform on at least one of the assets in the list.
ChangeSetDescription给定仅包含变更集 ID 的变更集,此方法将启动用于查询变更集相关描述的任务。
ChangeSetMoveMove an Asset or a list of Assets from their current changeset to a new changeset.
ChangeSetsGets a list of pending changesets owned by the current user.
ChangeSetStatusRetrieves a list of assets belonging to a changeset.
CheckoutCheckout an asset or a list of assets from the version control system.
CheckoutIsValidGiven an asset or a list of assets this function returns true if Provider.Checkout is a valid task to perform on at least one of the given assets.
ClearCache此方法将使所有资源的缓存状态信息无效。
DeleteStarts a task to delete an Asset or a list of Assets from the disk and from the version control system.
DeleteChangeSetsStarts a task that will attempt to delete the given changesets.
DeleteChangeSetsIsValidTests if deleting the given changesets is a valid task to perform.
DiffHead启动一个任务,用于显示给定资源与其最新版本之间的差异。
DiffIsValidReturns true if starting a Diff task is a valid operation for at least one asset in the given AssetList.
GetActiveConfigFields返回当前活动版本控制插件的配置字段。
GetActivePluginGets the current, user selected verson control Plugin.
GetAssetByGUIDReturns version control information about an asset from a given GUID.
GetAssetByPathReturns the version control information about an asset. Can be used with "AssetList.Add" to add assets to a list for further version control actions.
GetAssetListFromSelectionReturns the version control information about the currently selected Assets.
GetLatestStart a task for getting the latest version of an out of sync asset from the version control server.
GetLatestIsValidThe task tests the given asset list and returns true if Provider.GetLatest is valid operation for one or more assets.
IncomingStarts a task that queries the version control server for incoming changes.
IncomingChangeSetAssets给定传入的变更集,此方法将启动一个任务,用于在版本控制服务器中查询其资源是否属于变更集的一部分。
IsOpenForEdit如果资源可以进行编辑,则返回 true。
Lock尝试锁定资源,以便以独占方式编辑资源。
LockIsValidReturns true if the Provider.Lock task can be executed on one or more assets from the given asset list.
MergeInitiates a merge task to handle the merging of conflicting Assets. This invokes a merge tool, which you can set in the External Tools section of the Preferences window, on the conflicting Assets. When the merge task finishes, the AssetList only contains the Assets that the tool could merge.
Move使用版本控制插件将资源从一个路径移动到另一个路径。
ResolveStarts a task that will resolve the conflicting assets in version control.
ResolveIsValidTests if any of the assets in the list have the conflicted state and can be resolved.
RevertReverts the specified assets by undoing any changes done since the last time you synced.
RevertIsValidReturns true if Provider.Revert is a valid task to perform on at least one of the given assets in the list.
StatusStarts a task that will fetch the most recent status about the asset or assets from the revision control system.
SubmitStarts a task that submits the assets to version control.
SubmitIsValid如果提交资源是有效操作,则返回 true。
UnlockIsValidReturns true if unlocking the assets is a valid operation.
UpdateSettingsStarts a task that sends the version control settings to the version control system.

委托

PreCheckoutCallback在版本控制签出之前要调用的用户提供的回调的委托。
PreSubmitCallback在版本控制提交之前要调用的用户提供的回调的委托。