public TView MakeView <TView>(HexGridCell <BaseNode> cell, uint gridWidth, uint gridHeight) where TView : TileView { if (!tilePrefabMap.TryGetValue(cell.Value.GetType(), out var value)) { logger.Error("Could not find a prefab mapping for type '{0}'.", cell.Value.GetType().FullName); value = defaultViewPrefab; } TView val = InstantiateFunc(value) as TView; if ((UnityEngine.Object)val == (UnityEngine.Object)null) { logger.Error("Failed to Instantiate view prefab <{0}> as TileView", value); return(null); } RectTransform component = val.GetComponent <RectTransform>(); component.SetParent(tileContainer, worldPositionStays: false); val.name = cell.AxialCoord.ToString(); val.gameObject.SetActive(value: true); float num = (float)Screen.height / (float)(gridHeight + 1); float num2 = num / (Mathf.Sqrt(3f) / 2f); float size = num2 / 2f; Vector2 anchoredPosition = HexCoord.AxialToPixel(cell.AxialCoord, size).ToVector(); float num3 = num / 4f; if (gridWidth % 2u == 0) { anchoredPosition.y -= num3; anchoredPosition.x += 0.375f * num2; } else { anchoredPosition.y -= num3; } if (gridHeight % 2u == 0) { anchoredPosition.y -= num / 2f; } component.anchoredPosition = anchoredPosition; component.sizeDelta = new Vector2(num2, num); return(val); }
private void SetupTileController(uint orderedIndex, BaseNode node) { HexGridCell <BaseNode> hexGridCell = orderedCells[orderedIndex]; hexGridCell.Value = node; ITileController tileController = orderedControllers[orderedIndex]; TileView tileView = null; if (!tilePrefabMap.TryGetValue(node.GetType(), out var value)) { logger.Error("No tile view prefab mapping exists for type {0}.", node.GetType()); DestroyController(orderedIndex, destroyView: true); return; } if (tileController != null) { if (tileController.ViewType != value.GetType()) { DestroyController(orderedIndex, destroyView: true); } else { tileView = tileController.BaseView; } } if (tileView == null) { tileView = GetTileView(hexGridCell); if (tileView == null) { logger.Error("Failed to get a tile view for node of type {0}", node.Type); return; } } DestroyController(orderedIndex, destroyView: false); tileController = TileControllerFactory.MakeController(tileView, hexGridCell, this); orderedControllers[orderedIndex] = tileController; }
public void InspectNode(BaseNode node) { if (!(node is TNode)) { logger.Error("Invalid node type '{0}' passed to controller of type {1}", node.GetType().Name, GetType().Name); } else { CurrentBaseNode = node; CurrentNode = node as TNode; ClearContents(); OnInspectNode(); } }