Advertisement
443eb9

Untitled

Sep 9th, 2023 (edited)
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.77 KB | None | 0 0
  1. using HexagonSurvive.Map.Components;
  2. using HexagonSurvive.Map.Models;
  3. using Unity.Entities;
  4.  
  5. namespace HexagonSurvive.Map.Bakers
  6. {
  7.     public class HexMapBaker : Baker<HexMapMono>
  8.     {
  9.         public override void Bake(HexMapMono authoring)
  10.         {
  11.             Entity e = GetEntity(authoring, TransformUsageFlags.Renderable);
  12.             AddComponent(e, new HexMapRandom(authoring.seed));
  13.             AddComponent(e, new HexMapData
  14.             (
  15.                 authoring.seed,
  16.                 authoring.mapRadius,
  17.                 authoring.chunkRadius,
  18.                 authoring.terrainSettings,
  19.                 authoring.biomeSettings
  20.             ));
  21.         }
  22.     }
  23. }
  24.  
  25. ------------------------------------------------
  26.  
  27. using HexagonSurvive.Map.Components;
  28. using Lib;
  29. using Unity.Entities;
  30. using Unity.Mathematics;
  31. using Unity.Transforms;
  32.  
  33. namespace HexagonSurvive.Map.Aspects
  34. {
  35.     public readonly partial struct HexMapAspect : IAspect
  36.     {
  37.         public readonly Entity self;
  38.  
  39.         private readonly RefRW<LocalTransform> _transform;
  40.         private readonly RefRO<HexMapData> _data;
  41.         private readonly RefRW<HexMapRandom> _random;
  42.  
  43.         public float3 Position
  44.         {
  45.             get => _transform.ValueRO.Position;
  46.             set => _transform.ValueRW.Position = value;
  47.         }
  48.  
  49.         public HexMapData Data => _data.ValueRO;
  50.         public Random Random => _random.ValueRW.random;
  51.         public FastNoiseLite Noise => _random.ValueRO.noise;
  52.     }
  53. }
  54.  
  55. -------------------------------------------
  56.  
  57. using HexagonSurvive.Environment.Components;
  58. using HexagonSurvive.Map.Components;
  59. using Unity.Entities;
  60.  
  61. namespace HexagonSurvive.Containers.ECS
  62. {
  63.     public readonly partial struct EntityContainerAspect : IAspect
  64.     {
  65.         public readonly Entity self;
  66.  
  67.         private readonly RefRO<HexMapPrefabsData> _mapPrefabs;
  68.         private readonly RefRO<GlobalEnvironmentData> _envData;
  69.  
  70.         public HexMapPrefabsData MapPrefabs => _mapPrefabs.ValueRO;
  71.     }
  72. }
  73.  
  74. -----------------------------------------
  75.  
  76. using System.Collections.Generic;
  77. using HexagonSurvive.Environment.Components;
  78. using HexagonSurvive.Environment.Settings;
  79. using HexagonSurvive.Game.Managers;
  80. using HexagonSurvive.Map.Components;
  81. using Unity.Collections;
  82. using Unity.Entities;
  83. using UnityEngine;
  84.  
  85. namespace HexagonSurvive.Containers.ECS
  86. {
  87.     public class EntityContainerBaker : Baker<EntityContainerMono>
  88.     {
  89.         public override void Bake(EntityContainerMono authoring)
  90.         {
  91.             var builder = new BlobBuilder(Allocator.Temp);
  92.             ref BlobArray<Entity> trees = ref builder.ConstructRoot<BlobArray<Entity>>();
  93.             List<GameObject> treePrefabs = PrefabsContainer.Instance.treePrefabs;
  94.             BlobBuilderArray<Entity> arrayBuilder = builder.Allocate(ref trees, treePrefabs.Count);
  95.  
  96.             for (int i = 0; i < treePrefabs.Count; i++)
  97.                 arrayBuilder[i] = GetEntity(treePrefabs[i], TransformUsageFlags.Renderable);
  98.  
  99.             Entity e = GetEntity(authoring, TransformUsageFlags.None);
  100.             GlobalEnvironment gEnv = EnvironmentManager.Instance.globalEnvironment;
  101.             AddComponent(e, new GlobalEnvironmentData
  102.             {
  103.                 planeMeshRes = gEnv.planeMeshRes,
  104.                 planeMeshSize = gEnv.planeMeshSize
  105.             });
  106.             AddComponent(e, new HexMapPrefabsData
  107.             {
  108.                 hexChunk = GetEntity(PrefabsContainer.Instance.hexChunk, TransformUsageFlags.Renderable),
  109.                 hexUnit = GetEntity(PrefabsContainer.Instance.hexUnit, TransformUsageFlags.Renderable),
  110.                 trees = builder.CreateBlobAssetReference<BlobArray<Entity>>(Allocator.Persistent)
  111.             });
  112.             builder.Dispose();
  113.         }
  114.     }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement