示例#1
0
    private static void SaveAssetBundleData(AssetImporter assetImporter, string AssetbundleName, string AssetVarian)
    {
        if (!assetImporter)
        {
            return;
        }
        AssetbundleName = AssetbundleName.ToLower();
        AssetVarian     = AssetVarian.ToLower();
        if (assetImporter.assetBundleName.Equals(AssetbundleName) &&
            assetImporter.assetBundleVariant.Equals(AssetVarian))
        {
            return;
        }

        string filePatch = AssetBundleManagerEditor.ConverRelativePatchToObslotePatch(assetImporter.assetPath);

        filePatch += ".meta";

        if (!File.Exists(filePatch))
        {
            return;
        }

        string        text    = System.IO.File.ReadAllText(filePatch);
        List <string> alltext = new List <string>();

        alltext.AddRange(text.Split('\n'));
        string strAbVar = "  assetBundleVariant: ";
        string StrAbNa  = "  assetBundleName: ";

        for (int i = alltext.Count - 1; i >= 0; i--)
        {
            string s = alltext[i];
            if (s.Contains(StrAbNa))
            {
                alltext[i] = StrAbNa + AssetbundleName;
            }
            if (s.Contains(strAbVar))
            {
                alltext[i] = strAbVar + AssetVarian;
            }
        }

        string result = string.Empty;

        result = alltext[0];
        for (int i = 1; i < alltext.Count; i++)
        {
            result += '\n';
            result += alltext[i];
        }
        System.IO.File.WriteAllText(filePatch, result);
        assetImporter.assetBundleName = AssetbundleName;
        if (!AssetbundleName.Equals(string.Empty))
        {
            assetImporter.assetBundleVariant = AssetVarian;
        }
    }
    private static bool GetTextureInfo(AssetImporter assetImporter, out int width, out int height)
    {
        width  = 0;
        height = 0;
        string filePatch = AssetBundleManagerEditor.ConverRelativePatchToObslotePatch(assetImporter.assetPath);

        filePatch += ".meta";

        if (!File.Exists(filePatch))
        {
            return(false);
        }

        //CubeMap特殊处理一下
        if (IsCubeMap(assetImporter.assetPath))
        {
            width  = 2048;
            height = width;
            return(true);
        }

        string userData = assetImporter.userData;

        //if (!userData.Contains(TextureInfoBegin))
        //{
        //string text = System.IO.File.ReadAllText(filePatch);
        //List<string> alltext = new List<string>();
        //alltext.AddRange(text.Split('\n'));
        //string strAbVar = "  userData: ";
        //for (int i = alltext.Count - 1; i >= 0; i--)
        //{
        //    string s = alltext[i];
        //    if (s.Contains(strAbVar))
        //    {
        //        userData = s.Replace(strAbVar, string.Empty);
        //    }
        //}
        //}

        if (!userData.Contains(TextureInfoBegin))
        {
            return(false);
        }
        int begin = userData.IndexOf(TextureInfoBegin);
        int end   = userData.IndexOf(TextureInfoEnd);

        string reslut = userData.Substring(begin, end - begin);

        reslut = reslut.Replace(TextureInfoBegin, string.Empty);
        reslut = reslut.Replace(TextureInfoEnd, string.Empty);
        string[] str = reslut.Split(',');
        bool     re  = int.TryParse(str[0], out width);

        re = re && int.TryParse(str[1], out height);
        return(re);
    }
示例#3
0
    /// <summary>
    /// ab信息从meta中获取
    /// </summary>
    /// <param name="assetImporter"></param>
    public static void GetAssetBundleInfoFromMeta(string assetPath, out string AssetBundleName, out string AssetBundleVariant, out string guid)
    {
        AssetBundleName    = string.Empty;
        AssetBundleVariant = string.Empty;
        guid = string.Empty;
        if (assetPath.Equals(string.Empty))
        {
            return;
        }

        string filePatch = AssetBundleManagerEditor.ConverRelativePatchToObslotePatch(assetPath);

        filePatch += ".meta";

        if (!File.Exists(filePatch))
        {
            Debug.LogError("找不到文件,请确认文件路径:" + assetPath);
            return;
        }

        string        text    = System.IO.File.ReadAllText(filePatch);
        List <string> alltext = new List <string>();

        alltext.AddRange(text.Split('\n'));
        string strAbVar = "  assetBundleVariant: ";
        string StrAbNa  = "  assetBundleName: ";
        string StrGuid  = "guid: ";

        for (int i = 0; i < alltext.Count; i++)
        {
            string s = alltext[i];
            if (s.Contains(StrAbNa))
            {
                AssetBundleName = s.Replace(StrAbNa, string.Empty);
                AssetBundleName = AssetBundleName.Trim();
            }
            if (s.Contains(strAbVar))
            {
                AssetBundleVariant = s.Replace(strAbVar, string.Empty);
                AssetBundleVariant = AssetBundleVariant.Trim();
            }
            if (s.Contains(StrGuid))
            {
                guid = s.Replace(StrGuid, string.Empty);
                guid = guid.Trim();
            }
        }
    }
