@@ -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}
0 commit comments