Unity_ECS_Pure

m

TwoStickPure

TwoStickBootstrap.cs

(var)

(func)

public

static

void

Initialize()

// This method creates archetypes for entities we will spawn frequently in this game.

// Archetypes are optional but can speed up entity spawning substantially.

[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]

{ ... }

var entityManager = World.Active.GetOrCreateManager<EntityManager>();

// Create player archetype

PlayerArchetype = entityManager.CreateArchetype( typeof(Position), typeof(Rotation), typeof(PlayerInput), typeof(Health));

// Create an archetype for "shot spawn request" entities

ShotSpawnArchetype = entityManager.CreateArchetype(typeof(ShotSpawnData));

// Create an archetype for basic enemies.

BasicEnemyArchetype = entityManager.CreateArchetype( typeof(Enemy), typeof(Health), typeof(EnemyShootState), typeof(Position), typeof(Rotation),typeof(MoveSpeed), typeof(MoveForward));

InitializeAfterSceneLoad()

[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]

{ ... }

var settingsGO = GameObject.Find("Settings");

if (settingsGO == null) { ... }

SceneManager.sceneLoaded += OnSceneLoaded;

return;

InitializeWithScene();

InitializeWithScene(){ ... }

var settingsGO = GameObject.Find("Settings");

if (settingsGO == null) { ... }

SceneManager.sceneLoaded += OnSceneLoaded;

return;

Settings = settingsGO?.GetComponent<TwoStickSettings>();

if (!Settings) { return; }

// Get from scene by string name

PlayerLook = GetLookFromPrototype("PlayerRenderPrototype");

PlayerShotLook = GetLookFromPrototype("PlayerShotRenderPrototype");

EnemyShotLook = GetLookFromPrototype("EnemyShotRenderPrototype");

EnemyLook = GetLookFromPrototype("EnemyRenderPrototype");

EnemySpawnSystem.SetupComponentData(World.Active.GetOrCreateManager<EntityManager>());

???

World.Active.GetOrCreateManager<UpdatePlayerHUD>().SetupGameObjects();

var sceneSwitcher = GameObject.Find("SceneSwitcher");

if (sceneSwitcher != null) { ... }

NewGame();

NewGame() { ... }

// Access the ECS entity manager

var entityManager = World.Active.GetOrCreateManager<EntityManager>();

// Create an entity based on the player archetype. It will get default-constructed
// defaults for all the component types we listed.

Entity player = entityManager.CreateEntity(PlayerArchetype);

// We can tweak a few components to make more sense like this.

entityManager.SetComponentData(player, new Position {Value = new float3(0.0f, 0.0f,0.0f)});

entityManager.SetComponentData(player, new Rotation {Value = quaternion.identity});

entityManager.SetComponentData(player, new Health { Value = Settings.playerInitialHealth });

// Finally we add a shared component which dictates the rendered look

entityManager.AddSharedComponentData(player, PlayerLook);

???