facebook twitter hatena line email

「Unity/tinyモード」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(インストール後、なぜかエラー)
(インストール後、なぜかエラー)
行18: 行18:
  
 
の一番下にあるようにライブラリのTinyAssetExporter.csを書き換えるとうまくいった。
 
の一番下にあるようにライブラリのTinyAssetExporter.csを書き換えるとうまくいった。
 +
 +
<pre>
 +
Line 713.
 +
// 変更前
 +
foreach (var kvp in font.characterDictionary)
 +
{
 +
var ci = kvp.Value;
 +
var tinyCI = new Runtime.Text.TinyCharacterInfo(entity.Registry);
 +
tinyCI.value = (uint)ci.id;
 +
 +
tinyCI.advance = ci.xAdvance;
 +
 +
tinyCI.bearingX = ci.xOffset;
 +
tinyCI.bearingY = ci.yOffset;
 +
tinyCI.width = ci.width;
 +
tinyCI.height = ci.height;
 +
 +
 +
var min = new Vector2(ci.x / font.atlas.width, (font.atlas.height - ci.y - ci.height) / font.atlas.height);
 +
var off = new Vector2(ci.width / font.atlas.width, ci.height / font.atlas.height);
 +
tinyCI.characterRegion = new Rect(min.x, min.y, off.x, off.y);
 +
data.Add(tinyCI.Tiny);
 +
}
 +
 +
 +
// 変更後
 +
foreach (var kvp in font.glyphLookupTable)
 +
{
 +
var ci = kvp.Value;
 +
var tinyCI = new Runtime.Text.TinyCharacterInfo(entity.Registry);
 +
tinyCI.value = (uint)ci.index;
 +
 +
tinyCI.advance = ci.metrics.horizontalAdvance;
 +
 +
tinyCI.bearingX = ci.metrics.horizontalBearingX;
 +
tinyCI.bearingY = ci.metrics.horizontalBearingY;
 +
tinyCI.width = ci.metrics.width;
 +
tinyCI.height = ci.metrics.height;
 +
 +
 +
var min = new Vector2(ci.glyphRect.x / font.atlas.width, (font.atlas.height - ci.glyphRect.y - ci.glyphRect.height) / font.atlas.height);
 +
var off = new Vector2(ci.glyphRect.width / font.atlas.width, ci.glyphRect.height / font.atlas.height);
 +
tinyCI.characterRegion = new Rect(min.x, min.y, off.x, off.y);
 +
data.Add(tinyCI.Tiny);
 +
}
 +
</pre>
  
 
==tinyサンプルインポート==
 
==tinyサンプルインポート==

2019年9月26日 (木) 15:22時点における版

tinyモードインストール

Unity 2018.3.0.b12以上らしい。

2019.1.6f1にはあった。

  1. unityメニュー/window/PackageManager
  2. 上のadvancedタブを選択し、showPreviewPackages選択
  3. TinyModeがあるのでinstallする

2019/7/23時点だとversionは0.14.5でした。

unityのメインメニューにtinyが現れることを確認

インストール後、なぜかエラー

Library/PackageCache/com.unity.tiny@0.14.5-preview/Editor/Export/TinyAssetExporter.cs(712,38): error CS1061: 'TMP_FontAsset' does not contain a definition for 'characterDictionary' and no accessible extension method 'characterDictionary' accepting a first argument of type 'TMP_FontAsset' could be found (are you missing a using directive or an assembly reference?)

参考:https://forum.unity.com/threads/i-have-a-problem-with-tiny-unity.665527/

の一番下にあるようにライブラリのTinyAssetExporter.csを書き換えるとうまくいった。

Line 713.
// 変更前
foreach (var kvp in font.characterDictionary)
{
var ci = kvp.Value;
var tinyCI = new Runtime.Text.TinyCharacterInfo(entity.Registry);
tinyCI.value = (uint)ci.id;

tinyCI.advance = ci.xAdvance;

tinyCI.bearingX = ci.xOffset;
tinyCI.bearingY = ci.yOffset;
tinyCI.width = ci.width;
tinyCI.height = ci.height;


var min = new Vector2(ci.x / font.atlas.width, (font.atlas.height - ci.y - ci.height) / font.atlas.height);
var off = new Vector2(ci.width / font.atlas.width, ci.height / font.atlas.height);
tinyCI.characterRegion = new Rect(min.x, min.y, off.x, off.y);
data.Add(tinyCI.Tiny);
}


// 変更後
foreach (var kvp in font.glyphLookupTable)
{
var ci = kvp.Value;
var tinyCI = new Runtime.Text.TinyCharacterInfo(entity.Registry);
tinyCI.value = (uint)ci.index;

tinyCI.advance = ci.metrics.horizontalAdvance;

tinyCI.bearingX = ci.metrics.horizontalBearingX;
tinyCI.bearingY = ci.metrics.horizontalBearingY;
tinyCI.width = ci.metrics.width;
tinyCI.height = ci.metrics.height;


var min = new Vector2(ci.glyphRect.x / font.atlas.width, (font.atlas.height - ci.glyphRect.y - ci.glyphRect.height) / font.atlas.height);
var off = new Vector2(ci.glyphRect.width / font.atlas.width, ci.glyphRect.height / font.atlas.height);
tinyCI.characterRegion = new Rect(min.x, min.y, off.x, off.y);
data.Add(tinyCI.Tiny);
}

tinyサンプルインポート

unityメニュー/tiny/import samples/

tinyプレイ

FlyingYolkであれば、 FlyingYolk/FlyingYolk.utprojectを選択しプレイボタンを押す

tinyをbuild

File/Tiny/Build

Tiny/File/Build

でも同じ

TinyExport/FlyingYolk/html5/development/build/index.html にできている

公開するにはTinyExportを上げれば良い。その後index.html内の部分だけパスを修正すれば良い。

<script src="/~project/TinyExport/FlyingYolk/html5/development/artifacts/scripts/tsc-emit.js"></script>

<script src="../artifacts/scripts/tsc-emit.js"></script>

c#対応

今までTypeScriptでしたが、0.15.3でC#に対応したようです。

https://wakky.tech/tiny-unity-samples/

https://forum.unity.com/threads/project-tiny-c-preview-0-15-3-available.688969/