Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using HexagonSurvive.Map.Components;
- using HexagonSurvive.Map.Models;
- using Unity.Entities;
- namespace HexagonSurvive.Map.Bakers
- {
- public class HexMapBaker : Baker<HexMapMono>
- {
- public override void Bake(HexMapMono authoring)
- {
- Entity e = GetEntity(authoring, TransformUsageFlags.Renderable);
- AddComponent(e, new HexMapRandom(authoring.seed));
- AddComponent(e, new HexMapData
- (
- authoring.seed,
- authoring.mapRadius,
- authoring.chunkRadius,
- authoring.terrainSettings,
- authoring.biomeSettings
- ));
- }
- }
- }
- ------------------------------------------------
- using HexagonSurvive.Map.Components;
- using Lib;
- using Unity.Entities;
- using Unity.Mathematics;
- using Unity.Transforms;
- namespace HexagonSurvive.Map.Aspects
- {
- public readonly partial struct HexMapAspect : IAspect
- {
- public readonly Entity self;
- private readonly RefRW<LocalTransform> _transform;
- private readonly RefRO<HexMapData> _data;
- private readonly RefRW<HexMapRandom> _random;
- public float3 Position
- {
- get => _transform.ValueRO.Position;
- set => _transform.ValueRW.Position = value;
- }
- public HexMapData Data => _data.ValueRO;
- public Random Random => _random.ValueRW.random;
- public FastNoiseLite Noise => _random.ValueRO.noise;
- }
- }
- -------------------------------------------
- using HexagonSurvive.Environment.Components;
- using HexagonSurvive.Map.Components;
- using Unity.Entities;
- namespace HexagonSurvive.Containers.ECS
- {
- public readonly partial struct EntityContainerAspect : IAspect
- {
- public readonly Entity self;
- private readonly RefRO<HexMapPrefabsData> _mapPrefabs;
- private readonly RefRO<GlobalEnvironmentData> _envData;
- public HexMapPrefabsData MapPrefabs => _mapPrefabs.ValueRO;
- }
- }
- -----------------------------------------
- using System.Collections.Generic;
- using HexagonSurvive.Environment.Components;
- using HexagonSurvive.Environment.Settings;
- using HexagonSurvive.Game.Managers;
- using HexagonSurvive.Map.Components;
- using Unity.Collections;
- using Unity.Entities;
- using UnityEngine;
- namespace HexagonSurvive.Containers.ECS
- {
- public class EntityContainerBaker : Baker<EntityContainerMono>
- {
- public override void Bake(EntityContainerMono authoring)
- {
- var builder = new BlobBuilder(Allocator.Temp);
- ref BlobArray<Entity> trees = ref builder.ConstructRoot<BlobArray<Entity>>();
- List<GameObject> treePrefabs = PrefabsContainer.Instance.treePrefabs;
- BlobBuilderArray<Entity> arrayBuilder = builder.Allocate(ref trees, treePrefabs.Count);
- for (int i = 0; i < treePrefabs.Count; i++)
- arrayBuilder[i] = GetEntity(treePrefabs[i], TransformUsageFlags.Renderable);
- Entity e = GetEntity(authoring, TransformUsageFlags.None);
- GlobalEnvironment gEnv = EnvironmentManager.Instance.globalEnvironment;
- AddComponent(e, new GlobalEnvironmentData
- {
- planeMeshRes = gEnv.planeMeshRes,
- planeMeshSize = gEnv.planeMeshSize
- });
- AddComponent(e, new HexMapPrefabsData
- {
- hexChunk = GetEntity(PrefabsContainer.Instance.hexChunk, TransformUsageFlags.Renderable),
- hexUnit = GetEntity(PrefabsContainer.Instance.hexUnit, TransformUsageFlags.Renderable),
- trees = builder.CreateBlobAssetReference<BlobArray<Entity>>(Allocator.Persistent)
- });
- builder.Dispose();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement