Files
Continentis/Assets/UMod/Examples/ExampleScripts/Ex06_ListMods.cs

48 lines
2.0 KiB
C#
Raw Normal View History

2025-10-03 00:02:43 -04:00
using UnityEngine;
// Make sure we can access the uMod api
namespace UMod.Example
{
/// <summary>
2026-03-20 11:56:50 -04:00
/// An example script that shows how to list all mods currently installed.
/// This example makes use of the 'ModDirectory' but there are other methods.
/// To use this script simply attach it to a game object.
2025-10-03 00:02:43 -04:00
/// </summary>
[ExecuteInEditMode]
public class Ex06_ListMods : MonoBehaviour
{
// The path used for the mod directory
public string modDirectoryPath = "";
2026-03-20 11:56:50 -04:00
private ModDirectory modDirectory;
2025-10-03 00:02:43 -04:00
private void Start()
{
// Check if we are in-editor and not in play mode - if so the component has just been added
2026-03-20 11:56:50 -04:00
if (Application.isEditor && !Application.isPlaying)
2025-10-03 00:02:43 -04:00
{
// Make sure we dont alter the users suggestion
2026-03-20 11:56:50 -04:00
if (string.IsNullOrEmpty(modDirectoryPath))
2025-10-03 00:02:43 -04:00
// Initialize to a default directory
modDirectoryPath = Application.persistentDataPath + "/Mods";
return;
}
// Create the mod directory at the path
modDirectory = new ModDirectory(modDirectoryPath);
// Setup the mod directory before we can use it
//ModDirectory.DirectoryLocation = modDirectory;
// Check if there are any installed mods.
2026-03-20 11:56:50 -04:00
if (modDirectory.HasMods) //ModDirectory.HasMods == true)
2025-10-03 00:02:43 -04:00
// We can now use the mod directory to list all mods installed.
// Note that this method will list all valid mods located in the 'modDirectory' path.
2026-03-20 11:56:50 -04:00
foreach (var modName in modDirectory.GetModNames()) // ModDirectory.GetModNames())
2025-10-03 00:02:43 -04:00
// Print the mod name to the console.
ExampleUtil.Log(this, modName);
else
// There are no mods installed in 'modDirectory' so just print a message.
ExampleUtil.LogError(this, "There are no mods installed in the mod directory");
}
}
2026-03-20 11:56:50 -04:00
}