0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

テキストコンバーター

Posted at

UnityのJsonUtilityではDictionaryをJson化することができないので、自分で作ったテキストデータをDictionaryに変換するスクリプトを組んでみました。

#で始まる行はコメント
:で終わる行はキー
<>で囲まれた範囲を値

としてDictionaryにします。

と組み合わせることで、セリフや説明を多言語に対応させることを目的にしたものです。

MessageControl
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;

using UnityEngine;

public class MessageControl
{
    private string MessageData = "";

    private Regex SearchTag = new Regex(@"^[^#].+?:", RegexOptions.Multiline);
    private Regex BracketRange = new Regex(@"<[\s\S]*?>", RegexOptions.Multiline);
    private Regex BracketSelector = new Regex(@"<|>", RegexOptions.Multiline);

    public MessageControl(string strmes)
    {
        MessageData = strmes;
    }

    public Dictionary<string, string> ConvertDictionary()
    {
        Dictionary<string, string> rDic = new Dictionary<string, string>();
        MatchCollection matches = SearchTag.Matches(MessageData);

        bool hasContent = false;
        for (int i = 0; i < matches.Count; i++)
        {
            Match match = BracketRange.Match(MessageData, matches[i].Index);
            if (match.Success)
            {
                string key = matches[i].Value.ToUpper();
                string value = BracketSelector.Replace(match.Value, "").Replace("\r", "").Replace("\n", "");
                rDic.Add(key, value);
                hasContent = true;
            }
        }
        if (!hasContent)
        {
            rDic = null;
            Debug.Log("Dictionary Setup Failed.");
        }
        return rDic;
    }

}

テキストデータの例
#
# メッセージデータ日本語JP/英語EN
#
TUTORIAL00JP:
<
[ANIM20]それじゃ[RET]画面の見方とゲームのルール、操作方法について説明しよう[CLICK][NEXT]
>
TUTORIAL00EN:
<
[ANIM20]OK Then,[RET]I will explain about the rule of the game,and controls[CLICK][NEXT]
>
TUTORIAL01JP:
<
[PIC0][LOOK][ANIM21]まずはタイトル画面、[RET]ここでは各種エンディングを何人見たかということがわかる[CLICK]
[OUT]設定ボタンを押すと設定画面になり、GAMESTARTを押すとゲームがスタートする[CLICK]
[ANIM25]ま、そのくらいのことはわかってると思うけどね[CLICK][NEXT]
>
TUTORIAL01EN:
<
[PIC0][LOOK][ANIM21]First,let's take a look at this title screen.[CLICK]
The informations displaying how many peoples have looked each endings.[CLICK]
[OUT]The Option button is for opening to display setting screen,the GameStart button is for starting game[CLICK]
[ANIM25]You know about that, don't you?[CLICK][NEXT]
>
TUTORIAL02JP:
<
[PIC1][LOOK][ANIM21]これは設定画面だ[RET]BGM、効果音の音量設定、[OUT]言語は英語と日本語から選べる[CLICK]
さらにパーティクルを表示するかどうか設定でき、最後のオプションは条件を満たすと選択できるようになる[CLICK]
[ANIM25]最後のオプションの効果については今はまだヒミツだ[PREL500][CLICK][NEXT]
>
TUTORIAL02EN:
<
[PIC1][LOOK][ANIM21]This is setting screen.You can change the volume of BGM or SE on this.[CLICK]
[OUT]And also you can choose English or Japanese languages.[CLICK]
[ANIM25]Bottom option which named "Guardian" is secret yet.[PREL500][CLICK][NEXT]
>
TUTORIAL03JP:
<
[PIC2][ANIM25]次はゲーム画面について説明しよう[CLICK]
[PIC3][ANIM21]上部の長いバーがテンションゲージで、左側の丸いゲージがライフゲージだ[CLICK]
[ANIM25]テンションゲージは正しい場所を正しい順番でクリックすると増加する[CLICK]
前作とは違い、テンションゲージがMAXになることでエンディングに分岐する[CLICK]
[ANIM21]ライフゲージはクリックすることで減っていき、0になるとゲームオーバーだ[CLICK]
[ANIM25]ただしアイコンをクリックした場合はHPは減らないので安心してほしい[CLICK][NEXT]
>
TUTORIAL03EN:
<
[PIC2][ANIM25]Next,this is game playing screen.[CLICK]
[PIC3][ANIM21]Horizontal bar is progress of tension,circle gauge is your hitpoint.[CLICK]
[ANIM25]If you click correct place in correct order,tenstion bar will increase.[CLICK] 
When tensition bar filled,Ending movie will be started. [CLICK] 
[ANIM21]Though clicking on it will decrease your hit point.[CLICK]
If you lose all your hit points, game is over be careful.[CLICK][NEXT]
>
TUTORIAL04JP:
<
[PIC5][ANIM21]正しい部分をクリックすると左側の画面のようにハートマークが舞い、テンションゲージが増加する[CLICK]
[ANIM25]だが、ボクの視界内でクリックしたら右側の画面のように問答無用で凍らせてもらうぞ[CLICK]
[ANIM22]凍るとHPに大ダメージを受けて少しの間動けなくなり、ゲームオーバーに近づく[CLICK]
[ANIM25]まあ、せいぜい気をつけることだね[CLICK][NEXT]
>
TUTORIAL04EN:
<
[PIC5][ANIM21]When you click on the correct place, the heart particle will dance at click point[CLICK]
and then the tension bar will increase.[CLICK]
[ANIM25]But if you click on  in my sight, you will be frozen and will be taken damage.[CLICK][NEXT]
>
TUTORIAL05JP:
<
[ANIM21][PIC4]ゲーム画面のアイコンは左側がズームとオプション、右側は移動とカメラリセットだ[CLICK]
[ANIM25]左下の下向きの矢印ボタンをクリックすると全てのアイコンが消えた状態になり、[CLICK]
もう一度クリックすれば再びアイコンが表示される[CLICK][NEXT]
>
TUTORIAL05EN:
<
[ANIM21][PIC4]The User Interface icons on the screen are zoom and option buttons on the left,[CLICK]
 movement and camera reset buttons on the right.[CLICK]
 [ANIM25]Button with down arrow will hide all icons from screen.[CLICK][NEXT]
>
TUTORIAL06JP:
<
[PIC6][ANIM21]最後に説明するのはこのファンティアボタン[CLICK]
クリックするとファンティアのサークルページにジャンプできる[CLICK]
[ANIM25]ファンティアのサークルページではこのゲームの攻略動画を公開しているぞ[CLICK]
[ANIM26][PREL500]どうしてもエンディングの答えが知りたい場合は訪問してくれ[CLICK]
[ANIM25]説明はだいたい以上だ[CLICK][NEXT]
>
TUTORIAL06EN:
<
[PIC6][ANIM21]The last thing I'll explain is about this Fantia button.[CLICK]
This button navigate you to my circle page in Fantia by clicking.[CLICK]
[ANIM25]This game's walkthrough movie are available at my page in Fantia with plan named "nostalgy plan" .[CLICK]
[ANIM22]This is the end of the explanation.[CLICK][NEXT]
>


0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?