Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
CloseFor some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.
CloseT Extension object if it's supported by VersionControlObject. null otherwise.
Gets optional extension object.
You can implement optional extensions in your VersionControlObject to improve user experience. For example, the IIconOverlayExtension enables you to draw VCS status overlays over asset icons. See the documentation for the full list of extensions. Future versions of Unity might add new extensions or stop calling existing ones.
The default GetExtension implementation attempts to cast VersionControlObject to extension type. This allows you to implement extensions directly in your VersionControlObject derived class.
using UnityEditor.VersionControl; using UnityEngine;
[VersionControl("Custom")] public class CustomVersionControlObject : VersionControlObject, IIconOverlayExtension { static Texture2D s_Icon;
static Texture2D GetIcon() { if (s_Icon == null) { s_Icon = new Texture2D(8, 8); for (var y = 0; y < s_Icon.height; ++y) { for (var x = 0; x < s_Icon.width; ++x) { var border = y == 0 || y == s_Icon.height - 1 || x == 0 || x == s_Icon.width - 1; var color = border ? Color.white : Color.red; s_Icon.SetPixel(x, y, color); } } s_Icon.Apply(); } return s_Icon; }
public void DrawOverlay(string assetPath, IconOverlayType type, Rect rect) { var topLeft = new Rect(rect.x, rect.y, 8, 8); var icon = GetIcon(); GUI.DrawTexture(topLeft, icon); } }
To support extensions implemented in separate classes you must overwrite this method and return an appropriate object.
using UnityEditor.VersionControl; using UnityEngine;
public class CustomIconOverlayExtension : IIconOverlayExtension { public void DrawOverlay(string assetPath, IconOverlayType type, Rect rect) { var topLeft = new Rect(rect.x, rect.y, 8, 8); GUI.DrawTexture(topLeft, Texture2D.whiteTexture); } }
[VersionControl("Custom")] public class CustomVersionControlObject : VersionControlObject { readonly IIconOverlayExtension m_IconOverlayExtension = new CustomIconOverlayExtension();
public override T GetExtension<T>() { return m_IconOverlayExtension as T; } }
Additional resources: VersionControlObject, IIconOverlayExtension, IInspectorWindowExtension, IPopupMenuExtension, ISettingsInspectorExtension.
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.