Example #1
0
        protected override void Awake()
        {
            base.Awake();
            grid      = Player.I.grid;
            iconsZone = rectTransform.Find("Icons").GetComponent <RectTransform>();
            Vector2Int min = grid.GetGridPos(iconsZone.GetWorldMin());
            Vector2Int max = grid.GetGridPos(iconsZone.GetWorldMax());

            gridRect = new RectInt(min, max - min);
            // Saving previous grid icons
            previousIcons = new GridIcon[gridRect.size.x, gridRect.size.y];
            for (int y = 0; y < gridRect.size.y; y++)
            {
                for (int x = 0; x < gridRect.size.x; x++)
                {
                    previousIcons[x, y] = grid.grid[gridRect.x + x, gridRect.y + y];
                    previousIcons[x, y]?.gameObject.SetActive(false);
                }
            }
            // Placing new grid icons
            foreach (RectTransform transf in iconsZone)
            {
                GridIcon icon = transf.GetComponent <GridIcon>();
                if (icon == null)
                {
                    continue;
                }
                Vector2Int gridPos = grid.GetGridPos(transf.position);
                grid.grid[gridPos.x, gridPos.y] = icon;
                transf.position = grid.GetCanvasPos(gridPos);
                transf.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, grid.cellSize.x);
                transf.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, grid.cellSize.y);
            }
        }
Example #2
0
 private void InitGrid()
 {
     foreach (RectTransform transf in gridParent)
     {
         GridIcon icon = transf.GetComponent <GridIcon>();
         if (icon == null)
         {
             continue;
         }
         Vector2Int gridPos = GetGridPos(transf.position);
         grid[gridPos.x, gridPos.y] = icon;
         transf.position            = GetCanvasPos(gridPos);
         transf.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, cellSize.x);
         transf.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, cellSize.y);
     }
 }
Example #3
0
        public void OpenWindow(GridIcon icon)
        {
            GameObject go = null;

            if (icon.isFolder)
            {
                go = Instantiate(availableFolderWindows[Random.Range(0, availableFolderWindows.Length)].gameObject, frontWindows);
                FolderWindow foldWin = go.GetComponent <FolderWindow>();
                windowStack.Push(foldWin);
            }
            else
            {
                ImageWindow imgWin = null;
                switch (icon.ext)
                {
                case "png":
                case "jpg":
                case "bmp":
                    go = Instantiate(imgWindow.gameObject, frontWindows);
                    break;

                case "html":
                    go = Instantiate(webWindow.gameObject, frontWindows);
                    break;

                case "txt":
                    go = Instantiate(textWindow.gameObject, frontWindows);
                    break;

                case "pdf":
                    go = Instantiate(pdfWindow.gameObject, frontWindows);
                    break;
                }
                imgWin = go?.GetComponent <ImageWindow>();
                windowStack.Push(imgWin);
            }
        }