summaryrefslogtreecommitdiff
path: root/WorldlineKeepers/Assets/Scripts/Managers/ResourceManager.cs
blob: 0fd18df4117cfb470af92e71a474e9b837dd7c65 (plain)
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
using LitJson;
using System.Collections;
using System.Collections.Generic;
using System.IO;
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
using WK.Data;

namespace WK
{

    public class ResourceManager : Singleton<ResourceManager>
    {

        // 资源根目录是Assets/Bundle/,后续可能会把部分资源移动到streamingAssets目录
        public const string kAssetRoot = "Assets/Bundle/";

        public T LoadAsset<T>(string relativePath) where T : UnityEngine.Object
        {
#if UNITY_EDITOR
            string path = kAssetRoot + relativePath;
            T obj = AssetDatabase.LoadAssetAtPath(path, typeof(T)) as T;
            return obj;
#else
            return null ;
#endif
        }

        /// <summary>
        /// 根据filekey读资源
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="fileKey"></param>
        /// <returns></returns>
        public T LoadFile<T>(string fileKey) where T : UnityEngine.Object
        {
            FileDescriptor file = DataManager.Instance.GetFile(fileKey);
            if (file == null)
                return default(T);
            if(file.root == FileRoot.Bundle)
            {
#if UNITY_EDITOR
                string tmp = kAssetRoot + file.path;
                T obj = AssetDatabase.LoadAssetAtPath(tmp, typeof(T)) as T;
                return obj;
#endif
            }
            return null;
            //else if(file.root == FileRoot.Persistent)
            //{
            //    string tmp = Application.persistentDataPath + "/" + file.path;

            //}
            //else if(file.root == FileRoot.Streaming)
            //{

            //}
        }

    }

}