public void Stop() { animationTask?.Release(); animationTask = null; isPlaying = false; index = 0; }
public void Play() { if (isPlaying) { return; } if (gameObject == null || image == null) { Debug.LogError("SequenceFrame.gameObject is null, or SequenceFrame.image is null"); return; } if (frames.Count == 0) { Debug.LogError("There is no frames, please call \"SetFramesPath()\" first"); return; } isPlaying = true; startPlayTime = DateTime.Now; SetImage(frames[index]); animationTask = TaskLite.Invoke(t => { if (gameObject == null || image == null) { Debug.LogError("SequenceFrame.gameObject is null, or SequenceFrame.image is null"); return(true); } var now = DateTime.Now; var elapse = (now - startPlayTime).TotalMilliseconds; var standardized = elapse % (frames.Count * interval); int index = (int)(standardized / interval); if (this.index == index) { return(false); } this.index = index; SetImage(frames[index]); if (elapse >= frames.Count * interval && !Loop) { OnPlayedOver?.Invoke(Tag); return(true); } return(false); }); }
private void Update() { if (Input.GetKeyDown(KeyCode.Q)) { CreateThrottleTask(); } else if (Input.GetKeyDown(KeyCode.E)) { TaskLite.ReleaseAll(); } else if (Input.GetKeyDown(KeyCode.W)) { WebTest(); } }
private void RunTaskAsync() { string name = NameSimulation.GetRandomChinesePersonalName(2); for (int i = 0; i < 10; i++) { int idx = i; Thread thread = new Thread(() => { TaskLite.Invoke(t => { Debug.Log($"{name} {idx}"); return(true); }); }); thread.Start(); } }
private void CalcTextPreferredWidth() { //这里很无奈,UGUI中文字只有渲染过后才能拿到正确的preferredWidth //所以这里延迟1帧再进行赋值 taskDelay?.Release(); if (this.HorizontalOverflow == HorizontalWrapMode.Overflow && this.VerticalOverflow == VerticalWrapMode.Overflow) { taskDelay = TaskLite.Invoke(t => { //Debug.Log($"after one frame {textComponent.preferredWidth} {textComponent.preferredHeight}"); if (this != null && textComponent != null) { Size = new Vector2(textComponent.preferredWidth, textComponent.preferredHeight); } taskDelay = null; return(true); }); } }
public void Pause() { animationTask?.Release(); animationTask = null; isPlaying = false; }