This commit is contained in:
2026-11-24 15:51:02 +01:00
parent cca4d73e41
commit f4aa17114a
22092 changed files with 5042406 additions and 0 deletions
@@ -0,0 +1,804 @@
using System.Collections.Generic;
using Codice.Client.Common.Threading;
using Codice.CM.Client.Differences;
using Codice.CM.Client.Differences.Graphic;
using MergetoolGui;
using PlasticGui;
using Unity.PlasticSCM.Editor.Diff.Asset.Content.Meta;
using Unity.PlasticSCM.Editor.Diff.Asset.Common.Property;
using Unity.PlasticSCM.Editor.Diff.Asset.Content.Property;
using Unity.PlasticSCM.Editor.Diff.Asset.Content.UnityObject;
using Unity.PlasticSCM.Editor.Diff.Asset.Content.Filtering;
using Unity.PlasticSCM.Editor.Diff.Asset.Content.Search;
using Unity.PlasticSCM.Editor.Diff.Purged;
using Unity.PlasticSCM.Editor.Diff.Text;
using Unity.PlasticSCM.Editor.UI;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
using XDiffGui;
using Unity.PlasticSCM.Editor.Diff.Asset.Common;
namespace Unity.PlasticSCM.Editor.Diff.Asset.Content
{
internal class AssetContentControl : VisualElement, IBigFilePanelListener
{
internal AssetContentControl(
IBigFileDownloader bigFileDownloader,
IBigFileChecker bigFileChecker)
{
mBigFileDownloader = bigFileDownloader;
mBigFileChecker = bigFileChecker;
CreateGUI();
RegisterCallback<AttachToPanelEvent>(_ =>
{
AssetReloadNotifier.AssetsChanged += OnAssetsChanged;
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
});
RegisterCallback<DetachFromPanelEvent>(_ =>
{
AssetReloadNotifier.AssetsChanged -= OnAssetsChanged;
EditorApplication.playModeStateChanged -= OnPlayModeStateChanged;
});
}
internal void ShowData(DiffViewerData diffData)
{
if (diffData == null)
return;
mDiffViewerData = diffData;
DisplayCurrentData(isReload: false);
}
internal void Dispose()
{
mToolbarPanel.Dispose();
if (mBigFileMessagePanel != null)
mBigFileMessagePanel.Dispose();
if (mPurgedRevisionControl != null)
mPurgedRevisionControl.Dispose();
}
void IBigFilePanelListener.OnCalculateDifferencesButtonClick()
{
mBigFileMessagePanel.Disable();
IThreadWaiter waiter = ThreadWaiter.GetWaiter(10);
waiter.Execute(
/*threadOperationDelegate*/ delegate
{
mBigFileDownloader.DownloadFiles(mDiffViewerData, null);
},
/*afterOperationDelegate*/ delegate
{
mBigFileMessagePanel.Enable();
if (waiter.Exception != null)
{
MergetoolExceptionsHandler.DisplayException(
waiter.Exception);
return;
}
DisplayCurrentData(isReload: false);
});
}
void DisplayCurrentData(bool isReload)
{
DiffViewerData diffData = mDiffViewerData;
ReplaceMainView(mNormalContentPanel);
EntryData entryData = diffData.Left;
mContributorLabel.text = PlasticLocalization.Name.Content.GetString(
entryData.SymbolicName);
if (BigFileDiffCalculator.IsBigFileDiff(diffData, mBigFileDownloader, mBigFileChecker))
{
ShowBigFileMessage();
return;
}
if (diffData.Left?.IsPurged == true || diffData.Right?.IsPurged == true)
{
ShowPurgedRevision(diffData);
return;
}
ShowAssetContent(entryData.File, isReload);
}
void OnAssetsChanged(HashSet<string> changedFullPaths)
{
if (mDiffViewerData == null)
return;
if (!AssetReloadNotifier.IsWatchedPath(
mDiffViewerData.Left?.File, changedFullPaths)
&& !AssetReloadNotifier.IsWatchedPath(
mDiffViewerData.Right?.File, changedFullPaths))
return;
DisplayCurrentData(isReload: true);
}
// Entering or exiting play mode causes Unity to drop the objects we
// loaded into mObjectContents via LoadSerializedFileAndForget.
// Without a fresh load the next re-bind would render every header
// as a fallback ("Unknown" / generic file icon), since the
// underlying native objects are gone even though the C# refs remain.
void OnPlayModeStateChanged(PlayModeStateChange state)
{
if (mDiffViewerData == null)
return;
if (state != PlayModeStateChange.EnteredEditMode
&& state != PlayModeStateChange.EnteredPlayMode)
return;
DisplayCurrentData(isReload: true);
}
void ShowAssetContent(string file, bool isReload)
{
mContributorLabel.style.borderBottomWidth = 0;
ReplaceView(mListView);
mVisibleRows.Clear();
ExpansionSnapshot previousCache = isReload
? SnapshotExpansionState()
: null;
bool isMetaContent = MetaPath.IsMetaPath(file);
mObjectContents = isMetaContent
? MetaFileContents.BuildContentData(file)
: UnityObjectContents.BuildContentData(file);
ApplyExpansionState(previousCache);
UpdateAvailableFilters(isMetaContent);
RebuildVisibleRows();
}
void UpdateAvailableFilters(bool isMetaContent)
{
if (isMetaContent)
{
mToolbarPanel.UpdateAvailableFilters(null, null, show: false);
return;
}
mToolbarPanel.UpdateAvailableFilters(
ObjectContentOptions.ExtractGameObjects(mObjectContents, GetGameObjectIcon),
ObjectContentOptions.ExtractTypes(mObjectContents, GetObjectIcon),
show: true);
}
static UnityEngine.Texture GetGameObjectIcon(ObjectContent content)
{
GameObject go = content.GetGameObject();
if (go != null)
return EditorGUIUtility.ObjectContent(go, typeof(GameObject)).image;
return GetObjectIcon(content);
}
static UnityEngine.Texture GetObjectIcon(ObjectContent content)
{
UnityEngine.Object obj = content.Object;
if (obj == null)
return null;
return EditorGUIUtility.ObjectContent(obj, obj.GetType()).image;
}
ExpansionSnapshot SnapshotExpansionState()
{
ExpansionSnapshot snapshot = new ExpansionSnapshot();
foreach (ObjectContent obj in mObjectContents)
{
snapshot.Objects[BuildObjectKey(obj)] =
mExpandedObjects.Contains(obj.GetObjectId());
if (obj.ComponentContents == null)
continue;
for (int i = 0; i < obj.ComponentContents.Count; i++)
{
ObjectContent comp = obj.ComponentContents[i];
snapshot.Objects[BuildComponentKey(obj, comp, i)] =
mExpandedObjects.Contains(comp.GetObjectId());
}
}
foreach (string fullKey in mCollapsedGroups)
snapshot.CollapsedGroups.Add(fullKey);
return snapshot;
}
void ApplyExpansionState(ExpansionSnapshot previousCache)
{
mExpandedObjects.Clear();
mCollapsedGroups.Clear();
foreach (ObjectContent obj in mObjectContents)
{
if (ShouldExpand(previousCache?.Objects, BuildObjectKey(obj), DefaultExpand(obj)))
mExpandedObjects.Add(obj.GetObjectId());
if (obj.ComponentContents == null)
continue;
for (int i = 0; i < obj.ComponentContents.Count; i++)
{
ObjectContent comp = obj.ComponentContents[i];
if (ShouldExpand(previousCache?.Objects, BuildComponentKey(obj, comp, i), DefaultExpand(comp)))
mExpandedObjects.Add(comp.GetObjectId());
}
}
if (previousCache == null)
return;
foreach (string fullKey in previousCache.CollapsedGroups)
mCollapsedGroups.Add(fullKey);
}
static bool ShouldExpand(
Dictionary<string, bool> previousCache, string key, bool defaultExpand)
{
if (previousCache != null && previousCache.TryGetValue(key, out bool wasExpanded))
return wasExpanded;
return defaultExpand;
}
static bool DefaultExpand(ObjectContent obj)
{
return true;
}
static string BuildObjectKey(ObjectContent obj)
{
return "o:" + obj.GetDisplayName();
}
static string BuildComponentKey(
ObjectContent parent, ObjectContent comp, int index)
{
return "c:" + parent.GetDisplayName() + "/" + index + ":" + comp.GetDisplayName();
}
static string BuildGroupFullKey(ObjectContent owner, string groupKey)
{
return owner.GetObjectId() + ":" + groupKey;
}
void ShowBigFileMessage()
{
if (mBigFileMessagePanel == null)
mBigFileMessagePanel = new BigFileMessagePanel(this, false);
mBigFileMessagePanel.UpdateDisplayData(
BigFileDisplayData.Build(
mDiffViewerData, mBigFileDownloader));
mContributorLabel.style.borderBottomWidth = 1;
ReplaceView(mBigFileMessagePanel);
}
void ShowPurgedRevision(DiffViewerData data)
{
if (mPurgedRevisionControl == null)
mPurgedRevisionControl = new PurgedRevisionControl();
mPurgedRevisionControl.ShowData(data);
ReplaceMainView(mPurgedRevisionControl);
}
void ReplaceMainView(VisualElement panel)
{
if (hierarchy.childCount == 1 && hierarchy[0] == panel)
return;
Clear();
Add(panel);
}
void ReplaceView(VisualElement view)
{
if (mCurrentView == view)
return;
if (mCurrentView != null)
mContainerPanel.Remove(mCurrentView);
mContainerPanel.Add(view);
mCurrentView = view;
}
void RebuildVisibleRows()
{
mVisibleRows.Clear();
mKnownGroups.Clear();
mSearchIndex = PropertyContentSearchIndex.Build(mObjectContents, mSearchFilter);
CollectAllGroupKeys();
foreach (ObjectContent objContent in mObjectContents)
{
if (!PassesGameObjectFilter(objContent))
continue;
if (mSearchIndex.IsActive)
AddObjectRowsWithSearch(objContent);
else
AddObjectRows(objContent);
}
mListView.RefreshItems();
}
bool PassesGameObjectFilter(ObjectContent content)
{
return ObjectContentFilters.PassesGameObjectFilter(content, mSelectedGameObjects);
}
bool PassesTypeFilter(ObjectContent content)
{
return ObjectContentFilters.PassesTypeFilter(content, mSelectedTypes);
}
void AddObjectRows(ObjectContent objContent)
{
bool selfTypePasses = PassesTypeFilter(objContent);
bool anyChildPasses = HasVisibleChildComponent(objContent);
if (!selfTypePasses && !anyChildPasses)
return;
mVisibleRows.Add(new ContentRow(
ContentRowKind.ObjectHeader, objContent, null));
if (!mExpandedObjects.Contains(objContent.GetObjectId()))
return;
if (selfTypePasses)
AddPropertyRows(objContent, indentLevel: 0);
AddComponentRows(objContent);
}
bool HasVisibleChildComponent(ObjectContent parent)
{
if (parent.ComponentContents == null)
return false;
foreach (ObjectContent comp in parent.ComponentContents)
{
if (PassesTypeFilter(comp))
return true;
}
return false;
}
void AddComponentRows(ObjectContent parent)
{
if (parent.ComponentContents == null)
return;
foreach (ObjectContent compContent in parent.ComponentContents)
{
if (!PassesTypeFilter(compContent))
continue;
mVisibleRows.Add(new ContentRow(
ContentRowKind.ComponentHeader, compContent, null, indentLevel: 1));
if (!mExpandedObjects.Contains(compContent.GetObjectId()))
continue;
AddPropertyRows(compContent, indentLevel: 1);
}
}
void AddPropertyRows(ObjectContent objContent, int indentLevel)
{
PropertyTreeNode root = objContent.PropertyTree;
if (root == null)
return;
mWalker.Walk(
root.Children,
indentLevel,
mSearchIndex.IsNodeVisible,
node => BuildGroupFullKey(objContent, node.Path),
IsGroupExpanded,
(node, indent) => AddPropertyRow(
objContent, ToPropertyContent(node), indent),
(node, indent, fullKey) => AddContainerHeaderRow(
objContent, node, fullKey, indent));
}
// Containers with zero children render as a regular property row with
// the empty literal in the value column — that matches how Unity's
// Inspector shows empty arrays and keeps the visual hierarchy honest
// (a bold expandable header without children would lie about being
// expandable).
void AddContainerHeaderRow(
ObjectContent objContent,
PropertyTreeNode node,
string fullKey,
int indent)
{
if (node.Children.Count == 0)
{
AddPropertyRow(
objContent, ToEmptyContainerProperty(node), indent);
return;
}
mVisibleRows.Add(new ContentRow(
ContentRowKind.ContainerHeader, objContent, fullKey,
node.DisplayName, indent));
}
static PropertyContent ToEmptyContainerProperty(PropertyTreeNode node)
{
return new PropertyContent
{
Path = node.Path,
DisplayName = node.DisplayName,
TypeTag = node.TypeTag,
Value = node.Kind == NodeKind.Array ? "[]" : "{}",
Tag = null
};
}
void CollectAllGroupKeys()
{
foreach (ObjectContent objContent in mObjectContents)
{
CollectGroupKeysForOwner(objContent);
if (objContent.ComponentContents == null)
continue;
foreach (ObjectContent comp in objContent.ComponentContents)
CollectGroupKeysForOwner(comp);
}
}
void CollectGroupKeysForOwner(ObjectContent owner)
{
if (owner.PropertyTree == null)
return;
mWalker.CollectGroupKeys(
owner.PropertyTree.Children,
node => BuildGroupFullKey(owner, node.Path),
key => mKnownGroups.Add(key));
}
bool IsGroupExpanded(string fullKey)
{
if (mSearchIndex.IsActive)
return true;
return !mCollapsedGroups.Contains(fullKey);
}
static PropertyContent ToPropertyContent(PropertyTreeNode node)
{
return new PropertyContent
{
Path = node.Path,
DisplayName = node.DisplayName,
TypeTag = node.TypeTag,
Value = node.Value,
Tag = node.Tag
};
}
void AddPropertyRow(
ObjectContent owner, PropertyContent prop, int indentLevel)
{
mVisibleRows.Add(new ContentRow(
ContentRowKind.Property, owner, prop, indentLevel));
if (PropertyRow.IsTallProperty(prop.Tag))
mVisibleRows.Add(new ContentRow(
ContentRowKind.Property, owner, prop,
indentLevel, isSpacer: true));
}
void AddObjectRowsWithSearch(ObjectContent objContent)
{
bool selfTypePasses = PassesTypeFilter(objContent);
bool nameMatches = SearchMatcher.Contains(objContent.GetDisplayName(), mSearchFilter);
bool hasOwnPropertyMatch = selfTypePasses && SubtreeHasSearchMatch(objContent);
bool hasComponentMatch = HasComponentSearchMatch(objContent);
bool selfWouldShow = selfTypePasses
&& (hasOwnPropertyMatch || nameMatches);
bool nameMatchSurfacesChildren =
nameMatches && HasVisibleChildComponent(objContent);
if (!selfWouldShow && !hasComponentMatch && !nameMatchSurfacesChildren)
return;
mVisibleRows.Add(new ContentRow(
ContentRowKind.ObjectHeader, objContent, null));
if (hasOwnPropertyMatch
|| (selfTypePasses && nameMatches
&& mExpandedObjects.Contains(objContent.GetObjectId())))
{
AddPropertyRows(objContent, indentLevel: 0);
}
AddComponentRowsWithSearch(objContent, nameMatches);
}
void AddComponentRowsWithSearch(
ObjectContent parent, bool parentNameMatches)
{
if (parent.ComponentContents == null)
return;
foreach (ObjectContent compContent in parent.ComponentContents)
{
if (!PassesTypeFilter(compContent))
continue;
bool compNameMatches = SearchMatcher.Contains(
compContent.GetDisplayName(), mSearchFilter);
bool compHasPropertyMatch = SubtreeHasSearchMatch(compContent);
if (!parentNameMatches && !compNameMatches && !compHasPropertyMatch)
continue;
mVisibleRows.Add(new ContentRow(
ContentRowKind.ComponentHeader, compContent, null, indentLevel: 1));
if (compHasPropertyMatch
|| mExpandedObjects.Contains(compContent.GetObjectId()))
{
AddPropertyRows(compContent, indentLevel: 1);
}
}
}
bool SubtreeHasSearchMatch(ObjectContent objContent)
{
return mSearchIndex.SubtreeHasMatch(objContent);
}
bool HasComponentSearchMatch(ObjectContent objContent)
{
if (objContent.ComponentContents == null)
return false;
foreach (ObjectContent compContent in objContent.ComponentContents)
{
if (!PassesTypeFilter(compContent))
continue;
if (SearchMatcher.Contains(compContent.GetDisplayName(), mSearchFilter))
return true;
if (SubtreeHasSearchMatch(compContent))
return true;
}
return false;
}
void OnBindRow(VisualElement element, int index)
{
if (index < 0 || index >= mVisibleRows.Count)
return;
ContentRow row = mVisibleRows[index];
ContentRowElement rowElement = (ContentRowElement)element;
if (row.IsSpacer)
{
rowElement.BindSpacer();
return;
}
switch (row.Kind)
{
case ContentRowKind.ObjectHeader:
case ContentRowKind.ComponentHeader:
bool isExpanded = mExpandedObjects.Contains(
row.ObjectContent.GetObjectId());
rowElement.BindHeader(
row.ObjectContent,
isExpanded,
mSearchFilter,
row.IndentLevel);
return;
case ContentRowKind.ContainerHeader:
rowElement.BindGroupHeader(
row.GroupDisplayName,
row.GroupKey,
IsGroupExpanded(row.GroupKey),
mSearchFilter,
row.IndentLevel);
return;
default:
rowElement.BindProperty(
row.PropertyContent,
mSearchFilter,
row.IndentLevel);
return;
}
}
void OnObjectToggled(ObjectContent objContent)
{
int id = objContent.GetObjectId();
if (!mExpandedObjects.Remove(id))
mExpandedObjects.Add(id);
RebuildVisibleRows();
}
void OnGroupToggled(string groupFullKey)
{
if (!mCollapsedGroups.Remove(groupFullKey))
mCollapsedGroups.Add(groupFullKey);
RebuildVisibleRows();
}
void SetSearchFilter(string searchFilter)
{
mSearchFilter = searchFilter ?? string.Empty;
RebuildVisibleRows();
}
void SetGameObjectFilter(HashSet<string> selected)
{
mSelectedGameObjects = selected;
RebuildVisibleRows();
}
void SetTypeFilter(HashSet<string> selected)
{
mSelectedTypes = selected;
RebuildVisibleRows();
}
void ExpandAll()
{
foreach (ObjectContent objContent in mObjectContents)
{
mExpandedObjects.Add(objContent.GetObjectId());
if (objContent.ComponentContents == null)
continue;
foreach (ObjectContent compContent in objContent.ComponentContents)
mExpandedObjects.Add(compContent.GetObjectId());
}
mCollapsedGroups.Clear();
RebuildVisibleRows();
}
void CollapseAll()
{
mExpandedObjects.Clear();
foreach (string fullKey in mKnownGroups)
mCollapsedGroups.Add(fullKey);
RebuildVisibleRows();
}
void CreateGUI()
{
style.flexGrow = 1;
mToolbarPanel = new ContentToolbarPanel(
SetSearchFilter, ExpandAll, CollapseAll,
SetGameObjectFilter, SetTypeFilter);
mContributorLabel = new Label();
mContributorLabel.style.paddingLeft = 6;
mContributorLabel.style.paddingTop = 4;
mContributorLabel.style.paddingBottom = 4;
mContributorLabel.style.borderBottomColor = UnityStyles.Colors.BarBorder;
mListView = CreateListView();
mContainerPanel = new VisualElement();
mContainerPanel.style.flexGrow = 1;
mNormalContentPanel = new VisualElement();
mNormalContentPanel.style.flexGrow = 1;
mNormalContentPanel.Add(mToolbarPanel);
mNormalContentPanel.Add(mContributorLabel);
mNormalContentPanel.Add(mContainerPanel);
Add(mNormalContentPanel);
ReplaceView(mListView);
}
ListView CreateListView()
{
ListView result = new ListView();
result.style.flexGrow = 1;
result.fixedItemHeight = ContentRowElement.ROW_HEIGHT;
result.makeItem = () => new ContentRowElement(OnObjectToggled, OnGroupToggled);
result.bindItem = OnBindRow;
result.selectionType = SelectionType.None;
result.itemsSource = mVisibleRows;
return result;
}
ContentToolbarPanel mToolbarPanel;
Label mContributorLabel;
ListView mListView;
VisualElement mNormalContentPanel;
VisualElement mContainerPanel;
VisualElement mCurrentView;
BigFileMessagePanel mBigFileMessagePanel;
PurgedRevisionControl mPurgedRevisionControl;
List<ObjectContent> mObjectContents = new List<ObjectContent>();
readonly HashSet<int> mExpandedObjects = new HashSet<int>();
readonly HashSet<string> mCollapsedGroups = new HashSet<string>();
readonly HashSet<string> mKnownGroups = new HashSet<string>();
readonly List<ContentRow> mVisibleRows = new List<ContentRow>();
PropertyContentSearchIndex mSearchIndex = PropertyContentSearchIndex.Build(
new List<ObjectContent>(), null);
string mSearchFilter = string.Empty;
HashSet<string> mSelectedGameObjects;
HashSet<string> mSelectedTypes;
DiffViewerData mDiffViewerData;
readonly IBigFileDownloader mBigFileDownloader;
readonly IBigFileChecker mBigFileChecker;
static readonly PropertyTreeWalker<PropertyTreeNode> mWalker =
new PropertyTreeWalker<PropertyTreeNode>(
node => node.Kind,
node => node.Children);
class ExpansionSnapshot
{
internal readonly Dictionary<string, bool> Objects =
new Dictionary<string, bool>();
internal readonly HashSet<string> CollapsedGroups =
new HashSet<string>();
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 57a63f5d522d4da98a48cb71348c223e
timeCreated: 1772187002
@@ -0,0 +1,73 @@
using Unity.PlasticSCM.Editor.UI;
using UnityEngine;
using UnityEngine.UIElements;
using Unity.PlasticSCM.Editor.Diff.Asset.Common;
namespace Unity.PlasticSCM.Editor.Diff.Asset.Content
{
internal class ContentGroupHeaderRow : VisualElement
{
internal ContentGroupHeaderRow()
{
CreateGUI();
}
internal void Bind(
string label, bool isExpanded, string searchFilter, int indentLevel)
{
float padding = PropertyRow.BASE_PADDING_LEFT
+ indentLevel * PropertyRow.INDENT_PX;
mPanel.style.paddingLeft = padding;
mPanel.style.backgroundColor =
UnityStyles.Colors.Diff.AssetDiff.PropertyRowBackground;
mArrow.text = isExpanded
? HeaderRow.ARROW_DOWN : HeaderRow.ARROW_RIGHT;
bool hasSearch = !string.IsNullOrEmpty(searchFilter);
mLabel.enableRichText = hasSearch;
mLabel.text = hasSearch
? SearchHighlight.Apply(label ?? string.Empty, searchFilter)
: label ?? string.Empty;
}
void CreateGUI()
{
style.flexDirection = FlexDirection.Row;
style.flexGrow = 1;
mPanel = new VisualElement();
mPanel.style.flexGrow = 1;
mPanel.style.flexDirection = FlexDirection.Row;
mPanel.style.alignItems = Align.Center;
mPanel.style.paddingLeft = PropertyRow.BASE_PADDING_LEFT;
mPanel.style.paddingRight = 4;
mPanel.style.paddingTop = 1;
mPanel.style.paddingBottom = 1;
mArrow = new Label(HeaderRow.ARROW_RIGHT);
mArrow.style.width = 16;
mArrow.style.fontSize = 10;
mArrow.style.unityTextAlign = TextAnchor.MiddleCenter;
mArrow.style.color = UnityStyles.Colors.Diff.AssetDiff.ExpanderColor;
mPanel.Add(mArrow);
mLabel = new Label();
mLabel.style.fontSize = 12;
mLabel.style.unityFontStyleAndWeight = FontStyle.Bold;
mLabel.style.flexShrink = 1;
mLabel.style.overflow = Overflow.Hidden;
mLabel.style.textOverflow = TextOverflow.Ellipsis;
mLabel.style.color = UnityStyles.Colors.DefaultText;
mPanel.Add(mLabel);
Add(mPanel);
}
VisualElement mPanel;
Label mArrow;
Label mLabel;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: db010bdfb5124461bf82c83e532a3f26
timeCreated: 1747310600
@@ -0,0 +1,74 @@
using UnityEngine.UIElements;
using Unity.PlasticSCM.Editor.Diff.Asset.Common;
namespace Unity.PlasticSCM.Editor.Diff.Asset.Content
{
internal class ContentHeaderRow : VisualElement
{
internal ContentHeaderRow()
{
CreateGUI();
}
internal void Bind(
ObjectContent objContent,
bool isExpanded,
string searchFilter,
int indentLevel)
{
mbIsHovered = false;
float padding = HeaderRow.BASE_PADDING_LEFT
+ indentLevel * HeaderRow.INDENT_PX;
HeaderRow.ApplyContentBorder(
mContent, hasContent: true, padding, isExpanded,
suppressBottomBorder: objContent.IsGameObject());
string arrowText = isExpanded
? HeaderRow.ARROW_DOWN : HeaderRow.ARROW_RIGHT;
UnityEngine.Texture icon = ObjectIconResolver.GetIcon(objContent);
HeaderRow.ConfigurePanel(
mArrow, mIcon, mLabel, mAnnotation, mPanel,
hasContent: true, arrowText,
HeaderRow.GetBackgroundColor(hasContent: true, mbIsHovered), icon,
objContent.GetDisplayName(),
searchFilter);
}
void CreateGUI()
{
style.flexDirection = FlexDirection.Row;
style.flexGrow = 1;
mPanel = HeaderRow.BuildPanel(
out mContent, out mArrow, out mIcon, out mLabel, out mAnnotation);
mPanel.RegisterCallback<MouseEnterEvent>(OnPanelMouseEnter);
mPanel.RegisterCallback<MouseLeaveEvent>(OnPanelMouseLeave);
Add(mPanel);
}
void OnPanelMouseEnter(MouseEnterEvent evt)
{
HeaderRow.SetHovered(
ref mbIsHovered, hasContent: true, mPanel, bIsHovered: true);
}
void OnPanelMouseLeave(MouseLeaveEvent evt)
{
HeaderRow.SetHovered(
ref mbIsHovered, hasContent: true, mPanel, bIsHovered: false);
}
VisualElement mPanel;
VisualElement mContent;
Label mArrow;
Image mIcon;
Label mLabel;
Label mAnnotation;
bool mbIsHovered;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fe0c3fddc9d7444cad1202bea40ff63f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,58 @@
using Unity.PlasticSCM.Editor.Diff.Asset.Content.Property;
using Unity.PlasticSCM.Editor.UI;
using UnityEngine.UIElements;
using Unity.PlasticSCM.Editor.Diff.Asset.Common;
namespace Unity.PlasticSCM.Editor.Diff.Asset.Content
{
internal class ContentPropertyRow : VisualElement
{
internal ContentPropertyRow()
{
CreateGUI();
}
internal void Bind(
PropertyContent prop,
string searchFilter,
int indentLevel)
{
float padding = PropertyRow.BASE_PADDING_LEFT
+ indentLevel * PropertyRow.INDENT_PX;
mPanel.style.paddingLeft = padding;
mPanel.style.backgroundColor =
UnityStyles.Colors.Diff.AssetDiff.PropertyRowBackground;
string label = prop.DisplayName ?? prop.Path;
bool hasSearch = !string.IsNullOrEmpty(searchFilter);
string displayLabel = hasSearch
? SearchHighlight.Apply(label, searchFilter)
: label;
PropertyRow.ConfigureNameLabel(
mLabel, hasContent: true, hasSearch, displayLabel, prop.Path);
mValue.style.display = DisplayStyle.Flex;
mValue.SetData(prop.Tag, prop.Value, hasContent: true, counterpartTag: null);
}
void CreateGUI()
{
style.flexDirection = FlexDirection.Row;
style.flexGrow = 1;
mPanel = PropertyRow.BuildPanel(out mLabel);
mValue = new DiffValueDisplay();
mPanel.Add(mValue);
Add(mPanel);
}
VisualElement mPanel;
Label mLabel;
DiffValueDisplay mValue;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b7a6e00fe1c54225a6eaeb9fb907f498
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,55 @@
using Unity.PlasticSCM.Editor.Diff.Asset.Content.Property;
namespace Unity.PlasticSCM.Editor.Diff.Asset.Content
{
internal enum ContentRowKind : byte
{
ObjectHeader,
ComponentHeader,
ContainerHeader,
Property
}
internal readonly struct ContentRow
{
internal readonly ContentRowKind Kind;
internal readonly ObjectContent ObjectContent;
internal readonly PropertyContent PropertyContent;
internal readonly int IndentLevel;
internal readonly bool IsSpacer;
internal readonly string GroupKey;
internal readonly string GroupDisplayName;
internal ContentRow(
ContentRowKind kind,
ObjectContent objectContent,
PropertyContent propertyContent,
int indentLevel = 0,
bool isSpacer = false)
{
Kind = kind;
ObjectContent = objectContent;
PropertyContent = propertyContent;
IndentLevel = indentLevel;
IsSpacer = isSpacer;
GroupKey = null;
GroupDisplayName = null;
}
internal ContentRow(
ContentRowKind kind,
ObjectContent objectContent,
string groupKey,
string groupDisplayName,
int indentLevel)
{
Kind = kind;
ObjectContent = objectContent;
PropertyContent = null;
IndentLevel = indentLevel;
IsSpacer = false;
GroupKey = groupKey;
GroupDisplayName = groupDisplayName;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2628fb5d276334c46b602b8fb8e0af3c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,140 @@
using System;
using Unity.PlasticSCM.Editor.Diff.Asset.Content.Property;
using UnityEngine.UIElements;
namespace Unity.PlasticSCM.Editor.Diff.Asset.Content
{
internal class ContentRowElement : VisualElement
{
internal const float ROW_HEIGHT = 22f;
internal ContentRowElement(
Action<ObjectContent> toggleObjectCallback,
Action<string> toggleGroupCallback)
{
mToggleObjectCallback = toggleObjectCallback;
mToggleGroupCallback = toggleGroupCallback;
CreateGUI();
RegisterCallback<ClickEvent>(OnClicked);
}
internal void BindHeader(
ObjectContent objContent,
bool isExpanded,
string searchFilter,
int indentLevel = 0)
{
mBoundObjectContent = objContent;
mBoundGroupKey = null;
mBoundKind = BoundKind.ObjectHeader;
pickingMode = PickingMode.Position;
mHeaderRow.style.display = DisplayStyle.Flex;
mPropertyRow.style.display = DisplayStyle.None;
mGroupHeaderRow.style.display = DisplayStyle.None;
mHeaderRow.Bind(objContent, isExpanded, searchFilter, indentLevel);
}
internal void BindGroupHeader(
string label,
string groupKey,
bool isExpanded,
string searchFilter,
int indentLevel)
{
mBoundObjectContent = null;
mBoundGroupKey = groupKey;
mBoundKind = BoundKind.GroupHeader;
pickingMode = PickingMode.Position;
mHeaderRow.style.display = DisplayStyle.None;
mPropertyRow.style.display = DisplayStyle.None;
mGroupHeaderRow.style.display = DisplayStyle.Flex;
mGroupHeaderRow.Bind(label, isExpanded, searchFilter, indentLevel);
}
internal void BindProperty(
PropertyContent prop,
string searchFilter,
int indentLevel = 0)
{
mBoundObjectContent = null;
mBoundGroupKey = null;
mBoundKind = BoundKind.PropertyRow;
pickingMode = PickingMode.Position;
mHeaderRow.style.display = DisplayStyle.None;
mPropertyRow.style.display = DisplayStyle.Flex;
mGroupHeaderRow.style.display = DisplayStyle.None;
mPropertyRow.Bind(prop, searchFilter, indentLevel);
}
internal void BindSpacer()
{
mBoundObjectContent = null;
mBoundGroupKey = null;
mBoundKind = BoundKind.PropertyRow;
pickingMode = PickingMode.Ignore;
mHeaderRow.style.display = DisplayStyle.None;
mPropertyRow.style.display = DisplayStyle.None;
mGroupHeaderRow.style.display = DisplayStyle.None;
}
void CreateGUI()
{
style.flexDirection = FlexDirection.Column;
style.minHeight = ROW_HEIGHT;
style.overflow = Overflow.Visible;
mHeaderRow = new ContentHeaderRow();
Add(mHeaderRow);
mGroupHeaderRow = new ContentGroupHeaderRow();
Add(mGroupHeaderRow);
mPropertyRow = new ContentPropertyRow();
Add(mPropertyRow);
}
void OnClicked(ClickEvent evt)
{
switch (mBoundKind)
{
case BoundKind.ObjectHeader:
if (mBoundObjectContent != null)
mToggleObjectCallback?.Invoke(mBoundObjectContent);
return;
case BoundKind.GroupHeader:
if (mBoundGroupKey != null)
mToggleGroupCallback?.Invoke(mBoundGroupKey);
return;
}
}
readonly Action<ObjectContent> mToggleObjectCallback;
readonly Action<string> mToggleGroupCallback;
ContentHeaderRow mHeaderRow;
ContentGroupHeaderRow mGroupHeaderRow;
ContentPropertyRow mPropertyRow;
ObjectContent mBoundObjectContent;
string mBoundGroupKey;
BoundKind mBoundKind;
enum BoundKind : byte
{
None,
ObjectHeader,
GroupHeader,
PropertyRow
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0e3cb890d25a9473296427cdde6f83b7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,129 @@
using System;
using System.Collections.Generic;
using PlasticGui;
using Unity.PlasticSCM.Editor.UI;
using Unity.PlasticSCM.Editor.UI.UIElements;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
namespace Unity.PlasticSCM.Editor.Diff.Asset.Content
{
internal class ContentToolbarPanel : VisualElement
{
internal ContentToolbarPanel(
Action<string> filterChanged,
Action expandAll,
Action collapseAll,
Action<HashSet<string>> setGameObjectFilter,
Action<HashSet<string>> setTypeFilter)
{
mFilterChanged = filterChanged;
mExpandAll = expandAll;
mCollapseAll = collapseAll;
mSetGameObjectFilter = setGameObjectFilter;
mSetTypeFilter = setTypeFilter;
CreateGUI();
mDelayedFilterAction = new DelayedActionBySecondsRunner(
DelayedSearchChanged, UnityConstants.SEARCH_DELAYED_INPUT_ACTION_INTERVAL);
}
internal void Dispose()
{
mSearchField.UnregisterValueChangedCallback(OnSearchFieldValueChanged);
mGameObjectDropdown.SelectionChanged -= OnGameObjectSelectionChanged;
mTypeDropdown.SelectionChanged -= OnTypeSelectionChanged;
}
internal void UpdateAvailableFilters(
IList<MultiSelectDropdownItem> gameObjects,
IList<MultiSelectDropdownItem> types,
bool show)
{
DisplayStyle display = show ? DisplayStyle.Flex : DisplayStyle.None;
mGameObjectDropdown.style.display = display;
mTypeDropdown.style.display = display;
if (!show)
return;
mGameObjectDropdown.SetItems(gameObjects);
mTypeDropdown.SetItems(types);
}
void DelayedSearchChanged()
{
mFilterChanged(mSearchField.value);
}
void CreateGUI()
{
UnityEditor.UIElements.Toolbar toolbar = ControlBuilder.Toolbar.Create();
mGameObjectDropdown = ControlBuilder.Toolbar.CreateMultiSelectDropdownLeft(
PlasticLocalization.Name.DiffGameObjectFilterLabel.GetString());
mGameObjectDropdown.SelectionChanged += OnGameObjectSelectionChanged;
mGameObjectDropdown.style.display = DisplayStyle.None;
mTypeDropdown = ControlBuilder.Toolbar.CreateMultiSelectDropdown(
PlasticLocalization.Name.DiffTypeFilterLabel.GetString());
mTypeDropdown.SelectionChanged += OnTypeSelectionChanged;
mTypeDropdown.style.display = DisplayStyle.None;
mSearchField = ControlBuilder.Toolbar.CreateSearchField();
mSearchField.RegisterValueChangedCallback(OnSearchFieldValueChanged);
toolbar.Add(mGameObjectDropdown);
toolbar.Add(mTypeDropdown);
VisualElement spacer = new VisualElement();
spacer.style.flexGrow = 1;
toolbar.Add(spacer);
mExpandAllButton = ControlBuilder.Toolbar.CreateButtonLeft(
PlasticLocalization.Name.DiffExpandAllButton.GetString(), mExpandAll);
toolbar.Add(mExpandAllButton);
mCollapseAllButton = ControlBuilder.Toolbar.CreateButton(
PlasticLocalization.Name.DiffCollapseAllButton.GetString(), mCollapseAll);
toolbar.Add(mCollapseAllButton);
toolbar.Add(mSearchField);
Add(toolbar);
}
void OnSearchFieldValueChanged(ChangeEvent<string> evt)
{
mDelayedFilterAction.Run();
}
void OnGameObjectSelectionChanged()
{
mSetGameObjectFilter(mGameObjectDropdown.Selected);
}
void OnTypeSelectionChanged()
{
mSetTypeFilter(mTypeDropdown.Selected);
}
readonly Action<string> mFilterChanged;
readonly Action mExpandAll;
readonly Action mCollapseAll;
readonly Action<HashSet<string>> mSetGameObjectFilter;
readonly Action<HashSet<string>> mSetTypeFilter;
readonly DelayedActionBySecondsRunner mDelayedFilterAction;
ToolbarButton mExpandAllButton;
ToolbarButton mCollapseAllButton;
MultiSelectDropdown mGameObjectDropdown;
MultiSelectDropdown mTypeDropdown;
ToolbarSearchField mSearchField;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e534c3e00f154e72ba2a02fbe533bd1a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e0f244660204c468a8fe30e330135e0d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,27 @@
using System.Collections.Generic;
namespace Unity.PlasticSCM.Editor.Diff.Asset.Content.Filtering
{
internal static class ObjectContentFilters
{
internal static bool PassesGameObjectFilter(
ObjectContent content, HashSet<string> selected)
{
if (selected == null)
return true;
string name = content.GetObjectName();
return name != null && selected.Contains(name);
}
internal static bool PassesTypeFilter(
ObjectContent content, HashSet<string> selected)
{
if (selected == null)
return true;
string typeName = content.GetTypeName();
return typeName != null && selected.Contains(typeName);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5ba5950af72324af4be4d53de594d2b9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using Unity.PlasticSCM.Editor.UI.UIElements;
namespace Unity.PlasticSCM.Editor.Diff.Asset.Content.Filtering
{
internal static class ObjectContentOptions
{
internal static List<MultiSelectDropdownItem> ExtractGameObjects(
IList<ObjectContent> objectContents,
Func<ObjectContent, UnityEngine.Texture> iconResolver)
{
List<MultiSelectDropdownItem> result = new List<MultiSelectDropdownItem>();
HashSet<string> seen = new HashSet<string>();
foreach (ObjectContent content in objectContents)
{
string name = content.GetObjectName();
if (string.IsNullOrEmpty(name) || !seen.Add(name))
continue;
result.Add(new MultiSelectDropdownItem(name, iconResolver(content)));
}
return result;
}
internal static List<MultiSelectDropdownItem> ExtractTypes(
IList<ObjectContent> objectContents,
Func<ObjectContent, UnityEngine.Texture> iconResolver)
{
List<MultiSelectDropdownItem> result = new List<MultiSelectDropdownItem>();
HashSet<string> seen = new HashSet<string>();
foreach (ObjectContent content in objectContents)
{
AddTypeIfPresent(content, result, seen, iconResolver);
if (content.ComponentContents == null)
continue;
foreach (ObjectContent comp in content.ComponentContents)
AddTypeIfPresent(comp, result, seen, iconResolver);
}
return result;
}
static void AddTypeIfPresent(
ObjectContent content,
List<MultiSelectDropdownItem> result,
HashSet<string> seen,
Func<ObjectContent, UnityEngine.Texture> iconResolver)
{
string typeName = content.GetTypeName();
if (string.IsNullOrEmpty(typeName) || !seen.Add(typeName))
return;
result.Add(new MultiSelectDropdownItem(typeName, iconResolver(content)));
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4b00ba0e9b00a43229c0589749f0cf25
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0c9e6fa111057499c9ed2c22d2c00f95
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,68 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using Codice.LogWrapper;
using Unity.PlasticSCM.Editor.Diff.Asset.Common.Property;
using Unity.PlasticSCM.Editor.Diff.Asset.Common.Meta;
namespace Unity.PlasticSCM.Editor.Diff.Asset.Content.Meta
{
internal static class MetaFileContents
{
internal static List<ObjectContent> BuildContentData(string file)
{
Stopwatch sw = Stopwatch.StartNew();
string metaFileName = Path.GetFileName(file);
PropertyTreeNode tree = MetaPropertyTreeBuilder.Build(
File.ReadAllBytes(file));
PropertyTreeNode filteredTree = MetaTreeHelpers.FilterIgnoredKeys(tree);
if (filteredTree.Children.Count == 0)
return EmptyList;
// Each top-level YAML key becomes its own ObjectContent — analogous
// to a Component in a UnityObject diff. For an Object/Array key
// the section's tree carries the key's children directly (the
// "AudioImporter" wrapper is hoisted into the section header so
// it doesn't duplicate as the first child row).
List<ObjectContent> result = new List<ObjectContent>(
filteredTree.Children.Count);
foreach (PropertyTreeNode section in filteredTree.Children)
{
result.Add(new ObjectContent
{
MetaFileName = metaFileName,
MetaSectionName = section.DisplayName,
PropertyTree = WrapAsSectionRoot(section)
});
}
mLog.DebugFormat(
"{0} meta sections calculated in {1} ms for '{2}'",
result.Count, sw.ElapsedMilliseconds, metaFileName);
return result;
}
static PropertyTreeNode WrapAsSectionRoot(PropertyTreeNode section)
{
if (section.Kind == NodeKind.Leaf)
{
return PropertyTreeNode.CreateRoot(
new List<PropertyTreeNode> { section });
}
return PropertyTreeNode.CreateRoot(
new List<PropertyTreeNode>(section.Children));
}
static readonly List<ObjectContent> EmptyList =
new List<ObjectContent>();
static readonly ILog mLog = PlasticApp.GetLogger("MetaFileContents");
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c305dffd0bd94ae788894e50eb35e343
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,86 @@
using System.Collections.Generic;
using PlasticGui;
using Unity.PlasticSCM.Editor.Diff.Asset.Common.Property;
using Unity.PlasticSCM.Editor.Diff.Asset.Common;
namespace Unity.PlasticSCM.Editor.Diff.Asset.Content
{
internal class ObjectContent
{
internal UnityEngine.Object Object;
internal PropertyTreeNode PropertyTree;
internal List<ObjectContent> ComponentContents;
// Populated when this row represents a section of a .meta file —
// the originating .meta filename (MetaFileName) and the nicified
// top-level YAML key (MetaSectionName, e.g. "Audio Importer"),
// analogous to a Component header in UnityObject diffs. MetaFileName
// is the canonical "this is a meta row" flag (see IsMetaFileObject);
// Object is null on meta rows.
internal string MetaFileName;
internal string MetaSectionName;
// Gated on MetaFileName rather than Object being null, so we don't
// misclassify a UnityObject row whose underlying native object has
// been destroyed (Unity's overloaded == reports it null) as a meta
// row.
internal bool IsMetaFileObject
{
get { return !string.IsNullOrEmpty(MetaFileName); }
}
internal int GetObjectId()
{
if (IsMetaFileObject)
return (MetaFileName + ":" + MetaSectionName).GetHashCode();
return Object != null ? Object.GetObjectId() : 0;
}
internal string GetDisplayName()
{
if (IsMetaFileObject)
return GetMetaDisplayName();
if (Object == null)
return PlasticLocalization.Name.DiffUnknownObject.GetString();
// Components share their GameObject's name, so showing it would
// duplicate the parent header. For everything else the icon
// already conveys the type — show the object's own name.
if (Object is UnityEngine.Component)
return Object.GetType().Name;
return string.IsNullOrEmpty(Object.name) ? Object.GetType().Name : Object.name;
}
internal string GetTypeName()
{
return Object == null ? null : Object.GetType().Name;
}
internal string GetObjectName()
{
return Object == null ? null : Object.name;
}
internal bool IsGameObject()
{
return Object is UnityEngine.GameObject;
}
internal UnityEngine.GameObject GetGameObject()
{
if (Object is UnityEngine.GameObject go)
return go;
if (Object is UnityEngine.Component c)
return c.gameObject;
return null;
}
string GetMetaDisplayName()
{
return string.IsNullOrEmpty(MetaSectionName)
? MetaFileName
: MetaSectionName;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a03d6d8b450b42229e7201066ecd389d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 018268bdd48d54121b0fe237a6571615
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,11 @@
namespace Unity.PlasticSCM.Editor.Diff.Asset.Content.Property
{
internal class PropertyContent
{
internal string Path;
internal string DisplayName;
internal string TypeTag;
internal string Value;
internal object Tag;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4482fa6271aa4d47a88eb0abab598eb2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7b2b4aac3415145888e9c580fb869826
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,144 @@
using System.Collections.Generic;
using Unity.PlasticSCM.Editor.Diff.Asset.Common.Property;
using Unity.PlasticSCM.Editor.Diff.Asset.Common;
namespace Unity.PlasticSCM.Editor.Diff.Asset.Content.Search
{
internal class PropertyContentSearchIndex
{
internal bool IsActive { get; }
internal static PropertyContentSearchIndex Build(
IList<ObjectContent> objectContents, string searchTerm)
{
if (string.IsNullOrEmpty(searchTerm))
return new PropertyContentSearchIndex(isActive: false, null);
HashSet<PropertyTreeNode> visible = new HashSet<PropertyTreeNode>();
foreach (ObjectContent content in objectContents)
{
bool objectInScope = SearchMatcher.Contains(
content.GetDisplayName(), searchTerm);
CollectVisibleForObject(
content.PropertyTree, searchTerm, objectInScope, visible);
if (content.ComponentContents == null)
continue;
foreach (ObjectContent comp in content.ComponentContents)
{
bool componentInScope = objectInScope
|| SearchMatcher.Contains(
comp.GetDisplayName(), searchTerm);
CollectVisibleForObject(
comp.PropertyTree, searchTerm, componentInScope, visible);
}
}
return new PropertyContentSearchIndex(isActive: true, visible);
}
static void CollectVisibleForObject(
PropertyTreeNode root,
string searchTerm,
bool ownerNameMatches,
HashSet<PropertyTreeNode> visible)
{
if (root == null)
return;
if (ownerNameMatches)
{
foreach (PropertyTreeNode child in root.Children)
AddSubtree(child, visible);
return;
}
CollectVisible(root, searchTerm, visible);
}
internal bool IsNodeVisible(PropertyTreeNode node)
{
if (!IsActive)
return true;
return mVisibleNodes.Contains(node);
}
internal bool SubtreeHasMatch(ObjectContent content)
{
if (!IsActive)
return false;
if (content.PropertyTree == null)
return false;
foreach (PropertyTreeNode child in content.PropertyTree.Children)
{
if (mVisibleNodes.Contains(child))
return true;
}
return false;
}
PropertyContentSearchIndex(bool isActive, HashSet<PropertyTreeNode> visibleNodes)
{
IsActive = isActive;
mVisibleNodes = visibleNodes;
}
static bool CollectVisible(
PropertyTreeNode node,
string searchTerm,
HashSet<PropertyTreeNode> visible)
{
if (node == null)
return false;
if (node.Kind == NodeKind.Leaf)
{
string label = node.DisplayName ?? node.Path;
bool matches =
SearchMatcher.Contains(label, searchTerm) ||
SearchMatcher.Contains(node.Path, searchTerm);
if (matches)
visible.Add(node);
return matches;
}
bool nodeMatches =
SearchMatcher.Contains(node.DisplayName, searchTerm) ||
SearchMatcher.Contains(node.Path, searchTerm);
if (nodeMatches)
{
AddSubtree(node, visible);
return true;
}
bool anyChildMatches = false;
foreach (PropertyTreeNode child in node.Children)
{
if (CollectVisible(child, searchTerm, visible))
anyChildMatches = true;
}
if (anyChildMatches)
visible.Add(node);
return anyChildMatches;
}
static void AddSubtree(
PropertyTreeNode node, HashSet<PropertyTreeNode> visible)
{
visible.Add(node);
foreach (PropertyTreeNode child in node.Children)
AddSubtree(child, visible);
}
readonly HashSet<PropertyTreeNode> mVisibleNodes;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fc407072748964c61a00ee8d7e579db1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 17560f2306bb24c3f829b2c849fdf839
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,149 @@
using System.Collections.Generic;
using System.Diagnostics;
using Unity.PlasticSCM.Editor.Diff.Asset.Common.Property;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
using Codice.LogWrapper;
using Unity.PlasticSCM.Editor.Diff.Asset.Common;
using Unity.PlasticSCM.Editor.Diff.Asset.Common.UnityObject;
namespace Unity.PlasticSCM.Editor.Diff.Asset.Content.UnityObject
{
internal static class UnityObjectContents
{
internal static List<ObjectContent> BuildContentData(string file)
{
Stopwatch sw = Stopwatch.StartNew();
List<ObjectContent> objectContents = new List<ObjectContent>();
UnityEngine.Object[] objects = InternalEditorUtility.LoadSerializedFileAndForget(file);
foreach (UnityEngine.Object obj in objects)
{
if (obj == null)
continue;
objectContents.Add(BuildObjectContent(obj));
}
GroupComponentsUnderGameObjects(objectContents);
RemoveEmptyNonGameObjects(objectContents);
HierarchyOrderSorting.SortByHierarchyOrder(
objectContents, c => c.Object, objects);
mLog.DebugFormat(
"{0} object contents calculated in {1} ms",
objectContents.Count, sw.ElapsedMilliseconds);
return objectContents;
}
static ObjectContent BuildObjectContent(UnityEngine.Object obj)
{
ObjectContent content = new ObjectContent
{
Object = obj
};
using (SerializedObject so = new SerializedObject(obj))
content.PropertyTree = PropertyTreeBuilder.Build(so);
return content;
}
static void GroupComponentsUnderGameObjects(List<ObjectContent> objectContents)
{
Dictionary<GameObject, ObjectContent> gameObjectMap =
new Dictionary<GameObject, ObjectContent>();
foreach (ObjectContent content in objectContents)
{
if (content.Object is GameObject go)
gameObjectMap[go] = content;
}
if (gameObjectMap.Count == 0)
return;
List<ObjectContent> topLevel = new List<ObjectContent>(objectContents.Count);
foreach (ObjectContent content in objectContents)
{
if (content.Object is Component c && c.gameObject != null
&& gameObjectMap.TryGetValue(c.gameObject, out ObjectContent parent))
{
if (parent.ComponentContents == null)
parent.ComponentContents = new List<ObjectContent>();
parent.ComponentContents.Add(content);
continue;
}
topLevel.Add(content);
}
objectContents.Clear();
objectContents.AddRange(topLevel);
foreach (ObjectContent content in objectContents)
SortComponentsByGameObjectOrder(content);
}
static void SortComponentsByGameObjectOrder(ObjectContent gameObjectContent)
{
if (gameObjectContent.ComponentContents == null)
return;
if (!(gameObjectContent.Object is GameObject go))
return;
Component[] orderedComponents = go.GetComponents<Component>();
Dictionary<Component, int> orderIndex = new Dictionary<Component, int>(
orderedComponents.Length);
for (int i = 0; i < orderedComponents.Length; i++)
{
if (orderedComponents[i] != null)
orderIndex[orderedComponents[i]] = i;
}
gameObjectContent.ComponentContents.Sort((a, b) =>
{
int ia = a.Object is Component ca && orderIndex.TryGetValue(ca, out int va)
? va : int.MaxValue;
int ib = b.Object is Component cb && orderIndex.TryGetValue(cb, out int vb)
? vb : int.MaxValue;
return ia.CompareTo(ib);
});
}
// Drops objects whose property tree is empty after IgnoredProperties
// filtering — e.g. SceneRoots, whose only fields (m_ObjectHideFlags
// and m_Roots) are both ignored. GameObjects are kept regardless
// because they own their components.
static void RemoveEmptyNonGameObjects(List<ObjectContent> objectContents)
{
for (int i = objectContents.Count - 1; i >= 0; i--)
{
ObjectContent content = objectContents[i];
if (content.Object is GameObject)
continue;
PropertyTreeNode tree = content.PropertyTree;
if (tree != null && tree.Children.Count > 0)
continue;
objectContents.RemoveAt(i);
}
}
static readonly ILog mLog = PlasticApp.GetLogger("UnityObjectContents");
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 17a6aa48df0d4d69a081f9c2b83ecb1c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: