// @Brief : Initialize // @Param : pMocFilePath => Moc file path // : pTexturePaths => Texture paths // : pMotionFilePaths => Motion file paths // : bFromResources => From resources file public void Initialize(string pMocFilePath, string[] pTexturePaths, string[] pMotionFilePaths, bool bFromResources) { // Initialize live2d KrLive2DInitializer.Create(); // Load model byte[] pMocFile = KrResources.LoadBytes(pMocFilePath, bFromResources); m_pLive2dModel = Live2DModelUnity.loadModel(pMocFile); // Set render mode // NOTE : 1. There are advantages and disadvantages depending on the type // 2. Each drawing timing is different // Ref : http://sites.cybernoids.jp/cubism2/sdk_tutorial/platform-setting/unity/csharp/render-mode m_pLive2dModel.setRenderMode(Live2D.L2D_RENDER_DRAW_MESH); for (int sIndex = 0; sIndex < pTexturePaths.Length; sIndex++) { Texture2D pTexture = KrResources.LoadTexture2D(pTexturePaths[sIndex], bFromResources); // Set Texture m_pLive2dModel.setTexture(sIndex, pTexture); } // Load Motion m_pMotionDatas = new Dictionary <string, byte[]>(); for (int sIndex = 0; sIndex < pMotionFilePaths.Length; sIndex++) { m_pMotionDatas.Add(pMotionFilePaths[sIndex], KrResources.LoadBytes(pMotionFilePaths[sIndex], bFromResources)); } m_pMotionManager = new MotionQueueManager(); // Create idle motion m_pIdleMotionManager = new MotionQueueManager(); // NOTE : Let the 0th position of the motion list be the idle motion m_pIdleMotion = Live2DMotion.loadMotion(pMotionFilePaths[0]); m_pIdleMotion.setLoop(true); m_pIdleMotionManager.startMotion(m_pIdleMotion, false); SetPosition(Vector3.zero); }
// @Brief : OnDestroy void OnDestroy() { Live2D.dispose(); I = null; }
private static KrLive2DInitializer I = null; // singleton. //::::::::::::::::::::::::::::::::::::::::::::::::::::: // UNITY FUNCTION //::::::::::::::::::::::::::::::::::::::::::::::::::::: // @Brief : Awake void Awake() { I = this; // Initialize live2d Live2D.init(); }