likuku
likuku

Reputation: 358

How can I check if package is installed in the project

I'm creating a module that looks for a text field in scene. if TextMeshPro is installed it looks for it, and if not, look for regular textfield/text mesh

the question is: how can I condition (pseudo code)

if(textMeshProExists)
    Look for A
else
    Look for B

Upvotes: 1

Views: 3833

Answers (2)

Young40
Young40

Reputation: 156

a asmdef file can help this.

asmdef

Add one Version Defines, PACKAGE_ADDRESSABLES.

you can use it in your code.

enter image description here

Upvotes: 1

Hamid Yusifli
Hamid Yusifli

Reputation: 10137

You can use the Package Manager scripting API to interact with the Package Manager programmatically.

Browsing the list of packages in a Project:

using System;
using UnityEditor;
using UnityEditor.PackageManager.Requests;
using UnityEditor.PackageManager;
using UnityEngine;

namespace Unity.Editor.Example {
   static class ListPackageExample
   {
       static ListRequest Request;

       [MenuItem("Window/List Package Example")]
       static void List()
       {
           Request = Client.List();    // List packages installed for the Project
           EditorApplication.update += Progress;
       }

       static void Progress()
       {
           if (Request.IsCompleted)
           {
               if (Request.Status == StatusCode.Success)
                   foreach (var package in Request.Result)
                       Debug.Log("Package name: " + package.name);
               else if (Request.Status >= StatusCode.Failure)
                   Debug.Log(Request.Error.message);

               EditorApplication.update -= Progress;
           }
       }
   }
}

Upvotes: 5

Related Questions