// 유틸 : 번들 리스트 추가 // 1. 리소스의 최상위 폴더이름을 번들이름으로 하여 등록시킴. // 2. 프리팹을 제외한 모든 리소스를 번들 리스트로 등록시킴. void AddAssetBundleInfo(SHResourcesTableInfo pInfo) { if (null == pInfo) { return; } if (true == CheckFilteringToAssetBundleInfo(pInfo)) { return; } // 번들이름 만들기 string strBundleName = "Root"; string[] strSplitPath = pInfo.m_strPath.Split(new char[] { '/' }); if (1 < strSplitPath.Length) { strBundleName = strSplitPath[0]; } // 번들정보 생성하기 if (false == m_dicAssetBundles.ContainsKey(strBundleName)) { AssetBundleInfo pBundleInfo = new AssetBundleInfo(); pBundleInfo.m_strBundleName = strBundleName; m_dicAssetBundles.Add(strBundleName, pBundleInfo); } m_dicAssetBundles[strBundleName].AddResourceInfo(pInfo); }
// 다양화 : 로더로 부터 호출될 로드함수 public override void Load(SHLoadData pInfo, Action <string, SHLoadStartInfo> pStart, Action <string, SHLoadEndInfo> pDone) { pStart(pInfo.m_strName, new SHLoadStartInfo()); if (true == IsLoadResource(pInfo.m_strName.ToLower())) { pDone(pInfo.m_strName, new SHLoadEndInfo(true, eLoadErrorCode.None)); return; } SHResourcesTableInfo pResourceInfo = Single.Table.GetResourcesInfo(pInfo.m_strName); if (null == pResourceInfo) { Debug.LogFormat("리소스 테이블에 {0}가 없습니다.(파일이 없거나 리소스 리스팅이 안되었음)", pInfo.m_strName); pDone(pInfo.m_strName, new SHLoadEndInfo(false, eLoadErrorCode.Load_Resource)); return; } var pObject = LoadSync <Object>(pResourceInfo); if (null == pObject) { pDone(pInfo.m_strName, new SHLoadEndInfo(true, eLoadErrorCode.Load_Resource)); } else { pDone(pInfo.m_strName, new SHLoadEndInfo(true, eLoadErrorCode.None)); } }
// 유틸 : 어싱크로 리소스 로드하기 void LoadAsync(SHResourcesTableInfo pTable, Action <string, SHLoadStartInfo> pStart, Action <string, SHLoadEndInfo> pDone) { if (true == IsLoadResource(pTable.m_strName.ToLower())) { pStart(pTable.m_strName, new SHLoadStartInfo()); pDone(pTable.m_strName, new SHLoadEndInfo(true, eLoadErrorCode.None)); return; } #if UNITY_EDITOR DateTime pStartTime = DateTime.Now; #endif ResourceRequest pRequest = Resources.LoadAsync(pTable.m_strPath); pStart(pTable.m_strName, new SHLoadStartInfo(pRequest)); Single.Coroutine.Async(() => { if (null == pRequest.asset) { Debug.LogError(string.Format("{0} 파일이 없습니다!!!", pTable.m_strPath)); pDone(pTable.m_strName, new SHLoadEndInfo(false, eLoadErrorCode.Load_Resource)); return; } m_dicResources.Add(pTable.m_strName.ToLower(), pRequest.asset); pDone(pTable.m_strName, new SHLoadEndInfo(true, eLoadErrorCode.None)); #if UNITY_EDITOR Single.AppInfo.SetLoadResource(string.Format("Load : {0}({1}sec)", pTable.m_strName, ((DateTime.Now - pStartTime).TotalMilliseconds / 1000.0f))); #endif }, pRequest); }
// 유틸 : 파일로 부터 정보얻어서 테이블 데이터 객체만들기 SHResourcesTableInfo MakeFileInfo(FileInfo pFile) { // 알리아싱 string strRoot = "Resources"; string strFullName = pFile.FullName.Substring(pFile.FullName.IndexOf(strRoot) + strRoot.Length + 1).Replace("\\", "/"); string strExtension = Path.GetExtension(strFullName); // 예외처리 : 리스팅에서 제외할 파일 if (true == CheckExceptionFile(pFile)) { return(null); } // 기록 var pInfo = new SHResourcesTableInfo(); pInfo.m_strName = Path.GetFileNameWithoutExtension(strFullName); pInfo.m_strFileName = Path.GetFileName(strFullName); pInfo.m_strExtension = strExtension; pInfo.m_strSize = pFile.Length.ToString(); //pInfo.m_strLastWriteTime = pFile.LastWriteTime.ToString("yyyy-MM-dd-HH:mm:ss.fff"); pInfo.m_strHash = SHHash.GetMD5ToFile(pFile.FullName); pInfo.m_strPath = strFullName.Substring(0, strFullName.Length - strExtension.Length);; return(pInfo); }
public override bool?LoadJsonTable(JSONNode pJson, string strFileName) { if (null == pJson) { return(false); } int iMaxTable = pJson["ResourcesList"].Count; for (int iLoop = 0; iLoop < iMaxTable; ++iLoop) { JSONNode pDataNode = pJson["ResourcesList"][iLoop]; SHResourcesTableInfo pData = new SHResourcesTableInfo(); pData.m_strName = GetStrToJson(pDataNode, "s_Name"); pData.m_strFileName = GetStrToJson(pDataNode, "s_FileName"); pData.m_strExtension = GetStrToJson(pDataNode, "s_Extension"); pData.m_strSize = GetStrToJson(pDataNode, "s_Size"); //pData.m_strLastWriteTime = GetStrToJson(pDataNode, "s_LastWriteTime"); pData.m_strHash = GetStrToJson(pDataNode, "s_Hash"); pData.m_strPath = GetStrToJson(pDataNode, "s_Path"); pData.m_eResourceType = SHHard.GetResourceTypeToExtension(pData.m_strExtension); AddResources(pData.m_strName, pData); } return(true); }
// 유틸 : 리소스 리스트 추가 void AddResourceInfo(SHResourcesTableInfo pInfo) { if (null == pInfo) { return; } m_dicResources[pInfo.m_strFileName] = pInfo; }
// 인터페이스 : 파일명으로 리소스 경로 얻기 public string GetResoucesPath(string strName) { SHResourcesTableInfo pInfo = GetResouceInfo(strName); if (null == pInfo) { return(string.Empty); } return(pInfo.m_strPath); }
// 유틸 : 번들로 묶지 않을 파일에 대한 필터링 bool CheckFilteringToAssetBundleInfo(SHResourcesTableInfo pInfo) { // 프리팹파일 필터링 if (".prefab" == pInfo.m_strExtension) { return(true); } // 테이블파일 필터링 if (".bytes" == pInfo.m_strExtension) { return(true); } return(false); }
public eResourceType m_eResourceType; // 리소스 타입 #endregion #region Interface Functions public void CopyTo(SHResourcesTableInfo pData) { if (null == pData) { return; } m_strName = pData.m_strName; m_strFileName = pData.m_strFileName; m_strExtension = pData.m_strExtension; m_strSize = pData.m_strSize; //m_strLastWriteTime = pData.m_strLastWriteTime; m_strHash = pData.m_strHash; m_strPath = pData.m_strPath; m_eResourceType = pData.m_eResourceType; }
// 인터페이스 : 파일정보 Json 포맷으로 만들어주기 public static string MakeSaveFormat(SHResourcesTableInfo pInfo, string strPreFix) { if (null == pInfo) { return(string.Empty); } string strNewLine = "\r\n"; string strBuff = string.Empty; strBuff += string.Format("{0}\t\"s_Name\": \"{1}\",{2}", strPreFix, pInfo.m_strName, strNewLine); strBuff += string.Format("{0}\t\"s_FileName\": \"{1}\",{2}", strPreFix, pInfo.m_strFileName, strNewLine); strBuff += string.Format("{0}\t\"s_Extension\": \"{1}\",{2}", strPreFix, pInfo.m_strExtension, strNewLine); strBuff += string.Format("{0}\t\"s_Size\": \"{1}\",{2}", strPreFix, pInfo.m_strSize, strNewLine); //strBuff += string.Format("{0}\t\"s_LastWriteTime\": \"{1}\",{2}", // strPreFix, // pInfo.m_strLastWriteTime, // strNewLine); strBuff += string.Format("{0}\t\"s_Hash\": \"{1}\",{2}", strPreFix, pInfo.m_strHash, strNewLine); strBuff += string.Format("{0}\t\"s_Path\": \"{1}\"{2}", strPreFix, pInfo.m_strPath, strNewLine); return(strBuff); }
// 유틸 : 싱크로 리소스 로드하기 T LoadSync <T>(SHResourcesTableInfo pTable) where T : Object { if (null == pTable) { return(null); } if (true == IsLoadResource(pTable.m_strName.ToLower())) { return(m_dicResources[pTable.m_strName.ToLower()] as T); } #if UNITY_EDITOR DateTime pStartTime = DateTime.Now; #endif T pObject = null; var pBundleData = Single.AssetBundle.GetBundleData(Single.Table.GetBundleInfoToResourceName(pTable.m_strName)); if (null != pBundleData) { pObject = pBundleData.m_pBundle.LoadAsset <T>(pTable.m_strName); } else { pObject = Resources.Load <T>(pTable.m_strPath); } if (null == pObject) { Debug.LogError(string.Format("{0}을 로드하지 못했습니다!!\n리소스 테이블에는 목록이 있으나 실제 파일은 없을 수 있습니다.", pTable.m_strPath)); return(null); } #if UNITY_EDITOR Single.AppInfo.SetLoadResource(string.Format("Load : {0}({1}sec)", pTable.m_strName, ((DateTime.Now - pStartTime).TotalMilliseconds / 1000.0f))); #endif // Text 데이터들은 한번 로드하고 나면 컨테이너에 담고 안지우기 때문에 저장하지 않는다. if (eResourceType.Text != pTable.m_eResourceType) { m_dicResources.Add(pTable.m_strName.ToLower(), pObject); } return(pObject); }
// 인터페이스 : Resources폴더 내에 있는 파일을 SHResourceTableData형식에 맞게 Json으로 리스팅 public int SetListing(string strSearchPath) { SHUtils.Search(strSearchPath, (pFileInfo) => { // 파일 정보 생성 SHResourcesTableInfo pInfo = MakeFileInfo(pFileInfo); if (null == pInfo) { return; } // 예외체크 : 파일명 중복 string strDupPath = CheckToDuplication(m_dicResources, pInfo.m_strFileName); if (false == string.IsNullOrEmpty(strDupPath)) { string strFirst = string.Format("{0}", strDupPath); string strSecond = string.Format("{0}", pInfo.m_strPath); #if UNITY_EDITOR EditorUtility.DisplayDialog("[SHTools] Resources Listing", string.Format("중복 파일발견!! 파일명은 중복되면 안됩니다!!\r\n1번 파일을 리스팅 하겠습니다.\r\n1번 : {0}\r\n2번 {1}", strFirst, strSecond), "확인"); #endif if (false == m_dicDuplications.ContainsKey(pInfo.m_strFileName)) { m_dicDuplications[pInfo.m_strFileName] = new List <string>(); m_dicDuplications[pInfo.m_strFileName].Add(strFirst); } m_dicDuplications[pInfo.m_strFileName].Add(strSecond); return; } AddResourceInfo(pInfo); AddAssetBundleInfo(pInfo); }); return(m_dicResources.Count); }
public T GetResources <T>(string strFileName) where T : Object { if (true == string.IsNullOrEmpty(strFileName)) { return(null); } strFileName = Path.GetFileNameWithoutExtension(strFileName); if (false == IsLoadResource(strFileName.ToLower())) { SHResourcesTableInfo pInfo = Single.Table.GetResourcesInfo(strFileName); if (null == pInfo) { Debug.Log(string.Format("리소스 테이블에 {0}가 없습니다.(파일이 없거나 리소스 리스팅이 안되었음)", strFileName)); return(null); } return(LoadSync <T>(pInfo)); } return(m_dicResources[strFileName.ToLower()] as T); }
public override bool?LoadJsonTable(JSONNode pJson, string strFileName) { if (null == pJson) { return(false); } int iMaxTable = pJson["AssetBundleInfo"].Count; for (int iLoop = 0; iLoop < iMaxTable; ++iLoop) { JSONNode pDataNode = pJson["AssetBundleInfo"][iLoop]; AssetBundleInfo pData = new AssetBundleInfo(); pData.m_strBundleName = GetStrToJson(pDataNode, "s_BundleName"); pData.m_lBundleSize = (long)GetIntToJson(pDataNode, "s_BundleSize"); pData.m_pHash128 = SHHash.GetHash128(GetStrToJson(pDataNode, "s_BundleHash")); int iMaxUnit = pDataNode["p_Resources"].Count; for (int iLoopUnit = 0; iLoopUnit < iMaxUnit; ++iLoopUnit) { JSONNode pUnitNode = pDataNode["p_Resources"][iLoopUnit]; SHResourcesTableInfo pUnit = new SHResourcesTableInfo(); pUnit.m_strName = GetStrToJson(pUnitNode, "s_Name"); pUnit.m_strFileName = GetStrToJson(pUnitNode, "s_FileName"); pUnit.m_strExtension = GetStrToJson(pUnitNode, "s_Extension"); pUnit.m_strSize = GetStrToJson(pUnitNode, "s_Size"); //pUnit.m_strLastWriteTime = GetStrToJson(pUnitNode, "s_LastWriteTime"); pUnit.m_strHash = GetStrToJson(pUnitNode, "s_Hash"); pUnit.m_strPath = GetStrToJson(pUnitNode, "s_Path"); pUnit.m_eResourceType = SHHard.GetResourceTypeToExtension(pUnit.m_strExtension); pData.AddResourceInfo(pUnit); } AddData(pData.m_strBundleName, pData); } return(true); }
void AddResources(string strKey, SHResourcesTableInfo pData) { m_pData[strKey.ToLower().Trim()] = pData; }