embed:tutorial2
差分
このページの2つのバージョン間の差分を表示します。
次のリビジョン | 前のリビジョン | ||
embed:tutorial2 [2023/01/16 21:28] – 作成 machiaworx | embed:tutorial2 [2023/01/21 13:15] (現在) – [実装] machiaworx | ||
---|---|---|---|
行 1: | 行 1: | ||
- | m====== より実践的なソース組み込み ====== | + | ====== より実践的なソース組み込み ====== |
==== Unityのプロジェクトを新規作成 ==== | ==== Unityのプロジェクトを新規作成 ==== | ||
行 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=""; | + | |
+ | | ||
private int frame=0; | private int frame=0; | ||
| | ||
行 48: | 行 48: | ||
interpreter.hostData = this; | interpreter.hostData = this; | ||
- | //出力 | + | |
// | // | ||
interpreter.standardOutput = (string s,bool t) => Debug.Log(s); | interpreter.standardOutput = (string s,bool t) => Debug.Log(s); | ||
interpreter.implicitOutput = (string s,bool t) => Debug.Log($" | interpreter.implicitOutput = (string s,bool t) => Debug.Log($" | ||
interpreter.errorOutput = (string s,bool t) => { | interpreter.errorOutput = (string s,bool t) => { | ||
- | + | | |
- | | + | |
Debug.LogError(s); | Debug.LogError(s); | ||
}; | }; | ||
- | //新関数定義 | + | //組込関数定義のための変数 |
Intrinsic f; | Intrinsic f; | ||
- | //ボスの座標を一次保存、次のエリアで切替できるようにする | + | //文字列をテキスト枠に反映させる |
f = Intrinsic.Create(" | f = Intrinsic.Create(" | ||
f.AddParam(" | f.AddParam(" | ||
行 70: | 行 69: | ||
}; | }; | ||
+ | // | ||
RunScript(loadText); | RunScript(loadText); | ||
} | } | ||
| | ||
public void RunScript(string sourceCode) { | public void RunScript(string sourceCode) { | ||
+ | // | ||
string extraSource = " | string extraSource = " | ||
+ | | ||
+ | // | ||
interpreter.Reset(extraSource+sourceCode); | interpreter.Reset(extraSource+sourceCode); | ||
+ | | ||
+ | // | ||
interpreter.Compile(); | interpreter.Compile(); | ||
+ | // | ||
ValMap data = new ValMap(); | ValMap data = new ValMap(); | ||
- | | ||
data[" | data[" | ||
data[" | data[" | ||
data[" | data[" | ||
data[" | data[" | ||
- | | + | |
+ | // | ||
interpreter.SetGlobalValue(globalVarName, | interpreter.SetGlobalValue(globalVarName, | ||
} | } | ||
void Update(){ | void Update(){ | ||
+ | // | ||
try{ | try{ | ||
- | // | ||
if( !interpreter.Running()) | if( !interpreter.Running()) | ||
interpreter.Restart(); | interpreter.Restart(); | ||
interpreter.RunUntilDone(1.0f); | interpreter.RunUntilDone(1.0f); | ||
- | |||
}catch (MiniscriptException err) { | }catch (MiniscriptException err) { | ||
#if UNITY_EDITOR | #if UNITY_EDITOR | ||
行 101: | 行 105: | ||
#endif | #endif | ||
} | } | ||
- | + | ||
+ | // | ||
UpdateFromScript(); | UpdateFromScript(); | ||
} | } | ||
行 108: | 行 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) { | ||
行 114: | 行 120: | ||
if (data == null) return; | if (data == null) return; | ||
- | | + | |
- | Vector3 pos = t.localPosition; | + | |
- | float xx,yy; | + | |
- | + | ||
Value xval = data[" | Value xval = data[" | ||
Value yval = data[" | Value yval = data[" | ||
行 123: | 行 126: | ||
if (rotVal != null) t.localRotation = Quaternion.Euler(xval.FloatValue(), | if (rotVal != null) t.localRotation = Quaternion.Euler(xval.FloatValue(), | ||
+ | // | ||
Value cntval=data[" | Value cntval=data[" | ||
frame=cntval.IntValue(); | frame=cntval.IntValue(); | ||
行 130: | 行 134: | ||
</ | </ | ||
- | 終わったら画面UIのテキストをCubeの枠にドラッグ&ドロップしておいてください。 | + | 終わったらCubeからテキスト部分を参照しておいてください。 |
==== Miniscript言語で書いたソースコード用意 ==== | ==== Miniscript言語で書いたソースコード用意 ==== | ||
- | 以下のテキストを用意して、ScriptMoverクラスのテキストに登録しておいてください。 | + | 以下の内容のテキストファイルを用意してください。 |
serif=[" | serif=[" | ||
行 141: | 行 145: | ||
ship.cnt+=1 | ship.cnt+=1 | ||
change(serif[(ship.cnt/ | change(serif[(ship.cnt/ | ||
+ | | ||
+ | 終わったらCubeから作ったソースコードを参照しておいてください。 | ||
==== 動かしてみましょう ==== | ==== 動かしてみましょう ==== |
embed/tutorial2.1673872128.txt.gz · 最終更新: 2023/01/16 21:28 by machiaworx