Skip to content

Instantly share code, notes, and snippets.

@Densyakun
Last active July 23, 2019 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Densyakun/d9899952ecbe5ad4509e50b600bdb352 to your computer and use it in GitHub Desktop.
Save Densyakun/d9899952ecbe5ad4509e50b600bdb352 to your computer and use it in GitHub Desktop.
using Unity.Entities;
using Unity.Rendering;
using Unity.Transforms;
public class Main : MonoBehaviour
{
private World _world;
void OnEnable()
{
_world = World.Active = new World("MyWorld");
_world.CreateManager<EntityManager>();
_world.CreateManager<EndFrameTransformSystem>();
_world.CreateManager<RenderingSystemBootstrap>();
ScriptBehaviourUpdateOrder.UpdatePlayerLoop(_world);
}
void OnDisable()
{
ScriptBehaviourUpdateOrder.UpdatePlayerLoop(null);
_world.Dispose();
}
}
@Densyakun
Copy link
Author

OnEnableでWorldを作成し、Worldに各種Systemを追加しています。
SystemはWorldが自動的に動作させます。

一例として、OnDisableでWorldを破棄しています。
最終的に使わなくなったWorldは、このようにして破棄してください。

また、現時点ではスクリプト再読込時に自動的にWorldが使えなくなってしまうため、
StartではなくOnEnableとOnDisableにしています。

@Densyakun
Copy link
Author

現在のバージョンではEndFrameTransformSystemがRenderingSystemBootstrapがない

@Densyakun
Copy link
Author

Unity Physicsパッケージを利用したConvert To Entityなどで、
Awake内でWorldやSystemが使用される場合は対応できない

@Densyakun
Copy link
Author

Densyakun commented Jul 23, 2019

Meshを描画するために、EndFrameTransformSystemとRenderingSystemBootstrapを追加しています。

以前はWorld.CreateManager<EndFrameBarrier>()World.CreateManager<RenderMeshSystem>().ActiveCamera = mainCameraが必要だったと思われますが、現在は不要のようです。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment