예제 #1
0
        public IEnumerable <HexGridCell <TCellValue> > GetRingCells(CubeCoord center, uint radius)
        {
            CubeCoord direction = CubeCoord.Directions[4] * (int)radius;
            CubeCoord cube      = center + direction;

            for (uint i = 0u; i < 6; i++)
            {
                for (uint j = 0u; j < radius; j++)
                {
                    HexGridCell <TCellValue> cell = GetCell(cube);
                    if (cell != null)
                    {
                        yield return(cell);
                    }
                    cube = HexCoord.GetNeighbour(cube, i);
                }
            }
        }
예제 #2
0
        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);
        }