Unity读取Packages文件夹中的manifest.json文件

manifest.json

.

这片文章没啥技术含量 (。・∀・)ノ゙

打开工程目录Packages,找到manifest.json,长这样。

{
  "dependencies": {
    "com.unity.collab-proxy": "1.2.16",
    "com.unity.ide.rider": "1.1.4",
    "com.unity.ide.vscode": "1.2.1",
    "com.unity.test-framework": "1.1.16",
    "com.unity.textmeshpro": "2.1.1",
    "com.unity.timeline": "1.2.15",
    "com.unity.ugui": "1.0.0",
    "com.unity.modules.ai": "1.0.0",
    "com.unity.modules.androidjni": "1.0.0",
    "com.unity.modules.animation": "1.0.0",
    "com.unity.modules.assetbundle": "1.0.0",
    "com.unity.modules.audio": "1.0.0",
    "com.unity.modules.cloth": "1.0.0",
    "com.unity.modules.director": "1.0.0",
    "com.unity.modules.imageconversion": "1.0.0",
    "com.unity.modules.imgui": "1.0.0",
    "com.unity.modules.jsonserialize": "1.0.0",
    "com.unity.modules.particlesystem": "1.0.0",
    "com.unity.modules.physics": "1.0.0",
    "com.unity.modules.physics2d": "1.0.0",
    "com.unity.modules.screencapture": "1.0.0",
    "com.unity.modules.terrain": "1.0.0",
    "com.unity.modules.terrainphysics": "1.0.0",
    "com.unity.modules.tilemap": "1.0.0",
    "com.unity.modules.ui": "1.0.0",
    "com.unity.modules.uielements": "1.0.0",
    "com.unity.modules.umbra": "1.0.0",
    "com.unity.modules.unityanalytics": "1.0.0",
    "com.unity.modules.unitywebrequest": "1.0.0",
    "com.unity.modules.unitywebrequestassetbundle": "1.0.0",
    "com.unity.modules.unitywebrequestaudio": "1.0.0",
    "com.unity.modules.unitywebrequesttexture": "1.0.0",
    "com.unity.modules.unitywebrequestwww": "1.0.0",
    "com.unity.modules.vehicles": "1.0.0",
    "com.unity.modules.video": "1.0.0",
    "com.unity.modules.vr": "1.0.0",
    "com.unity.modules.wind": "1.0.0",
    "com.unity.modules.xr": "1.0.0"
  }
}

解析类

namespace Assets.Script.DownPackage.Serializable
{
    using System;
    using System.Collections.Generic;

    [Serializable]
    public class Manifest
    {
        public Dictionary<string, string> dependencies = new Dictionary<string, string>();
    }
}

测试读取

注:需要Newtonsoft.Json

namespace Assets.Script.DownPackage
{
    using Assets.Script.DownPackage.Serializable;
    using Newtonsoft.Json;
    using System.IO;
    using UnityEngine;

    public class TestReadManifest : MonoBehaviour
    {
        private Manifest manifest;
        private string manifestJsonPath;
        private void Start()
        {
            //E:\AR\Assets
            DirectoryInfo assetPath = new DirectoryInfo(Application.dataPath);
            //E:\AR
            string projectPath = assetPath.Parent.FullName;
            //E:\AR\Packages
            string packagePath = Path.Combine(projectPath, "Packages");
            manifestJsonPath = Path.Combine(packagePath, "manifest.json");

            string manifestJson = File.ReadAllText(manifestJsonPath);
            manifest = JsonConvert.DeserializeObject<Manifest>(manifestJson);

            foreach (var package in manifest.dependencies)
            {
                Debug.Log(package.Key + " - " + package.Value);
            }
        }
    }
}
点赞

发表评论

昵称和uid可以选填一个,填邮箱必填(留言回复后将会发邮件给你)
tips:输入uid可以快速获得你的昵称和头像

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据

Title - Artist
0:00