private void RenderOuterComponent(Entity module, float opacity = 1.0f) { for (var x = 0; x < module.GetState <PhysicalState>().InternalWidth; x++) { for (var y = 0; y < module.GetState <PhysicalState>().InternalHeight; y++) { var grid = new GridCoordinate(x, y); var tile = SimplePool.Spawn(Tile); //SetOpacity(tile, opacity); tile.transform.parent = outerRendererRoot.transform; tile.transform.position = GridCoordinate.GridToPosition(grid); } } }
private GridCoordinate GetComponentCenter(Entity entity) { var coreComponent = entity.GetState <PhysicalState>(); var midpoint = new GridCoordinate( Mathf.RoundToInt(coreComponent.InternalWidth / 2.0f), Mathf.RoundToInt(coreComponent.InternalHeight / 2.0f) ); return(midpoint); }
public void RemoveEntityFromEntity(Entity entityToRemove) { ChildEntities.ForEach(entity => { if (Equals(entity, entityToRemove)) { childEntityLookup[entityToRemove.GetState <PhysicalState>().BottomLeftCoordinate].Remove(entityToRemove); ChildEntities.Remove(entityToRemove); } }); }
private void RenderInnerComponents(Entity entityToRender, float opacity = 1.0f) { for (var x = 0; x < entityToRender.GetState <PhysicalState>().InternalWidth; x++) { for (var y = 0; y < entityToRender.GetState <PhysicalState>().InternalHeight; y++) { var grid = new GridCoordinate(x, y); Profiler.BeginSample("Get entities at grid"); var innerEntities = entityToRender.GetState <PhysicalState>().GetEntitiesAtGrid(grid); Profiler.EndSample(); foreach (var innerEntity in innerEntities) { Profiler.BeginSample("Resources Loading"); var innerModuleAsset = Resources.Load <GameObject>(innerEntity.GetState <EntityTypeState>().EntityType); Profiler.EndSample(); if (innerModuleAsset == null) { UnityEngine.Debug.LogError(innerEntity.GetState <EntityTypeState>().EntityType); } var moduleGameObject = SimplePool.Spawn(innerModuleAsset); //SetOpacity(moduleGameObject, opacity); moduleGameObject.transform.parent = innerRendererRoot.transform; moduleGameObject.transform.position = GridCoordinate.GridToPosition(grid); var possibleRenderer = moduleGameObject.GetComponent <IEntityRenderer>(); if (possibleRenderer != null) { possibleRenderer.OnRenderEntity(innerEntity); } } } } }
public static bool AddEntityToEntity([NotNull] Entity entityToAdd, [NotNull] GridCoordinate locationToAddIt, [NotNull] Entity entityToAddItTo) { var physicalState = entityToAdd.GetState <PhysicalState>(); physicalState.ParentEntity = entityToAddItTo; physicalState.BottomLeftCoordinate = locationToAddIt; var targetEntityPhysicalState = entityToAddItTo.GetState <PhysicalState>(); var entitiesAtTargetLocation = targetEntityPhysicalState.GetEntitiesAtGrid(locationToAddIt).ToList(); if (!entitiesAtTargetLocation.Any() || entitiesAtTargetLocation.All(entity => !entity.GetState <PhysicalState>().IsTangible)) { targetEntityPhysicalState.ChildEntities.Add(entityToAdd); UpdateLocationLookup(entityToAdd, locationToAddIt, targetEntityPhysicalState); return(true); } return(false); }
public IEnumerable <Entity> GetNeighbouringEntities() { if (IsRoot()) { return(new List <Entity>()); } var parentGrid = ParentEntity.GetState <PhysicalState>(); var results = new List <Entity>(); foreach (Direction direction in Enum.GetValues(typeof(Direction))) { var neighbourGrid = GridOperations.GetGridInDirection(BottomLeftCoordinate, direction); var neighbour = parentGrid.GetEntitiesAtGrid(neighbourGrid); if (neighbour != null) { results.AddRange(neighbour); } } return(results); }