private void CreateBarrier(MapColliderInfo colliderMap, MapTerrainInfo terrainMap, int x, int y) { if (MapColliderUtils.UnReachable(colliderMap, x, y)) { return; } for (int y2 = -1 + y; y2 < (1 + y); y2++) { for (int x2 = -1 + x; x2 < (1 + x); x2++) { MapColliderUtils.AddCost(colliderMap, x2, y2, 3); } } MapColliderUtils.SetCostValue(colliderMap, x, y, 255); // Instantiate a barrier on (x, y) var barrierRenderer = EntityPrefabContainer.BarrierRenderer; var drawPos = barrierRenderer.GetComponent <Position2DComponent> ().Value.Offset; drawPos += new float2(x, y); var heading = barrierRenderer.GetComponent <Heading2DComponent> ().Value.Value; PostUpdateCommands.CreateEntity(EntityPrefabContainer.BarrierArchetype); PostUpdateCommands.SetComponent(new Position2D() { Value = new float2(x, y), Offset = drawPos - new float2(x, y) }); PostUpdateCommands.SetComponent(new Heading2D() { Value = heading }); PostUpdateCommands.SetComponent(new TransformMatrix { Value = MathUtils.GetTransformMatrix(drawPos, heading) }); PostUpdateCommands.SetComponent( barrierRenderer.GetComponent <BarrierComponent> ().Value ); PostUpdateCommands.SetSharedComponent( barrierRenderer.GetComponent <TerrainRendererComponent> ().Value ); var barrierColPos = new Vector3(x, 0, y); var barrierCol = Object.Instantiate(EntityPrefabContainer.BarrierColliderPrefab, barrierColPos, Quaternion.identity); terrainMap.Terrains[x, y] |= TerrainType.Barrier; MapTerrainUtils.AddCollider(terrainMap, barrierCol); }
public static GameObject GetCollider(MapTerrainInfo map, float2 pos) { int hash = Hash(pos); List <GameObject> colliders; map.BarrierColliders.TryGetValue(hash, out colliders); if (colliders != null && colliders.Count > 0) { return(colliders[0]); } return(null); }
public static void AddCollider(MapTerrainInfo map, GameObject collider) { int hash = Hash(new float2(collider.transform.position.x, collider.transform.position.z)); List <GameObject> colliders; map.BarrierColliders.TryGetValue(hash, out colliders); if (colliders == null) { colliders = new List <GameObject> (1); colliders.Add(collider); map.BarrierColliders[hash] = colliders; } else if (!colliders.Contains(collider)) { colliders.Add(collider); map.BarrierColliders[hash] = colliders; } }
public static void RemoveColliders(MapTerrainInfo map, float2 pos, bool destroy = false) { int hash = Hash(pos); List <GameObject> colliders; map.BarrierColliders.TryGetValue(hash, out colliders); if (colliders != null) { map.BarrierColliders.Remove(hash); if (colliders.Count > 0 && destroy) { foreach (var collider in colliders) { if (collider != null) { Object.Destroy(collider); } } } } }