问题描述及使用流程:
由于想要实现信号播放时间线动画的功能,我用鱼片大佬提供的时间线播放预制体修改了一下当中的TextTrigger脚本。基本就是复制粘贴大法,运行后文字可以显示,但会有报错代码。时间线也没有正常播放。
小弟才疏学浅,编程不是很好,所以有没有大佬帮我看下是哪里没有写对。。。
import { TypeWriter } from "./TypeWriter";
import TextShow_Generate from "./ui-generate/TextShow_generate";
@Component
export default class TextTrigger extends Script {
@Property({ displayName: "开始信号", group: "接收信号" })
public startEvent: string = ""
@Property({ displayName: "TimelineID", group: "接收信号" })
public TimelineID: string = ""
@Property({ displayName: "1白删除线", group: "文本文字" })
public Text01: string = ""
@Property({ displayName: "2青删除线", group: "文本文字" })
public Text02: string = ""
@Property({ displayName: "3白删除线", group: "文本文字" })
public Text03: string = ""
@Property({ displayName: "4白下划线", group: "文本文字" })
public Text04: string = ""
@Property({ displayName: "5红下划线", group: "文本文字" })
public Text05: string = ""
@Property({ displayName: "6白下划线", group: "文本文字" })
public Text06: string = ""
/** 当脚本被实例后,会在第一帧更新前调用此函数 */
director: lighter.timeline.Director;
protected onStart(): void {
console.log("TextTrigger onStart");
this.director = lighter.timeline.Director.create();
if (this.startEvent != "") { //修改的部分
Event.addLocalListener(this.startEvent, () => { //修改的部分
this.showText(); //修改的部分
})
}
}
showText() {
const text = LanguageUtil.getText(`<s>${this.Text01}<color=#cyan>${this.Text02}</color>${this.Text03}</s><u>${this.Text04}<size=30><color=#red>${this.Text05}</color></size>${this.Text06}</u>`) //修改的部分
console.log("showText", text);
const ui = UIService.show(TextShow_Generate);
new TypeWriter(text,
(txt => {
ui.mTextBlock.text = txt;
}),
() => {
setTimeout(() => {
UIService.hide(TextShow_Generate);
this.director.play(`${this.TimelineID}`); //修改的部分
}, 2000);
}
)
}
/**
* 周期函数 每帧执行
* 此函数执行需要将this.useUpdate赋值为true
* @param dt 当前帧与上一帧的延迟 / 秒
*/
protected onUpdate(dt: number): void {
}
/** 脚本被销毁时最后一帧执行完调用此函数 */
protected onDestroy(): void {
}
}
相关截图或视频:
这是报错内容
[2024.12.06-18.19.59:366][310]Log file open, 12/06/24 18:19:59
[2024.12.06-18.19.59:366][310]MWTS:: Display: start load lighter library.....
[2024.12.06-18.19.59:366][310]MWTS:: Display: load lighter library complete!
[2024.12.06-18.19.59:366][310]MWTS:: Display: start load animation library.....
[2024.12.06-18.19.59:374][310]MWTS:: Display: load animation library complete!
[2024.12.06-18.19.59:374][310]MWTS:: Display: start load timeline library.....
[2024.12.06-18.19.59:385][311]MWTS:: Display: load timeline library complete!
[2024.12.06-18.20.04:619][361]MWTS:: Display: TextTrigger onStart
[2024.12.06-18.20.04:619][361]MWTS:: Display: 欢迎使用Timeline播放组件!
[2024.12.06-18.20.04:619][361]MWTS:: Display: 当前播放资源:,
[2024.12.06-18.20.04:620][361]MWTS:: Display: 使用方法:
[2024.12.06-18.20.04:620][361]MWTS:: Display: 按空格键暂停/播放
[2024.12.06-18.20.04:620][361]MWTS:: Display: 按回车键重新播放
[2024.12.06-18.20.04:620][361]MWTS:: Display: 按ESC键停止播放
[2024.12.06-18.20.04:620][361]MWTS:: Display: tips:正式发布前记得删除场景上的#DirectorComponent对象喔
[2024.12.06-18.20.04:620][361]MWTS:: Error: the director has no any preset clip. please set a clip first
[2024.12.06-18.20.04:904][364]MWTS:: Display: showText,<s>123<color=#cyan>456</color>789</s><u>2424<size=30><color=#red>494</color></size>5757</u>
[2024.12.06-18.20.07:925][394]MWTS:: Error: unhandledRejection,TypeError: Cannot read properties of undefined (reading 'getAsset'),TypeError: Cannot read properties of undefined (reading 'getAsset')
at Director.play (E:\MetaApp\Editor_Win64\MetaWorldSaved\Saved\MetaWorld\Project\Edit\手搓核弹\手搓核弹\dist\game.js:19995:44)
at Object.callBack (E:\MetaApp\Editor_Win64\MetaWorldSaved\Saved\MetaWorld\Project\Edit\手搓核弹\手搓核弹\dist\game.js:21287:31)
at timerTick (E:\KouDai\Editor\online\v0.41.0.5.20241125160613\WindowsNoEditor\MW\Mobile\WindowsNoEditor\MetaWorldMobile\Content\JavaScript\MWUserBootstrap.js:31310:13)
at E:\KouDai\Editor\online\v0.41.0.5.20241125160613\WindowsNoEditor\MW\Mobile\WindowsNoEditor\MetaWorldMobile\Content\JavaScript\puerts\lazyload.js:923:31
[2024.12.06-18.20.45:461][194]MWTS:: Display: showText,<s>123<color=#cyan>456</color>789</s><u>2424<size=30><color=#red>494</color></size>5757</u>
[2024.12.06-18.20.48:129][221]MWTS:: Error: unhandledRejection,TypeError: Cannot read properties of undefined (reading 'getAsset'),TypeError: Cannot read properties of undefined (reading 'getAsset')
at Director.play (E:\MetaApp\Editor_Win64\MetaWorldSaved\Saved\MetaWorld\Project\Edit\手搓核弹\手搓核弹\dist\game.js:19995:44)
at Object.callBack (E:\MetaApp\Editor_Win64\MetaWorldSaved\Saved\MetaWorld\Project\Edit\手搓核弹\手搓核弹\dist\game.js:21287:31)
at timerTick (E:\KouDai\Editor\online\v0.41.0.5.20241125160613\WindowsNoEditor\MW\Mobile\WindowsNoEditor\MetaWorldMobile\Content\JavaScript\MWUserBootstrap.js:31310:13)
at E:\KouDai\Editor\online\v0.41.0.5.20241125160613\WindowsNoEditor\MW\Mobile\WindowsNoEditor\MetaWorldMobile\Content\JavaScript\puerts\lazyload.js:923:31
[2024.12.06-18.20.54:361][283]MWTS:: Display: showText,<s>123<color=#cyan>456</color>789</s><u>2424<size=30><color=#red>494</color></size>5757</u>
[2024.12.06-18.20.57:362][313]MWTS:: Error: unhandledRejection,TypeError: Cannot read properties of undefined (reading 'getAsset'),TypeError: Cannot read properties of undefined (reading 'getAsset')
at Director.play (E:\MetaApp\Editor_Win64\MetaWorldSaved\Saved\MetaWorld\Project\Edit\手搓核弹\手搓核弹\dist\game.js:19995:44)
at Object.callBack (E:\MetaApp\Editor_Win64\MetaWorldSaved\Saved\MetaWorld\Project\Edit\手搓核弹\手搓核弹\dist\game.js:21287:31)
at timerTick (E:\KouDai\Editor\online\v0.41.0.5.20241125160613\WindowsNoEditor\MW\Mobile\WindowsNoEditor\MetaWorldMobile\Content\JavaScript\MWUserBootstrap.js:31310:13)
at E:\KouDai\Editor\online\v0.41.0.5.20241125160613\WindowsNoEditor\MW\Mobile\WindowsNoEditor\MetaWorldMobile\Content\JavaScript\puerts\lazyload.js:923:31
[2024.12.06-18.21.00:844][348]MWTS:: Display: showText,<s>123<color=#cyan>456</color>789</s><u>2424<size=30><color=#red>494</color></size>5757</u>
[2024.12.06-18.21.03:983][402]Log file closed, 12/06/24 18:21:03
补充信息(版本、日志等):
鱼片大佬的预制体 |