Unity 关联 Live2D 学习
前期配置: 安装Live2D Cubism Editor 4.0
找到模型后再Live2D Cubism Editor 4.0打开,3以上版本导出为moc3文件。
再下载CubismSdkForUnity-4-r.3 导入到unity
将导出模型文件夹直接导入asset即可,高版本Cubsim会直接形成预制件。
在3.0及更高版本中,该过程已更新.CusbimModel3Json.LoadAtPath使用后加载模型.ToModel()
using UnityEngine;
using Live2D.Cubism.Framework.Json;
using System.IO;
using System;
void Start()
{
string path = Application.dataPath + ("/Resources/hiyoriPrefab/hiyori_pro_t10.model3.json");
CubismModel3Json model3Json = CubismModel3Json.LoadAtPath(path, BuiltinLoadAssetAtPath);
model3Json.ToModel();
}
public static object BuiltinLoadAssetAtPath(Type assetType, string absolutePath)
{
if (assetType == typeof(byte[]))
{
return File.ReadAllBytes(absolutePath);
}
else if (assetType == typeof(string))
{
return File.ReadAllText(absolutePath);
}
else if (assetType == typeof(Texture2D))
{
var texture = new Texture2D(1, 1);
texture.LoadImage(File.ReadAllBytes(absolutePath));
return texture;
}
return new NotSupportedException();
}
注意在最高2.1版本加载资源必应要 初始化 Live2D.init()
Live2D . Init ( ) ;
var live2dModel = Live2DModelUnity . loadModel ( ( T ) Resources . Load ( path ) as T ) ;
再加载纹理图片
live2dModel . setTexture ( textureNumber , texture ) ;
当然也可以去load模型moc的二进制文件再调用loadModel。注意moc文件在cubsim高版本已经不支持导出。

浙公网安备 33010602011771号