private void UpdateIconObjectsVisibility(Furniture furniture, FurnitureChildObjects statuses) { if (statuses.StatusIndicators != null && statuses.StatusIndicators.Count > 0) { // TODO: Cache the Enum.GetValues call? foreach (BuildableComponent.Requirements req in Enum.GetValues(typeof(BuildableComponent.Requirements)).Cast <BuildableComponent.Requirements>()) { if (req == BuildableComponent.Requirements.None) { continue; } GameObject go; if (statuses.StatusIndicators.TryGetValue(req, out go) == false) { continue; } if ((furniture.Requirements & req) == 0) { go.SetActive(false); } else { go.SetActive(true); } } } }
private void UpdateIconObjectsVisibility(Furniture furniture, FurnitureChildObjects statuses) { if (statuses.StatusIndicators != null && statuses.StatusIndicators.Count > 0) { foreach (BuildableComponent.Requirements req in Enum.GetValues(typeof(BuildableComponent.Requirements)).Cast <BuildableComponent.Requirements>() .Where(x => x != BuildableComponent.Requirements.None && statuses.StatusIndicators.ContainsKey(x))) { if ((furniture.Requirements & req) == 0) { statuses.StatusIndicators[req].SetActive(false); } else { statuses.StatusIndicators[req].SetActive(true); } } } }
protected override void OnCreated(Furniture furniture) { GameObject furn_go = new GameObject(); // Add our tile/GO pair to the dictionary. objectGameObjectMap.Add(furniture, furn_go); // FIXME: This hardcoding is not ideal! if (furniture.HasTypeTag("Door")) { // Check to see if we actually have a wall north/south, and if so // set the furniture verticalDoor flag to true. Tile northTile = world.GetTileAt(furniture.Tile.X, furniture.Tile.Y + 1, furniture.Tile.Z); Tile southTile = world.GetTileAt(furniture.Tile.X, furniture.Tile.Y - 1, furniture.Tile.Z); if (northTile != null && southTile != null && northTile.Furniture != null && southTile.Furniture != null && northTile.Furniture.HasTypeTag("Wall") && southTile.Furniture.HasTypeTag("Wall")) { furniture.VerticalDoor = true; } } SpriteRenderer sr = furn_go.AddComponent <SpriteRenderer>(); sr.sprite = GetSpriteForFurniture(furniture); sr.sortingLayerName = "Furniture"; sr.color = furniture.Tint; furn_go.name = furniture.Type + "_" + furniture.Tile.X + "_" + furniture.Tile.Y; furn_go.transform.position = furniture.Tile.Vector3 + ImageUtils.SpritePivotOffset(sr.sprite, furniture.Rotation); furn_go.transform.Rotate(0, 0, furniture.Rotation); furn_go.transform.SetParent(objectParent.transform, true); sr.sortingOrder = Mathf.RoundToInt(furn_go.transform.position.y * -1); FurnitureChildObjects childObjects = new FurnitureChildObjects(); childObjectMap.Add(furniture, childObjects); childObjects.Overlay = new GameObject(); childObjects.Overlay.transform.parent = furn_go.transform; childObjects.Overlay.transform.position = furn_go.transform.position; SpriteRenderer spriteRendererOverlay = childObjects.Overlay.AddComponent <SpriteRenderer>(); Sprite overlaySprite = GetOverlaySpriteForFurniture(furniture); if (overlaySprite != null) { spriteRendererOverlay.sprite = overlaySprite; spriteRendererOverlay.sortingLayerName = "Furniture"; spriteRendererOverlay.sortingOrder = Mathf.RoundToInt(furn_go.transform.position.y * -1) + 1; } // indicators (power, fluid, ...) BuildableComponent.Requirements furnReq = furniture.GetPossibleRequirements(); foreach (BuildableComponent.Requirements req in Enum.GetValues(typeof(BuildableComponent.Requirements))) { if (req != BuildableComponent.Requirements.None && (furnReq & req) == req) { GameObject indicator = new GameObject(); indicator.transform.parent = furn_go.transform; indicator.transform.localScale = new Vector3(IndicatorScale, IndicatorScale, IndicatorScale); indicator.transform.position = furn_go.transform.position + statusIndicatorOffsets[req]; SpriteRenderer powerSpriteRenderer = indicator.AddComponent <SpriteRenderer>(); powerSpriteRenderer.sprite = GetStatusIndicatorSprite(req); powerSpriteRenderer.sortingLayerName = "Power"; powerSpriteRenderer.color = Color.red; childObjects.AddStatus(req, indicator); } } UpdateIconObjectsVisibility(furniture, childObjects); if (furniture.Animations != null) { furniture.Animations.Renderer = sr; } // Register our callback so that our GameObject gets updated whenever // the object's into changes. furniture.Changed += OnChanged; furniture.Removed += OnRemoved; furniture.IsOperatingChanged += OnIsOperatingChanged; }