はじめに
少し前に話題になったProject Tinyですが、最近は全く聞かなくなってしまったような気がします。
調べたところJanuary 22, 2021にProject Tiny Full Preview 0.32が公開され、それ以降はバージョンアップはされていないようです。
Unity - Project Tiny 0.32 preview is available: UI & new Skinned Mesh Renderer -Blendshape sample - Unity Forum
これをみるとオワッタか・・・と思うかもしれませんが、一応Dec 9, 2021にECS頑張ってるよとの報告があったので、それに付随してProject Tinyも進んでいると信じたいです。
forum.unity.com
今更チュートリアルかいかとも思われるかもしれませんが、DOTSの練習にもなると思いますし触ってみたいと思います。
docs.google.com

Unity DOTS・Project Tinyに幸あれ。
導入方法
Package Managerからインストール or manifest.jsonでインストールを行います。
com.unity.tiny.all

また必要な依存先のパッケージも自動でインストールしてくれるので便利です。
環境
Unity 2020.1.17f1 URP*1
Project Tiny Full 0.32.0-preview.55
↓ 依存先
DOTS Runtime 0.32.0-preview.54
Entities 0.17.0-preview.41
Project Tiny 0.32.0-preview.54
Project Tiny for Web 0.32.0-preview.54
Project Tiny for Desktop 0.32.0-preview.54
Unity Physics 0.6.0-preview.3
2D Entities Physics 0.2.0-preview.5
Platforms 0.10.0-preview.10
Platforms Andriod 0.10.0-preview.10
Platforms iOS 0.10.0-preview.10
Platforms Linux 0.10.0-preview.10
Platforms macOS 0.10.0-preview.10
Platforms Web 0.10.0-preview.10
Platforms Windows 0.10.0-preview.10
Platforms 0.10.0-preview.10
Render-Pipeline Universal 8.3.1 (8.2.0)*2
Hybrid Renderer 0.11.0-preview.42
フォルダ・アセンブリの下準備
1. Assetsフォルダ直下にGameSystemsというフォルダを作成
2. 作成したフォルダの中にGameSystemsという名前のAssembly Definitionを作成
3. Assembly DefinitionのAssembly Definition Referencesに以下を追加する
- Unity.Entities
- Unity.Collections
- Unity.Transforms
- Unity.Mathematics
- Unity.Tiny.Core
- Unity.Tiny.Rendering
- Unity.Scenes*3

私の場合は以下のようなフォルダ構成になっています。
Assets
|-- GameSystems
| |-- GameSystems.asmdef
|-- Scenes
| |-- Main.scene
|-- Settings
|-- URPで用いる設定ファイル等
スクリプト作成
ECSの説明はしませんが、まずはComponent Dataを作成します。
using Unity.Entities; namespace GameSystems { [GenerateAuthoringComponent] public struct RotateComponent : IComponentData { public float Speed; } }
次にそれを利用したSystemを作成。
using Unity.Entities; using Unity.Mathematics; using Unity.Transforms; namespace GameSystems { public class RotateSystem : SystemBase { protected override void OnUpdate() { var deltaTime = Time.DeltaTime; Entities.ForEach((ref Rotation rot, in RotateComponent rc) => { rot.Value = math.mul(rot.Value, quaternion.RotateY(deltaTime * rc.Speed)); }) .ScheduleParallel(); } } }
勝手にnamespaceをつけたり、in修飾子に変えたりしましたがほぼチュートリアル通りです。
ScheduleParallel()なのでJobSystemを用いたマルチスレッドで動作しますが、対象のEntityが少ないと逆に時間がかかってしまうことがあるので注意です。

Assets
|-- GameSystems
| |-- GameSystems.asmdef
| |-- RotateComponent.cs
| |-- RotateSystem.cs
|-- Scenes
| |-- Main.scene
|-- Settings
|-- URPで用いる設定ファイル等
シーン作成
Main.sceneというシーンを新規作成し、Main CameraゲームオブジェクトにアタッチされているAudio Listenerを削除します。
Hierarchyから3D Object -> Cubeを選択してCubeを作成、位置を調整してあげます。

Cubeをクリックしてインスペクターから以下の操作をします。
Box Colliderを削除RotateComponentをアタッチし、Speedを0.2に設定UniversalRenderingPipline/LitなMaterialを設定
また後ろに壁を作成しました。(私の環境だとCameraのBackgroundが反映されなかったので暫定的に)
Box Colliderを削除- 大きさを調整
UniversalRenderingPipline/UnlitなMaterialを設定




サブシーンを作成する
次にScene上に存在するゲームオブジェクトを全て選択している状態で右クリックしNew Sub Scene -> From Selectionを選択し、サブシーンを作成します。

少しだけ補足すると、サブシーンは事前にGameObjectをEntityへと変換してくれる便利機能です。Conver to Entityをサブシーン内のゲームオブジェクトに事前に実行しているようなイメージです。
Assets
|-- GameSystems
| |-- GameSystems.asmdef
| |-- RotateComponent.cs
| |-- RotateSystem.cs
|-- Materials
| |-- Wall.mat
| |-- Cube.mat
|-- Scenes
| |-- Main.scene
| |-- SubScene.scene
|-- Settings
|-- URPで用いる設定ファイル等
buildconfiguration作成
Assetsフォルダ以下にBuildというフォルダを作成。
その中でCreate -> Build -> DOTS Runtime Build Configurationを選択して、buildconfigurationファイルを作成します。
またインスペクターより以下の設定をします。
SceneListにMain.sceneを設定Dots Runtime Build ProfileのTargetは自身の環境を設定Dots Runtime Root AssemblyにGameSystems.asmdefを設定Tiny Rendering Settingをアタッチ

Assets
|-- Build
| |-- DotsRuntimeBuildConfiguration.buildconfiguration
|-- GameSystems
| |-- GameSystems.asmdef
| |-- RotateComponent.cs
| |-- RotateSystem.cs
|-- Materials
| |-- Wall.mat
| |-- Cube.mat
|-- Scenes
| |-- Main.scene
| |-- SubScene.scene
|-- Settings
|-- URPで用いる設定ファイル等
動作確認をする
DotsRuntimeBuildConfiguration.buildconfigurationの右上のBuild and Runを選択すれば、ビルド・再生してくれます。

