看到标题有没一种“怎么又是快速”的感觉。但是事实上确实很快速,有人为你铺好路你点个鼠标当然快。
一.准备
先去下载开源项目 ytx1991/Azusa-Live2D
会得到一个DLL,live2d.dll。
IDE随便什么都行。
二.创建工程
我就以vs2012控制台程序为例。
显式调用dll。
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 | #include <windows.h> #include <process.h> int _tmain(int argc, _TCHAR* argv[]) { HINSTANCE dll; typedef int( * dllmain)(); typedef bool( * dllstart)(int); dllmain CreateWin; dllstart Live2DStart; dll=LoadLibraryA("Live2D.dll"); if(dll) { CreateWin=(dllmain)GetProcAddress(dll,"CreateWin"); Live2DStart=(dllstart)GetProcAddress(dll,"Live2DStart"); if(CreateWin) { CreateWin(); } if(Live2DStart) { int pid = (int)_getpid(); Live2DStart(pid); } } system("pause"); return 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 | [DllImport("Live2D.dll")] public static extern bool Live2DStart(int tid); [DllImport("Live2D.dll")] public static extern bool Live2DAbort(int hinst); [DllImport("Live2D.dll")] public static extern bool SetExpression(int hinst, string expid, int index); [DllImport("Live2D.dll")] public static extern bool StartMotion(int hinst, string motiontype, int motionindex, int priority, int index); [DllImport("Live2D.dll")] public static extern int AddModel(int hinst, string path); [DllImport("Live2D.dll", EntryPoint = "RemoveModels")] public static extern bool RemoveModel(int hinst); [DllImport("Live2D.dll")] public static extern bool GetModelInfo(int hinst, int index, StringBuilder info); [DllImport("Live2D.dll")] public static extern bool SetEyeBallDirection(int hinst, float x, float y, int index); [DllImport("Live2D.dll")] public static extern bool SetFaceDirection(int hinst, float x, float y, float z, int index); [DllImport("Live2D.dll")] public static extern bool SetBodyDirection(int hinst, float x, int index); [DllImport("Live2D.dll")] public static extern bool SetViewDepth(int hinst, int x, int y, int depth); [DllImport("Live2D.dll", CharSet = CharSet.Unicode)] public static extern bool ShowMessage(int hinst, int x, int y, int width, int height, string text, int fontHeight, int fontWidth, int fontWeight, bool italic, string family, uint color); |
参照上面的就能完成大部分功能了。
四。最后
我挖出这些接口只是为了学习,如果无意冒犯了原作者想隐藏的某些,可以说一下我马上删掉,毕竟原作者没给出DLL源码