//::::::::::::::::::::::::::::::::::::::::::::::::::::: // PUBLIC FUNCTION //::::::::::::::::::::::::::::::::::::::::::::::::::::: // @Brief : Create // @Return : KrLive2DInitializer instance public static KrLive2DInitializer Create() { if (I == null) { GameObject pPrefab = KrResources.LoadDataInApp <GameObject>("Prefabs/Live2DInitializer"); Instantiate(pPrefab); } return(I); }
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // PUBLIC FUNCTION //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // @Brief : Create // @Param : pParent => Charageki manager parent // : pScripts => Script paths // : pCharaParent => Character parent // : eViewMode => Character display mode // : fAutoTime => Wait time after completion of processing of auto mode // : pAssetBasePath => Asset base path // : pServerBaseUrl => Server base url // @Return : KrCharagekiManager instance public static KrCharagekiManager Create(Transform pParent, string[] pScripts, Transform pCharaParent, KrCharagekiUICharacterContainer.eVIEW_MODE eViewMode, float fAutoTime, string pAssetBasePath = "", string pServerBaseUrl = "") { GameObject pPrefab = KrResources.LoadDataInApp <GameObject>(c_pPREFAB_PATH); GameObject pObj = Instantiate <GameObject>(pPrefab, pParent); pObj.SetActive(true); KrCharagekiManager pManager = pObj.GetComponent <KrCharagekiManager>(); pManager.Initialize(pScripts, pCharaParent, eViewMode, fAutoTime, pAssetBasePath, pServerBaseUrl); return(pManager); }
// @Brief : Create // @Param : pParent => Object parent // pData => Character data // @Return : KrCharagekiUI2DCharacter instance public static KrCharagekiUILive2DCharacter Create(Transform pParent, KrCharagekiUICharacterData pData) { GameObject pPrefab = KrResources.LoadDataInApp <GameObject>(c_pPREFAB_PATH); GameObject pObject = Instantiate <GameObject>(pPrefab); pObject.transform.SetParent(pParent, false); KrCharagekiUILive2DCharacter pCharacter = pObject.GetComponent <KrCharagekiUILive2DCharacter>(); pCharacter.Initialize(pData); return(pCharacter); }
// @Brief : Initialize // @Param : pData => Character data protected override void Initialize(KrCharagekiUICharacterData pData) { base.Initialize(pData); m_pActionSpriteDic = new Dictionary <uint, Sprite>(); foreach (KeyValuePair <uint, string> pKeyValue in KrCharagekiDef.s_p2D_CHARA_ACTION_IMAGE) { string pDataPath = KrCharagekiDef.s_pASSET_BASE_PATH + string.Format(pKeyValue.Value, m_pCharaData.GetCharacterId()); Sprite pSprite = KrResources.LoadSprite(pDataPath, KrCharagekiDef.IsLoadingFromResources()); m_pActionSpriteDic.Add(pKeyValue.Key, pSprite); } Hide(); }
//::::::::::::::::::::::::::::::::::::::::::::::::::::: // PUBLIC FUNCTION //::::::::::::::::::::::::::::::::::::::::::::::::::::: // @Brief : Create // @Param : pMocFilePath => Moc file path // : pTexturePaths => Texture paths // : pMotionFilePaths => Motion file paths // : bFromResources => From resources file // : pParent => Object parent public static KrLive2DModel Create(string pMocFilePath, string[] pTexturePaths, string[] pMotionFilePaths, bool bFromResources, Transform pParent = null) { GameObject pPrefab = KrResources.LoadDataInApp <GameObject>("Prefabs/Live2DModel"); GameObject pObject = Instantiate(pPrefab); pObject.transform.SetParent(pParent); KrLive2DModel pLive2DModel = pObject.GetComponent <KrLive2DModel>(); pLive2DModel.Initialize(pMocFilePath, pTexturePaths, pMotionFilePaths, bFromResources); return(pLive2DModel); }
// @Brief : Compile script private void Compile() { StreamReader pReader = KrResources.LoadText(m_pFilePath); KrCharagekiScript pScript = new KrCharagekiScript(); try { pScript.LoadScript(pReader); } finally { if (pReader != null) { pReader.Close(); } } }
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // PRIVATE FUNCTION //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // @Brief : Load script // @Return : KrCharagekiScript instance private KrCharagekiScript LoadScript() { KrCharagekiScript pScript = new KrCharagekiScript(); for (int sIndex = 0; sIndex < m_pScriptPaths.Length; sIndex++) { StreamReader pReader = KrResources.LoadText(KrCharagekiDef.s_pASSET_BASE_PATH + m_pScriptPaths[sIndex], KrCharagekiDef.IsLoadingFromResources()); try { pScript.LoadScript(pReader); } finally { if (pReader != null) { pReader.Close(); } } } return(pScript); }
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // PUBLIC //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // @Brief : Csv Load // @Param : pPath => Asset path // : bFromResources => From resources file public static KrCsvData Load(string pPath, bool bFromResources) { KrCsvData pCsvData = new KrCsvData(); StreamReader pStreamReader = KrResources.LoadText(pPath, bFromResources); KrDebug.Log("Load csv. path = " + pPath, typeof(KrCsvData)); if (pStreamReader.Peek() > -1) { string pOneLineColumnNames = pStreamReader.ReadLine(); KrDebug.Log("ColumnName = " + pOneLineColumnNames, typeof(KrCsvData)); // Setting column names string[] pColmnNames = pOneLineColumnNames.Split(new char[] { ',' }); pCsvData.SetColumnNames(pColmnNames); } string pOneLineValues = ""; while (pStreamReader.Peek() > -1) { pOneLineValues += pStreamReader.ReadLine(); // Setting values string[] pSplit = pOneLineValues.Split(new char[] { ',' }); if (pSplit.Length >= pCsvData.GetColumnNum()) { //Csv treats " as two minutes pOneLineValues = pOneLineValues.Replace("\"\"", "\""); KrDebug.Log(pOneLineValues, typeof(KrCsvData)); pCsvData.SetRow(pSplit); pOneLineValues = ""; } else { pOneLineValues += System.Environment.NewLine; } } pStreamReader.Close(); return(pCsvData); }
// @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 : Load audio clip // @Param : pPath => Asset path // : bFromResources => From resources file // @Return : Audio clip private AudioClip LoadAudioClip(string pPath, bool bFromResources = false) { if (string.IsNullOrEmpty(pPath)) { KrDebug.Warning(false, "The path is empty. path = " + pPath, typeof(KrAudioManager)); return(null); } if (bFromResources) { return(KrResources.LoadDataInApp <AudioClip>(pPath)); } else { if (!System.IO.File.Exists(pPath)) { KrDebug.Warning(false, "The file of the specified path does not exist. path = " + pPath, typeof(KrAudioManager)); return(null); } KrWav pWav = new KrWav(pPath, bFromResources); return(pWav.CreateAudioClip()); } }
// @Brief : Create // @Param : pPath => Asset path under the resources folder // : pParent => Parent of generated prefab // @Return : Component specified in template private T Create <T>(string pPath, Transform pParent) { GameObject pPrefab = KrResources.LoadDataInApp <GameObject>(pPath); return(Create <T>(pPrefab, pParent)); }
// @Brief : Load public void LoadSprite() { m_pBgSprite = KrResources.LoadSprite(KrCharagekiDef.s_pASSET_BASE_PATH + m_pImagePath, KrCharagekiDef.IsLoadingFromResources()); }
protected string m_pName = null; // asset name //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // CONSTRUCTOR //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // @Brief : Constructor // @Param : pPath => Absolute path of Audio asset. // : bFromResources => From resources file // @Return : KrWav instance public KrAudioDataFormat(string pPath, bool bFromResources) { m_pName = System.IO.Path.GetFileNameWithoutExtension(pPath); byte[] pBytes = KrResources.LoadBytes(pPath, bFromResources); ConvertBytes(pBytes); }