private static BundleProperties LoadBundleById(Document doc, List <bundle> listBundles, string sid) { bundle bundleItem = listBundles.Find(delegate(bundle b) { return(b.id == sid); }); if (null == bundleItem) { return(null); } else { double[] bundleDim = bundleItem.flatDimensions.ToArray(); // instantiate bundle BundleProperties bundleProperties = new BundleProperties( doc, bundleItem.name, bundleItem.description , bundleDim[0], bundleDim[1], bundleDim[2] , bundleItem.flatWeight, (int)bundleItem.numberFlats , System.Drawing.Color.FromArgb((int)bundleItem.color[0], (int)bundleItem.color[1], (int)bundleItem.color[2])); // insert in list if (null != doc) { doc.AddType(bundleProperties); } return(bundleProperties); } }
/// <summary> /// 加载ab配置表 /// </summary> /// <returns></returns> public bool LoadAssetBundleConfig() { //#if UNITY_EDITOR // if (!ResourceManager.Instance.m_LoadFormAssetBundle) // return false; //#endif m_ResouceItemDic.Clear(); //string configPath = ABLoadPath + m_ABConfigABName; //AssetBundle configAB = AssetBundle.LoadFromFile(configPath); //TextAsset textAsset = configAB.LoadAsset<TextAsset>(m_ABConfigABName); TextAsset textAsset = Resources.Load("AssetbundleConfig1") as TextAsset; if (textAsset == null) { Debug.LogError("AssetBundleConfig is no exist!"); } string json = textAsset.text; Debug.Log(json); var configjson = JsonUtility.FromJson <AssetBundleJson>(json); for (int i = 0; i < configjson.ABbundles.Count; i++) { bundle abBase = configjson.ABbundles[i]; ResouceItem item = new ResouceItem(); item.m_Crc = abBase.crc; item.m_AssetName = abBase.AssetName; item.m_ABName = abBase.ABName; item.m_DependAssetBundle = abBase.ABDependce; if (m_ResouceItemDic.ContainsKey(item.m_Crc)) { Debug.LogError("重复的Crc 资源名:" + item.m_AssetName + " ab包名:" + item.m_ABName); } else { m_ResouceItemDic.Add(item.m_Crc, item); } } return(true); //MemoryStream stream = new MemoryStream(textAsset.bytes); //BinaryFormatter bf = new BinaryFormatter(); //AssetBundleConfig config = (AssetBundleConfig)bf.Deserialize(stream); //stream.Close(); //for (int i = 0; i < config.ABList.Count; i++) //{ // ABBase abBase = config.ABList[i]; // ResouceItem item = new ResouceItem(); // item.m_Crc = abBase.Crc; // item.m_AssetName = abBase.AssetName; // item.m_ABName = abBase.ABName; // item.m_DependAssetBundle = abBase.ABDependce; // if (m_ResouceItemDic.ContainsKey(item.m_Crc)) // { // Debug.LogError("重复的Crc 资源名:" + item.m_AssetName + " ab包名:" + item.m_ABName); // } // else // { // m_ResouceItemDic.Add(item.m_Crc, item); // } //} //return true; }
static void WriteData(Dictionary <string, string> resPathDic) { AssetBundleJson configJson = new AssetBundleJson(); configJson.ABbundles = new List <bundle>(); foreach (string path in resPathDic.Keys) { if (!ValidPath(path)) { continue; } bundle abBase = new bundle(); abBase.path = path; abBase.crc = Crc32.GetCrc32(path); abBase.ABName = resPathDic[path]; abBase.AssetName = path.Remove(0, path.LastIndexOf("/") + 1); abBase.ABDependce = new List <string>(); string[] resDependce = AssetDatabase.GetDependencies(path); for (int i = 0; i < resDependce.Length; i++) { string tempPath = resDependce[i]; if (tempPath == path || path.EndsWith(".cs")) { continue; } string abName = ""; if (resPathDic.TryGetValue(tempPath, out abName)) { if (abName == resPathDic[path]) { continue; } if (!abBase.ABDependce.Contains(abName)) { abBase.ABDependce.Add(abName); } } } configJson.ABbundles.Add(abBase); } //AssetBundleConfig config = new AssetBundleConfig(); //config.ABList = new List<ABBase>(); //foreach (string path in resPathDic.Keys) //{ // if (!ValidPath(path)) // continue; // ABBase abBase = new ABBase(); // abBase.Path = path; // abBase.Crc = Crc32.GetCrc32(path); // abBase.ABName = resPathDic[path]; // abBase.AssetName = path.Remove(0, path.LastIndexOf("/") + 1); // abBase.ABDependce = new List<string>(); // string[] resDependce = AssetDatabase.GetDependencies(path); // for (int i = 0; i < resDependce.Length; i++) // { // string tempPath = resDependce[i]; // if (tempPath == path || path.EndsWith(".cs")) // continue; // string abName = ""; // if (resPathDic.TryGetValue(tempPath, out abName)) // { // if (abName == resPathDic[path]) // continue; // if (!abBase.ABDependce.Contains(abName)) // { // abBase.ABDependce.Add(abName); // } // } // } // config.ABList.Add(abBase); // Debug.Log("ABList" + abBase.ABName + abBase.Path); //} //写入xml //string xmlPath = Application.dataPath + "/AssetbundleConfig.xml"; //if (File.Exists(xmlPath)) File.Delete(xmlPath); //FileStream fileStream = new FileStream(xmlPath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite); //StreamWriter sw = new StreamWriter(fileStream, System.Text.Encoding.UTF8); //XmlSerializer xs = new XmlSerializer(config.GetType()); //xs.Serialize(sw, config); //sw.Close(); //fileStream.Close(); // write to json string jsonPath = Application.dataPath + "/JsonTest/AssetbundleConfig.json"; string json = EditorJsonUtility.ToJson(configJson); Debug.Log("json: final " + json); System.IO.File.WriteAllText(jsonPath, json); ////写入二进制 //foreach (ABBase abBase in config.ABList) //{ // abBase.Path = ""; //} //FileStream fs = new FileStream(ABBYTEPATH, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite); //fs.Seek(0, SeekOrigin.Begin); //fs.SetLength(0); //BinaryFormatter bf = new BinaryFormatter(); //bf.Serialize(fs, config); //fs.Close(); //AssetDatabase.Refresh(); //SetABName("assetbundleconfig", ABBYTEPATH); }