少年修仙传客户端代码仓库
hch
2023-07-26 21b387a93d39309a9d88d587f79b2f5865aa4cf3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using System.Collections.Generic;
using System.IO;
using IFix.Core;
using UnityEngine;
 
/// <summary>
/// 脚本补丁加载器
/// </summary>
public class PatchLoader
{
    private static List<AssetVersion> patchAssets;
 
    //使用本地的版本文件加载,editor测试用
    public static void InitLocalPatchAsset()
    {
        patchAssets = new List<AssetVersion>();
        var path = StringUtility.Contact(ResourcesPath.Instance.StreamingAssetPath, "AssetsVersion.txt");
        if (AssetSource.patchFromEditor || !File.Exists(path))
            return;
        var lines = File.ReadAllLines(path);
        for (int i = 0; i < lines.Length; i++)
        {
            var assetVersion = new AssetVersion(lines[i]);
            if (assetVersion.GetAssetCategory() == AssetVersion.AssetCategory.Patch)
                patchAssets.Add(assetVersion);
        }
    }
 
    //初始化补丁资源列表
    public static void InitPatchAsset(List<AssetVersion> list)
    {
        patchAssets = list;
    }
 
    //加载补丁
    public static void LoadPatch()
    {
        try
        {
            if (AssetSource.patchFromEditor)
            {
                if (!Directory.Exists(ResourcesPath.PATCH_EDITOR))
                    return;
                var dic = new DirectoryInfo(ResourcesPath.PATCH_EDITOR);
                foreach (var file in dic.GetFiles())
                {
                    if (file.Exists)
                    {
                        PatchManager.Load(new FileStream(file.FullName, FileMode.Open));
                        DebugEx.LogFormat("已加载补丁:{0}", file.FullName);
                    }
                }
                return;
            }
            if (patchAssets == null)
                return;
            foreach (var asset in patchAssets)
            {
                var patchPath = AssetVersionUtility.GetAssetFilePath(asset.relativePath);
                if (File.Exists(patchPath))
                {
                    PatchManager.Load(new FileStream(patchPath, FileMode.Open));
                    DebugEx.LogFormat("已加载补丁:{0}", patchPath);
                }
            }
        }
        catch (Exception e)
        {
            DebugEx.LogError(e);
        }
    }
 
}