Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions package-examples/Editor/API/SearchWalker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ static IEnumerable<PatchItem> EnumerateObjects(ICollection<PatchItem> ids)
var containerPath = AssetDatabase.GUIDToAssetPath(gid.assetGUID);

var mainInstanceID = GetMainAssetInstanceID(containerPath);
#if UNITY_6000_5_OR_NEWER
AssetDatabase.OpenAsset((EntityId)mainInstanceID);
#else
AssetDatabase.OpenAsset(mainInstanceID);
#endif
yield return null;

var scene = UnityEngine.SceneManagement.SceneManager.GetActiveScene();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ public static SearchProvider ExampleEditorBundles()
{
Func<UnityEngine.Object, bool> FR = r => string.Equals(AssetDatabase.GetAssetPath(r), "Library/unity editor resources", StringComparison.Ordinal);
return EasySearchProvider.Create(ExampleProvider.res.ToString(), "Resources", Resources.FindObjectsOfTypeAll<UnityEngine.Object>().Where(FR))
#if UNITY_6000_5_OR_NEWER
.SetDescriptionHandler(r => $"{r.GetType().FullName} ({(int)EntityId.ToULong(r.GetEntityId())})")
#else
.SetDescriptionHandler(r => $"{r.GetType().FullName} ({r.GetInstanceID()})")
#endif
.AddAction("select", o => Selection.activeObject = o)
.AddAction("copy", "Copy Name", r => EditorGUIUtility.systemCopyBuffer = r.name)
.AddOption(ShowDetailsOptions.Actions | ShowDetailsOptions.Inspector)
Expand Down
6 changes: 6 additions & 0 deletions package/Collections/SearchCollectionTreeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
using UnityEngine;
using System.Reflection;

#if UNITY_6000_5_OR_NEWER
using TreeView = UnityEditor.IMGUI.Controls.TreeView<int>;
using TreeViewItem = UnityEditor.IMGUI.Controls.TreeViewItem<int>;
using TreeViewState = UnityEditor.IMGUI.Controls.TreeViewState<int>;
#endif

namespace UnityEditor.Search.Collections
{
class SearchCollectionTreeView : TreeView
Expand Down
6 changes: 5 additions & 1 deletion package/Collections/SearchCollectionTreeViewItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
using UnityEditor.IMGUI.Controls;
using UnityEngine;

#if UNITY_6000_5_OR_NEWER
using TreeViewItem = UnityEditor.IMGUI.Controls.TreeViewItem<int>;
#endif

namespace UnityEditor.Search.Collections
{
{
class SearchCollectionTreeViewItem : SearchTreeViewItem
{
#if UNITY_2021_2_OR_NEWER
Expand Down
4 changes: 4 additions & 0 deletions package/Collections/SearchCollectionView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
using UnityEditor.IMGUI.Controls;
using UnityEngine;

#if UNITY_6000_5_OR_NEWER
using TreeViewState = UnityEditor.IMGUI.Controls.TreeViewState<int>;
#endif

namespace UnityEditor.Search.Collections
{
interface ISearchCollectionHostView
Expand Down
4 changes: 4 additions & 0 deletions package/Collections/SearchTreeViewItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
using UnityEditor.IMGUI.Controls;
using UnityEngine;

#if UNITY_6000_5_OR_NEWER
using TreeViewItem = UnityEditor.IMGUI.Controls.TreeViewItem<int>;
#endif

namespace UnityEditor.Search.Collections
{
class SearchTreeViewItem : TreeViewItem
Expand Down
10 changes: 9 additions & 1 deletion package/Dependencies/Dependency.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public static int GetReferenceCount(string id)
internal static IEnumerable<string> EnumerateIdFromObjects(IEnumerable<UnityEngine.Object> objects)
{
foreach (var obj in objects)
yield return GlobalObjectId.GetGlobalObjectIdSlow(obj.GetInstanceID()).ToString();
yield return GlobalObjectId.GetGlobalObjectIdSlow(obj).ToString();
}

internal static IEnumerable<string> EnumeratePaths(IEnumerable<string> globalIds)
Expand All @@ -304,14 +304,22 @@ internal static IEnumerable<IdInfo> EnumerateIdInfos(IEnumerable<string> globalI

var info = new IdInfo();
info.globalId = gid.ToString();
#if UNITY_6000_5_OR_NEWER
info.instanceID = GlobalObjectId.GlobalObjectIdentifierToEntityIdSlow(gid);
#else
info.instanceID = GlobalObjectId.GlobalObjectIdentifierToInstanceIDSlow(gid);
#endif
info.path = AssetDatabase.GetAssetPath(info.instanceID);
if (!string.IsNullOrEmpty(info.path))
{
info.isAssetId = true;
yield return info;
}
#if UNITY_6000_5_OR_NEWER
else if (EditorUtility.EntityIdToObject(info.instanceID) is UnityEngine.Object obj)
#else
else if (EditorUtility.InstanceIDToObject(info.instanceID) is UnityEngine.Object obj)
#endif
{
info.path = SearchUtils.GetObjectPath(obj).Substring(1);
yield return info;
Expand Down
9 changes: 9 additions & 0 deletions package/Dependencies/DependencyBuiltinStates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,12 @@ static DependencyViewerState StateFromObjects(string stateName, IEnumerable<stri
if (idInfo.isAssetId)
selectedPaths.Add($"\"{idInfo.path}\"");
else
#if UNITY_6000_5_OR_NEWER
// Keep the int wire format: the lower 32 bits of an EntityId hold the legacy instance id.
selectedInstanceIds.Add((int)EntityId.ToULong(idInfo.instanceID));
#else
selectedInstanceIds.Add(idInfo.instanceID);
#endif
}

var fetchSceneRefs = config.flags.HasFlag(DependencyViewerFlags.ShowSceneRefs);
Expand All @@ -159,7 +164,11 @@ static DependencyViewerState StateFromObjects(string stateName, IEnumerable<stri
var state = new DependencyViewerState(stateName, idsOfInterest) { config = config };
if (selectedInstanceIds.Count == 1)
{
#if UNITY_6000_5_OR_NEWER
var selectedObject = EditorUtility.EntityIdToObject(selectedInstanceIds.First());
#else
var selectedObject = EditorUtility.InstanceIDToObject(selectedInstanceIds.First());
#endif
var thumbnail = AssetPreview.GetMiniThumbnail(selectedObject);
state.windowTitle = new GUIContent(selectedObject.name, thumbnail);
if (selectedObject is GameObject go)
Expand Down
10 changes: 9 additions & 1 deletion package/Dependencies/DependencyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,15 @@ internal static IEnumerable<SearchItem> SceneUses(SearchExpressionContext c)

static IEnumerable<SearchItem> GetSceneObjectDependencies(SearchContext context, SearchProvider sceneProvider, SearchProvider depProvider, int instanceId)
{
#if UNITY_6000_5_OR_NEWER
var obj = EditorUtility.EntityIdToObject(instanceId);
#else
var obj = EditorUtility.InstanceIDToObject(instanceId);
#endif
if (!obj)
yield break;

var go = EditorUtility.InstanceIDToObject(instanceId) as GameObject;
var go = obj as GameObject;
if (!go && obj is Component goc)
{
foreach (var ce in GetComponentDependencies(context, sceneProvider, depProvider, goc))
Expand Down Expand Up @@ -149,7 +153,11 @@ static void CreateItemsFromSelection(Action<SearchItem> yielder)
if (!string.IsNullOrEmpty(assetPath))
yielder(SearchExpression.CreateItem(assetPath));
else
#if UNITY_6000_5_OR_NEWER
yielder(SearchExpression.CreateItem((int)EntityId.ToULong(obj.GetEntityId())));
#else
yielder(SearchExpression.CreateItem(obj.GetInstanceID()));
#endif
#else
if (!string.IsNullOrEmpty(assetPath))
yielder(EvaluatorUtils.CreateItem(assetPath));
Expand Down
3 changes: 2 additions & 1 deletion package/Dependencies/DependencyTableViewIMGUI.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#if !UNITY_7000_0_OR_NEWER
// PropertyTable (IMGUI) was deprecated in 6000.5; this view is only used below 2023.1 (see DependencyViewer.CreateTableView).
#if !UNITY_6000_5_OR_NEWER
#pragma warning disable CS0618
using System.Collections.Generic;
using System;
Expand Down
13 changes: 13 additions & 0 deletions package/Dependencies/DependencyViewerState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ struct IdInfo
{
public string globalId;
public string path;
#if UNITY_6000_5_OR_NEWER
public EntityId instanceID;
#else
public int instanceID;
#endif
public bool isAssetId;
}

Expand Down Expand Up @@ -178,12 +182,21 @@ IEnumerable<string> EnumeratePaths()
{
if (!GlobalObjectId.TryParse(sgid, out var gid))
continue;
#if UNITY_6000_5_OR_NEWER
var instanceId = GlobalObjectId.GlobalObjectIdentifierToEntityIdSlow(gid);
var assetPath = AssetDatabase.GetAssetPath(instanceId);
if (!string.IsNullOrEmpty(assetPath))
yield return assetPath;
else if (EditorUtility.EntityIdToObject(instanceId) is UnityEngine.Object obj)
yield return SearchUtils.GetObjectPath(obj).Substring(1);
#else
var instanceId = GlobalObjectId.GlobalObjectIdentifierToInstanceIDSlow(gid);
var assetPath = AssetDatabase.GetAssetPath(instanceId);
if (!string.IsNullOrEmpty(assetPath))
yield return assetPath;
else if (EditorUtility.InstanceIDToObject(instanceId) is UnityEngine.Object obj)
yield return SearchUtils.GetObjectPath(obj).Substring(1);
#endif
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion package/Dependencies/Graph/DependencyGraphViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ void DrawNodeWindow(in Rect windowRect, Event evt, in Node node)
{
selectedNode = node;
if (selectedObject)
EditorGUIUtility.PingObject(selectedObject.GetInstanceID());
EditorGUIUtility.PingObject(selectedObject);
}
else if (evt.clickCount == 2)
{
Expand Down
2 changes: 2 additions & 0 deletions package/Dependencies/Graph/DependencyUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ public static int GetMainAssetInstanceID(string path)
{
#if !USE_SEARCH_EXTENSION_API
return Utils.GetMainAssetInstanceID(path);
#elif UNITY_6000_5_OR_NEWER
return (int)EntityId.ToULong(SearchUtils.GetMainAssetEntityId(path));
#else
return SearchUtils.GetMainAssetInstanceID(path);
#endif
Expand Down
5 changes: 5 additions & 0 deletions package/Dependencies/SearchViewModelEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ public string currentGroup
#else
public int viewId { get; set; }
#endif

#if UNITY_6000_5_OR_NEWER
string m_CurrentResultViewId;
string ISearchView.currentResultViewId { get => m_CurrentResultViewId; set => m_CurrentResultViewId = value; }
#endif
public Action<GenericMenu, SearchItem> addToItemContextualMenu;
public Action<SearchAction, SearchItem[], bool> executeAction;
#endregion
Expand Down
5 changes: 5 additions & 0 deletions package/Overlays/SearchViewElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ IEnumerable<SearchQueryError> ISearchView.GetAllVisibleErrors()
throw new NotImplementedException();
}

#if UNITY_6000_5_OR_NEWER
string m_CurrentResultViewId;
string ISearchView.currentResultViewId { get => m_CurrentResultViewId; set => m_CurrentResultViewId = value; }
#endif

#if UNITY_6000_4_OR_NEWER
EntityId ISearchView.GetViewId()
{
Expand Down