@@ -10,29 +10,40 @@ namespace AGXUnity.Model
1010 [ HelpURL ( "https://us.download.algoryx.se/AGXUnity/documentation/current/editor_interface.html#soil-failure-volumes" ) ]
1111 public class DeformableTerrainFailureVolume : ScriptComponent
1212 {
13+ [ field: SerializeField ]
1314 public bool AddAllTerrainsOnStart { get ; set ; } = true ;
1415
15- private HashSet < DeformableTerrainBase > m_terrains = new HashSet < DeformableTerrainBase > ( ) ;
16+ [ field: SerializeField ]
17+ private List < DeformableTerrainBase > m_terrains = new List < DeformableTerrainBase > ( ) ;
1618
1719 public DeformableTerrainBase [ ] Terrains => m_terrains . ToArray ( ) ;
1820
1921 public bool Add ( DeformableTerrainBase terrain )
2022 {
21- return m_terrains . Add ( terrain ) ;
23+ if ( m_terrains . Contains ( terrain ) ) {
24+ Debug . LogWarning ( $ "Failure volume '{ name } ' already contains terrain '{ terrain . name } '" ) ;
25+ return false ;
26+ }
27+ m_terrains . Add ( terrain ) ;
28+ return true ;
2229 }
2330
2431 public bool Remove ( DeformableTerrainBase terrain )
2532 {
33+ if ( ! m_terrains . Contains ( terrain ) ) {
34+ Debug . LogWarning ( $ "Failure volume '{ name } ' does not contain terrain '{ terrain . name } '" ) ;
35+ return false ;
36+ }
2637 return m_terrains . Remove ( terrain ) ;
2738 }
2839
2940 protected override bool Initialize ( )
3041 {
3142 if ( AddAllTerrainsOnStart ) {
3243#if UNITY_2022_2_OR_NEWER
33- m_terrains . UnionWith ( FindObjectsByType < DeformableTerrainBase > ( FindObjectsSortMode . None ) ) ;
44+ m_terrains . AddRange ( FindObjectsByType < DeformableTerrainBase > ( FindObjectsSortMode . None ) . Where ( t => ! m_terrains . Contains ( t ) ) ) ;
3445#else
35- m_terrains . UnionWith ( FindObjectsOfType < DeformableTerrainBase > ( ) ) ;
46+ m_terrains . AddRange ( FindObjectsOfType < DeformableTerrainBase > ( ) . Where ( t => ! m_terrains . Contains ( t ) ) ) ;
3647#endif
3748 }
3849 return base . Initialize ( ) ;
@@ -59,5 +70,4 @@ private void TriggerFailure()
5970 terr . ConvertToDynamicMassInShape ( shape ) ;
6071 }
6172 }
62-
6373}
0 commit comments