Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using HexagonSurvive.Map.Components;
- using HexagonSurvive.Map.Enums;
- using Unity.Entities;
- using Unity.Mathematics;
- using Unity.Transforms;
- namespace HexagonSurvive.Map.Aspects
- {
- public readonly partial struct HexUnitAspect : IAspect
- {
- public readonly Entity self;
- private readonly RefRW<LocalToWorld> _localToWorld;
- private readonly RefRW<PostTransformMatrix> _transformMatrix;
- private readonly RefRW<HexUnitData> _data;
- public HexUnitData Data => _data.ValueRO;
- public Entity NaturalEntity
- {
- get => _data.ValueRO.naturalEntity;
- set => _data.ValueRW.naturalEntity = value;
- }
- /// <summary>
- /// Only used in map generation
- /// </summary>
- public void AdjustData(int altitude, float height, bool walkable, Biome biome)
- {
- _data.ValueRW.altitude = altitude;
- _data.ValueRW.height = height;
- _data.ValueRW.walkable = walkable;
- _data.ValueRW.biome = biome;
- }
- public void Transform(float3 position, float3 rotation, float3 scale)
- {
- // _localToWorld.ValueRW.Value = float4x4.TRS(position, quaternion.Euler(rotation), scale);
- _localToWorld.ValueRW.Value = float4x4.Translate(position);
- _transformMatrix.ValueRW.Value = float4x4.Scale(scale);
- }
- }
- }
- ------------------------------------------------
- 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();
- }
- }
- }
- ------------------------------------
- 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