This class provides access to the version control API.
Note that the Version Control window is refreshed after every version control operation. This means that looping through multiple assets and doing an individual operation on each (i.e. Checkout) will be slower than passing an AssetList containing all of the assets and performing a version control operation on it once.
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(); } }
Also note that Provider operations just execute the VCS commands, and do not automatically refresh the Version Control window. To update this window, use 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 | Gets the currently executing task. |
enabled | Returns true if the version control provider is enabled and a valid Unity Pro License was found. |
isActive | Returns true if a version control plugin has been selected and configured correctly. |
offlineReason | Returns the reason for the version control provider being offline (if it is offline). |
onlineState | Returns the OnlineState of the version control provider. |
requiresNetwork | This is true if a network connection is required by the currently selected version control plugin to perform any action. |
Add | Adds an assets or list of assets to version control. |
AddIsValid | Given a list of assets this function returns true if Add is a valid task to perform. |
ChangeSetDescription | Given a changeset only containing the changeset ID, this will start a task for quering the description of the changeset. |
ChangeSetMove | Move an asset or list of assets from their current changeset to a new changeset. |
ChangeSets | Get a list of pending changesets owned by the current user. |
ChangeSetStatus | Retrieves the list of assets belonging to a changeset. |
Checkout | Checkout an asset or list of asset from the version control system. |
CheckoutIsValid | Given an asset or a list of assets this function returns true if Checkout is a valid task to perform. |
ClearCache | This will invalidate the cached state information for all assets. |
Delete | This will statt a task for deleting an asset or assets both from disk and from version control system. |
DeleteChangeSets | Starts a task that will attempt to delete the given changeset. |
DeleteChangeSetsIsValid | Test if deleting a changeset is a valid task to perform. |
DiffHead | Starts a task for showing a diff of the given assest versus their head revision. |
DiffIsValid | Return true is starting a Diff task is a valid operation. |
GetActiveConfigFields | Returns the configuration fields for the currently active version control plugin. |
GetActivePlugin | Gets the currently user selected verson control plugin. |
GetAssetByGUID | Returns version control information about an asset. |
GetAssetByPath | Returns version control information about an asset. |
GetAssetListFromSelection | Return version control information about the currently selected assets. |
GetLatest | Start a task for getting the latest version of an asset from the version control server. |
GetLatestIsValid | Returns true if getting the latest version of an asset is a valid operation. |
Incoming | Start a task for quering the version control server for incoming changes. |
IncomingChangeSetAssets | Given an incoming changeset this will start a task to query the version control server for which assets are part of the changeset. |
IsOpenForEdit | Returns true if an asset can be edited. |
Lock | Attempt to lock an asset for exclusive editing. |
LockIsValid | Return true if the task can be executed. |
Merge | This method will initiate a merge task handle merging of the conflicting assets. |
Move | Uses the version control plugin to move an asset from one path to another. |
Resolve | Start a task that will resolve conflicting assets in version control. |
ResolveIsValid | Tests if any of the assets in the list is resolvable. |
Revert | Reverts the specified assets by undoing any changes done since last time you synced. |
RevertIsValid | Return true if Revert is a valid task to perform. |
Status | Start a task that will fetch the most recent status from revision control system. |
Submit | Start a task that submits the assets to version control. |
SubmitIsValid | Returns true if submitting the assets is a valid operation. |
UnlockIsValid | Returns true if locking the assets is a valid operation. |
UpdateSettings | Start a task that sends the version control settings to the version control system. |