private void ReceivePlaybackState(object[] e) { var clip = GetClip(e); if (clip == null) { return; } if ((bool)e[2]) { animation.PlayClip(clip, (bool)e[4]); } else { animation.StopClip(clip); } clip.clipTime = (float)e[3]; }
public IEnumerator StartRecording(List <FreeControllerAnimationTarget> controllers, List <FloatParamAnimationTarget> floatParams) { // TODO: Handle stopping in the middle of it // TODO: Handle starting while it's already recording // TODO: Counter should use in-game rather than helptext _animation.StopAll(); _animation.ResetAll(); var keyframesOps = new KeyframesOperations(_clip); for (var i = 5; i > 0; i--) { SuperController.singleton.helpText = $"Start recording in {i}..."; var next = Time.realtimeSinceStartup + 1f; while (Time.realtimeSinceStartup < next) { yield return(0); if (Input.GetKeyDown(KeyCode.Escape)) { yield break; } } } SuperController.singleton.helpText = "Recording..."; foreach (var target in controllers) { keyframesOps.RemoveAll(target); } foreach (var target in floatParams) { keyframesOps.RemoveAll(target); } _clip.DirtyAll(); _animation.RebuildAnimationNow(); yield return(0); foreach (var target in controllers) { target.recording = true; target.StartBulkUpdates(); } foreach (var target in floatParams) { target.recording = true; target.StartBulkUpdates(); } _animation.PlayClip(_clip, false); while (_animation.playTime <= _clip.animationLength && _animation.isPlaying) { if (Input.GetKeyDown(KeyCode.Escape)) { break; } yield return(0); } _animation.StopAll(); _animation.ResetAll(); SuperController.singleton.helpText = ""; // TODO: This needs to be guaranteed. We could register the enumerator inside a disposable class, dispose being called in different cancel situations foreach (var target in controllers) { target.recording = false; target.EndBulkUpdates(); } foreach (var target in floatParams) { target.recording = false; target.EndBulkUpdates(); } _clip.DirtyAll(); }
private void InitPlaybackButtons(Transform buttonPrefab) { var container = new GameObject("Playback"); container.transform.SetParent(transform, false); var gridLayout = container.AddComponent <HorizontalLayoutGroup>(); gridLayout.spacing = 4f; gridLayout.childForceExpandWidth = false; gridLayout.childControlWidth = true; var playAll = Instantiate(buttonPrefab); playAll.SetParent(container.transform, false); playAll.GetComponent <UIDynamicButton>().label = "\u25B6 Seq"; playAll.GetComponent <UIDynamicButton>().button.onClick.AddListener(() => _animation.PlayAll()); playAll.GetComponent <LayoutElement>().preferredWidth = 0; playAll.GetComponent <LayoutElement>().flexibleWidth = 100; var playClip = Instantiate(buttonPrefab); playClip.SetParent(container.transform, false); playClip.GetComponent <UIDynamicButton>().label = "\u25B6 Clip"; playClip.GetComponent <UIDynamicButton>().button.onClick.AddListener(() => _animation.PlayClip(_animation.current, false)); playClip.GetComponent <LayoutElement>().preferredWidth = 0; playClip.GetComponent <LayoutElement>().flexibleWidth = 100; var stop = Instantiate(buttonPrefab); stop.SetParent(container.transform, false); stop.GetComponent <UIDynamicButton>().label = "\u25A0 Stop"; stop.GetComponent <UIDynamicButton>().button.onClick.AddListener(() => { if (_animation.isPlaying) { _animation.StopAll(); } else { _animation.ResetAll(); } }); stop.GetComponent <LayoutElement>().preferredWidth = 0; stop.GetComponent <LayoutElement>().flexibleWidth = 30; }