//For IJobParallelFor public void Execute(int i) { for (int j = i + 1; j < Colliders.Length; j++) { if (RTSPhysics.Intersect(Colliders[i], Colliders[j])) { Debug.Log("Collision Detected " + i + " with " + j); } } }
public void Execute(int i) { for (int j = i + 1; j < Colliders.Length; j++) { if (RTSPhysics.Intersect(Colliders[i], Colliders[j])) { Debug.Log("发生碰撞"); } } }
public void Execute(Entity entity, int index, [ReadOnly] ref PlayerInput input, [ReadOnly] ref AABB aabb) { if (input.LeftClick) { if (Selected.Exists(entity)) { CommandBuffer.RemoveComponent <PlayerUnitSelect>(entity); } // Add select component to unit if (RTSPhysics.Intersect(aabb, ray)) { CommandBuffer.AddComponent(entity, new PlayerUnitSelect()); } } }
public void Execute ([ReadOnly] ref PlayerInput pInput, ref UnitNavAgent navAgent, [ReadOnly] ref PlayerUnitSelect selected) { bool noIntersection = true; foreach (var c in Colliders) { if (RTSPhysics.Intersect(c, ray)) { noIntersection = false; } } if (pInput.RightClick && noIntersection) { navAgent.finalDestination = mousePos; navAgent.agentStatus = NavAgentStatus.Moving; } }
public void Execute (Entity entity, int i, [ReadOnly] ref PlayerInput input, [ReadOnly] ref AABB aabb) { if (input.LeftClick) { //If selected component exists on our unit, unselect before we recalc selected if (Selected.Exists(entity)) { commandBuffer.RemoveComponent <PlayerUnitSelect>(i, entity); commandBuffer.AddComponent(i, entity, new Deselecting()); } //Add select component to unit if (RTSPhysics.Intersect(aabb, ray)) { commandBuffer.AddComponent(i, entity, new PlayerUnitSelect()); commandBuffer.AddComponent(i, entity, new Selecting()); } } }
protected override void OnUpdate() { bool projectileSent = false; var mousePos = Input.mousePosition; Ray ray = Camera.main.ScreenPointToRay(mousePos); AABB closestC = new AABB(); using (var entity = selectedUnits.ToEntityArray(Allocator.TempJob)) using (var collider = entities.ToComponentDataArray <AABB>(Allocator.TempJob)) using (var closestHit = entities.ToEntityArray(Allocator.TempJob)) { foreach (var e in entity) { if (EntityManager.HasComponent <PlayerUnitSelect>(e)) { var pInput = EntityManager.GetComponentData <PlayerInput>(e); if (pInput.RightClick) { var aabb = EntityManager.GetComponentData <AABB>(e); bool Intersection = false; AABB b = new AABB(); foreach (var c in collider) { if (RTSPhysics.Intersect(c, ray)) { Intersection = true; b = c; } } if (Intersection) { float3 nearestT = b.position; closestC = b; projectileSent = true; float3 t = float3.zero; Ray r = new Ray(aabb.position, b.position - aabb.position); Debug.DrawRay(r.origin, r.direction, Color.yellow, 5); foreach (var c in collider) { if (!c.Equals(aabb)) { if (RTSPhysics.Intersect(c, r)) { t = c.position; if (RTSPhysics.Distance(aabb.position, t) < RTSPhysics.Distance(aabb.position, nearestT)) { nearestT = t; closestC = c; } } } } } } } } foreach (var e in closestHit) { if (closestC.Equals(EntityManager.GetComponentData <AABB>(e)) && projectileSent) { var hc = EntityManager.GetComponentData <HealthComponent>(e); hc.currentHealth--; EntityManager.SetComponentData <HealthComponent>(e, hc); } } } }