using SK.Framework; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Playables; using UnityEngine.UI; /// /// 结构认知动画控制 /// public class StructuralCognition_Ani : MonoBehaviour, IBeginDragHandler, IEndDragHandler { public Variables variables; public PlayableDirector DeviceTimeLine; /// /// TimeLine进度条 /// public Slider _TimelineProgress; [Header("Settings")] [SerializeField] private bool updateInPlayMode = true; private bool isDragging; public Animator[] animators; void Start() { DeviceTimeLine = variables.Get("TimeLine动画"); _TimelineProgress = variables.Get("动画节点滑动条"); Freeze(); // 确保 duration 有值 DeviceTimeLine.Evaluate(); //director.Play(); _TimelineProgress.minValue = 0f; _TimelineProgress.maxValue = (float)DeviceTimeLine.duration; _TimelineProgress.wholeNumbers = false; _TimelineProgress.onValueChanged.AddListener(OnSliderValueChanged); _TimelineProgress.onValueChanged.AddListener((Value) => { }); } void Update() { // Timeline → Slider if (!isDragging && DeviceTimeLine.state == PlayState.Playing) { _TimelineProgress.value = (float)DeviceTimeLine.time; } } public void Freeze() { foreach (var animator in animators) { if (animator != null) animator.speed = 0f; } } public void Resume() { foreach (var animator in animators) { if (animator != null) animator.speed = 1f; } } void OnSliderValueChanged(float value) { if (!isDragging) return; // Slider → Timeline DeviceTimeLine.time = value; DeviceTimeLine.Evaluate(); } public void OnBeginDrag(PointerEventData eventData) { isDragging = true; DeviceTimeLine.Pause(); Freeze(); } public void OnEndDrag(PointerEventData eventData) { isDragging = false; DeviceTimeLine.time = _TimelineProgress.value; DeviceTimeLine.Evaluate(); DeviceTimeLine.Play(); Resume(); } }