当前位置:   article > 正文

Unity编辑器拓展——自定义包新建文件夹,自定义manifest和下载包_unity mainfest dependencies

unity mainfest dependencies

自定义包——新建文件夹

情景--------------------------

看油管的。写链接敏感了。
Editor + 程序集定义(资源,创建。不加不会运行) + json。以下三个文件/夹按下面步骤得到
在这里插入图片描述

Editor

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Random = UnityEngine.Random;
using static System.IO.Directory;
using static System.IO.Path;
using static UnityEngine.Application;
using static UnityEditor.AssetDatabase;
using UnityEditor;

namespace NewBehaviourScript00
{
    public static class ToolsMenu
    {
        
        [MenuItem("My/Setup/Create Default Folders")]
        public static void CreateDefaultFolders()
        {
            Dir( "_Project","Scripts","Art","Scene");
            Refresh();
        }

        public static void Dir(string root, params string[] dir)
        {
            var fullPath = Combine( dataPath, root);
            foreach (var newDirectory in dir)
            {
                CreateDirectory( Combine(fullPath, newDirectory));
            }
        }
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32

程序集定义

在这里插入图片描述

json

{
  "name": "com.wuweisheng.tools",
  "version": "0.0.1-preview.1",
  "displayName": "创建目录"
}
  • 1
  • 2
  • 3
  • 4
  • 5

效果---------------------

在这里插入图片描述

自定义manifest和下载包

精简manifest前---------------------------------------------

按视频前后差异
类似目录D:\Data\Projects\Unity\U_Test\Packages\manifest.json(不允许//注释符,下面只是看Up删除了哪些)

{
  "dependencies": {
    "com.unity.collab-proxy": "1.13.5",
    "com.unity.ide.rider": "3.0.7",
    //"com.unity.ide.visualstudio": "2.0.11",//负责比如unity双击脚本后打开visual studio
    //"com.unity.ide.vscode": "1.2.4",
    //"com.unity.test-framework": "1.1.29",
    "com.unity.textmeshpro": "3.0.6",
    "com.unity.timeline": "1.6.2",
    "com.unity.ugui": "1.0.0",
    //"com.unity.visualscripting": "1.7.2",
    "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"
  }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44

精简manifest后

{
  "dependencies": {
    "com.unity.collab-proxy": "1.13.5",
    "com.unity.ide.rider": "3.0.7",
    "com.unity.textmeshpro": "3.0.6",
    "com.unity.timeline": "1.6.2",
    "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.audio": "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.ui": "1.0.0",
    "com.unity.modules.uielements": "1.0.0",
    "com.unity.modules.umbra": "1.0.0",
    "com.unity.modules.unitywebrequest": "1.0.0",
    "com.unity.modules.unitywebrequestassetbundle": "1.0.0",
    "com.unity.modules.unitywebrequestwww": "1.0.0"
  }
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

用精简的manifest拿到gist ID

在这里插入图片描述

下载包的代码(放Editor)------------------------

using UnityEngine;
using Random = UnityEngine.Random;
using static System.IO.Directory;
using static System.IO.Path;
using static UnityEngine.Application;
using static UnityEditor.AssetDatabase;
using UnityEditor;
using System.Threading.Tasks;
using System.Net.Http;
using System.IO;
using System;

namespace NewBehaviourScript00
{
    
    public static class ToolsMenu
    {
        public const string topItem = "MyTools";
     
        #region 导包
        /// <summary>https://gist.github.com/给你的ID</summary>
        const string gistID = "2dba9dc3384c1a2e1b6d3299052f317a";

        [MenuItem(topItem + "/Setup/Load New Manifest")]
        static async void LoadNewManifest() => await Packages.ReplacePaackagesFromGist(id: gistID );
        [MenuItem(topItem + "/Setup/输入系统")]
        static void AddNewInputSystem() => Packages.InstallUnitPackage("inputsystem");
        [MenuItem(topItem + "/Setup/后期处理")]
        static void AddPostPocessing() => Packages.InstallUnitPackage("postprocessing");
        [MenuItem(topItem + "/Setup/摄像机")]
        static void AddCinemachine() => Packages.InstallUnitPackage("cinemachine");



        #endregion

    }

    public static class Packages
    {
        /// <summary>你的github账户名字</summary>
        const string githubName = "WarbleWavelet";

        /// <summary>拿到manifest,进行包的下载</summary>
        public static async Task ReplacePaackagesFromGist( string id, string user= githubName)
        {
            var url = GetGistUrl(id, user);
            var contents = await GetContents(url);
            ReplacePackageFile(contents);
                
        }
        /// <summary>https://gist.github.com/ 填写你精简后的manifest得到的来宾ID</summary>
        private static string GetGistUrl(string id, string user = githubName)
        {
           return $"https://gist.githubusercontent.com/{user}/{id}/raw";
        }

        /// <summary>下载</summary>
        public static async Task<string> GetContents(string url)
        {
            var client = new HttpClient();
            var response = await client.GetAsync(url);
            var content = await response.Content.ReadAsStringAsync();
            return content;

        }

        /// <summary>覆盖本地manifest.json</summary>
        public static void ReplacePackageFile(string contents)
        {
            var existing = Path.Combine(Application.dataPath, "../Packages/manifest.json");
            File.WriteAllText(existing, contents);
            UnityEditor.PackageManager.Client.Resolve();
        }
        /// <summary>相当于在包管理器安装包</summary>
        internal static void InstallUnitPackage(string packageName)
        {
            UnityEditor.PackageManager.Client.Add($"com.unity.{packageName}") ;
        }
    }
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82

效果 下载Cinemachine

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/82028
推荐阅读
相关标签
  

闽ICP备14008679号