Version: 2021.2

VersionControlObject

class in UnityEditor.VersionControl

/

继承自:ScriptableObject

切换到手册

描述

The abstract base class for representing a version control system.

You can add support for a custom VCS by creating a new class derived from VersionControlObject and applying the VersionControlAttribute.

using UnityEditor.VersionControl;
using UnityEngine;

[VersionControl("Custom")] public class CustomVersionControlObject : VersionControlObject { public override void OnActivate() { Debug.Log("Custom VCS activated."); }

public override void OnDeactivate() { Debug.Log("Custom VCS deactivated."); } }

Using the example above, a new VCS option called Custom will show up in Version Control settings window. You should only perform VCS operations when a VersionControlObject is activated. OnActivate and OnDeactivate methods are called on your class to notify your code about the change.

Any persistent settings that must survive between Unity sessions (for example, the username or password) must be handled either by the underlying VCS, by using EditorUserSettings, or stored in a file. This is because the VersionControlObject is not serialized to disk and a new instance is created every time Unity starts up or when the VCS is activated.

The VersionControlObject is derived from ScriptableObject. This makes domain reloading handling simpler. You can add OnEnable method to restore the state if needed.

You can use AssetModificationProcessor and AssetPostprocessor.OnPostprocessAllAssets to get notifications from Unity when it wants to edit, add or remove assets.

See Also: VersionControlAttribute, VersionControlManager, EditorUserSettings, ScriptableObject, AssetModificationProcessor, AssetPostprocessor.

变量

isConnectedTests whether the VersionControlObject is connected to an underlying version control system.

公共函数

GetExtensionGets optional extension object.
OnActivateCalled when your version control system is activated.
OnDeactivateCalled when your version control system is deactivated.
RefreshCalled when the cached state should be discarded and the new state should be retrieved from the underlying VCS.

继承的成员

变量

hideFlags该对象应该隐藏、随场景一起保存还是由用户修改?
name对象的名称。

公共函数

GetInstanceIDGets the instance ID of the object.
ToString返回对象的名称。

静态函数

Destroy移除 GameObject、组件或资源。
DestroyImmediate立即销毁对象 /obj/。强烈建议您改用 Destroy。
DontDestroyOnLoad在加载新的 Scene 时,请勿销毁 Object。
FindObjectOfType返回第一个类型为 type 的已加载的激活对象。
FindObjectsOfTypeGets a list of all loaded objects of Type type.
Instantiate克隆 original 对象并返回克隆对象。
CreateInstance创建脚本化对象的实例。

运算符

bool该对象是否存在?
operator !=比较两个对象是否引用不同的对象。
operator ==比较两个对象引用,判断它们是否引用同一个对象。

消息

Awake当 ScriptableObject 脚本启动时调用此函数。
OnDestroy当脚本化对象将销毁时调用此函数。
OnDisable当脚本化对象超出范围时调用此函数。
OnEnable当对象加载时调用此函数。
OnValidateEditor-only function that Unity calls when the script is loaded or a value changes in the Inspector.
Reset重置为默认值。