Unite以前のツクールは、使ったことないですが、
初心者向け講座では、JSONでやるように、というていみでしょうか。。。
UnityでJSONを扱うのは、それほど難しくないです。
using System;
using UnityEngine;
(省略)
namespace RPGMaker.Codebase.Addon
{
public class Hoge
{
public void hoge(string structFooArray) {
var fooArray = JsonUtility.FromJson<FooArray>(structFooArray);
foreach (var foo in fooArray.array)
{
Debug.Log($"Text: {foo.text}, ColorNum: {foo.colorNum}");
}
}
[Serializable]
public class Foo
{
public string text;
public int colorNum;
}
[Serializable]
public class FooArray
{
public Foo[] array;
}
}
}
イベントから、引数にJSONデータを文字列として渡します。
{"array":[
{"text": "aaa", "colorNum": 1},
{"text": "bbb", "colorNum": 2}
]}
作成日:
Unite以前のツクールは、使ったことないですが、 初心者向け講座では、JSONでやるように、というていみでしょうか。。。
UnityでJSONを扱うのは、それほど難しくないです。
using System; using UnityEngine; (省略) namespace RPGMaker.Codebase.Addon { public class Hoge { public void hoge(string structFooArray) { var fooArray = JsonUtility.FromJson<FooArray>(structFooArray); foreach (var foo in fooArray.array) { Debug.Log($"Text: {foo.text}, ColorNum: {foo.colorNum}"); } } [Serializable] public class Foo { public string text; public int colorNum; } [Serializable] public class FooArray { public Foo[] array; } } }
イベントから、引数にJSONデータを文字列として渡します。
{"array":[ {"text": "aaa", "colorNum": 1}, {"text": "bbb", "colorNum": 2} ]}
作成日:
アイネロさん
すみません。説明不足でした。
Unite以前のツクールですと下記のようなアノテーションを指定できるようです。
/*: ja * @param 構造体型 * @type struct<array> */ /*~struct~array: * @param text * @type string * * @param colorNum * @type number */
この場合に例えばstruct<array>[]とすると、struct<array>[]に適した入力欄をUniteが用意してくれないか、と期待していたのですが…(パラメータの入力を間違えてしまいそうでどうにかならんかとの質問でした)
Json形式でないと駄目そうですね。
ご教授いただき、ありがとうございます。
作成日:
更新日:
やってみたら動きました。
こんなイメージでしょうか?
FooArrayの構造体と、Fooの構造体の2つを使っているので2つ書いてみました。
using System; using UnityEngine; /*:ja * @addondesc Foo * @author * @help * * * @command hoge * @text test * @desc test * * @arg FooArray * @text data * @desc data * @type struct<FooArray> * */ /*~struct~FooArray: * @param array * @type struct<Foo>[] * */ /*~struct~Foo: * @param text * @type string * * @param colorNum * @type number */ namespace RPGMaker.Codebase.Addon { public class Hoge { public void hoge(string structFooArray) { var fooArray = JsonUtility.FromJson<FooArray>(structFooArray); foreach (var foo in fooArray.array) { Debug.Log($"Text: {foo.text}, ColorNum: {foo.colorNum}"); } } [Serializable] public class Foo { public string text; public int colorNum; } [Serializable] public class FooArray { public Foo[] array; } } }
作成日:
アイネロさん
おおー
試してみたらできました!
どこかで見落としてしまっていたのかわからないですが、1つ目のtextとcolorNumを対にする形で入力すると2つ目のtextとcolorNumを入力できるようになり、まさに期待していたものです。
助かりました。わざわざ試していただき、ありがとうございます!