You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
	
	
		
			
				
					
						
							|  |  |  |  | using UnityEditor; | 
					
						
							|  |  |  |  | using UnityEditor.Timeline; | 
					
						
							|  |  |  |  | using UnityEngine; | 
					
						
							|  |  |  |  | using UnityEngine.Playables; | 
					
						
							|  |  |  |  | using UnityEngine.Timeline; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | [ExecuteInEditMode] | 
					
						
							|  |  |  |  | public class TimelineTool : MonoBehaviour | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     private PlayableDirector PlayableDirector; | 
					
						
							|  |  |  |  |     private GameObject animator; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private void OnEnable() | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         PlayableDirector = GetComponent<PlayableDirector>(); | 
					
						
							|  |  |  |  |         animator = GetComponentInChildren<Animator>().gameObject; | 
					
						
							|  |  |  |  |         Selection.selectionChanged += OnSelectionChanged; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private void OnDisable() | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         Selection.selectionChanged -= OnSelectionChanged; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private void OnSelectionChanged() | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         var selectedObject = UnityEditor.Selection.activeObject; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         if (selectedObject == null) return; | 
					
						
							|  |  |  |  |         if (selectedObject.GetType() != typeof(TimelineAsset)) return; | 
					
						
							|  |  |  |  |         // 打印选定对象的名称 | 
					
						
							|  |  |  |  |         var timeline = (TimelineAsset)selectedObject; | 
					
						
							|  |  |  |  |         PlayableDirector.playableAsset = timeline; | 
					
						
							|  |  |  |  |         foreach (var track in timeline.GetOutputTracks()) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             if (track is AnimationTrack) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 PlayableDirector.SetGenericBinding(track, animator); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             if (track is AttackTrack) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 PlayableDirector.SetGenericBinding(track, transform); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         EditorApplication.delayCall += () => { Selection.activeGameObject = gameObject; }; | 
					
						
							|  |  |  |  |         TimelineEditor.GetOrCreateWindow().ShowTab(); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | } |