55using System ;
66using UnityEditor . UIElements ;
77using UnityEngine ;
8+ using UnityEngine . Assertions ;
89using UnityEngine . Audio ;
910using UnityEngine . UIElements ;
1011using Object = UnityEngine . Object ;
@@ -59,13 +60,25 @@ internal SerializedObject SerializedObject
5960
6061 internal string TargetPath { get ; private set ; }
6162
63+ internal void UpdateTargetPath ( )
64+ {
65+ if ( m_AudioContainer != null )
66+ {
67+ TargetPath = AssetDatabase . GetAssetPath ( m_AudioContainer ) ;
68+ }
69+ else
70+ {
71+ TargetPath = null ;
72+ }
73+ }
74+
6275 internal void Reset ( )
6376 {
6477 Stop ( ) ;
6578 m_AudioContainer = null ;
6679 m_SerializedObject = null ;
6780 m_IsPlayingOrPausedLocalFlag = false ;
68- TargetPath = null ;
81+ UpdateTargetPath ( ) ;
6982 }
7083
7184 internal VisualElement GetResourceTrackerElement ( )
@@ -164,7 +177,7 @@ void UpdateTarget()
164177
165178 if ( m_AudioContainer != null )
166179 {
167- TargetPath = AssetDatabase . GetAssetPath ( m_AudioContainer ) ;
180+ UpdateTargetPath ( ) ;
168181 }
169182
170183 if ( targetChanged )
@@ -174,17 +187,7 @@ void UpdateTarget()
174187
175188 if ( trackedSourceChanged )
176189 {
177- if ( m_ResourceTrackerElement != null )
178- {
179- m_ResourceTrackerElement . Unbind ( ) ;
180- }
181-
182- if ( m_TrackedSource != null )
183- {
184- var trackedSourceSO = new SerializedObject ( m_TrackedSource ) ;
185- var trackedSourceResourceProperty = trackedSourceSO . FindProperty ( "m_Resource" ) ;
186- m_ResourceTrackerElement . TrackPropertyValue ( trackedSourceResourceProperty , OnResourceChanged ) ;
187- }
190+ UpdateResourceTrackerElement ( ) ;
188191 }
189192 }
190193
@@ -199,9 +202,28 @@ void OnResourceChanged(SerializedProperty property)
199202 m_AudioContainer = container ;
200203
201204 if ( m_AudioContainer != null )
202- TargetPath = AssetDatabase . GetAssetPath ( m_AudioContainer ) ;
205+ {
206+ UpdateTargetPath ( ) ;
207+ }
203208
204209 TargetChanged ? . Invoke ( this , EventArgs . Empty ) ;
210+
211+ UpdateResourceTrackerElement ( ) ;
212+ }
213+
214+ private void UpdateResourceTrackerElement ( )
215+ {
216+ if ( m_ResourceTrackerElement != null )
217+ {
218+ m_ResourceTrackerElement . Unbind ( ) ;
219+ }
220+
221+ if ( m_TrackedSource != null )
222+ {
223+ var trackedSourceSO = new SerializedObject ( m_TrackedSource ) ;
224+ var trackedSourceResourceProperty = trackedSourceSO . FindProperty ( "m_Resource" ) ;
225+ m_ResourceTrackerElement . TrackPropertyValue ( trackedSourceResourceProperty , OnResourceChanged ) ;
226+ }
205227 }
206228
207229 internal void Play ( )
0 commit comments