private void makeBait() { Unity.Entities.EntityManager eM = World.DefaultGameObjectInjectionWorld.EntityManager; EntityArchetype bait = eM.CreateArchetype( typeof(Translation), typeof(RenderMesh), typeof(Scale), typeof(Rotation), typeof(RenderBounds), typeof(bait), typeof(LocalToWorld)); Entity entity = eM.CreateEntity(bait); eM.AddComponentData(entity, new Translation { Value = new float3(0, 0, 0) } ); eM.SetSharedComponentData(entity, new RenderMesh { mesh = baitMesh, material = baitMaterial } ); }
void Awake() { instance = this; float screenRatio = (float)Screen.width / (float)Screen.height; float targetRatio = ((float)GridWidth * CellSize) / ((float)GridHeight * CellSize); if (screenRatio >= targetRatio) { Camera.main.orthographicSize = ((float)GridHeight * CellSize) / 2; } else { float differenceInSize = targetRatio / screenRatio; Camera.main.orthographicSize = ((float)GridHeight * CellSize) / 2 * differenceInSize; } //Grab Entity Manager em = World.DefaultGameObjectInjectionWorld.EntityManager; //Cell ArchType CellArchtype = em.CreateArchetype( typeof(LocalToWorld), typeof(Translation), typeof(Rotation), typeof(NonUniformScale), typeof(CellComponent)); // Generate our grid CreateGrid(); }
private void makeEntity(int i) { Unity.Entities.EntityManager eM = World.DefaultGameObjectInjectionWorld.EntityManager; EntityArchetype boid = eM.CreateArchetype( typeof(Translation), typeof(RenderMesh), typeof(Scale), typeof(Rotation), typeof(RenderBounds), typeof(Flock_settings), typeof(LocalToWorld)); Entity entity = eM.CreateEntity(boid); eM.AddComponentData(entity, new Translation { Value = new float3(i % 24, (int)i / 4, 0) } ); eM.AddComponentData(entity, new Flock_settings { direction = new float3(0, 0, 0), flockHeading = new float3(0, 0, 0), flockCentre = new float3(0, 0, 0), separationHeading = new float3(0, 0, 0), velocity = new float3(0, 0, 0), index = i, numFlockmates = 0 } ); eM.SetSharedComponentData(entity, new RenderMesh { mesh = boidMesh, material = boidMaterial } ); eM.AddComponentData(entity, new Scale { Value = .1f } ); }
public override void OnEntityCreated(Context f, Lockstep.UnsafeECS.Entity *pEntity) { if (pEntity == null) { int i = 0; Debug.LogError("OnEntityCreated null"); return; } if (pEntity->TypeId != EntityIds.Boid) { //Debug.LogError("OnEntityCreated not a Enemy" + pEntity->EnumType()); return; } var pBoid = (Boid *)pEntity; if (_entityPrefabs == null) { //TODO read config to setup Entity Prefabs var _spawners = GameObject.FindObjectsOfType <SSSamples.Boids.Authoring.SpawnRandomInSphere>(); _entityManager = Unity.Entities.World.Active.EntityManager; _entityPrefabs = new Unity.Entities.Entity[_spawners.Length]; for (int i = 0; i < _spawners.Length; i++) { _entityPrefabs[i] = _spawners[i].PrefabEntity; } } var uEntity = _entityManager.Instantiate(_entityPrefabs[pBoid->AssetData.AssetId]); _id2GameObject[pEntity->LocalId] = uEntity; _entityManager.SetComponentData(uEntity, new Unity.Transforms.LocalToWorld { Value = float4x4.TRS( pBoid->LocalToWorld.Position.ToVector3(), //quaternion.identity, quaternion.LookRotationSafe(pBoid->LocalToWorld.Forward.ToVector3(), Unity.Mathematics.math.up()), new float3(1.0f, 1.0f, 1.0f)) }); _entityManager.AddComponentData(uEntity, pEntity->_ref); }
void FetchMesh() { Unity.Entities.EntityManager entityManager = space.EntityManager; ChunkSpawnSystem chunkSpawnSystem = space.GetOrCreateSystem <VoxelSystemGroup>().chunkSpawnSystem; foreach (KeyValuePair <int, Unity.Entities.Entity> KVP in chunkSpawnSystem.chunks) { Chunk chunk = entityManager.GetComponentData <Chunk>(KVP.Value); if (chunk.world == world) { if (chunk.chunkRenders.Length > 0) { mesh = entityManager.GetSharedComponentData <Unity.Rendering.RenderMesh>(chunk.chunkRenders[0]).mesh; } else { Debug.LogError("No chunk renders in chunk: " + chunk.Value.chunkPosition); } break; } } }
/// <summary> /// Moves all entities managed by the specified EntityManager to the <see cref="World"/> of this EntityManager and fills /// an array with their <see cref="Entity"/> objects. /// </summary> /// <remarks> /// After the move, the entities are managed by this EntityManager. Use the `output` array to make post-move /// changes to the transferred entities. /// /// Each world has one EntityManager, which manages all the entities in that world. This function /// allows you to transfer entities from one World to another. /// /// **Important:** This function creates a sync point, which means that the EntityManager waits for all /// currently running Jobs to complete before moving the entities and no additional Jobs can start before /// the function is finished. A sync point can cause a drop in performance because the ECS framework may not /// be able to make use of the processing power of all available cores. /// </remarks> /// <param name="output">An array to receive the Entity objects of the transferred entities.</param> /// <param name="srcEntities">The EntityManager whose entities are appropriated.</param> /// <param name="entityRemapping">A set of entity transformations to make during the transfer.</param> /// <exception cref="ArgumentException"></exception> public void MoveEntitiesFrom(out NativeArray <Entity> output, EntityManager srcEntities, NativeArray <EntityRemapUtility.EntityRemapInfo> entityRemapping) { MoveEntitiesFromInternalAll(srcEntities, entityRemapping); EntityRemapUtility.GetTargets(out output, entityRemapping); }
// ---------------------------------------------------------------------------------------------------------- // PUBLIC // ---------------------------------------------------------------------------------------------------------- /// <summary> /// Moves all entities managed by the specified EntityManager to the world of this EntityManager. /// </summary> /// <remarks> /// The entities moved are owned by this EntityManager. /// /// Each <see cref="World"/> has one EntityManager, which manages all the entities in that world. This function /// allows you to transfer entities from one World to another. /// /// **Important:** This function creates a sync point, which means that the EntityManager waits for all /// currently running Jobs to complete before moving the entities and no additional Jobs can start before /// the function is finished. A sync point can cause a drop in performance because the ECS framework may not /// be able to make use of the processing power of all available cores. /// </remarks> /// <param name="srcEntities">The EntityManager whose entities are appropriated.</param> public void MoveEntitiesFrom(EntityManager srcEntities) { using (var entityRemapping = srcEntities.CreateEntityRemapArray(Allocator.TempJob)) MoveEntitiesFromInternalAll(srcEntities, entityRemapping); }
public void Convert(Unity.Entities.Entity entity, Unity.Entities.EntityManager dstManager, GameObjectConversionSystem conversionSystem) { dstManager.AddComponentData(entity, new LogoSpawner { PrefabEntity = conversionSystem.GetPrimaryEntity(PrefabEntity), InstanceCount = InstanceCount }); }
public override void DoAwake(IServiceContainer services) { ViewConfig = Resources.Load <GameViewConfig>(GameViewConfig.ResPath); _entityManager = Unity.Entities.World.All[0].EntityManager; //.GetOrCreateManager<EntityManager>(); }
// Use this for initialization void Start() { manager = Unity.Entities.World.Active.GetOrCreateManager <Unity.Entities.EntityManager>(); AddCube(amount); }
/// <summary> /// Sets the value of a component of an entity. /// </summary> /// <param name="entity">The entity.</param> /// <param name="componentData">The data to set.</param> /// <typeparam name="T">The component type.</typeparam> /// <exception cref="ArgumentException">Thrown if the component type has no fields.</exception> public static void SetComponentData <T>(this EntityManager manager, Entity entity, T componentData) where T : class, IComponentData { var type = ComponentType.ReadWrite <T>(); manager.SetComponentObject(entity, type, componentData); }
public void Convert(Unity.Entities.Entity entity, Unity.Entities.EntityManager dstManager, GameObjectConversionSystem conversionSystem) { dstManager.AddComponentData(entity, new CubeRotationComponent { speed = speed }); }
public void Convert(Unity.Entities.Entity entity, Unity.Entities.EntityManager dstManager, GameObjectConversionSystem conversionSystem) { dstManager.AddComponentData(entity, new RotatorVS { Speed = Speed }); }
public void Convert(Unity.Entities.Entity entity, Unity.Entities.EntityManager dstManager, GameObjectConversionSystem conversionSystem) { dstManager.AddComponentData(entity, new TimedSelfDestruct { Duration = Duration, TimeStarted = TimeStarted }); }
public ArchetypeChunkComponentObjects <T> GetComponentObjects <T>(ArchetypeChunkComponentType <T> componentType, EntityManager manager) where T : class { #if ENABLE_UNITY_COLLECTIONS_CHECKS AtomicSafetyHandle.CheckReadAndThrow(componentType.m_Safety); #endif var archetype = m_Chunk->Archetype; var typeIndexInArchetype = ChunkDataUtility.GetIndexInTypeArray(archetype, componentType.m_TypeIndex); int offset, length; var array = manager.ManagedComponentStore.GetManagedObjectRange(m_Chunk, typeIndexInArchetype, out offset, out length); var componentArray = new ArchetypeChunkComponentObjects <T>(offset, length, array); return(componentArray); }
public T GetSharedComponentData <T>(ArchetypeChunkSharedComponentType <T> chunkSharedComponentData, EntityManager entityManager) where T : struct, ISharedComponentData { return(entityManager.GetSharedComponentData <T>(GetSharedComponentIndex(chunkSharedComponentData))); }
public EntityManagerDebug(EntityManager entityManager) { m_Manager = entityManager; }
public void Convert(Unity.Entities.Entity entity, Unity.Entities.EntityManager dstManager, GameObjectConversionSystem conversionSystem) { dstManager.AddComponentData(entity, new CurrentTurnActorTag { }); }
public void Convert(Unity.Entities.Entity entity, Unity.Entities.EntityManager dstManager, GameObjectConversionSystem conversionSystem) { dstManager.AddSharedComponentData(entity, new PlayerViewPrefab { Prefab = conversionSystem.GetPrimaryEntity(Prefab) }); }
public void Convert(Unity.Entities.Entity entity, Unity.Entities.EntityManager dstManager, GameObjectConversionSystem conversionSystem) { dstManager.AddComponentData(entity, new CameraControllerVS { Player = conversionSystem.GetPrimaryEntity(Player) }); }
public void Convert(Unity.Entities.Entity entity, Unity.Entities.EntityManager dstManager, GameObjectConversionSystem conversionSystem) { dstManager.AddComponentData(entity, new PlayerViewTag { }); }
/// <summary> /// Gets the value of a component for an entity. /// </summary> /// <param name="entity">The entity.</param> /// <typeparam name="T">The type of component to retrieve.</typeparam> /// <returns>A struct of type T containing the component value.</returns> /// <exception cref="ArgumentException">Thrown if the component type has no fields.</exception> public static T GetComponentData <T>(this EntityManager manager, Entity entity) where T : class, IComponentData { var ecs = manager.GetCheckedEntityDataAccess(); return(ecs->GetComponentData <T>(entity, ecs->ManagedComponentStore)); }
public void Convert(Unity.Entities.Entity entity, Unity.Entities.EntityManager dstManager, GameObjectConversionSystem conversionSystem) { dstManager.AddComponentData(entity, new PaddleInputData { inputName = inputName }); }
/// <summary> /// Moves all entities managed by the specified EntityManager to the <see cref="World"/> of this EntityManager. /// </summary> /// <remarks> /// After the move, the entities are managed by this EntityManager. /// /// Each World has one EntityManager, which manages all the entities in that world. This function /// allows you to transfer entities from one world to another. /// /// **Important:** This function creates a sync point, which means that the EntityManager waits for all /// currently running Jobs to complete before moving the entities and no additional Jobs can start before /// the function is finished. A sync point can cause a drop in performance because the ECS framework may not /// be able to make use of the processing power of all available cores. /// </remarks> /// <param name="srcEntities">The EntityManager whose entities are appropriated.</param> /// <param name="entityRemapping">A set of entity transformations to make during the transfer.</param> /// <exception cref="ArgumentException">Thrown if you attempt to transfer entities to the EntityManager /// that already owns them.</exception> public void MoveEntitiesFrom(EntityManager srcEntities, NativeArray <EntityRemapUtility.EntityRemapInfo> entityRemapping) { MoveEntitiesFromInternalAll(srcEntities, entityRemapping); }
public void Convert(Unity.Entities.Entity entity, Unity.Entities.EntityManager dstManager, GameObjectConversionSystem conversionSystem) { dstManager.AddComponentData(entity, new PlayerReadyStateComponent { IsReady = IsReady }); }
/// <summary> /// Moves a selection of the entities managed by the specified EntityManager to the <see cref="World"/> of this EntityManager /// and fills an array with their <see cref="Entity"/> objects. /// </summary> /// <remarks> /// After the move, the entities are managed by this EntityManager. Use the `output` array to make post-move /// changes to the transferred entities. /// /// Each world has one EntityManager, which manages all the entities in that world. This function /// allows you to transfer entities from one World to another. /// /// **Important:** This function creates a sync point, which means that the EntityManager waits for all /// currently running Jobs to complete before moving the entities and no additional Jobs can start before /// the function is finished. A sync point can cause a drop in performance because the ECS framework may not /// be able to make use of the processing power of all available cores. /// </remarks> /// <param name="srcEntities">The EntityManager whose entities are appropriated.</param> /// <param name="filter">A EntityQuery that defines the entities to move. Must be part of the source /// World.</param> /// <exception cref="ArgumentException"></exception> public void MoveEntitiesFrom(EntityManager srcEntities, EntityQuery filter) { using (var entityRemapping = srcEntities.CreateEntityRemapArray(Allocator.TempJob)) MoveEntitiesFromInternalQuery(srcEntities, filter, entityRemapping); }
public void Convert(Unity.Entities.Entity entity, Unity.Entities.EntityManager dstManager, GameObjectConversionSystem conversionSystem) { dstManager.AddComponentData(entity, new SetBulletVelocity { TargetEntity = TargetEntity, TargetPosition = TargetPosition }); }
/// <summary> /// Moves a selection of the entities managed by the specified EntityManager to the <see cref="World"/> of this EntityManager. /// </summary> /// <remarks> /// After the move, the entities are managed by this EntityManager. /// /// Each world has one EntityManager, which manages all the entities in that world. This function /// allows you to transfer entities from one World to another. /// /// **Important:** This function creates a sync point, which means that the EntityManager waits for all /// currently running Jobs to complete before moving the entities and no additional Jobs can start before /// the function is finished. A sync point can cause a drop in performance because the ECS framework may not /// be able to make use of the processing power of all available cores. /// </remarks> /// <param name="srcEntities">The EntityManager whose entities are appropriated.</param> /// <param name="filter">A EntityQuery that defines the entities to move. Must be part of the source /// World.</param> /// <param name="entityRemapping">A set of entity transformations to make during the transfer.</param> /// <exception cref="ArgumentException">Thrown if the EntityQuery object used as the `filter` comes /// from a different world than the `srcEntities` EntityManager.</exception> public void MoveEntitiesFrom(EntityManager srcEntities, EntityQuery filter, NativeArray <EntityRemapUtility.EntityRemapInfo> entityRemapping) { MoveEntitiesFromInternalQuery(srcEntities, filter, entityRemapping); }
public void Convert(Unity.Entities.Entity entity, Unity.Entities.EntityManager dstManager, GameObjectConversionSystem conversionSystem) { dstManager.AddComponentData(entity, new LogoPosition { Value = Value }); }
static void ApplyBlobAssetChanges( EntityManager entityManager, NativeArray <EntityGuid> packedEntityGuids, NativeMultiHashMap <int, Entity> packedEntities, NativeArray <ComponentType> packedTypes, NativeArray <BlobAssetChange> createdBlobAssets, NativeArray <byte> createdBlobAssetData, NativeArray <ulong> destroyedBlobAssets, NativeArray <BlobAssetReferenceChange> blobAssetReferenceChanges) { if (createdBlobAssets.Length == 0 && blobAssetReferenceChanges.Length == 0) { return; } var patcherBlobAssetSystem = entityManager.World.GetOrCreateSystem <EntityPatcherBlobAssetSystem>(); var blobAssetDataPtr = (byte *)createdBlobAssetData.GetUnsafePtr(); for (var i = 0; i < createdBlobAssets.Length; i++) { if (!patcherBlobAssetSystem.TryGetBlobAsset(createdBlobAssets[i].Hash, out _)) { patcherBlobAssetSystem.AllocateBlobAsset(blobAssetDataPtr, createdBlobAssets[i].Length, createdBlobAssets[i].Hash); } blobAssetDataPtr += createdBlobAssets[i].Length; } for (var i = 0; i < destroyedBlobAssets.Length; i++) { patcherBlobAssetSystem.ReleaseBlobAsset(entityManager, destroyedBlobAssets[i]); } for (var i = 0; i < blobAssetReferenceChanges.Length; i++) { var packedComponent = blobAssetReferenceChanges[i].Component; var component = packedTypes[packedComponent.PackedTypeIndex]; var targetOffset = blobAssetReferenceChanges[i].Offset; BlobAssetReferenceData targetBlobAssetReferenceData; if (patcherBlobAssetSystem.TryGetBlobAsset(blobAssetReferenceChanges[i].Value, out var blobAssetPtr)) { targetBlobAssetReferenceData = new BlobAssetReferenceData { m_Ptr = (byte *)blobAssetPtr.Data }; } if (packedEntities.TryGetFirstValue(packedComponent.PackedEntityIndex, out var entity, out var iterator)) { do { if (!entityManager.Exists(entity)) { Debug.LogWarning($"ApplyBlobAssetReferencePatches<{component}>({packedEntityGuids[packedComponent.PackedEntityIndex]}) but entity to patch does not exist."); } else if (!entityManager.HasComponent(entity, component)) { Debug.LogWarning($"ApplyBlobAssetReferencePatches<{component}>({packedEntityGuids[packedComponent.PackedEntityIndex]}) but component in entity to patch does not exist."); } else { if (component.IsBuffer) { var pointer = (byte *)entityManager.GetBufferRawRW(entity, component.TypeIndex); UnsafeUtility.MemCpy(pointer + targetOffset, &targetBlobAssetReferenceData, sizeof(BlobAssetReferenceData)); } #if !NET_DOTS else if (component.IsManagedComponent) { var obj = entityManager.GetComponentObject <object>(entity, component); var pointer = (byte *)UnsafeUtility.PinGCObjectAndGetAddress(obj, out ulong handle); pointer += TypeManager.ObjectOffset; UnsafeUtility.MemCpy(pointer + targetOffset, &targetBlobAssetReferenceData, sizeof(BlobAssetReferenceData)); UnsafeUtility.ReleaseGCObject(handle); } #endif else { var pointer = (byte *)entityManager.GetComponentDataRawRW(entity, component.TypeIndex); UnsafeUtility.MemCpy(pointer + targetOffset, &targetBlobAssetReferenceData, sizeof(BlobAssetReferenceData)); } } }while (packedEntities.TryGetNextValue(out entity, ref iterator)); } } // Workaround to catch some special cases where the memory is never released. (e.g. reloading a scene, toggling live-link on/off). patcherBlobAssetSystem.ReleaseUnusedBlobAssets(); }