public void CreateEnvironment() { foreach (HexTile tile in HexGrid.Instance) { TileVisual tv = Instantiate(tileVisual, tile.worldPos, Quaternion.identity).GetComponent <TileVisual>(); tv.SetTile(tile); tv.transform.parent = this.transform; MeshRenderer rend = tv.GetComponent <MeshRenderer>(); rend.material = GetMaterial(tile.type); GameObject randomPrefab = null; switch (tile.type) { case TileType.Wood: randomPrefab = woodResourcePrefabs[Random.Range(0, woodResourcePrefabs.Count)]; break; case TileType.Stone: randomPrefab = stoneResourcePrefabs[Random.Range(0, stoneResourcePrefabs.Count)]; break; case TileType.Blocked: randomPrefab = blockedTile; break; } if (randomPrefab != null) { GameObject go = Instantiate(randomPrefab, tv.transform, false) as GameObject; IInteractable interactable = go.GetComponent <IInteractable>(); if (interactable != null && interactable is ResourceInteractable) { interactable.OnCompleted += tv.InteractableClearTile; } } } }
public static void UpdateBatteryTile(int?percentage) { if (!SecondaryTile.Exists(BatteryTileId)) { return; } var deviceId = SettingsHelper.GetValue(Constants.LastSavedDeviceIdSettingKey, string.Empty); var deviceName = SettingsHelper.GetValue(Constants.LastSavedDeviceNameSettingKey, string.Empty); var tileVisual = new TileVisual { Branding = TileBranding.NameAndLogo, TileMedium = CreateMediumTileBinding(percentage ?? 0, deviceName), TileWide = CreateWideTileBinding(percentage ?? 0, deviceName), TileLarge = CreateLargeTileBinding(percentage ?? 0, deviceName) }; var tileContent = new TileContent { Visual = tileVisual }; var tileNotification = new TileNotification(tileContent.GetXml()); TileUpdateManager.CreateTileUpdaterForSecondaryTile(BatteryTileId).Update(tileNotification); }
private TileContent GenerateTileContent(int mode, int s) { TileVisual visual = new TileVisual(); //MEDIUM TILE WILL SWITCH BETWEEN CANDIDATES USING A NOTIFICATION QUEUE if (s % 2 == 0) { visual.TileMedium = GenerateTileBindingMediumImage(mode); } else { visual.TileMedium = GenerateTileBindingMedium(mode); } if (mode == 1) { //WIDE AND LARGE TILES DO NOT NEED A NOTIFICATION QUEUE TO DISPLAY BOTH CANDIDATES visual.TileWide = GenerateTileBindingWide(); visual.TileLarge = GenerateTileBindingLarge(); //SADLY, SMALL TILES DO NOT SUPPORT A NOTIFICATION QUEUE visual.TileSmall = GenerateTileBindingSmall(); } return(new TileContent() { Visual = visual }); }
void SwapTiles(TileVisual a, TileVisual b) { Vector2Int tmp = a.position; a.position = b.position; b.position = tmp; }
public string CreateAdaptiveTile(string prefix, string leftTitle, string leftValue, string rightTitle, string rightValuevalue, string dateTitle, string dateContent) { // Create a TileBinding for Large and Wide var bigTilebinding = new TileBinding(); bigTilebinding.Content = CreateTileContent(prefix, leftTitle, leftValue, rightTitle, rightValuevalue, dateTitle, dateContent); var mediumTileBinding = new TileBinding(); mediumTileBinding.Content = CreateTileContent(string.Empty, leftTitle, leftValue, rightTitle, rightValuevalue, string.Empty, dateContent); //Create visual object var tileVisual = new TileVisual(); tileVisual.TileLarge = tileVisual.TileWide = bigTilebinding; tileVisual.TileMedium = mediumTileBinding; //Create tile object var tileObject = new TileContent(); tileObject.Visual = tileVisual; return(tileObject.GetContent()); }
public void SwapTiles(TileVisual a, TileVisual b) { GameObject tmp = grid[a.position.x, a.position.y]; grid[a.position.x, a.position.y] = grid[b.position.x, b.position.y]; grid[b.position.x, b.position.y] = tmp; }
private TileContent GenerateTileContent(int mode) { TileVisual visual = new TileVisual(); //MEDIUM TILE WILL SWITCH BETWEEN CANDIDATES USING A NOTIFICATION QUEUE //USER CAN CHOOSE BETWEEN CARTOON HEADS AND PHOTO BACKGROUNDS if (doPhoto) { visual.TileMedium = GenerateTileBindingMediumImage(mode); } else { visual.TileMedium = GenerateTileBindingMedium(mode); } if (mode == 1) { //WIDE AND LARGE TILES DO NOT NEED A NOTIFICATION QUEUE TO DISPLAY BOTH CANDIDATES visual.TileWide = GenerateTileBindingWide(); visual.TileLarge = GenerateTileBindingLarge(); //SADLY, SMALL TILES DO NOT SUPPORT A NOTIFICATION QUEUE visual.TileSmall = GenerateTileBindingSmall(); } return(new TileContent() { Visual = visual }); }
public void NotifyEntityMovementEnd(MoveableEntity ent) { // Get the visual for the old tile it was on and unlink the entity from it. TileVisual oldTV = mapTerrainVisuals.GetAt(ent.t.x, ent.t.y); GameObject entGO; if (oldTV != null) { entGO = oldTV.entityGO; mapTerrainVisuals.GetAt(ent.t.x, ent.t.y).entityGO = null; } else { // There was no old tile visual. We will have to create a new one. entGO = TileVisual.CreateEntityVisual(map.GetAt(ent.movingTo)); } // Set as the entity visual for another tile visual, but only if that tile is on screen... TileVisual newTV = mapTerrainVisuals.GetAt(ent.movingTo.x, ent.movingTo.y); if (newTV != null) { if (newTV.entityGO != null) { Destroy(newTV.entityGO); } newTV.entityGO = entGO; } else { // This enttity game object isn't needed. Destroy(entGO); } }
private TileContent BuildLiveTile(List <ResponsiveNotificationText> messages) { var results = messages.ElementAt(0); var fixtures = messages.ElementAt(1); if (!results.Matches.Any() && !fixtures.Matches.Any()) { return(null); } TileVisual root = new TileVisual(); TileBinding wideBinding = new TileBinding(); TileBindingContentAdaptive wideBindingContent = new TileBindingContentAdaptive(); wideBinding.Content = wideBindingContent; TileBinding largeBinding = new TileBinding(); TileBindingContentAdaptive largeBindingContent = new TileBindingContentAdaptive(); largeBinding.Content = largeBindingContent; foreach (var notificationGroup in messages) { if (notificationGroup.Matches.Any()) { var group = new AdaptiveGroup(); var subgroup = new AdaptiveSubgroup() { HintTextStacking = AdaptiveSubgroupTextStacking.Center }; subgroup.Children.Add(new AdaptiveText() { Text = notificationGroup.MatchType, HintStyle = AdaptiveTextStyle.Body }); foreach (var match in notificationGroup.Matches) { subgroup.Children.Add(new AdaptiveText() { Text = match, HintStyle = AdaptiveTextStyle.Caption }); } group.Children.Add(subgroup); wideBindingContent.Children.Add(group); largeBindingContent.Children.Add(group); } } root.TileLarge = largeBinding; root.TileWide = wideBinding; return(new TileContent() { Visual = root }); }
public TileVisual GetTileAtMouse() { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100f, layer)) { TileVisual tile = hit.collider.GetComponent <TileVisual>(); return(tile); } return(null); }
public void NotifyEntityMovementStart(MoveableEntity ent) { TileVisual tv = mapTerrainVisuals.GetAt(ent.t.x, ent.t.y); if (tv == null || tv.entityGO == null) { return; } else { animations.Add(new Transition(tv.entityGO, new Vector3(ent.movingTo.x, ent.movingTo.y), ent.actionTimer)); } }
public void NotifyEntityHealthChange(Entity ent) { // See if we are visible. TileVisual tv = mapTerrainVisuals.GetAt(ent.t.x, ent.t.y); if (tv != null) { // Now if the entity has 0 health... if (ent.health == 0) { // Destroy the entity visual. Destroy(tv.entityGO); tv.entityGO = null; } // Otherwise if the entity has full health... else if (ent.health == ent.maxHealth) { // Hide the entities damage bar. tv.entityGO.transform.GetChild(0).gameObject.SetActive(false); } // Otherwise... else { // Show the entities damage bar. if (tv.entityGO == null) { Debug.Log(ent.t.x + ", " + ent.t.y + ", " + ent.GetSprite() + ", " + ent.dead + ", " + ent.health + "/" + ent.maxHealth); } else { GameObject bar = tv.entityGO.transform.GetChild(0).gameObject; bar.SetActive(true); // Scale it appropriately. 0.9 scale should be 100% health. bar.transform.localScale = new Vector3(ReMap(ent.health, 0, ent.maxHealth, 0, 0.9f), 0.075f, 1f); } } } }
public void NotifyTileItemChanged(Tile t) { // Check the tile is visible. TileVisual tv = mapTerrainVisuals.GetAt(t.x, t.y); if (tv != null) { // If the tile already had an item visual, remove it. if (tv.itemGO != null) { Destroy(tv.itemGO); tv.itemGO = null; } // Create the new tile visual, if one is to be created. if (t.storedItem != null) { tv.itemGO = TileVisual.CreateItemVisual(t); } } }
private void Update() { if (!isBuilding) { return; } TileVisual tile = GetTileAtMouse(); if (tile == null) { return; } Material mat = TowerManager.Instance.CanBuildAt(tile.tile) ? canBuild : cantBuild; //Draw visual representation of tower Graphics.DrawMesh(towerPrefabs[index].GetComponentInChildren <MeshFilter>().sharedMesh, Matrix4x4.Translate(tile.transform.position), mat, 0); if (Input.GetMouseButtonDown(0)) { if (TowerManager.Instance.CanBuildAt(tile.tile) == false) { UISoundPlayer.Instance.PlayAlertSound(); Debug.Log("Can't build here"); return; } TowerManager.Instance.BuyTowerAt(tile.tile, towerPrefabs[index]); //Instantiate particle Instantiate(builParticle, tile.transform.position, Quaternion.identity); isBuilding = false; } }
private static async Task <TileContent> GetCoinTileContent(HttpClient httpClient, string coinType, CancellationToken token, TraceWriter log) { HttpResponseMessage result = await httpClient.GetAsync($"https://api.coinbase.com/v2/prices/{coinType}-USD/spot", token); if (result.IsSuccessStatusCode) { string coinString = await result.Content.ReadAsStringAsync(); CoinbaseResponse coinResponse = JsonConvert.DeserializeObject <CoinbaseResponse>(coinString); TileVisual tileVisual = new TileVisual() { Arguments = coinType, TileSmall = new TileBinding { Content = new TileBindingContentAdaptive { TextStacking = TileTextStacking.Center, Children = { new AdaptiveText { Text = $"{coinType} to USD" }, new AdaptiveText { Text = $"${coinResponse.Data.Amount}", HintStyle = AdaptiveTextStyle.CaptionSubtle } } } }, TileMedium = new TileBinding { Content = new TileBindingContentAdaptive { TextStacking = TileTextStacking.Center, Children = { new AdaptiveText { Text = $"{coinType} to USD" }, new AdaptiveText { Text = $"${coinResponse.Data.Amount}", HintStyle = AdaptiveTextStyle.CaptionSubtle } } } }, TileLarge = new TileBinding { Content = new TileBindingContentAdaptive { TextStacking = TileTextStacking.Center, Children = { new AdaptiveText { Text = $"{coinType} to USD" }, new AdaptiveText { Text = $"${coinResponse.Data.Amount}", HintStyle = AdaptiveTextStyle.CaptionSubtle }, } } }, TileWide = new TileBinding { Content = new TileBindingContentAdaptive { TextStacking = TileTextStacking.Center, Children = { new AdaptiveText { Text = $"{coinType} to USD" }, new AdaptiveText { Text = $"${coinResponse.Data.Amount}", HintStyle = AdaptiveTextStyle.CaptionSubtle }, } } } }; TileContent tileContent = new TileContent { Visual = tileVisual }; return(tileContent); } else { log.Error($"Failed to get a response from Coinbase. HTTP Status: {result.StatusCode}, Response body: {await result.Content.ReadAsStringAsync()}"); return(null); } }
private void EvaluateMessages(Messages obj) { if (obj == Messages.ExpenseChanged) { var vm = SimpleIoc.Default.GetInstance <MainViewModel>(); if (vm != null && vm.ExpenseCollections != null) { var newNotes = vm.ExpenseCollections.SelectMany(noteCollectionModel => noteCollectionModel.Expenses).ToList(); var adap2 = new TileBindingContentAdaptive() { Children = { new TileText() { Style = TileTextStyle.Body, Text = newNotes.Sum(n => n.Amount).ToString("0.##") + " total spent" }, // For spacing new TileText() { Style = TileTextStyle.Body, Text = newNotes.Where(n => n.CreateTime > DateTime.Now.Subtract(TimeSpan.FromDays(7))).Sum(n => n.Amount).ToString("0.##") + " spent last 7 days" }, // For spacing new TileText() { Style = TileTextStyle.Body, Text = newNotes.Where(n => n.CreateTime > DateTime.Now.Subtract(DateTime.Now - DateTime.Today)).Sum(n => n.Amount).ToString("0.##") + " spent today" }, } }; var tileLarge = new TileBinding() { Branding = TileBranding.None, Content = adap2 }; var tileSmall = new TileBinding() { Branding = TileBranding.None, Content = new TileBindingContentAdaptive() { Children = { new TileText() { Style = TileTextStyle.Header, Text = newNotes.Count.ToString("00"), Align = TileTextAlign.Center } } } }; var tileVisual = new TileVisual() { TileLarge = tileLarge, TileMedium = tileLarge, TileWide = tileLarge, TileSmall = tileSmall, }; var tileContent = new TileContent() { Visual = tileVisual }; var notif = new TileNotification(tileContent.GetXml()); var updater = TileUpdateManager.CreateTileUpdaterForApplication(); updater.Update(notif); } } }
public void SetTileVisual(TileVisual tileVisual) { tileVisual.SetGrid(GridManager.Instance.tileGrid, grid); }