Пример #1
0
    /// <summary>
    /// 创建游戏物体实例
    /// </summary>
    /// <param name="resType"></param>
    /// <param name="name"></param>
    /// <param name="isCache"></param>
    /// <returns></returns>
    public GameObject LoadAsset(EnumResType resType, string name, bool isCache)
    {
        UnityEngine.Object tmpGo      = LoadAsset <UnityEngine.Object>(resType, name, isCache);
        GameObject         goInstance = GameObject.Instantiate(tmpGo) as GameObject;

        return(goInstance);
    }
Пример #2
0
    /// <summary>
    /// 释放缓存资源
    /// </summary>
    /// <param name="resType"></param>
    /// <param name="name"></param>
    public void ReleaseCache(EnumResType resType, string name)
    {
        string fullPath = GetFullPath(resType, name);

        if (assetDic.ContainsKey(fullPath))
        {
            UnityEngine.Object tmpObj = assetDic[fullPath];
            Resources.UnloadAsset(tmpObj);
            assetDic.Remove(fullPath);
        }
    }
Пример #3
0
    /// <summary>
    /// 加载资源的方法
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="resType"></param>
    /// <param name="name"></param>
    /// <param name="isCache"></param>
    /// <returns></returns>
    public T LoadAsset <T>(EnumResType resType, string name, bool isCache) where T : UnityEngine.Object
    {
        string fullPath = GetFullPath(resType, name);

        if (assetDic.ContainsKey(fullPath))
        {
            return(assetDic[fullPath] as T);
        }

        T tmpRes = Resources.Load(fullPath) as T;

        if (tmpRes == null)
        {
            Debug.Log("资源不存在/路径错误");
        }

        if (isCache)
        {
            assetDic.Add(fullPath, tmpRes);
        }

        return(tmpRes);
    }
Пример #4
0
    /// <summary>
    /// 获取完整路径
    /// </summary>
    /// <param name="resType"></param>
    /// <param name="name"></param>
    /// <returns></returns>
    private string GetFullPath(EnumResType resType, string name)
    {
        StringBuilder fullPath = new StringBuilder();

        switch (resType)
        {
        case EnumResType.None:
            break;

        case EnumResType.Audio:
            fullPath.Append("Audio/");
            break;

        case EnumResType.UIPrefab:
            fullPath.Append("UIPrefab/");
            break;

        case EnumResType.TextAsset:
            fullPath.Append("TextAsset/");
            break;

        case EnumResType.Texture:
            fullPath.Append("");
            break;

        case EnumResType.SceneUI:
            fullPath.Append("");
            break;

        case EnumResType.WindowUI:
            fullPath.Append("");
            break;
        }
        fullPath.Append(name);
        return(fullPath.ToString());
    }