Skip to content
Merged
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 AGXUnity/Collide/Mesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,11 @@ private void CreateRenderMeshes()
var renderColors = new List<Color>();

var prevState = Random.state;
#if UNITY_6000_3_OR_NEWER
Random.InitState( GetEntityId().GetHashCode() );
#else
Random.InitState( GetInstanceID() );
#endif
foreach ( var collisionMesh in PrecomputedCollisionMeshes ) {
var meshes = collisionMesh.CreateRenderMeshes( transform );
renderMeshes.AddRange( meshes );
Expand Down
4 changes: 4 additions & 0 deletions AGXUnity/Constraints/Constraint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,11 @@ protected override bool Initialize()

// Not possible to handle collisions if connected frame parent is null/world.
if ( CollisionsState != ECollisionsState.KeepExternalState && AttachmentPair.ConnectedObject != null ) {
#if UNITY_6000_3_OR_NEWER
string groupName = gameObject.name + "_" + gameObject.GetEntityId();
#else
string groupName = gameObject.name + "_" + gameObject.GetInstanceID().ToString();
#endif
GameObject go1 = null;
GameObject go2 = null;
if ( CollisionsState == ECollisionsState.DisableReferenceVsConnected ) {
Expand Down
5 changes: 5 additions & 0 deletions AGXUnity/Model/WheelJoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,12 @@ protected override bool Initialize()

// Not possible to handle collisions if connected frame parent is null/world.
if ( CollisionsState != Constraint.ECollisionsState.KeepExternalState && AttachmentPair.ConnectedObject != null ) {
#if UNITY_6000_3_OR_NEWER
string groupName = gameObject.name + "_" + gameObject.GetEntityId();
#else
string groupName = gameObject.name + "_" + gameObject.GetInstanceID().ToString();
#endif

GameObject go1 = null;
GameObject go2 = null;
if ( CollisionsState == Constraint.ECollisionsState.DisableReferenceVsConnected ) {
Expand Down
4 changes: 4 additions & 0 deletions AGXUnity/Rendering/CableRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,11 @@ private void RenderGameObjects()

var go = m_segmentSpawner.CreateSegment( prevEndPosition, endPosition, radius );

#if UNITY_6000_3_OR_NEWER
int id = go.GetEntityId().GetHashCode();
#else
int id = go.GetInstanceID();
#endif

(MeshRenderer, MeshRenderer) meshRenderers;
if ( m_segmentRenderers.TryGetValue( id, out meshRenderers ) && meshRenderers.Item1 != null ) {
Expand Down
10 changes: 9 additions & 1 deletion AGXUnity/RigidBodyEmitterSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,20 @@ protected override bool Initialize()
}

var templateGroupNames = new List<string>();
var baseGroupName = $"es_{Shape.GetInstanceID().ToString()}";
#if UNITY_6000_3_OR_NEWER
var baseGroupName = $"es_{Shape.GetEntityId().ToString()}";
#else
var baseGroupName = $"es_{Shape.GetInstanceID()}";
#endif
foreach ( var template in m_templates ) {
foreach ( var emitter in m_emitters ) {
if ( !emitter.ContainsTemplate( template ) )
continue;
#if UNITY_6000_3_OR_NEWER
var templateGroupName = $"{baseGroupName}_{template.GetEntityId()}";
#else
var templateGroupName = $"{baseGroupName}_{template.GetInstanceID()}";
#endif
var nativeTemplate = emitter.GetNativeTemplate( template );
if ( nativeTemplate != null ) {
foreach ( var geometry in nativeTemplate.getGeometries() )
Expand Down
4 changes: 4 additions & 0 deletions AGXUnity/RuntimeObjects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ private void Update()

private static string GetName( MonoBehaviour script )
{
#if UNITY_6000_3_OR_NEWER
return script.name + "_ro_" + script.GetEntityId().ToString();
#else
return script.name + "_ro_" + script.GetInstanceID().ToString();
#endif
}

private static RuntimeObjects RecoverAndGetInstance()
Expand Down
9 changes: 9 additions & 0 deletions Editor/AGXUnityEditor/InspectorGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -778,8 +778,13 @@ public static void ToolArrayGUI<T>( Tools.CustomTargetTool context,
getDefaultTypename;
using ( IndentScope.Single ) {
foreach ( var item in items ) {
#if UNITY_6000_3_OR_NEWER
if ( !Foldout( EditorData.Instance.GetData( context.Targets[ 0 ],
item.GetEntityId().ToString() ),
#else
if ( !Foldout( EditorData.Instance.GetData( context.Targets[ 0 ],
item.GetInstanceID().ToString() ),
#endif
GUI.MakeLabel( InspectorEditor.Skin.TagTypename( getTypename( item ) ) +
' ' +
item.name ) ) ) {
Expand Down Expand Up @@ -950,7 +955,11 @@ public static EditorDataEntry GetItemToolArrayGUIData( Object target,
Object item,
Action<EditorDataEntry> onCreate = null )
{
#if UNITY_6000_3_OR_NEWER
return EditorData.Instance.GetData( target, $"{identifier}_" + item.GetEntityId().ToString(), onCreate );
#else
return EditorData.Instance.GetData( target, $"{identifier}_" + item.GetInstanceID().ToString(), onCreate );
#endif
}

private static void HandleItemEditorDisable<T>( Tools.CustomTargetTool tool, T item )
Expand Down
2 changes: 1 addition & 1 deletion Editor/AGXUnityEditor/Settings/EditorData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void GC()
while ( index < m_data.Count ) {
var data = m_data[ index ];
#if UNITY_6000_3_OR_NEWER
var obj = EditorUtility.EntityIdToObject( data.InstanceId );
var obj = EditorUtility.EntityIdToObject( data.EntityId );
#else
var obj = EditorUtility.InstanceIDToObject( data.InstanceId );
#endif
Expand Down
23 changes: 18 additions & 5 deletions Editor/AGXUnityEditor/Settings/EditorDataEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ public class EditorDataEntry
{
public static uint CalculateKey( UnityEngine.Object target, string identifier )
{
#if UNITY_6000_3_OR_NEWER
return ( ( target == null ? "0" : target.GetEntityId() ) + "_" + identifier ).To32BitFnv1aHash();
#else
return ( ( target == null ? "0" : target.GetInstanceID().ToString() ) + "_" + identifier ).To32BitFnv1aHash();
#endif
}

[SerializeField]
private uint m_key = uint.MaxValue;
[SerializeField]
private int m_instanceId = int.MaxValue;
[SerializeField]
private bool m_isStatic = false;

[SerializeField]
private bool m_bool = false;
[SerializeField]
Expand Down Expand Up @@ -164,15 +165,27 @@ public Color Color

public uint Key { get { return m_key; } private set { m_key = value; } }

public int InstanceId { get { return m_instanceId; } private set { m_instanceId = value; } }
#if UNITY_6000_3_OR_NEWER
[SerializeField]
private EntityId m_instanceId = new EntityId();
public EntityId EntityId { get { return m_instanceId; } private set { m_instanceId = value; } }
#else
[SerializeField]
private int m_instanceId = int.MaxValue;

public int InstanceId { get { return m_instanceId; } private set { m_instanceId = value; } }
#endif
public bool IsStatic { get { return m_isStatic; } }

public EditorDataEntry( UnityEngine.Object target, uint key )
{
Key = key;
if ( target != null )
#if UNITY_6000_3_OR_NEWER
EntityId = target.GetEntityId();
#else
InstanceId = target.GetInstanceID();
#endif
else
m_isStatic = true;
}
Expand All @@ -192,7 +205,7 @@ private void OnValueChanged()
// This is to trigger an update of the target GUI when the value has been changed.
// E.g., clicking expand/collapse on a foldout we'd like the GUI to instantly respond.
#if UNITY_6000_3_OR_NEWER
UnityEngine.Object obj = EditorUtility.EntityIdToObject( InstanceId );
UnityEngine.Object obj = EditorUtility.EntityIdToObject( EntityId );
#else
UnityEngine.Object obj = EditorUtility.InstanceIDToObject( InstanceId );
#endif
Expand Down
20 changes: 13 additions & 7 deletions Editor/AGXUnityEditor/Tools/BuiltInToolsTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ public BuiltInToolsTool()
AddKeyHandler( "SelectObject", SelectGameObjectKeyHandler );
AddKeyHandler( "SelectRigidBody", SelectRigidBodyKeyHandler );
AddKeyHandler( "PickHandler", PickHandlerKeyHandler );
#if UNITY_6000_3_OR_NEWER
EditorApplication.hierarchyWindowItemByEntityIdOnGUI += HandleHierarchyDragDrop;
#else
EditorApplication.hierarchyWindowItemOnGUI += HandleHierarchyDragDrop;
#endif
}

public override void OnSceneViewGUI( SceneView sceneView )
Expand Down Expand Up @@ -223,19 +227,21 @@ private static void AssignMaterial( GameObject go, AGXUnity.ShapeMaterial materi
assignAll();
}

private void HandleHierarchyDragDrop( int instanceId, Rect pos )
{
#if UNITY_6000_3_OR_NEWER
private void HandleHierarchyDragDrop( EntityId entityId, Rect pos )
{
InspectorGUI.HandleDragDrop<AGXUnity.ShapeMaterial>( pos,
Event.current,
material =>
HasShapeMaterialProperty( EditorUtility.EntityIdToObject( instanceId ) as GameObject, false ),
material =>
{
AssignMaterial( EditorUtility.EntityIdToObject( instanceId ) as GameObject,
HasShapeMaterialProperty( EditorUtility.EntityIdToObject( entityId ) as GameObject, false ),
material => {
AssignMaterial( EditorUtility.EntityIdToObject( entityId ) as GameObject,
material );
} );
}
#else
private void HandleHierarchyDragDrop( int instanceId, Rect pos )
{
InspectorGUI.HandleDragDrop<AGXUnity.ShapeMaterial>( pos,
Event.current,
material =>
Expand All @@ -244,8 +250,8 @@ private void HandleHierarchyDragDrop( int instanceId, Rect pos )
AssignMaterial( EditorUtility.InstanceIDToObject( instanceId ) as GameObject,
material );
} );
#endif
}
#endif

private void HandleSceneViewDragDrop( Event current, SceneView sceneView )
{
Expand Down
9 changes: 8 additions & 1 deletion Editor/AGXUnityEditor/Tools/DisableCollisionsTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,18 @@ public void OnInspectorGUI()
"Cancel" );

if ( applyCancelState == InspectorGUI.PositiveNegativeResult.Positive ) {
string selectedGroupName = m_mainObject.GetInstanceID().ToString();
string mainObjectGroupName = "";
#if UNITY_6000_3_OR_NEWER
string selectedGroupName = m_mainObject.GetEntityId().ToString();
for ( int i = 0; i < m_selected.Count; ++i )
mainObjectGroupName += m_selected[ i ].GetEntityId().ToString() +
( i != m_selected.Count - 1 ? "_" : "" );
#else
string selectedGroupName = m_mainObject.GetInstanceID().ToString();
for ( int i = 0; i < m_selected.Count; ++i )
mainObjectGroupName += m_selected[ i ].GetInstanceID().ToString() +
( i != m_selected.Count - 1 ? "_" : "" );
#endif

Undo.SetCurrentGroupName( "Disabling collisions" );
var undoGroupId = Undo.GetCurrentGroup();
Expand Down
1 change: 0 additions & 1 deletion Editor/AGXUnityEditor/Utils/DrawGizmoCallbackHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ private static void HandleColorizedBodies( DebugRenderManager manager )
#else
var bodies = UnityEngine.Object.FindObjectsOfType<RigidBody>();
#endif
Array.Sort( bodies, ( b1, b2 ) => { return b1.GetInstanceID() > b2.GetInstanceID() ? -1 : 1; } );

foreach ( var body in bodies ) {
// Create the color for all bodies for the colors to be consistent.
Expand Down
5 changes: 3 additions & 2 deletions Editor/AGXUnityEditor/Windows/ConvertMaterialsWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,12 @@ private string GetShaderPath( Material mat )
var so = new SerializedObject( mat );
var sp = so.FindProperty( "m_Shader" );
sp.Next( true );
var id = sp.intValue;

#if UNITY_6000_3_OR_NEWER
AssetDatabase.TryGetGUIDAndLocalFileIdentifier( (EntityId)id, out string guid, out long _ );
var entityId = sp.entityIdValue;
AssetDatabase.TryGetGUIDAndLocalFileIdentifier( entityId, out string guid, out long _ );
#else
var id = sp.intValue;
AssetDatabase.TryGetGUIDAndLocalFileIdentifier( id, out string guid, out long _ );
#endif
return AssetDatabase.GUIDToAssetPath( guid ); ;
Expand Down
Loading