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.
		
		
		
		
		
			
		
			
				
	
	
		
			67 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			C#
		
	
			
		
		
	
	
			67 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			C#
		
	
| using UnityEditor;
 | |
| using UnityEditor.Timeline;
 | |
| using UnityEngine;
 | |
| using UnityEngine.Playables;
 | |
| using UnityEngine.Timeline;
 | |
| 
 | |
| [ExecuteInEditMode]
 | |
| public class TimelineTool : MonoBehaviour
 | |
| {
 | |
|     private PlayableDirector PlayableDirector;
 | |
|     public GameObject self;
 | |
|     public GameObject target;
 | |
|     public Animator self_animator;
 | |
|     public Animator target_animator;
 | |
| 
 | |
|     private void OnEnable()
 | |
|     {
 | |
|         PlayableDirector = GetComponent<PlayableDirector>();
 | |
|         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 AttackTrack)
 | |
|             {
 | |
|                 PlayableDirector.SetGenericBinding(track, self);
 | |
|             }
 | |
| 
 | |
|             if (track is AnimationTrack)
 | |
|             {
 | |
|                 PlayableDirector.SetGenericBinding(track, self_animator);
 | |
|             }
 | |
| 
 | |
|             if (track is ThrowPositionTrack)
 | |
|             {
 | |
|                 PlayableDirector.SetGenericBinding(track, target);
 | |
|             }
 | |
| 
 | |
|             if (track is ThrowAnimationTrack)
 | |
|             {
 | |
|                 PlayableDirector.SetGenericBinding(track, target_animator);
 | |
|             }
 | |
|             
 | |
|             if (track is ThrowTurnTrack)
 | |
|             {
 | |
|                 PlayableDirector.SetGenericBinding(track, target);
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         EditorApplication.delayCall += () => { Selection.activeGameObject = gameObject; };
 | |
|         TimelineEditor.GetOrCreateWindow().ShowTab();
 | |
|     }
 | |
| } |