示例#4
0
    /// <summary>
    /// 保存AssetBundle,版本升级后,再onpostallassets阶段,ab名不会写入到meta文件了,需要手动写入
    /// </summary>
    /// <param name="assetImporter"></param>
    private static void SaveAssetBundleUserData(AssetImporter assetImporter, string userData)
    {
        if (!assetImporter)
        {
            return;
        }

        string filePatch = AssetBundleManagerEditor.ConverRelativePatchToObslotePatch(assetImporter.assetPath);

        filePatch += ".meta";

        if (!File.Exists(filePatch))
        {
            return;
        }
        //if (assetImporter.userData.Equals(userData))
        //{
        //    return;
        //}
        assetImporter.userData = userData;
        string        text    = System.IO.File.ReadAllText(filePatch);
        List <string> alltext = new List <string>();

        alltext.AddRange(text.Split('\n'));
        string StrUSD = "  userData: ";

        for (int i = alltext.Count - 1; i >= 0; i--)
        {
            string s = alltext[i];
            if (s.Contains(StrUSD))
            {
                alltext[i] = StrUSD + userData;
            }
        }

        string result = string.Empty;

        result = alltext[0];
        for (int i = 1; i < alltext.Count; i++)
        {
            result += '\n';
            result += alltext[i];
        }
        System.IO.File.WriteAllText(filePatch, result);
    }
    private static AssetBundleManagerEditor.AssetBundleEditorInfo BuildAnimatorClipAssetBundleInfo(AssetImporter assetImporter, string referenceAssetbundleName)
    {
        string AbName    = string.Empty;
        string AbVirtant = string.Empty;

        if (!assetImporter)
        {
            return(null);
        }

        string asPatch = assetImporter.assetPath;

        //移除头部
        asPatch = asPatch.Replace(ArtitsPatch, "");

        string[] strs = asPatch.Split('/');

        //没有放到其他文件夹下,则使用默认的包
        if (strs.Length <= 1)
        {
            asPatch = "Default";
        }
        else
        {
            //移除名字
            asPatch = asPatch.Replace(strs[strs.Length - 1], "");

            //再移除最后的斜杠
            asPatch = asPatch.Remove(asPatch.Length - 1);
        }


        //最后就是包名
        AbName    = "animclip/" + asPatch;
        AbVirtant = AssetBundleManager.AnimatorClipVariant;

        string assetName = Path.GetFileNameWithoutExtension(assetImporter.assetPath);
        string assetGUID = AssetBundleManagerEditor.GetAssetGUIDFromMeta(assetImporter.assetPath);

        if (assetName.Equals(string.Empty) || assetGUID.Equals(string.Empty))
        {
            return(null);
        }
        if (!referenceAssetbundleName.Equals(string.Empty))
        {
            AbName = referenceAssetbundleName;
        }
        AssetBundleManagerEditor.AssetBundleEditorInfo info = new AssetBundleManagerEditor.AssetBundleEditorInfo();
        info.AssetBundleName   = AbName;
        info.AssetBundleVarian = AbVirtant;
        info.guid      = assetGUID;
        info.assetName = assetName;


        AssetBundleManagerEditor.AssetFileInfo fileInfo = AssetBundleManagerEditor.GetFileInfo(AssetBundleManagerEditor.ConverRelativePatchToObslotePatch(assetImporter.assetPath));
        if (fileInfo != null)
        {
            info.Asset_X = fileInfo.fileLengthInMB;
            info.Asset_Y = fileInfo.fileLengthInMB;
        }
        return(info);
    }