自定义包——新建文件夹
情景--------------------------
看油管的。写链接敏感了。 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));
}
}
}
}
程序集定义
json
{
"name": "com.wuweisheng.tools",
"version": "0.0.1-preview.1",
"displayName": "创建目录"
}
效果---------------------
自定义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.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"
}
}
精简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"
}
}
用精简的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 导包
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
{
const string githubName = "WarbleWavelet";
public static async Task ReplacePaackagesFromGist( string id, string user= githubName)
{
var url = GetGistUrl(id, user);
var contents = await GetContents(url);
ReplacePackageFile(contents);
}
private static string GetGistUrl(string id, string user = githubName)
{
return $"https://gist.githubusercontent.com/{user}/{id}/raw";
}
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;
}
public static void ReplacePackageFile(string contents)
{
var existing = Path.Combine(Application.dataPath, "../Packages/manifest.json");
File.WriteAllText(existing, contents);
UnityEditor.PackageManager.Client.Resolve();
}
internal static void InstallUnitPackage(string packageName)
{
UnityEditor.PackageManager.Client.Add($"com.unity.{packageName}") ;
}
}
}
效果 下载Cinemachine
|