private void DisableSelectionReentrant(Entity entity) { BufferFromEntity <Child> cb = GetBufferFromEntity <Child>(); if (cb.HasComponent(entity)) { DynamicBuffer <Child> children = GetBuffer <Child>(entity); foreach (var c in children) { DisableFresnel(c.Value); DisableSelectionReentrant(c.Value); } } }
private void AddContentsToRoomList(NativeList <Entity> entities, BufferFromEntity <RoomContentReference> contentReferencesFromEntity) { Job.WithReadOnly(contentReferencesFromEntity).WithCode(() => { var roomEntities = entities.ToArray(Allocator.Temp); for (int i = 0; i < roomEntities.Length; i++) { var roomEntity = roomEntities[i]; var buffer = contentReferencesFromEntity[roomEntity]; AddEntitiesInContentReferences(entities, buffer); } roomEntities.Dispose(); }).Schedule(); }
protected static void AddCollisionEventsToDynamicBuffers(NativeList <StatefulCollisionEvent> collisionEventList, ref BufferFromEntity <StatefulCollisionEvent> bufferFromEntity, NativeHashMap <Entity, byte> entitiesWithCollisionEventBuffers) { for (int i = 0; i < collisionEventList.Length; i++) { var collisionEvent = collisionEventList[i]; if (entitiesWithCollisionEventBuffers.ContainsKey(collisionEvent.EntityA)) { bufferFromEntity[collisionEvent.EntityA].Add(collisionEvent); } if (entitiesWithCollisionEventBuffers.ContainsKey(collisionEvent.EntityB)) { bufferFromEntity[collisionEvent.EntityB].Add(collisionEvent); } } }
protected static void AddTriggerEventsToDynamicBuffers(NativeList <StatefulTriggerEvent> triggerEventList, ref BufferFromEntity <StatefulTriggerEvent> bufferFromEntity, NativeHashMap <Entity, byte> entitiesWithTriggerBuffers) { for (int i = 0; i < triggerEventList.Length; i++) { var triggerEvent = triggerEventList[i]; if (entitiesWithTriggerBuffers.ContainsKey(triggerEvent.EntityA)) { bufferFromEntity[triggerEvent.EntityA].Add(triggerEvent); } if (entitiesWithTriggerBuffers.ContainsKey(triggerEvent.EntityB)) { bufferFromEntity[triggerEvent.EntityB].Add(triggerEvent); } } }
public static void InvokeDeserialize <T>(BufferFromEntity <T> snapshotFromEntity, Entity entity, uint snapshot, uint baseline, uint baseline2, uint baseline3, DataStreamReader reader, ref DataStreamReader.Context ctx, NetworkCompressionModel compressionModel) where T : struct, ISnapshotData <T> { DynamicBuffer <T> snapshotArray = snapshotFromEntity[entity]; var baselineData = default(T); if (baseline != snapshot) { for (int i = 0; i < snapshotArray.Length; ++i) { if (snapshotArray[i].Tick == baseline) { baselineData = snapshotArray[i]; break; } } } if (baseline3 != snapshot) { var baselineData2 = default(T); var baselineData3 = default(T); for (int i = 0; i < snapshotArray.Length; ++i) { if (snapshotArray[i].Tick == baseline2) { baselineData2 = snapshotArray[i]; } if (snapshotArray[i].Tick == baseline3) { baselineData3 = snapshotArray[i]; } } baselineData.PredictDelta(snapshot, ref baselineData2, ref baselineData3); } var data = default(T); data.Deserialize(snapshot, ref baselineData, reader, ref ctx, compressionModel); // Replace the oldest snapshot and add a new one if (snapshotArray.Length == GhostSystemConstants.SnapshotHistorySize) { snapshotArray.RemoveAt(0); } snapshotArray.Add(data); }
protected override void OnUpdate() { BufferFromEntity <Waypoint> allWaypointBuffers = GetBufferFromEntity <Waypoint>(true); Entities .ForEach((ref BodyInput bodyInput, ref PathMovement pathMovement, ref Rotation rotation, in Translation translation) => { DynamicBuffer <float3> waypoints = allWaypointBuffers[pathMovement.Path].Reinterpret <float3>(); float3 nextPosition = waypoints[pathMovement.CurrentTargetWaypoint]; //check if the waypoint has been reached float distanceSq = math.lengthsq(translation.Value.xz - nextPosition.xz); if (distanceSq < .2f) { //waypoint reached if (pathMovement.CurrentTargetWaypoint == waypoints.Length - 1) { if (pathMovement.IsLooping) { pathMovement.CurrentTargetWaypoint = 0; } else { pathMovement.CurrentTargetWaypoint--; } } else { pathMovement.CurrentTargetWaypoint++; } nextPosition = waypoints[pathMovement.CurrentTargetWaypoint]; //instantly face next waypoint //TODO: slowly rotate to face the waypoint (not writing to Rotation, but passing the correct BodyInput.Movement.x value) float3 dir = math.normalize(nextPosition - translation.Value); rotation.Value = quaternion.LookRotation(dir, math.up()); bodyInput.Movement = new float2(0f, .5f); //slow down } else { bodyInput.Movement = new float2(0f, math.clamp(bodyInput.Movement.y + 0.05f, 0f, 1f)); //accelerate } }).Schedule(); }
private int GetLinkedEntitiesCount(BufferFromEntity <LinkedEntityGroup> linkedFE, NativeArray <Entity> roots) { int count = 0; for (int i = 0; i < roots.Length; i++) { if (linkedFE.HasComponent(roots[i])) { count += linkedFE[roots[i]].Length; } else { count++; } } return(count); }
/// <summary> /// Plays back the EnableCommandBuffer. /// </summary> /// <param name="entityManager">The EntityManager with which to play back the EnableCommandBuffer</param> /// <param name="linkedFEReadOnly">A ReadOnly accessor to the entities' LinkedEntityGroup</param> public void Playback(EntityManager entityManager, BufferFromEntity <LinkedEntityGroup> linkedFEReadOnly) { CheckDidNotPlayback(); bool ran = false; var entities = RunPrepInJob(linkedFEReadOnly, ref ran); if (ran) { entityManager.RemoveComponent <Disabled>(entities); entities.Dispose(); } else { entityManager.RemoveComponent <Disabled>(m_entityOperationCommandBuffer.GetLinkedEntities(linkedFEReadOnly, Allocator.Temp)); } m_playedBack.Value = true; }
protected static void AddTriggerEventsToDynamicBuffers(NativeList <StatefulTriggerEvent> nl_triggerEventList, ref BufferFromEntity <StatefulTriggerEvent> a_bufferFromEntity, NativeHashMap <Entity, byte> nhm_entitiesWithTriggerBuffers) { // Debug.Log ( "nhm: " + nl_triggerEventList.Length + " >> " + nhm_entitiesWithTriggerBuffers.Count () ) ; for (int i = 0; i < nl_triggerEventList.Length; i++) { var triggerEvent = nl_triggerEventList[i]; if (nhm_entitiesWithTriggerBuffers.ContainsKey(triggerEvent.EntityA)) { a_bufferFromEntity[triggerEvent.EntityA].Add(triggerEvent); } if (nhm_entitiesWithTriggerBuffers.ContainsKey(triggerEvent.EntityB)) { a_bufferFromEntity[triggerEvent.EntityB].Add(triggerEvent); } } }
public override void UpdateSystem() { EntityCommandBuffer.ParallelWriter ecb = m_endSimulationECB.CreateCommandBuffer().AsParallelWriter(); BufferFromEntity <Child> childLookup = GetBufferFromEntity <Child>(); Entities.WithReadOnly(childLookup).ForEach((Entity entity, int entityInQueryIndex, in Health health) => { if (health.health <= 0) { ecb.DestroyEntityWithChildren(entityInQueryIndex, entity, childLookup); Debug.Log("Entity " + entity + " has died!"); } }).ScheduleParallel(); m_endSimulationECB.AddJobHandleForProducer(Dependency); }
protected override void OnUpdate() { BufferFromEntity <WayPoint> buffers = GetBufferFromEntity <WayPoint>(); // used to access things with waypoint buffer Entities.ForEach((Entity crowdEntity, DynamicBuffer <PriorityElement> priBuffer) => { Entity wayPointHolder = priBuffer[0].WPHolder; // get the entity that holds the waypoints DynamicBuffer <WayPoint> wayPointBuffer = buffers[wayPointHolder]; // Get the waypoint buffer for (int i = 0; i < wayPointBuffer.Length; i++) { WayPoint wp = wayPointBuffer[i]; wp.value.x++; wayPointBuffer[i] = wp; //Do stuff with waypoints } }); }
/// <summary> /// Fills the native list with entities stored in the EntityOperationCommandBuffer sorted by SortKey and their LinkedEntityGroup entities if they have them. /// </summary> /// <param name="linkedFEReadOnly">A ReadOnly accessor to the Entities' LinkedEntityGroup</param> /// <param name="entities">The list to fill. The list will automatically be resized to fit the new entities.</param> /// <param name="append">If true, entities will be appended. If false, the list will be overwritten.</param> public void GetLinkedEntities(BufferFromEntity <LinkedEntityGroup> linkedFEReadOnly, ref NativeList <Entity> entities, bool append = false) { CheckReadAccess(); var roots = GetEntities(Allocator.Temp); int count = GetLinkedEntitiesCount(linkedFEReadOnly, roots); if (append) { int originalLength = entities.Length; entities.ResizeUninitialized(originalLength + count); var subArray = entities.AsArray().GetSubArray(originalLength, count); GetLinkedEntitiesFill(linkedFEReadOnly, roots, subArray); } else { entities.ResizeUninitialized(count); GetLinkedEntitiesFill(linkedFEReadOnly, roots, entities); } }
private void GetLinkedEntitiesFill(BufferFromEntity <LinkedEntityGroup> linkedFE, NativeArray <Entity> roots, NativeArray <Entity> entities) { int count = 0; for (int i = 0; i < roots.Length; i++) { if (linkedFE.HasComponent(roots[i])) { var currentGroup = linkedFE[roots[i]]; NativeArray <Entity> .Copy(currentGroup.AsNativeArray().Reinterpret <Entity>(), 0, entities, count, currentGroup.Length); count += currentGroup.Length; } else { entities[count] = roots[i]; count++; } } }
public static Entity FindActiveAction(BufferFromEntity <AbilityOwner.OwnedAbility> bufferFromEntity, Entity entity) { if (!bufferFromEntity.Exists(entity)) { return(Entity.Null); } var ownedAbilities = bufferFromEntity[entity]; for (int i = 0; i < ownedAbilities.Length; i++) { var ability = ownedAbilities[i]; if (ability.isAction && ability.isActive) { return(ability.entity); } } return(Entity.Null); }
public static Entity FindAbility(BufferFromEntity <AbilityOwner.OwnedAbility> bufferFromEntity, Entity entity, AbilityTagValue tagValue) { if (!bufferFromEntity.Exists(entity)) { return(Entity.Null); } var ownedAbilities = bufferFromEntity[entity]; for (int i = 0; i < ownedAbilities.Length; i++) { var ability = ownedAbilities[i]; if (ability.tagValue == tagValue) { return(ability.entity); } } return(Entity.Null); }
protected override void OnUpdate() { var ecbSync = m_EndSimulationEcbSystem.CreateCommandBuffer(); var ecb = m_EndSimulationEcbSystem.CreateCommandBuffer().AsParallelWriter(); BufferFromEntity <ChildBufferElement> buffersOfAllEntities = GetBufferFromEntity <ChildBufferElement>(false); var mapper = World.GetExistingSystem <SyncSendSystem>().Sender.Mapper; Entities .WithNone <ConnectedInitialized>() .ForEach((Entity entity, in ConnectedEntity connected) => { var val = connected.value; var parent = mapper.ToUnityEntity(val); if (HasComponent <Mapped>(parent)) { // checksb for parent existence DynamicBuffer <ChildBufferElement> bufferOfOneEntity; if (!buffersOfAllEntities.HasComponent(parent)) { bufferOfOneEntity = ecbSync.AddBuffer <ChildBufferElement>(parent); } else { bufferOfOneEntity = buffersOfAllEntities[parent]; } var index = bufferOfOneEntity.Add(new ChildBufferElement { Value = entity }); ecbSync.AddComponent(entity, new ConnectedInitialized { Index = index }); } }) .WithoutBurst() .Run(); m_EndSimulationEcbSystem.AddJobHandleForProducer(this.Dependency); }
protected override void OnUpdate() { float deltaTime = Time.DeltaTime; //Run the actual system only a few times a second if (timerToRunSystem > 0.3f) { //Each Enemy Entity Entities .WithAll <FollowPlayerTag>() .WithoutBurst() .ForEach((Entity entity, ref ActiveNodeIndexData nodeData, ref OJO_TargetPointData target) => { //load path that is calculated by NavMeshCalculation BufferFromEntity <Float3BufferElement> buffer = GetBufferFromEntity <Float3BufferElement>(); DynamicBuffer <Float3BufferElement> enemyBuffer = buffer[entity]; if (nodeData.nodeInPath > 0 && nodeData.nodeInPath < enemyBuffer.Length) { target.bufferLength = enemyBuffer.Length; target.targetPoint = enemyBuffer[nodeData.nodeInPath].Value; //as long as the buffer length is longer than the next desired point position in the buffer //the next position should be assigned if (target.bufferLength > nodeData.nodeInPath + 1) { target.nextTargetPoint = enemyBuffer[nodeData.nodeInPath + 1].Value; } else { target.nextTargetPoint = enemyBuffer[nodeData.nodeInPath].Value; } } }).Run(); timerToRunSystem = 0f; } else { timerToRunSystem += deltaTime; } }
protected override void OnUpdate() { Entities.WithAll <Tag_Bob>().ForEach((Entity bobEntity) => { // Cycle through all Entities with Tag_Bob component BufferFromEntity <IntBufferElement> intBufferFromEntity = GetBufferFromEntity <IntBufferElement>(); // used to access things with IntBufferElement Buffer Entity aliceEntity = Entity.Null; // Initially set Alice reference to Null // Find an Alice Entity Entities.WithAll <Tag_Alice>().ForEach((Entity aliceEntityTmp) => { aliceEntity = aliceEntityTmp; }); DynamicBuffer <IntBufferElement> aliceDynamicBuffer = intBufferFromEntity[aliceEntity]; // Get Alice's buffer using the BufferFromEntity and the Alice Entity reference for (int i = 0; i < aliceDynamicBuffer.Length; i++) //go through everything in the buffer and increment { IntBufferElement intBufferEle = aliceDynamicBuffer[i]; intBufferEle.Value++; aliceDynamicBuffer[i] = intBufferEle; } }); }
public static bool ExistsInHierarchy <T>( Entity entity, BufferFromEntity <Child> childrenFromEntity, ComponentDataFromEntity <T> componentFromEntity, bool includeRoot = false) where T : struct, IComponentData { if (includeRoot && componentFromEntity.HasComponent(entity)) { return(true); } var children = childrenFromEntity[entity]; for (var i = 0; i < children.Length; ++i) { if (ExistsInHierarchy(children[i].Value, childrenFromEntity, componentFromEntity, true)) { return(true); } } return(false); }
protected override void OnUpdate() { EntityQuery fetchWPQuery = GetEntityQuery(fetchWPQueryDec); // query the entities BufferFromEntity <WayPoint> buffers = GetBufferFromEntity <WayPoint>(); // used to access things with waypoint buffer ComponentDataFromEntity <FollowWayPointsStorage> storageComponents = GetComponentDataFromEntity <FollowWayPointsStorage>(); NativeArray <Entity> fetchWPEntityArray = fetchWPQuery.ToEntityArray(Allocator.TempJob);//get the array of entities NativeArray <FetchWayPoints> fetchWPArray = fetchWPQuery.ToComponentDataArray <FetchWayPoints>(Allocator.TempJob); FetchWPJob fetchJob = new FetchWPJob { // creates the "follow waypoints" job entityCommandBuffer = commandBufferSystem.CreateCommandBuffer(), entityArray = fetchWPEntityArray, fetchWayPointsArray = fetchWPArray, wpBuffers = buffers, storageComponents = storageComponents }; JobHandle jobHandle = IJobExtensions.Schedule(fetchJob, this.Dependency); commandBufferSystem.AddJobHandleForProducer(jobHandle); // tell the system to execute the command buffer after the job has been completed this.Dependency = jobHandle; }
protected override void OnCreate() { var entity = EntityManager.CreateEntity(); #region add-with-manager EntityManager.AddBuffer <MyBufferElement>(entity); #endregion #region add-with-archetype Entity e = EntityManager.CreateEntity(typeof(MyBufferElement)); #endregion #region reinterpret-snippet DynamicBuffer <int> intBuffer = EntityManager.GetBuffer <MyBufferElement>(entity).Reinterpret <int>(); #endregion #region access-manager DynamicBuffer <MyBufferElement> dynamicBuffer = EntityManager.GetBuffer <MyBufferElement>(entity); #endregion #region lookup-snippet BufferFromEntity <MyBufferElement> lookup = GetBufferFromEntity <MyBufferElement>(); var buffer = lookup[entity]; buffer.Add(17); buffer.RemoveAt(0); #endregion }
private static void ProcessOutput(ref ComponentDataFromEntity <BeltSegment> segments, ref BufferFromEntity <BeltItem> items, ref BeltItem sOutput1, Entity enext) { if (sOutput1.Type != ItemType.None) { var next = segments[enext]; if (next.DistanceToInsertAtStart == 0) // full { return; } if (sOutput1.Distance > 0) { sOutput1.Distance--; return; } if (BeltUpdateSystem.InsertInSegment(ref items, ref segments, sOutput1, enext)) { sOutput1.Type = ItemType.None; } } }
static void GetComponentDataFromChildren <T>(Entity entity, BufferFromEntity <Child> childrenFromEntity, ComponentDataFromEntity <T> componentFromEntity, NativeList <T> result, int depth) where T : struct, IComponentData { if (depth == -1) { return; } if (componentFromEntity.HasComponent(entity)) { result.Add(componentFromEntity[entity]); } if (!childrenFromEntity.HasComponent(entity)) { return; } var children = childrenFromEntity[entity]; for (var i = 0; i < children.Length; ++i) { GetComponentDataFromChildren(children[i].Value, childrenFromEntity, componentFromEntity, result, depth - 1); } }
protected override void OnCreateManager( ) { base.OnCreateManager( ); // Test bounds // Many bounds, to many octrees // Where each bounds has one entity target. // Results return, weather collision with an instance occured. // Toggle manually only one example systems at the time if (!(ExampleSelector.selector == Selector.IsBoundsCollidingSystem_Bounds2Octree)) { return; // Early exit } Debug.Log("Start Test Is Bounds Colliding Octree System"); // ***** Initialize Octree ***** // // Create new octree // See arguments details (names) of _CreateNewOctree and coresponding octree readme file. EntityCommandBuffer ecb = barrier.CreateCommandBuffer(); Entity newOctreeEntity = EntityManager.CreateEntity( ); AddNewOctreeSystem._CreateNewOctree(ecb, newOctreeEntity, 8, float3.zero, 1, 1, 1); EntityManager.AddComponent(newOctreeEntity, typeof(IsBoundsCollidingTag)); // Assign target bounds entity, to octree entity Entity octreeEntity = newOctreeEntity; // ***** Example Components To Add / Remove Instance ***** // // Example of adding and removing some instanceses, hence entity blocks. // Add int i_instances2AddCount = ExampleSelector.i_generateInstanceInOctreeCount; // Example of x octrees instances. // 100 NativeArray <Entity> a_instanceEntities = Common._CreateInstencesArray(EntityManager, i_instances2AddCount); // Request to add n instances. // User is responsible to ensure, that instances IDs are unique in the octrtree. EntityManager.AddBuffer <AddInstanceBufferElement> (octreeEntity); // Once system executed and instances were added, buffer will be deleted. BufferFromEntity <AddInstanceBufferElement> addInstanceBufferElement = GetBufferFromEntity <AddInstanceBufferElement> (); Common._RequesAddInstances(ecb, octreeEntity, addInstanceBufferElement, ref a_instanceEntities, i_instances2AddCount); // Remove EntityManager.AddBuffer <RemoveInstanceBufferElement> (octreeEntity); // Once system executed and instances were removed, component will be deleted. BufferFromEntity <RemoveInstanceBufferElement> removeInstanceBufferElement = GetBufferFromEntity <RemoveInstanceBufferElement> (); // Request to remove some instances // Se inside method, for details int i_instances2RemoveCount = ExampleSelector.i_deleteInstanceInOctreeCount = 53; // Example of x octrees instances / entities to delete. // 53 Common._RequestRemoveInstances(ecb, octreeEntity, removeInstanceBufferElement, ref a_instanceEntities, i_instances2RemoveCount); // Ensure example array is disposed. a_instanceEntities.Dispose(); // ***** Example Bounds Components For Collision Checks ***** // Debug.Log("Octree: create dummy boundary box, to test for collision."); float3 f3_blockCenter = new float3(10, 2, 10); // Only test Blocks.PublicMethods._AddBlockRequestViaCustomBufferWithEntity(ecb, EntityManager.CreateEntity(), f3_blockCenter, new float3(1, 1, 1) * 5); // Create test bounds // Many bounds, to many octrees // Where each bounds has one octree entity target. for (int i = 0; i < 10; i++) { ecb.CreateEntity( ); // Check bounds collision with octree and return colliding instances. ecb.AddComponent(new IsActiveTag()); ecb.AddComponent(new IsBoundsCollidingTag()); // This may be overritten by, other system. Check corresponding collision check system. ecb.AddComponent(new BoundsData() { bounds = new Bounds() { center = float3.zero, size = new float3(5, 5, 5) } }); // Check bounds collision with octree and return colliding instances. ecb.AddComponent(new OctreeEntityPair4CollisionData() { octree2CheckEntity = newOctreeEntity }); ecb.AddComponent(new IsCollidingData()); // Check bounds collision with octree and return colliding instances. // ecb.AddBuffer <CollisionInstancesBufferElement> () ; // Not required in this system } // for }
public BufferWithEntity(Entity entity, BufferFromEntity <T> bufferFromEntity) { this.Entity = entity; this.BufferFromEntity = bufferFromEntity; }
static int GetBufferValueByMethod(BufferFromEntity <EcsIntElement> bfe, Entity entity) { return(bfe[entity][0].Value); }
protected override unsafe void OnUpdate() { EntityQuery query = GetEntityQuery(ComponentType.ReadWrite <TrailBufferElement>()); NativeArray <Entity> entitis = query.ToEntityArray(Allocator.Persistent); int segmentCount = entitis.Length; int trailElementCount = 0; BufferFromEntity <TrailBufferElement> buffers = GetBufferFromEntity <TrailBufferElement>(); for (int i = 0; i < entitis.Length; ++i) { trailElementCount += buffers[entitis[i]].Length; } if (!m_TrailElements.IsCreated || m_TrailElements.Length < trailElementCount) { if (m_TrailElements.IsCreated) { m_TrailElements.Dispose(); } m_TrailElements = new NativeArray <float3>(CalcWrappingArraySize(trailElementCount), Allocator.Persistent); m_TrailElementBufferInShader?.Dispose(); m_TrailElementBufferInShader = new ComputeBuffer(m_TrailElements.Length, sizeof(TrailBufferElement)); } if (!m_Segments.IsCreated || m_Segments.Length < segmentCount) { if (m_Segments.IsCreated) { m_Segments.Dispose(); } m_Segments = new NativeArray <int3>(CalcWrappingArraySize(segmentCount), Allocator.Persistent); m_SegmentBufferInShader?.Dispose(); m_SegmentBufferInShader = new ComputeBuffer(m_Segments.Length, sizeof(TrailBufferElement)); } int offset = 0; float3 *trailElementsPtr = (float3 *)m_TrailElements.GetUnsafePtr(); int3 * segmentsPtr = (int3 *)m_Segments.GetUnsafePtr(); for (int i = 0; i < segmentCount; ++i) { DynamicBuffer <float3> trailbuffer = buffers[entitis[i]].Reinterpret <float3>(); Entity entity = entitis[i]; int bufferlength = trailbuffer.Length; UnsafeUtility.MemCpy(trailElementsPtr, trailbuffer.GetUnsafePtr(), sizeof(float3) * bufferlength); *segmentsPtr = new int3(offset, bufferlength, entity.Index); offset += bufferlength; segmentsPtr++; trailElementsPtr += bufferlength; for (int j = 0; j < trailbuffer.Length; ++j) { if (trailbuffer[j].x == 0.0f && trailbuffer[j].y == 0.0f && trailbuffer[j].z == 0.0f) { Debug.Log(entity.Index); } } } m_TrailElementBufferInShader.SetData(m_TrailElements); m_SegmentBufferInShader.SetData(m_Segments); m_MaterialPropertyBlock.SetBuffer("_Positions", m_TrailElementBufferInShader); m_MaterialPropertyBlock.SetBuffer("_Segments", m_SegmentBufferInShader); m_MeshInstancedArgs.SetData(m_TrailMesh, (uint)segmentCount); Graphics.DrawMeshInstancedIndirect( m_TrailMesh, 0, m_Material, new Bounds(Vector3.zero, Vector3.one * 1000), m_MeshInstancedArgs.m_Buffer, 0, m_MaterialPropertyBlock ); entitis.Dispose(); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { // EntityCommandBuffer ecb = barrier.CreateCommandBuffer () ; NativeArray <Entity> na_collisionChecksEntities = group.ToEntityArray(Allocator.TempJob); // ComponentDataFromEntity <OctreeEntityPair4CollisionData> a_octreeEntityPair4CollisionData = GetComponentDataFromEntity <OctreeEntityPair4CollisionData> () ; ComponentDataFromEntity <RayData> a_rayData = GetComponentDataFromEntity <RayData> (); ComponentDataFromEntity <RayMaxDistanceData> a_rayMaxDistanceData = GetComponentDataFromEntity <RayMaxDistanceData> (); ComponentDataFromEntity <IsCollidingData> a_isCollidingData = GetComponentDataFromEntity <IsCollidingData> (); BufferFromEntity <CollisionInstancesBufferElement> collisionInstancesBufferElement = GetBufferFromEntity <CollisionInstancesBufferElement> (); // Test ray // Debug // ! Ensure test this only with single, or at most few ray entiities. ComponentDataFromEntity <RayEntityPair4CollisionData> a_rayEntityPair4CollisionData = new ComponentDataFromEntity <RayEntityPair4CollisionData> (); // As empty. EntityCommandBuffer ecb = eiecb.CreateCommandBuffer(); GetCollidingRayInstances_Common._DebugRays(ref ecb, ref na_collisionChecksEntities, ref a_rayData, ref a_rayMaxDistanceData, ref a_isCollidingData, ref collisionInstancesBufferElement, ref a_rayEntityPair4CollisionData, false, false); na_collisionChecksEntities.Dispose(); eiecb.AddJobHandleForProducer(inputDeps); // Test ray Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); // Debug.DrawLine ( ray.origin, ray.origin + ray.direction * 100, Color.red ) ; int i_groupLength = group.CalculateEntityCount(); JobHandle setRayTestJobHandle = new SetRayTestJob { //a_collisionChecksEntities = na_collisionChecksEntities, ray = ray, // a_rayData = a_rayData, // a_rayMaxDistanceData = a_rayMaxDistanceData, }.Schedule(group, inputDeps); JobHandle jobHandle = new Job { //ecb = ecb, // a_collisionChecksEntities = na_collisionChecksEntities, // a_octreeEntityPair4CollisionData = a_octreeEntityPair4CollisionData, // a_rayData = a_rayData, // a_rayMaxDistanceData = a_rayMaxDistanceData, // a_isCollidingData = a_isCollidingData, // collisionInstancesBufferElement = collisionInstancesBufferElement, // Octree entity pair, for collision checks a_isActiveTag = GetComponentDataFromEntity <IsActiveTag> (true), a_octreeRootNodeData = GetComponentDataFromEntity <RootNodeData> (true), nodeBufferElement = GetBufferFromEntity <NodeBufferElement> (true), nodeInstancesIndexBufferElement = GetBufferFromEntity <NodeInstancesIndexBufferElement> (true), nodeChildrenBufferElement = GetBufferFromEntity <NodeChildrenBufferElement> (true), instanceBufferElement = GetBufferFromEntity <InstanceBufferElement> (true) }.Schedule(group, setRayTestJobHandle); return(jobHandle); }
void DestroyHierarchy(EntityCommandBuffer.Concurrent cmdBuffer, Entity entity, int index, BufferFromEntity <Child> childrenFromEntity) { cmdBuffer.DestroyEntity(index, entity); if (!childrenFromEntity.Exists(entity)) { return; } var children = childrenFromEntity[entity]; for (var i = 0; i < children.Length; ++i) { DestroyHierarchy(cmdBuffer, children[i].Value, index, childrenFromEntity); } }
protected override JobHandle OnUpdate(JobHandle inputDeps) { // EntityCommandBuffer ecb = barrier.CreateCommandBuffer () ; EntityArray a_collisionChecksEntities = group.GetEntityArray(); ComponentDataFromEntity <BoundsEntityPair4CollisionData> a_boundsEntityPair4CollisionData = GetComponentDataFromEntity <BoundsEntityPair4CollisionData> (); ComponentDataFromEntity <IsCollidingData> a_isCollidingData = GetComponentDataFromEntity <IsCollidingData> (); BufferFromEntity <CollisionInstancesBufferElement> collisionInstancesBufferElement = GetBufferFromEntity <CollisionInstancesBufferElement> (); ComponentDataFromEntity <RootNodeData> a_octreeRootNodeData = GetComponentDataFromEntity <RootNodeData> (); BufferFromEntity <NodeBufferElement> nodeBufferElement = GetBufferFromEntity <NodeBufferElement> (); BufferFromEntity <NodeInstancesIndexBufferElement> nodeInstancesIndexBufferElement = GetBufferFromEntity <NodeInstancesIndexBufferElement> (); BufferFromEntity <NodeChildrenBufferElement> nodeChildrenBufferElement = GetBufferFromEntity <NodeChildrenBufferElement> (); BufferFromEntity <InstanceBufferElement> instanceBufferElement = GetBufferFromEntity <InstanceBufferElement> (); // Ray entity pair, for collision checks ComponentDataFromEntity <IsActiveTag> a_isActiveTag = GetComponentDataFromEntity <IsActiveTag> (); ComponentDataFromEntity <BoundsData> a_boundsData = GetComponentDataFromEntity <BoundsData> (); // Test bounds // Debug // ! Ensure test this only with single, or at most few ray entiities. GetCollidingBoundsInstances_Common._DebugBounds(barrier.CreateCommandBuffer(), a_collisionChecksEntities, a_isCollidingData, collisionInstancesBufferElement, false); // Test bounds Bounds checkBounds = new Bounds() { center = new float3(10, 2, 10), size = new float3(1, 1, 1) * 5 // Total size of boundry }; int i_groupLength = group.CalculateLength(); var setBoundsTestJob = new SetBoundsTestJob { checkBounds = checkBounds, a_collisionChecksEntities = a_collisionChecksEntities, a_boundsEntityPair4CollisionData = a_boundsEntityPair4CollisionData, a_boundsData = a_boundsData, }.Schedule(i_groupLength, 8, inputDeps); var job = new Job { //ecb = ecb, a_collisionChecksEntities = a_collisionChecksEntities, a_boundsEntityPair4CollisionData = a_boundsEntityPair4CollisionData, a_isCollidingData = a_isCollidingData, collisionInstancesBufferElement = collisionInstancesBufferElement, a_octreeRootNodeData = a_octreeRootNodeData, nodeBufferElement = nodeBufferElement, nodeInstancesIndexBufferElement = nodeInstancesIndexBufferElement, nodeChildrenBufferElement = nodeChildrenBufferElement, instanceBufferElement = instanceBufferElement, // Ray entity pair, for collision checks a_isActiveTag = a_isActiveTag, a_boundsData = a_boundsData, }.Schedule(i_groupLength, 8, setBoundsTestJob); return(job); }