11using System ;
22using System . Collections . Generic ;
33using System . Linq ;
4- using Unity . Collections . LowLevel . Unsafe ;
54
65namespace UnityEngine . Perception . GroundTruth
76{
@@ -16,6 +15,7 @@ public class PoseTimestampRecord
1615 /// </summary>
1716 [ Tooltip ( "The percentage within the clip that the pose starts, a value from 0 (beginning) to 1 (end)" ) ]
1817 public float startOffsetPercent ;
18+
1919 /// <summary>
2020 /// The label to use for any captures inside of this time period
2121 /// </summary>
@@ -29,49 +29,65 @@ public class PoseTimestampRecord
2929 [ CreateAssetMenu ( fileName = "AnimationPoseConfig" , menuName = "Perception/Animation Pose Config" ) ]
3030 public class AnimationPoseConfig : ScriptableObject
3131 {
32+ const string k_Unset = "unset" ;
33+
3234 /// <summary>
3335 /// The animation clip used for all of the timestamps
3436 /// </summary>
3537 public AnimationClip animationClip ;
38+
3639 /// <summary>
37- /// The list of timestamps, order dependent
40+ /// The list of timestamps
3841 /// </summary>
39- public List < PoseTimestampRecord > timestamps ;
42+ [ SerializeField ] List < PoseTimestampRecord > m_Timestamps = new List < PoseTimestampRecord > ( ) ;
4043
41- SortedList < float , string > sortedTimestamps ;
42- void OnEnable ( )
44+ /// <summary>
45+ /// The sorted list of timestamps
46+ /// </summary>
47+ public List < PoseTimestampRecord > timestamps
4348 {
44- sortedTimestamps = new SortedList < float , string > ( timestamps . Count ) ;
45- foreach ( var ts in timestamps )
49+ get => m_Timestamps ;
50+ set
4651 {
47- sortedTimestamps . Add ( ts . startOffsetPercent , ts . poseLabel ) ;
52+ m_Timestamps = value ;
53+ SortTimestamps ( ) ;
4854 }
4955 }
5056
51- const string k_Unset = "unset" ;
52-
5357 /// <summary>
5458 /// Retrieves the pose for the clip at the current time.
5559 /// </summary>
5660 /// <param name="time">The time in question</param>
5761 /// <returns>The pose for the passed in time</returns>
5862 public string GetPoseAtTime ( float time )
5963 {
60- if ( time < 0 || time > 1 ) return k_Unset ;
61- if ( timestamps == null || ! timestamps . Any ( ) ) return k_Unset ;
64+ if ( time < 0f || time > 1f ) return k_Unset ;
65+ if ( m_Timestamps == null || ! m_Timestamps . Any ( ) ) return k_Unset ;
6266
6367 // Special case code if there is only 1 timestamp in the config
64- if ( sortedTimestamps . Keys . Count == 1 )
68+ if ( m_Timestamps . Count == 1 )
6569 {
66- return time > sortedTimestamps . Keys [ 0 ] ? sortedTimestamps . Values [ 0 ] : k_Unset ;
70+ return time > m_Timestamps [ 0 ] . startOffsetPercent ? m_Timestamps [ 0 ] . poseLabel : k_Unset ;
6771 }
6872
69- for ( var i = 0 ; i < sortedTimestamps . Keys . Count - 1 ; i ++ )
73+ for ( var i = 0 ; i < m_Timestamps . Count - 1 ; i ++ )
7074 {
71- if ( time >= sortedTimestamps . Keys [ i ] && time <= sortedTimestamps . Keys [ i + 1 ] ) return sortedTimestamps . Values [ i ] ;
75+ if ( time >= m_Timestamps [ i ] . startOffsetPercent && time <= m_Timestamps [ i + 1 ] . startOffsetPercent )
76+ return m_Timestamps [ i ] . poseLabel ;
7277 }
7378
74- return time < sortedTimestamps . Keys . Last ( ) ? k_Unset : sortedTimestamps . Values . Last ( ) ;
79+ var last = m_Timestamps . Last ( ) ;
80+ return time < last . startOffsetPercent ? k_Unset : last . poseLabel ;
81+ }
82+
83+ void OnEnable ( )
84+ {
85+ SortTimestamps ( ) ;
86+ }
87+
88+ void SortTimestamps ( )
89+ {
90+ m_Timestamps . Sort ( ( stamp1 , stamp2 ) => stamp1 . startOffsetPercent . CompareTo ( stamp2 . startOffsetPercent ) ) ;
7591 }
7692 }
7793}
0 commit comments