🐙

猫コメント

2025/01/29に公開

はじめに

概要

コメントを取得できるようになったらしいので、にゃーん、だけ話すワールド

きっかけ

https://x.com/Mittsujp/status/1883906456099103099
この投稿をみちゃったいました。やらない理由がなかったのでとりあえず簡単にできるサンプル作りました

開発環境(ワールド作り)

  • Unity 2021.3.4f1
  • Windows10
  • Cluster Creator Kit 2.30.1.2

関連記事

コメントが取得できる API を追加しました!
Interface Comment

実装

コメントに「に」「ゃ」以外の文字列が含まれていたら移動するギミック


TransferDestinationをグローバルに移動できるので、籠を作った後そこに配置すればよいと思います
すみませんが、Youtubeでの投稿や、イベントでゴーストでの投稿、といったいろいろな動作確認はしていません。
正規表現のほうがかっこいいかもしれません。パフォーマンスは高いのでしょうか

const transferDestination = $.subNode("TransferDestination");

$.onStart(() => {
    $.state.destination = transferDestination.getGlobalPosition();
});

$.onCommentReceived((comments) => {
    $.log("comments " + comments.map(c => c.body));
    const allowedChars = "にやゃぃんー~";
    let destination = $.state.destination;

    for (const comment of comments) {
        if (comment.via !== "cluster") {
            // Youtube comments
            continue;
        }
        const containsAllowedChars = [...comment.body].every(char => allowedChars.includes(char));
        if (containsAllowedChars) { continue; }

        let playerHandle = comment.sender;
        if (playerHandle == null) {
            // ghost or group viewing users
            continue;
        }
        playerHandle.setPosition(destination);
    }
})

Discussion