Пример #1
0
        // Begin a new game.
        public static void 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);
            var settingsGO = GameObject.Find("Settings");

            Settings = settingsGO?.GetComponent <TwoStickSettings>();
            if (!Settings)
            {
                Debug.Log("Settings f****d up in NewGame");
            }
            Entity player = ZenEntityFactory.CreateLinkedEntity(Settings.PlayerPrefab, PlayerArchetype);

            // We can tweak a few components to make more sense like this.
            entityManager.SetComponentData(player, new Position2D {
                Value = new float2(0.0f, 0.0f)
            });
            entityManager.SetComponentData(player, new Heading2D  {
                Value = new float2(0.0f, 1.0f)
            });
            entityManager.SetComponentData(player, new Health {
                Value = Settings.playerInitialHealth
            });

            entityManager.AddSharedComponentData(player, PlayerPrefab);

            // Finally we add a shared component which dictates the rendered look
            //entityManager.AddSharedComponentData(player, PlayerLook);
        }
Пример #2
0
        public static void SetupComponentData(EntityManager entityManager)
        {
            var arch = entityManager.CreateArchetype(typeof(EnemySpawnCooldown), typeof(EnemySpawnSystemState));
            //var stateEntity = entityManager.CreateEntity(arch);
            var stateEntity = ZenEntityFactory.CreateLinkedEntity(TwoStickBootstrap.Settings.EnemyPrefab, arch);
            var oldState    = Random.state;

            Random.InitState(0xaf77);
            entityManager.SetComponentData(stateEntity, new EnemySpawnCooldown {
                Value = 0.0f
            });
            entityManager.SetComponentData(stateEntity, new EnemySpawnSystemState
            {
                SpawnedEnemyCount = 0,
                RandomState       = Random.state
            });
            Random.state = oldState;
        }