コード例 #1
0
        public static ITileController MakeController(TileView view, HexGridCell <BaseNode> cell, IHexGridController console)
        {
            ITileController tileController;

            switch (cell.Value.Type)
            {
            case BaseNode.NodeType.Group:
                tileController = new GroupTileController(console, view, cell);
                break;

            case BaseNode.NodeType.Invokable:
                tileController = new InvokableTileController(console, view, cell);
                break;

            case BaseNode.NodeType.Tweakable:
                tileController = new TweakableTileController(console, view as TweakableTileView, cell);
                break;

            case BaseNode.NodeType.Watchable:
                tileController = new WatchableTileController(console, view, cell);
                break;

            case BaseNode.NodeType.Unknown:
                tileController = new TileController <TileView, BaseNode>(console, view, cell);
                break;

            default:
                LogManager.GetCurrentClassLogger().Error("Invalid or unsupported BaseNode.Type value: {0}", cell.Value.Type);
                tileController = null;
                break;
            }
            tileController.Init();
            return(tileController);
        }
コード例 #2
0
        public HexGridCell <TCellValue> GetCell(AxialCoord axialCoord)
        {
            HexGridCell <TCellValue> value = null;

            cells.TryGetValue(axialCoord.ToString(), out value);
            return(value);
        }
コード例 #3
0
 public TileController(IHexGridController grid, TView view, HexGridCell <BaseNode> cell)
 {
     this.grid = grid;
     View      = view;
     BaseCell  = cell;
     Node      = BaseCell.Value as TNode;
 }
コード例 #4
0
 private TileView GetTileView(HexGridCell <BaseNode> cell)
 {
     if (cell == null || cell.Value == null)
     {
         logger.Error("A cell instance must be provided for cell: {0}", cell);
         return(null);
     }
     return(tileViewFactory.MakeView <TileView>(cell, gridWidth, gridHeight));
 }
コード例 #5
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);
                }
            }
        }
コード例 #6
0
        public IEnumerable <HexGridCell <TCellValue> > GetSpiralCells(CubeCoord center, uint radius)
        {
            HexGridCell <TCellValue> centerCell = GetCell(center);

            if (centerCell != null)
            {
                yield return(centerCell);
            }
            for (uint i = 1u; i <= radius; i++)
            {
                foreach (HexGridCell <TCellValue> cell in GetRingCells(center, i))
                {
                    if (cell != null)
                    {
                        yield return(cell);
                    }
                }
            }
        }
コード例 #7
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);
        }
コード例 #8
0
        public static Dictionary <string, HexGridCell <TCellValue> > MakeRectangleGrid <TCellValue>(uint width, uint height) where TCellValue : class
        {
            Dictionary <string, HexGridCell <TCellValue> > dictionary = new Dictionary <string, HexGridCell <TCellValue> >();
            int num  = (int)width / 2;
            int num2 = (int)height / 2;

            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    int num3 = j - num;
                    int num4 = -1 * (i - num2);
                    int q    = num3;
                    int r    = num4 - (num3 - (num3 & 1)) / 2;
                    HexGridCell <TCellValue> hexGridCell = new HexGridCell <TCellValue>(new AxialCoord(q, r), null);
                    dictionary.Add(hexGridCell.AxialCoord.ToString(), hexGridCell);
                }
            }
            return(dictionary);
        }
コード例 #9
0
        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;
        }
コード例 #10
0
 public InvokableTileController(IHexGridController console, TileView view, HexGridCell <BaseNode> cell)
     : base(console, view, cell)
 {
     invokable = base.Node.Invokable;
 }
コード例 #11
0
        public void SetCellValue(TCellValue value, AxialCoord coord)
        {
            HexGridCell <TCellValue> cell = GetCell(coord);

            cell.Value = value;
        }
コード例 #12
0
 public WatchableTileController(IHexGridController console, TileView view, HexGridCell <BaseNode> cell)
     : base(console, view, cell)
 {
     watchable = base.Node.Watchable;
 }
コード例 #13
0
 public TweakableTileController(IHexGridController console, TweakableTileView view, HexGridCell <BaseNode> cell)
     : base(console, view, cell)
 {
     tweakable = base.Node.Tweakable;
 }
コード例 #14
0
 public GroupTileController(IHexGridController console, TileView view, HexGridCell <BaseNode> cell)
     : base(console, view, cell)
 {
 }