Files
.vs
Assets
Library
APIUpdater
Artifacts
Bee
BuildPlayerData
PackageCache
com.unity.collab-proxy@2.5.2
.Resources
Documentation~
Editor
PlasticSCM
AssetMenu
AssetOverlays
Cache
AssetStatus.cs
AssetStatus.cs.meta
Cache.meta
DrawAssetOverlay.cs
DrawAssetOverlay.cs.meta
Assets
AssetsUtils
CollabMigration
Configuration
Developer
Gluon
Help
Hub
Inspector
SceneView
Tool
Toolbar
UI
Views
WebApi
ApplicationDataPath.cs
ApplicationDataPath.cs.meta
AssemblyInfo.cs
AssemblyInfo.cs.meta
AssetMenu.meta
AssetOverlays.meta
Assets.meta
AssetsUtils.meta
AutoRefresh.cs
AutoRefresh.cs.meta
BuildGetEventExtraInfoFunction.cs
BuildGetEventExtraInfoFunction.cs.meta
CheckWorkspaceTreeNodeStatus.cs
CheckWorkspaceTreeNodeStatus.cs.meta
CollabMigration.meta
CollabPlugin.cs
CollabPlugin.cs.meta
Configuration.meta
Developer.meta
DrawGuiModeSwitcher.cs
DrawGuiModeSwitcher.cs.meta
EnumExtensions.cs
EnumExtensions.cs.meta
FindWorkspace.cs
FindWorkspace.cs.meta
GetRelativePath.cs
GetRelativePath.cs.meta
Gluon.meta
Help.meta
Hub.meta
Inspector.meta
MetaPath.cs
MetaPath.cs.meta
NewIncomingChanges.cs
NewIncomingChanges.cs.meta
OrganizationsInformation.cs
OrganizationsInformation.cs.meta
ParentWindow.cs
ParentWindow.cs.meta
PlasticApp.cs
PlasticApp.cs.meta
PlasticConnectionMonitor.cs
PlasticConnectionMonitor.cs.meta
PlasticMenuItem.cs
PlasticMenuItem.cs.meta
PlasticNotification.cs
PlasticNotification.cs.meta
PlasticPlugin.cs
PlasticPlugin.cs.meta
PlasticPluginIsEnabledPreference.cs
PlasticPluginIsEnabledPreference.cs.meta
PlasticProjectSettingsProvider.cs
PlasticProjectSettingsProvider.cs.meta
PlasticShutdown.cs
PlasticShutdown.cs.meta
PlasticWindow.cs
PlasticWindow.cs.meta
ProjectWindow.cs
ProjectWindow.cs.meta
QueryVisualElementsExtensions.cs
QueryVisualElementsExtensions.cs.meta
SceneView.meta
SwitchModeConfirmationDialog.cs
SwitchModeConfirmationDialog.cs.meta
Tool.meta
Toolbar.meta
UI.meta
UVCPackageVersion.cs
UVCPackageVersion.cs.meta
Unity.PlasticSCM.Editor.asmdef
Unity.PlasticSCM.Editor.asmdef.meta
UnityConfigurationChecker.cs
UnityConfigurationChecker.cs.meta
VCSPlugin.cs
VCSPlugin.cs.meta
ViewSwitcher.cs
ViewSwitcher.cs.meta
Views.meta
VisualElementExtensions.cs
VisualElementExtensions.cs.meta
WebApi.meta
WorkspaceWindow.cs
WorkspaceWindow.cs.meta
PlasticSCM.meta
Lib
.signature
CHANGELOG.md
CHANGELOG.md.meta
Editor.meta
LICENSE.md
LICENSE.md.meta
Lib.meta
README.md
README.md.meta
Third Party Notices.md
Third Party Notices.md.meta
ValidationConfig.json
ValidationConfig.json.meta
package.json
package.json.meta
com.unity.editorcoroutines@1.0.0
com.unity.ext.nunit@1.0.6
com.unity.feature.development@1.0.1
com.unity.ide.rider@3.0.31
com.unity.ide.visualstudio@2.0.22
com.unity.ide.vscode@1.2.5
com.unity.modules.ai@1.0.0
com.unity.modules.androidjni@1.0.0
com.unity.modules.animation@1.0.0
com.unity.modules.assetbundle@1.0.0
com.unity.modules.audio@1.0.0
com.unity.modules.cloth@1.0.0
com.unity.modules.director@1.0.0
com.unity.modules.imageconversion@1.0.0
com.unity.modules.imgui@1.0.0
com.unity.modules.jsonserialize@1.0.0
com.unity.modules.particlesystem@1.0.0
com.unity.modules.physics2d@1.0.0
com.unity.modules.physics@1.0.0
com.unity.modules.screencapture@1.0.0
com.unity.modules.subsystems@1.0.0
com.unity.modules.terrain@1.0.0
com.unity.modules.terrainphysics@1.0.0
com.unity.modules.tilemap@1.0.0
com.unity.modules.ui@1.0.0
com.unity.modules.uielements@1.0.0
com.unity.modules.umbra@1.0.0
com.unity.modules.unityanalytics@1.0.0
com.unity.modules.unitywebrequest@1.0.0
com.unity.modules.unitywebrequestassetbundle@1.0.0
com.unity.modules.unitywebrequestaudio@1.0.0
com.unity.modules.unitywebrequesttexture@1.0.0
com.unity.modules.unitywebrequestwww@1.0.0
com.unity.modules.vehicles@1.0.0
com.unity.modules.video@1.0.0
com.unity.modules.vr@1.0.0
com.unity.modules.wind@1.0.0
com.unity.modules.xr@1.0.0
com.unity.performance.profile-analyzer@1.2.2
com.unity.settings-manager@2.0.1
com.unity.test-framework@1.1.33
com.unity.testtools.codecoverage@1.2.6
com.unity.textmeshpro@3.0.6
com.unity.timeline@1.7.6
com.unity.ugui@1.0.0
com.unity.visualscripting@1.9.4
PackageManager
PlayModeViewStates
PlayerDataCache
ScriptAssemblies
Search
ShaderCache
SplashScreenCache
StateCache
UIElements
AnnotationManager
ArtifactDB
ArtifactDB-lock
BuildPlayer.prefs
BuildSettings.asset
EditorOnlyScriptingSettings.json
EditorOnlyVirtualTextureState.json
EditorSnapSettings.asset
EditorUserBuildSettings.asset
InspectorExpandedItems.asset
LastBuild.buildreport
LastSceneManagerSetup.txt
LibraryFormatVersion.txt
MonoManager.asset
SceneVisibilityState.asset
ScriptMapper
ShaderCache.db
SourceAssetDB
SourceAssetDB-lock
SpriteAtlasDatabase.asset
Style.catalog
expandedItems
ilpp.pid
Logs
Packages
ProjectSettings
UserSettings
obj
.vsconfig
Assembly-CSharp.Player.csproj
Assembly-CSharp.csproj
TM1.sln
Unity.CollabProxy.Editor.csproj
Unity.EditorCoroutines.Editor.csproj
Unity.Performance.Profile-Analyzer.Editor.csproj
Unity.PlasticSCM.Editor.csproj
Unity.Rider.Editor.csproj
Unity.Settings.Editor.csproj
Unity.TestTools.CodeCoverage.Editor.OpenCover.Model.csproj
Unity.TestTools.CodeCoverage.Editor.OpenCover.Mono.Reflection.csproj
Unity.TestTools.CodeCoverage.Editor.csproj
Unity.TextMeshPro.Editor.csproj
Unity.TextMeshPro.Player.csproj
Unity.TextMeshPro.csproj
Unity.Timeline.Editor.csproj
Unity.Timeline.Player.csproj
Unity.Timeline.csproj
Unity.VSCode.Editor.csproj
Unity.VisualScripting.Core.Editor.csproj
Unity.VisualScripting.Core.Player.csproj
Unity.VisualScripting.Core.csproj
Unity.VisualScripting.Flow.Editor.csproj
Unity.VisualScripting.Flow.Player.csproj
Unity.VisualScripting.Flow.csproj
Unity.VisualScripting.SettingsProvider.Editor.csproj
Unity.VisualScripting.Shared.Editor.csproj
Unity.VisualScripting.State.Editor.csproj
Unity.VisualScripting.State.Player.csproj
Unity.VisualScripting.State.csproj
Unity.VisualStudio.Editor.csproj
UnityEditor.TestRunner.csproj
UnityEditor.UI.csproj
UnityEngine.TestRunner.Player.csproj
UnityEngine.TestRunner.csproj
UnityEngine.UI.Player.csproj
UnityEngine.UI.csproj

