StoryPannelCtr.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import { _decorator, AudioClip, AudioSource, Component, Label, Node } from "cc"
  2. import { processCtr } from "./socket/processCtr"
  3. const { ccclass, property } = _decorator
  4. @ccclass("StoryPannelCtr")
  5. export class StoryPannelCtr extends Component {
  6. @property({ type: processCtr })
  7. public processCtr: processCtr | null = null
  8. @property
  9. typeSpeed: number = 0.2 // 每个字符出现的间隔时间
  10. @property
  11. maxLines: number = 18 // 最大行数
  12. @property(AudioClip)
  13. public typingClip: AudioClip = null!;
  14. public audioSource: AudioSource = null!;
  15. private fullText: string = ""
  16. private currentText: string = ""
  17. private allLines: string[] = []
  18. public label: Label | null = null
  19. private currentLine: string = ""
  20. private processedCharsCount: number = 0
  21. public isOnProcess:boolean = false
  22. public storyContent: string =
  23. "《隐形守护者》巧妙的结合了影视剧专业的演技造诣和电子游戏独有的交互体验,用电子游戏独有的表现手法,让玩家对当时那段充满色彩的历史有了新的认识。剧本没有模仿传统谍战剧,整个故事设定都非常符合当时那个年代,游戏中的每个人物都信手拈来展现出难以想象的独创性。游戏提供了传统游戏所不具备的沉浸式的互动体验、真正意义上的多样选择所导致的不同结局。更强调简化的互动性和操作性,以完全影视剧的镜头和剧本来叙事。游戏采用高成本但效果好的真人实拍的方式。对剧本细节的打磨和对当时人物环境的考究。通过演员精湛的演技给玩家营造出真实的体验。这款游戏用一种特殊的方式,为玩家讲述了一个精彩的抗战背景下的谍战故事。《隐形守护者》是一部国内首款创新性互动影像作品。全程采用真人拍摄,以定格图像辅之以影视化剪辑的手法。游戏还利用真人互动影像的优势为用户进行了一场行之有效的爱国主义教育。人实景拍摄,所有场景均为实拍影像,包括为了增加历史真实感而添加的影像史料。加上精良的影音演绎的方式大大的增加了代入感,选角上,演员颜值、演技双在线,除了主角肖途展现出贯穿全剧的人性弧光外,女性角色都演绎得各有特点。而极为考究的场景、道具和服装,也都彰显出制作组的用心和细致。而全程语音加持,以及根据剧情推进或激燃或紧张的配乐,让人有亲临谍战大片的错觉。看似是一个拥有四大结局,多达12个小时的故事情节,但从整个故事来看,它的主旋律其实很简单。"
  24. updateStory(str: string) {
  25. console.log("开始更新故事!!!!!!!!!!!!!")
  26. //this.fullText = str.replace(/[\r\n]+/g, ' ').trim();
  27. this.fullText = str.replace(/[\r\n]+/g, ' ').replace(/\s+/g, ' ').trim();
  28. if (!this.node) {
  29. console.warn("RichText component is not assigned!")
  30. return
  31. }
  32. //初始化中间值
  33. this.processedCharsCount = 0;
  34. this.currentLine = "";
  35. this.allLines = [];
  36. this.audioSource.pause()
  37. this.currentText = ""
  38. this.label.string = this.currentText
  39. this.typeWrite()
  40. this.audioSource.play()
  41. }
  42. typeWrite() {
  43. if (this.processedCharsCount < this.fullText.length) {
  44. const nextChar = this.fullText[this.processedCharsCount]
  45. this.currentLine += nextChar
  46. this.processedCharsCount++
  47. // 检查当前行的长度,决定是否开始新的一行
  48. if ((this.currentLine.length === 24 && nextChar !== " ") || this.currentLine.length === 25) {
  49. this.allLines.push(this.currentLine)
  50. this.currentLine = ""
  51. }
  52. // 检查所有行的总数,删除早期的行以维持 maxLines 的限制
  53. while (this.allLines.length > this.maxLines - 1) {
  54. // -1 是因为还有 currentLine
  55. this.allLines.shift()
  56. }
  57. if (this.label) {
  58. this.label.string = [...this.allLines, this.currentLine].join("\n")
  59. }
  60. this.scheduleOnce(() => {
  61. this.typeWrite()
  62. }, this.typeSpeed)
  63. }
  64. else{
  65. //初始化中间值
  66. this.processedCharsCount = 0;
  67. this.currentLine = "";
  68. this.allLines = [];
  69. this.audioSource.pause()
  70. if(this.isOnProcess)
  71. {
  72. console.log("展示剧情处理完成,处理下一个")
  73. this.processCtr.doneProcessing()
  74. }
  75. }
  76. }
  77. start() {
  78. this.label = this.getComponent(Label);
  79. this.audioSource = this.node.getComponent(AudioSource)
  80. }
  81. update(deltaTime: number) {}
  82. }