Ejemplo n.º 1
0
            public override void Action(int instanceId, string pathName, string resourceFile)
            {
                var template = AssetDBHelper.LoadAsset <UnityEngine.Object>(resourceFile);

                FileTools.Copy(PathTools.Asset2File(AssetDatabase.GetAssetPath(template)), pathName, true);
                AssetDatabase.Refresh();
            }
Ejemplo n.º 2
0
    private static void CopyPartTexture(RagdollPresetMetadata preset, WorkshopItemType part, string targetFolder)
    {
        string sourcePath = FileTools.Combine(preset.folder, part.ToString() + ".png");
        string text       = FileTools.Combine(targetFolder, part.ToString() + ".png");
        RagdollPresetPartMetadata part2 = preset.GetPart(part);

        if (part2 == null || string.IsNullOrEmpty(part2.modelPath) || part2.suppressCustomTexture)
        {
            FileTools.DeleteFile(text);
        }
        else
        {
            FileTools.Copy(sourcePath, text, deleteIfMissing: true);
        }
        if (part2 != null && part2.suppressCustomTexture)
        {
            part2.suppressCustomTexture = false;
        }
    }
Ejemplo n.º 3
0
    public void MigrateLegacySkin()
    {
        string text = Path.Combine(Application.persistentDataPath, "characterTexture" + 0 + ".png");

        if (File.Exists(text))
        {
            RagdollPresetMetadata ragdollPresetMetadata = new RagdollPresetMetadata();
            ragdollPresetMetadata.folder   = text;
            ragdollPresetMetadata.itemType = WorkshopItemType.RagdollPreset;
            ragdollPresetMetadata.main     = new RagdollPresetPartMetadata
            {
                modelPath = "builtin:LegacyBody"
            };
            RagdollPresetMetadata ragdollPresetMetadata2 = ragdollPresetMetadata;
            ragdollPresetMetadata2.title  = "Legacy";
            ragdollPresetMetadata2.folder = GenerateNewPresetPath();
            ragdollPresetMetadata2.Save(ragdollPresetMetadata2.folder);
            AddItem(WorkshopItemSource.LocalWorkshop, ragdollPresetMetadata2);
            string targetPath = FileTools.Combine(ragdollPresetMetadata2.folder, WorkshopItemType.ModelFull.ToString() + ".png");
            FileTools.Copy(text, targetPath, deleteIfMissing: true);
            File.Delete(text);
        }
    }
Ejemplo n.º 4
0
    public static void BuildAssetBundle()
    {
        singlePathSet.Clear();
        bundleDic.Clear();
        //查找所有一级资源(以及需要被代码直接加载的资源)
        //这里建议所有需要单独加载的资源放在统一的文件夹内,要不容易落下
        //这个模块没有放在外部,而写在代码里,主要是考虑很多路径是变量,放在外部不好管理
        string[] strings = AssetDatabase.FindAssets("t:prefab t:scene t:AudioClip", new string[] { "Assets" });
        for (int i = 0, count = strings.Length; i < count; i++)
        {
            singlePathSet.Add(AssetDatabase.GUIDToAssetPath(strings[i]));
        }
        //所有数据打包
        strings = AssetDatabase.FindAssets("", new string[] { "Assets/Resources/Data" });
        for (int i = 0, count = strings.Length; i < count; i++)
        {
            singlePathSet.Add(AssetDatabase.GUIDToAssetPath(strings[i]));
        }
        //反射资源路径类(因为在这个类里的一定都是需要单独加载的),遍历所有路径进行添加,由于set添加重复元素不会报错,所以这里不用处理
        FieldInfo[] fieldInfos = typeof(ResPath).GetFields();
        for (int i = 0; i < fieldInfos.Length; i++)
        {
            singlePathSet.Add(fieldInfos[i].GetValue(null).ToString());
        }
        //在这里添加单独引用的资源

        foreach (var item in singlePathSet)
        {
            bundleDic.Add(item, item);
        }
        foreach (var item in singlePathSet)
        {
            CheckDepends(item, item);
        }
        //转为打包格式
        Dictionary <string, List <string> > dependsDic = new Dictionary <string, List <string> >();

        foreach (var kv in bundleDic)
        {
            string singlePath = kv.Value;
            //场景特殊处理,场景不能和其他东西在一个Bundle里
            if (singlePath.EndsWith(".unity"))
            {
                singlePath = kv.Key;
            }
            if (!dependsDic.ContainsKey(singlePath))
            {
                dependsDic.Add(singlePath, new List <string>());
            }
            dependsDic[singlePath].Add(kv.Key);
        }

        //最终打包List
        List <AssetBundleBuild> buildList = new List <AssetBundleBuild>();

        foreach (var kv in dependsDic)
        {
            AssetBundleBuild build = new AssetBundleBuild();
            build.assetBundleName = AssetBundleLoad.GetAbName(kv.Key);
            build.assetNames      = kv.Value.ToArray();
            buildList.Add(build);
        }

        string path = AssetBundleLoad.GetAbPath();

        //这里得创建下文件夹,他不会帮你创建
        if (!Directory.Exists(path))
        {
            Directory.CreateDirectory(path);
        }
        BuildPipeline.BuildAssetBundles(path, buildList.ToArray(), BuildAssetBundleOptions.UncompressedAssetBundle, EditorUserBuildSettings.activeBuildTarget);
        //删除多余资源
        DeleteUnUsefulAssetBundle();

        //把新hash变成老的
        string newHashPath = GetNewHashPath();

        if (File.Exists(newHashPath))
        {
            FileTools.Copy(newHashPath, GetOldHashPath());
        }
        //写入最新hash
        FileTools.WriteAllText(GetNewHashPath(), JsonMapper.ToJson(GetAllAssetbundleHashList()));
        Debug.Log("打包完成");
    }