Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- {
- hexUnit = GetEntity(authoring.hexUnit, TransformUsageFlags.NonUniformScale),
- trees = builder.CreateBlobAssetReference<BlobArray<Entity>>(Allocator.Persistent),
- waterSurface = GetEntity(PrefabsContainer.Instance.waterSurface, TransformUsageFlags.Renderable)
- });
- builder.Dispose();
- }
- }
- }
- -------------------------------------
- [UpdateInGroup(typeof(InitializationSystemGroup))]
- public partial struct HexMapInitSystem : ISystem
- {
- ...
- // there's too much code in this class, so I picked the related code only
- private void InstantiateUnit(ref SystemState state, float2 pos)
- {
- Entity hexUnit = state.EntityManager.Instantiate(_prefabs.hexUnit);
- HexUnitAspect unitAspect = SystemAPI.GetAspect<HexUnitAspect>(hexUnit);
- float height = GetUnitHeight(pos);
- int altitude = StepAltitude(height);
- TerrainNoiseProperties settings = _map.Data.tnProp;
- float unitHeight = altitude * settings.stepHeight + settings.baseHeight;
- Biome biome = height > settings.seaLevel
- ? GetBiomeLand(unitAspect, pos, unitHeight)
- : GetBiomeWater(unitAspect, pos, unitHeight);
- unitAspect.AdjustData
- (
- altitude,
- unitHeight / 2,
- unitHeight > _map.Data.tnProp.seaLevel,
- biome
- );
- unitAspect.Transform
- (
- new float3(pos.x, unitHeight / 4, pos.y),
- float3.zero,
- new float3(1, unitHeight / 2, 1)
- );
- // GenerateVegetation(ref state, unitAspect);
- }
- ...
- }
- ------------------------------------
- using UnityEngine;
- namespace HexagonSurvive.Containers.ECS
- {
- public class EntityContainerMono : MonoBehaviour
- {
- public PrefabsContainer prefabs;
- public GameObject hexUnit;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement