Ejemplo n.º 1
0
    private static void HandleGameModeAssets()
    {
        //This will be called when unity reloads scripts


        //Make sure the GameModes folder exists
        CreateFolder(GameModeMgrEditor.gameModeFolder);


        //Find the GUID of all assets in the gameModeFolder
        string[] allGameModesGUIDs = AssetDatabase.FindAssets("", new string[] { GameModeMgrEditor.gameModeFolder });

        GameModeBase[] allGameModes = new GameModeBase[allGameModesGUIDs.Length];

        int GUIDIndex = 0;

        foreach (string GUID in allGameModesGUIDs)
        {
            //Get the asset path from the GUID
            string assetPath = AssetDatabase.GUIDToAssetPath(GUID);

            //Load the asset
            GameModeBase gameMode = AssetDatabase.LoadAssetAtPath <GameModeBase>(assetPath);

            //Make sure the script hasnt been deleted
            if (gameMode != null)
            {
                //Add it to the array
                allGameModes[GUIDIndex] = gameMode;
            }
            else
            {
                //The script has been deleted. Delete the asset file as well
                Debug.Log("Missing script file for GameMode '" + System.IO.Path.GetFileNameWithoutExtension(assetPath) + "', deleting.");
                AssetDatabase.DeleteAsset(assetPath);
            }

            GUIDIndex++;
        }


        //Find all classes that inherit GameModeBase
        foreach (System.Type type in GameMode.GameMode.GetAllClassesInheritingClass <GameModeBase>(false))
        {
            //Make sure this GameMode class has its own asset file
            if (allGameModes.Any(gameMode => gameMode != null && gameMode.name == type.Name))
            {
                //Debug.Log(type.Name + " has an asset file.");
            }
            else
            {
                Debug.Log("Discovered new GameMode class '" + type.Name + "'. Creating a settings asset in " + GameModeMgrEditor.gameModeFolder);

                CreateGameModeAsset(type);
            }
        }
    }