Exemple #1
0
    /// <summary>
    /// Initializes the game list, drawing from the directories specified in the README
    /// </summary>
    void Start()
    {
        originalScales = new Vector3[positions.Length];
        for (int i = 0; i < originalScales.Length; i++)
        {
            originalScales[i] = positions[i].localScale;
        }
        buttons = new List <GameButton>();
        games   = new List <Game>();
        DirectoryInfo library = Directory.CreateDirectory(Application.persistentDataPath + "/Games");

        DirectoryInfo[] possibleGames = library.GetDirectories();
        foreach (DirectoryInfo gameDir in possibleGames)
        {
            // Get all the files that we need.
            FileInfo[] gameFile = gameDir.GetFiles("*.exe*");
            if (gameFile.Length == 0)
            {
                continue;
            }
            FileInfo[] textFile  = gameDir.GetFiles(textPath);
            FileInfo[] imageFile = gameDir.GetFiles("*.png");

            // Load Description
            string desc = "No description available.";
            if (textFile.Length != 0)
            {
                FileInfo text = textFile[0];
                desc = File.ReadAllText(text.FullName);
            }

            // Load image
            Texture2D image = null;
            if (imageFile.Length != 0)
            {
                image = new Texture2D(2, 2, TextureFormat.BGRA32, false);
                image.LoadImage(File.ReadAllBytes(imageFile[0].FullName));
            }

            // Load game
            FileInfo game = gameFile[0];
            string   path = game.FullName;
            string   name = game.Name.Replace(".exe", "");
            games.Add(new Game(name, path, desc, image));
        }
        for (int i = 0; i < positions.Length; i++)
        {
            GameButton btn = Instantiate(gameButtonPrefab, positions[i]).GetComponent <GameButton>();
            btn.UpdateGame(games[Mod(-2 + i, games.Count)], false);
            buttons.Add(btn);
        }
        loadingPanel?.SetActive(false);
        UpdateInfo(buttons[2].game);
        StartCoroutine(HandleInput());
    }