yyl
2025-05-19 284d53f23b058c650749f03f0079a76dce7f4347
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
using System;
using UnityEngine.U2D;
using LitJson;
using System.IO;
using UnityEngine.Networking;
 
#if UNITY_EDITOR
using UnityEditor;
#endif
 
using LaunchCommon;
 
public class ResManager : Singleton<ResManager>
{
    
 
    //不下载时本地安卓测试路径
    // public string assetBundlesPath = Application.dataPath + "/../AssetBundles/Android/";
    // public static string bytesFolderName = "logicbytes/";
    public string StreamingAssetPath
    {
        get
        {
            return ResourcesPath.Instance.StreamingAssetPath;
        }
    }
    public string ExternalStorePath 
    {
        get
        {
            return ResourcesPath.Instance.ExternalStorePath;
        }
    }
 
    //用于editor 下的资源路径
    public string ResourcesOutPath 
    {
        get
        {
            return ResourcesPath.ResourcesOutPath;
        }
    }
 
    public string CONFIG_FODLER
    {
        get
        {
            return ResourcesPath.CONFIG_FODLER;
        }
    }
 
    public string ResourcesOutAssetPath
    {
        get
        {
            return ResourcesPath.ResourcesOutAssetPath;
        }
    }
    
 
 
    public void Init()
    {
 
    }
 
    public void Release()
    {
 
    }
    
    private string GetExtension(Type type)
    {
        if (type == typeof(GameObject))
            return ".prefab";
        else if (type == typeof(Sprite))
            return ".png";
        else if (type == typeof(Texture2D))
            return ".png";
        else if (type == typeof(Shader))
            return ".shader";
        else if (type == typeof(TextAsset))
            return ".txt";
        else if (type == typeof(AudioClip))
            return ".wav";
        else if (type == typeof(Font))
            return ".ttf";
        else if (type == typeof(Material))
            return ".mat";
        else
        {
            Debug.LogErrorFormat("GetExtension() => 不支持的资源类型: {0}.", type.Name);
            return "";
        }
    }
 
    public T LoadAsset<T> (string directory, string name) where T : UnityEngine.Object
    {
        T asset = null;
#if UNITY_EDITOR
        var path = string.Concat($"Assets/ResourcesOut/{directory}/{name}", GetExtension(typeof(T)));
        asset = UnityEditor.AssetDatabase.LoadAssetAtPath<T>(path);
#else
        if (prefabBundle == null)
        {
            // string _path = GetAssetFilePath("builtin/prefabs");
            string _path = GetAssetFilePath($"builtin/{directory}");
            prefabBundle = AssetBundle.LoadFromFile(_path);
        }
        asset = prefabBundle.LoadAsset(name) as t;
#endif
        if (asset == null)
        {
            Debug.LogErrorFormat("LoadBuiltInPrefab() => 加载不到资源: {0}.", name);
        }
 
        return asset;
    }
 
 
 
    public void UnloadAsset(string assetBundleName)
    {
        
    }
 
    
 
 
}