256 lines
8.1 KiB
C#
Raw Normal View History

2025-01-17 13:10:20 +01:00
using System;
using UnityEditor;
using UnityEngine;
using Codice.LogWrapper;
using PlasticGui;
using Unity.PlasticSCM.Editor.AssetsOverlays.Cache;
using Unity.PlasticSCM.Editor.AssetUtils;
using Unity.PlasticSCM.Editor.UI;
namespace Unity.PlasticSCM.Editor.AssetsOverlays
{
internal static class DrawAssetOverlay
{
internal static void Enable(
string wkPath,
IAssetStatusCache assetStatusCache)
{
if (mIsEnabled)
return;
mLog.Debug("Enable");
mWkPath = wkPath;
mAssetStatusCache = assetStatusCache;
mIsEnabled = true;
mRepaintProjectWindow = ProjectWindow.Repaint;
EditorApplication.projectWindowItemOnGUI += OnProjectWindowItemGUI;
mRepaintProjectWindow();
}
internal static void Disable()
{
mLog.Debug("Disable");
mIsEnabled = false;
EditorApplication.projectWindowItemOnGUI -= OnProjectWindowItemGUI;
mRepaintProjectWindow();
mWkPath = null;
mAssetStatusCache = null;
}
internal static string GetStatusString(AssetStatus assetStatus)
{
if (ClassifyAssetStatus.IsPrivate(assetStatus))
return PlasticLocalization.GetString(
PlasticLocalization.Name.Private);
if (ClassifyAssetStatus.IsIgnored(assetStatus))
return PlasticLocalization.GetString(
PlasticLocalization.Name.StatusIgnored);
if (ClassifyAssetStatus.IsAdded(assetStatus))
return PlasticLocalization.GetString(
PlasticLocalization.Name.StatusAdded);
if (ClassifyAssetStatus.IsConflicted(assetStatus))
return PlasticLocalization.GetString(
PlasticLocalization.Name.StatusConflicted);
if (ClassifyAssetStatus.IsDeletedOnServer(assetStatus))
return PlasticLocalization.GetString(
PlasticLocalization.Name.StatusDeletedOnServer);
if (ClassifyAssetStatus.IsLockedRemote(assetStatus))
return PlasticLocalization.GetString(
PlasticLocalization.Name.StatusLockedRemote);
if (ClassifyAssetStatus.IsOutOfDate(assetStatus))
return PlasticLocalization.GetString(
PlasticLocalization.Name.StatusOutOfDate);
if (ClassifyAssetStatus.IsLocked(assetStatus))
return PlasticLocalization.GetString(
PlasticLocalization.Name.StatusLockedByMe);
if (ClassifyAssetStatus.IsRetained(assetStatus))
return PlasticLocalization.GetString(
PlasticLocalization.Name.StatusRetained);
if (ClassifyAssetStatus.IsCheckedOut(assetStatus))
return PlasticLocalization.GetString(
PlasticLocalization.Name.StatusCheckout);
return string.Empty;
}
internal static string GetTooltipText(
AssetStatus statusValue,
LockStatusData lockStatusData)
{
string statusText = GetStatusString(statusValue);
if (lockStatusData == null)
return statusText;
// example:
// Changed by:
// * dani_pen@hotmail.com
// * workspace wkLocal"
char bulletCharacter = '\u25cf';
string line1 = ClassifyAssetStatus.IsLocked(statusValue) ?
statusText + ":" :
PlasticLocalization.GetString(
PlasticLocalization.Name.AssetOverlayTooltipStatus,
statusText);
string line2 = string.Format("{0} {1}",
bulletCharacter,
lockStatusData.LockedBy);
string line3 = string.Format("{0} {1}",
bulletCharacter,
PlasticLocalization.GetString(
PlasticLocalization.Name.AssetOverlayTooltipOn,
lockStatusData.HolderBranchName));
return string.Format(
"{0}" + Environment.NewLine +
"{1}" + Environment.NewLine +
"{2}",
line1,
line2,
line3);
}
static void OnProjectWindowItemGUI(string guid, Rect selectionRect)
{
if (string.IsNullOrEmpty(guid))
return;
if (Event.current.type != EventType.Repaint)
return;
string fullPath = AssetsPath.GetFullPathUnderWorkspace.
ForGuid(mWkPath, guid);
if (fullPath == null)
return;
AssetStatus assetStatus = mAssetStatusCache.GetStatus(fullPath);
string tooltipText = GetTooltipText(
assetStatus,
mAssetStatusCache.GetLockStatusData(fullPath));
DrawOverlayIcon.ForStatus(
selectionRect,
assetStatus,
tooltipText);
}
internal static class DrawOverlayIcon
{
internal static void ForStatus(
Rect selectionRect,
AssetStatus status,
string tooltipText)
{
Texture overlayIcon = GetOverlayIcon(status);
if (overlayIcon == null)
return;
Rect overlayRect = OverlayRect.GetOverlayRect(
selectionRect,
OVERLAY_ICON_OFFSET);
GUI.DrawTexture(
overlayRect, overlayIcon, ScaleMode.ScaleToFit);
Rect tooltipRect = GetTooltipRect(selectionRect, overlayRect);
GUI.Label(tooltipRect, new GUIContent(string.Empty, tooltipText));
}
internal static Texture GetOverlayIcon(AssetStatus assetStatus)
{
if (ClassifyAssetStatus.IsPrivate(assetStatus))
return Images.GetPrivatedOverlayIcon();
if (ClassifyAssetStatus.IsIgnored(assetStatus))
return Images.GetIgnoredOverlayIcon();
if (ClassifyAssetStatus.IsAdded(assetStatus))
return Images.GetAddedOverlayIcon();
if (ClassifyAssetStatus.IsConflicted(assetStatus))
return Images.GetConflictedOverlayIcon();
if (ClassifyAssetStatus.IsDeletedOnServer(assetStatus))
return Images.GetDeletedRemoteOverlayIcon();
if (ClassifyAssetStatus.IsLockedRemote(assetStatus))
return Images.GetLockedRemoteOverlayIcon();
if (ClassifyAssetStatus.IsOutOfDate(assetStatus))
return Images.GetOutOfSyncOverlayIcon();
if (ClassifyAssetStatus.IsLocked(assetStatus))
return Images.GetLockedLocalOverlayIcon();
if (ClassifyAssetStatus.IsRetained(assetStatus))
return Images.GetRetainedOverlayIcon();
if (ClassifyAssetStatus.IsCheckedOut(assetStatus))
return Images.GetCheckedOutOverlayIcon();
return null;
}
static Rect Inflate(Rect rect, float width, float height)
{
return new Rect(
rect.x - width,
rect.y - height,
rect.width + 2f * width,
rect.height + 2f * height);
}
static Rect GetTooltipRect(
Rect selectionRect,
Rect overlayRect)
{
if (selectionRect.width > selectionRect.height)
{
return overlayRect;
}
return Inflate(overlayRect, 3f, 3f);
}
}
static Action mRepaintProjectWindow;
static bool mIsEnabled;
static IAssetStatusCache mAssetStatusCache;
static string mWkPath;
const float OVERLAY_ICON_OFFSET = 20f;
static readonly ILog mLog = PlasticApp.GetLogger("DrawAssetOverlay");
}
}