ユーザ用ツール

サイト用ツール


embed:tutorial2

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン前のリビジョン
次のリビジョン
前のリビジョン
embed:tutorial2 [2023/01/16 21:46] machiaworxembed:tutorial2 [2023/01/21 13:15] (現在) – [実装] machiaworx
行 31: 行 31:
 using Miniscript; using Miniscript;
 using TMPro; using TMPro;
- 
  
 public class ScriptMover : MonoBehaviour public class ScriptMover : MonoBehaviour
行 40: 行 39:
     public Interpreter interpreter;     public Interpreter interpreter;
  
-    public string globalVarName="";+    //ここにグローバル変数を格納するクラス名を指定してください。 
 +    public string globalVarName="ship";
     private int frame=0;     private int frame=0;
          
行 53: 行 53:
         interpreter.implicitOutput = (string s,bool t) => Debug.Log($"implicit {s}");         interpreter.implicitOutput = (string s,bool t) => Debug.Log($"implicit {s}");
         interpreter.errorOutput = (string s,bool t) => {         interpreter.errorOutput = (string s,bool t) => {
- 
             //エラーログ出力。(Unity側のエラーとして動く)             //エラーログ出力。(Unity側のエラーとして動く)
             Debug.LogError(s);             Debug.LogError(s);
行 70: 行 69:
         };         };
  
 +        //ソースコードの起動準備を行う。
         RunScript(loadText);         RunScript(loadText);
     }     }
行 76: 行 76:
         //前提になるソースコードを最初から埋め込んでおく。         //前提になるソースコードを最初から埋め込んでおく。
         string extraSource = "ship.reset = function(); self.x=0; self.y=0; self.rot=0;end function\n";         string extraSource = "ship.reset = function(); self.x=0; self.y=0; self.rot=0;end function\n";
 +        
 +        //上記前提ソースコード+テキストのソースコードを読み込ませる。
         interpreter.Reset(extraSource+sourceCode);         interpreter.Reset(extraSource+sourceCode);
                  
行 81: 行 83:
         interpreter.Compile();         interpreter.Compile();
  
-        //グローバル変数の定義今回は1個のマップにまとめてる+        //グローバル変数の初期化
         ValMap data = new ValMap();         ValMap data = new ValMap();
         data["cnt"]=new ValNumber(0);         data["cnt"]=new ValNumber(0);
行 87: 行 89:
         data["y"] = new ValNumber(this.transform.localRotation.y);         data["y"] = new ValNumber(this.transform.localRotation.y);
         data["rot"] = new ValNumber(this.transform.localRotation.z);         data["rot"] = new ValNumber(this.transform.localRotation.z);
 +        
 +        //グローバル変数の定義。今回は1個のマップにまとめてる
         interpreter.SetGlobalValue(globalVarName, data);         interpreter.SetGlobalValue(globalVarName, data);
     }     }
行 101: 行 105:
 #endif #endif
         }         }
 +        
 +        //処理したスクリプトのグローバル変数から各種動きを反映する
         UpdateFromScript();         UpdateFromScript();
     }     }
行 107: 行 113:
         ValMap data = null;         ValMap data = null;
         try {         try {
 +            //変数名が最初に定義したものかを確認、一致してれば以降読み込めてるものとして処理する。
             data = interpreter.GetGlobalValue(globalVarName) as ValMap;             data = interpreter.GetGlobalValue(globalVarName) as ValMap;
         } catch (UndefinedIdentifierException) {         } catch (UndefinedIdentifierException) {
行 127: 行 134:
 </code> </code>
  
-終わったら画面UIのテキストをCubeの枠にドラッグ&ドロップしておいてください。+終わったらCubeからテキスト部分参照しておいてください。
  
 ==== Miniscript言語で書いたソースコード用意 ==== ==== Miniscript言語で書いたソースコード用意 ====
  
-以下のテキストを用意して、ScriptMoverクラスのテキストに登録しておいてください。+以下の内容のテキストファイルを用意してください。
  
   serif=["This is Miniscript's test.","This is sample."]   serif=["This is Miniscript's test.","This is sample."]
行 138: 行 145:
   ship.cnt+=1   ship.cnt+=1
   change(serif[(ship.cnt/600)%2])   change(serif[(ship.cnt/600)%2])
 +  
 +終わったらCubeから作ったソースコードを参照しておいてください。
  
 ==== 動かしてみましょう ==== ==== 動かしてみましょう ====
embed/tutorial2.1673873201.txt.gz · 最終更新: 2023/01/16 21:46 by machiaworx