LoginSignup
1
1

Unity package nameからPackage情報を取得する方法

Last updated at Posted at 2024-05-08

UnityのEditor C# スクリプトでパッケージ情報をパッケージネームから取得する方法。
Unity Package Managerでインストールされたパッケージ情報を取得します。

PackageInfoManager.cs

using System.Linq;
using UnityEngine;
using UnityEditor;
using UnityEditor.PackageManager;

public static class PackageInfoManager
{
    [MenuItem("TEST / Package Info Test")]
    public static void PackageInfoTest()
    {
        var PackageInfomation = GetPackageInfo("com.unity.inputsystem");
        Debug.Log(PackageInfomation.displayName);
        Debug.Log(PackageInfomation.version);
        Debug.Log(PackageInfomation.name);
        Debug.Log(PackageInfomation.packageId);
        Debug.Log(PackageInfomation.source);
        Debug.Log(PackageInfomation.resolvedPath);
    }

    /// <summary>
    /// Get package information by package name
    /// </summary>
    public static UnityEditor.PackageManager.PackageInfo GetPackageInfo(string packageName)
    {
        var request = Client.List(true, true);
        while (!request.IsCompleted) { }
        if (request.Status == StatusCode.Success) { return request.Result.FirstOrDefault(pkg => pkg.name == packageName); }
        return null;
    }
}

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1