Skip to content

Commit 56d0738

Browse files
quick find and replace for InstanceID to EntityId (#626)
* quick find and replace for InstanceID to EntityId * add ifdef depending on unity version --------- Co-authored-by: Jonathan Brodsky <jonathan.brodsky@unity3d.com>
1 parent 85bba5a commit 56d0738

File tree

15 files changed

+73
-35
lines changed

15 files changed

+73
-35
lines changed

AssetIdRemapUtility/Editor/AssetIdRemapBuilderEditor.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,11 @@ static string GetSelectedDirectory()
455455

456456
if (o != null)
457457
{
458+
#if UNITY_6000_4_OR_NEWER
459+
string path = AssetDatabase.GetAssetPath(o.GetEntityId());
460+
#else
458461
string path = AssetDatabase.GetAssetPath(o.GetInstanceID());
462+
#endif
459463

460464
if (!string.IsNullOrEmpty(path))
461465
{

Debug/Editor/DebugEditor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static void EndSectionHeader()
7070

7171
static string GetPropertyId(ProBuilderMesh mesh, string property)
7272
{
73-
return string.Format("{0}.{1}", mesh.GetInstanceID(), property);
73+
return string.Format("{0}.{1}", mesh.GetObjectId(), property);
7474
}
7575

7676
void DoSharedVerticesInfo(ProBuilderMesh mesh)

Editor/EditorCore/EditorHandleDrawing.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ static Material CreateMaterial(Shader shader, string materialName)
240240
static Mesh CreateMesh()
241241
{
242242
var mesh = new Mesh();
243-
mesh.name = "EditorMeshHandles.MeshHandle" + mesh.GetInstanceID();
243+
mesh.name = "EditorMeshHandles.MeshHandle" + mesh.GetObjectId();
244244
mesh.hideFlags = HideFlags.HideAndDontSave;
245245
return mesh;
246246
}

Editor/EditorCore/EditorUtility.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ internal static bool AssetStoreWindowIsOpen()
168168
[Conditional("DEBUG_MESH_SYNC")]
169169
static void LogMeshSyncEvent(ProBuilderMesh mesh, MeshSyncState state, string msg)
170170
{
171-
Debug.Log($"{mesh} {mesh.GetInstanceID()} {state} {msg}");
171+
Debug.Log($"{mesh} {mesh.GetObjectId()} {state} {msg}");
172172
}
173173

174174
/// <summary>
@@ -300,7 +300,7 @@ internal static void InitObject(ProBuilderMesh pb)
300300

301301
pb.unwrapParameters = new UnwrapParameters(Lightmapping.s_UnwrapParameters);
302302
pb.Optimize();
303-
303+
304304
// PBLD-137 - if Resident Drawer is on, it will start throwing errors if submeshCount != materialCount
305305
if (pb.mesh.subMeshCount == 0)
306306
pb.renderer.sharedMaterial = null;

Editor/EditorCore/FileUtility.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ internal static string GetSelectedDirectory()
158158

159159
if (o != null)
160160
{
161-
string path = AssetDatabase.GetAssetPath(o.GetInstanceID());
161+
string path = AssetDatabase.GetAssetPath(o.GetObjectId());
162162

163163
if (!string.IsNullOrEmpty(path))
164164
{

Editor/EditorCore/ProBuilderMeshEditor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ public override void OnInspectorGUI()
177177

178178
GUILayout.Label("Identifiers", EditorStyles.boldLabel);
179179
EditorGUI.showMixedValue = targets.Length > 1;
180-
EditorGUILayout.IntField("ProBuilderMesh", m_Mesh.GetInstanceID());
181-
EditorGUILayout.IntField("UnityEngine.Mesh", sharedMesh != null ? sharedMesh.GetInstanceID() : -1);
180+
EditorGUILayout.IntField("ProBuilderMesh", m_Mesh.GetObjectId());
181+
EditorGUILayout.IntField("UnityEngine.Mesh", sharedMesh != null ? sharedMesh.GetObjectId() : -1);
182182
EditorGUILayout.TextField("UnityEngine.Mesh.name", sharedMesh != null ? sharedMesh.name : "null");
183183
EditorGUI.showMixedValue = false;
184184
#endif

Editor/EditorCore/RepairActions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static void MenuForceSceneRefresh()
2525
{
2626
UnityEditor.EditorUtility.DisplayProgressBar(
2727
"Refreshing ProBuilder Objects",
28-
"Reshaping pb_Object " + all[i].GetInstanceID() + ".",
28+
"Reshaping pb_Object " + all[i].GetObjectId() + ".",
2929
((float)i / all.Length));
3030

3131
try
@@ -103,7 +103,7 @@ static void RebuildSharedIndexes(ProBuilderMesh[] targets)
103103
{
104104
UnityEditor.EditorUtility.DisplayProgressBar(
105105
"Refreshing ProBuilder Objects",
106-
"Rebuilding mesh " + targets[i].GetInstanceID() + ".",
106+
"Rebuilding mesh " + targets[i].GetObjectId() + ".",
107107
((float)i / targets.Length));
108108

109109
ProBuilderMesh pb = targets[i];

Editor/EditorCore/StripProBuilderScripts.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static void StripAllScenes()
4040
{
4141
if (c > 32 && UnityEditor.EditorUtility.DisplayCancelableProgressBar(
4242
"Stripping ProBuilder Scripts",
43-
"Working over " + all[i].GetInstanceID() + ".",
43+
"Working over " + all[i].GetObjectId() + ".",
4444
((float)i / all.Count)))
4545
break;
4646

Runtime/Core/InternalUtility.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,5 +135,39 @@ public static T DemandComponent<T>(this GameObject gameObject) where T : Compone
135135
component = gameObject.AddComponent<T>();
136136
return component;
137137
}
138+
139+
#if UNITY_6000_4_OR_NEWER
140+
/// <summary>
141+
/// Returns the <see cref="EntityId"/> identifier for the given <see cref="UnityEngine.Object"/>.
142+
/// This method abstracts the Unity version differences between <c>GetEntityId()</c>
143+
/// (available in Unity 6000.4 or newer) and <c>GetInstanceID()</c> in older Unity versions.
144+
///
145+
/// Use this method to obtain an object identifier that is compatible with APIs expecting
146+
/// <see cref="EntityId"/> in newer Unity versions, such as
147+
/// <see cref="UnityEditor.AssetDatabase.GetAssetPath(EntityId)"/>.
148+
/// </summary>
149+
/// <param name="o">The Unity object to get an identifier for.</param>
150+
/// <returns>The object's unique <see cref="EntityId"/>.</returns>
151+
internal static EntityId GetObjectId(this Object o)
152+
{
153+
return o.GetEntityId();
154+
}
155+
#else
156+
/// <summary>
157+
/// Returns the integer identifier for the given <see cref="UnityEngine.Object"/>.
158+
/// This method abstracts the Unity version differences between <c>GetEntityId()</c>
159+
/// (available in Unity 6000.4 or newer) and <c>GetInstanceID()</c> in older Unity versions.
160+
///
161+
/// Use this method to obtain an object identifier that is compatible with APIs expecting
162+
/// an integer in older Unity versions, such as
163+
/// <see cref="UnityEditor.AssetDatabase.GetAssetPath(int)"/>.
164+
/// </summary>
165+
/// <param name="o">The Unity object to get an identifier for.</param>
166+
/// <returns>The object's unique integer identifier.</returns>
167+
internal static int GetObjectId(this Object o)
168+
{
169+
return o.GetInstanceID();
170+
}
171+
#endif
138172
}
139173
}

Runtime/Core/MeshHandles.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ internal static void CreateEdgeMesh(ProBuilderMesh mesh, Mesh target)
5858

5959
target.Clear();
6060
target.indexFormat = edgeCount * 2 > ushort.MaxValue ? Rendering.IndexFormat.UInt32 : Rendering.IndexFormat.UInt16;
61-
target.name = "ProBuilder::EdgeMesh" + target.GetInstanceID();
61+
target.name = "ProBuilder::EdgeMesh" + target.GetObjectId();
6262
target.vertices = mesh.positionsInternal;
6363
target.subMeshCount = 1;
6464
target.SetIndices(s_IndexList, MeshTopology.Lines, 0);
@@ -81,7 +81,7 @@ internal static void CreateEdgeMesh(ProBuilderMesh mesh, Mesh target, Edge[] edg
8181

8282
target.Clear();
8383
target.indexFormat = vertexCount > ushort.MaxValue ? Rendering.IndexFormat.UInt32 : Rendering.IndexFormat.UInt16;
84-
target.name = "ProBuilder::EdgeMesh" + target.GetInstanceID();
84+
target.name = "ProBuilder::EdgeMesh" + target.GetObjectId();
8585
target.vertices = mesh.positionsInternal;
8686
target.subMeshCount = 1;
8787
target.SetIndices(s_IndexList, MeshTopology.Lines, 0);

0 commit comments

Comments
 (0)