UnityNovelProj Unity で VisualNovel を作成する

url: https://www.youtube.com/watch?v=Wz_8GeQC0_w&list=PLGSox0FgA5B58Ki4t4VqAPDycEpmkBd0i&index=75
title: "Episode 21 p5   Operator Lines"
description: "Make a Visual Novel in Unity 2023 - Episode 21 (part5) Operator LinesLets add the new logical line that will allow us to create and modify variables in the d..."
host: www.youtube.com
favicon: https://www.youtube.com/s/desktop/9af06a99/img/favicon_32x32.png
image: https://i.ytimg.com/vi/Wz_8GeQC0_w/maxresdefault.jpg

ダイアログファイルで式を扱えるようにする

$db.var = expression という形式をダイアログファイルで記載できるようにします。 右辺にある文字列については変数埋め込みもできるようにします。

createCharacter(ganyariya -enabled true)
[wait]ganyariya.Move(-x 0.5 -y 0.6 -i true)
ganyariya.Show()

input "what is your favorite game?"

$answerText = "oh! your favorite game is <input>."

ganyariya "$answerText iine!"

$answerText = "$answerText is $answerText dayo!"

ganyariya "$answerText again"

$num.x = 10
$num.y = 20
$num.x += $num.y

ganyariya "num.x is $num.x"

実現方法としては

  • LL_Operator という LogicalLine の一種として実現する
    • 「1 行」の文章について、LogicalLine の条件を満たす特定のパターンであれば通常シナリオではなく、ユーザインタラクションとして実行する
  • LL_Operator かどうかは、正規表現で @"^\$[a-zA-Z0-9_.]+\s*(?:[+\-*/]=|=)\s*" を満たすかどうかを確認する
  • LL_Operator であれば、$db.bar = right-expression について db.bar= (op)right-expression (rhs) に分解する
    • rhs についてはじめに LogicalLineUtils.Expressions.EvaluateRhs で評価する
    • その後 $db.bar op rhs という式全体について評価する

となっています。

問題点

これらの処理をがんばって正規表現で何とかする、という仕組みをとっています。 これは辛いため lua など、Unity ライブラリにあるスクリプトライブラリを使って、自前の式評価をやめる、というのが大事です。