Categorii: Tot - unity - settings - manager

realizată de Mike Ton 6 ani în urmă

376

Unity_ECS_Pure

The provided code outlines the initialization and setup process for a Unity game using the Entity Component System (ECS) framework. The main function, NewGame, creates a player entity and sets various components such as health, rotation, and position.

Unity_ECS_Pure

Unity_ECS_Pure

TwoStickPure

TwoStickBootstrap.cs
(func)

public

static

void

NewGame() { ... }

entityManager.AddSharedComponentData(player, PlayerLook);

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

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

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

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

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

Entity player = entityManager.CreateEntity(PlayerArchetype);

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

// Access the ECS entity manager

InitializeWithScene(){ ... }

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

NewGame();

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

World.Active.GetOrCreateManager().SetupGameObjects();

EnemySpawnSystem.SetupComponentData(World.Active.GetOrCreateManager());

???

// Get from scene by string name

EnemyLook = GetLookFromPrototype("EnemyRenderPrototype");

EnemyShotLook = GetLookFromPrototype("EnemyShotRenderPrototype");

PlayerShotLook = GetLookFromPrototype("PlayerShotRenderPrototype");

PlayerLook = GetLookFromPrototype("PlayerRenderPrototype");

Settings = settingsGO?.GetComponent();

if (!Settings) { return; }

InitializeAfterSceneLoad()

InitializeWithScene();

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

return;

SceneManager.sceneLoaded += OnSceneLoaded;

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

[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]

Initialize()

{ ... }

// Create an archetype for basic enemies.

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

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

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

// Create player archetype

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

var entityManager = World.Active.GetOrCreateManager();

[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]

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

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

(var)