/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~异步加载~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
    /// <summary>
    /// 添加异步资源加载
    /// </summary>
    /// <param name="path">资源路径</param>
    /// <param name="type">资源类型</param>
    /// <param name="callback">资源成功或失败回调函数</param>
    /// 例:ResourceManager.Instance.AddAsync("Prefab/Scene/Map_1003", eResType.PREFAB, delegate(sResLoadResult info){});
    /// <returns></returns>
    public ulong AddAsync(string path, eResType type, System.Action <sResLoadResult> callback)
    {
        if (m_BackLoadThread == null || string.IsNullOrEmpty(path))
        {
            return(0);
        }

        //判断是否已经加载过
        Object res = ResourceLoaderManager.Instance.GetResource(path);

        if (res != null)
        {
            if (callback != null)
            {
                callback(new sResLoadResult(true, path));
            }
            return(0);
        }

        ulong         id   = ShareGUID();
        sResLoadChunk info = new sResLoadChunk(path, type, callback);

        info.ID = id;
        m_BackLoadThread.Add(info);
        return(id);
    }
예제 #2
0
    private IEnumerator LoadAudioClip(eResType type, System.Action callback)
    {
        string path = GetAudioClipPath(type);

        Debuger.Log("[AudioSoundManager] LoadAudioClip:" + path);
        if (System.IO.File.Exists(path))
        {
            Debuger.LogError("file is exist!!!!!");
        }
        if (!string.IsNullOrEmpty(path) && !AudioDictionary.ContainsKey(type))
        {
            WWW www = new WWW(path);
            yield return(www);

            if (string.IsNullOrEmpty(www.error))
            {
                AudioClip clip = www.GetAudioClipCompressed(true, AudioType.AIFF);
                AudioDictionary.Add(type, clip);

                if (callback != null)
                {
                    callback();
                }

                www.Dispose();
                www = null;
            }
            else
            {
                Debuger.LogError(www.error);
            }
        }
    }
예제 #3
0
    /// <summary>
    /// 下载音效
    /// </summary>
    /// <param name="aduioname"></param>
    /// <param name="type"></param>
    /// <returns></returns>
    private string GetAudioClipPath(eResType type)
    {
        string path = string.Empty;
        string streamingAssetsPath = string.Empty;

#if UNITY_EDITOR
        streamingAssetsPath = "file://" + Application.streamingAssetsPath;
#elif UNITY_IPHONE
        streamingAssetsPath = Application.dataPath + "/Raw";
#elif UNITY_ANDROID
        streamingAssetsPath = "jar:file://" + Application.dataPath + "!/assets";
#endif
        switch (type)
        {
        case eResType.OnOverClip:
            //path = System.IO.Path.Combine(streamingAssetsPath, mOnOverClipName);
            path = streamingAssetsPath + mOnOverClipName;
            break;

        case eResType.OnFilledClip:
            //path = System.IO.Path.Combine(streamingAssetsPath, mOnFilledClipName);
            path = streamingAssetsPath + mOnFilledClipName;
            break;

        default:
            break;
        }
        return(path);
    }
예제 #4
0
 public sResLoadChunk(string path, eResType type, Action <sResLoadResult> call)
 {
     ID        = 0;
     Path      = path;
     Type      = type;
     Stage     = eResChunkStage.UNLOAD;
     StartTime = Time.realtimeSinceStartup;
     Callback  = call;
 }
예제 #5
0
        public ResName(string abName, string assetName, string extension)
        {
            AssetName = null;
            ABName    = null;
            Extension = null;
            ABGroup   = null;
            FullName  = "";

            if (!string.IsNullOrEmpty(assetName))
            {
                if (assetName.StartsWith(RESOURCES_PREFIX))
                {
                    ResType = eResType.Internal;
                }
                else if (assetName.StartsWith(FILE_PREFIX))
                {
                    ResType = eResType.SingleFile;
                }
                else if (string.Equals(extension, ".unity", StringComparison.OrdinalIgnoreCase))
                {
                    ResType = eResType.Scene;
                }
                else
                {
                    ResType = eResType.Asset;
                }
            }
            else if (!string.IsNullOrEmpty(abName))
            {
                ResType = eResType.Assetbundle;
            }

            if (!string.IsNullOrEmpty(abName))
            {
                ABName    = abName.ToLower();
                FullName += ABName + "#";
            }

            if (!string.IsNullOrEmpty(assetName))
            {
                AssetName = ResType != eResType.SingleFile ? assetName.ToLower() : assetName;
                FullName += AssetName;
            }

            if (!string.IsNullOrEmpty(extension))
            {
                Extension = ResType != eResType.SingleFile ? extension.ToLower() : extension;
                FullName += Extension;
            }
        }
    /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~同步加载~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
    /// <summary>
    /// 增加同步资源加载
    /// </summary>
    /// <param name="path">资源路径</param>
    /// <param name="type">资源类型</param>
    /// <returns></returns>
    public ulong AddSync(string path, eResType type)
    {
        if (m_FrontLoadThread == null || string.IsNullOrEmpty(path))
        {
            return(0);
        }

        ulong         id   = ShareGUID();
        sResLoadChunk info = new sResLoadChunk(path, type, null);

        info.ID = id;
        m_FrontLoadThread.Add(info);
        return(id);
    }
    /// <summary>
    /// 下载音效
    /// </summary>
    /// <param name="aduioname"></param>
    /// <param name="type"></param>
    /// <returns></returns>
    private AudioClip GetAudioClip(string aduioname, eResType type = eResType.CLIP)
    {
        AudioClip audioclip = null;

        switch (type)
        {
        case eResType.AB:
            break;

        case eResType.CLIP:
            audioclip = GetResAudioClip(aduioname);
            break;

        default:
            break;
        }
        return(audioclip);
    }
예제 #8
0
    public void Load(string name, UnityAction <UnityEngine.Object, object> callBack, eResType type, object paraObj = null)
    {
        StringBuilder filepath = new StringBuilder();

        switch (type)
        {
        case eResType.UI: filepath = filepath.Append(PathTool.uiPath); break;

        case eResType.EFFECT: filepath = filepath.Append(PathTool.effectPath); break;

        case eResType.AUDIO: filepath = filepath.Append(PathTool.audioPath); break;

        case eResType.TXT: filepath = filepath.Append(PathTool.txtPath); break;

        case eResType.MAT: filepath = filepath.Append(PathTool.matPath); break;

        case eResType.SCENES: filepath = filepath.Append(PathTool.scenePath); break;

        case eResType.PREFABS: filepath = filepath.Append(PathTool.prefabsPath); break;

        case eResType.MODEL: filepath = filepath.Append(PathTool.modelPath); break;

        default: filepath = filepath.Append(""); Debug.LogError("Unkown eResType"); break;
        }


        filepath.Append(name);
        UnityEngine.Object obj;
        if (pool.ContainsKey(name))
        {
            obj = pool[name];
        }
        else
        {
            obj        = Resources.Load(filepath.ToString());
            pool[name] = obj;
        }

        if (callBack != null)
        {
            callBack(obj, paraObj);
        }
    }
예제 #9
0
    /// <summary>
    /// 播放
    /// </summary>
    /// <param name="audioname"></param>
    public void PlaySound(eResType type, float volume = 1)
    {
        if (type == eResType.None)
        {
            return;
        }
        AudioClip sound = null;

        if (AudioDictionary.TryGetValue(type, out sound))
        {
            this.PlayClip(sound, volume);
        }
        else
        {
            StartCoroutine(LoadAudioClip(type, () =>
            {
                if (AudioDictionary.TryGetValue(type, out sound))
                {
                    this.PlayClip(sound, volume);
                }
            }));
        }
    }