Ejemplo n.º 1
0
        public void AsyncLoadGameObjectItem(string path, GameObjectItem gameObjectItem, OnAsyncGameObjFinished dealFinished,
                                            LoadAssetPriority priority)
        {
            ResourceItem item = GetAssetFromAssetCache(gameObjectItem.Crc);

            if (item != null)
            {
                gameObjectItem.ResourceItem = item;
                if (dealFinished != null)
                {
                    dealFinished(path, gameObjectItem);
                }
                return;
            }
            //判断是否在加载中
            AsyncLoadAssetParam para = null;

            if (!m_loadingAssetDict.TryGetValue(gameObjectItem.Crc, out para) || para == null)
            {
                para            = m_asyncLoadAssetParamPool.Spawn(true);
                para.m_crc      = gameObjectItem.Crc;
                para.m_path     = path;
                para.m_priority = priority;
                m_loadingAssetDict.Add(gameObjectItem.Crc, para);
                m_loadingAssetList[(int)priority].Add(para);
            }
            AsyncCallBack callback = m_asyncCallBackPool.Spawn(true);

            callback.m_gameObjDealFinished = dealFinished;
            callback.m_gameObjectItem      = gameObjectItem;
            para.m_callbackList.Add(callback);
        }
Ejemplo n.º 2
0
 public void Reset()
 {
     m_callbackList.Clear();
     m_crc      = 0;
     m_path     = "";
     m_Sprite   = false;
     m_priority = LoadAssetPriority.LOW;
 }
Ejemplo n.º 3
0
        //异步加载资源, 仅仅是不需要实例化的资源,音频,图片等
        public void AsyncLoadAsset <T>(string path, OnAsyncResourceObjFinished dealFinished,
                                       LoadAssetPriority priority, object param1 = null,
                                       object param2 = null, object param3 = null, uint crc = 0) where T : UnityEngine.Object
        {
            if (crc == 0)
            {
                crc = CrcHelper.StringToCRC32(path);
            }
            ResourceItem item = GetAssetFromAssetCache(crc);

            if (item != null)
            {
                if (dealFinished != null)
                {
                    dealFinished(path, item.Obj, param1, param2, param3);
                }
                return;
            }
            //判断是否在加载中
            AsyncLoadAssetParam para = null;

            if (!m_loadingAssetDict.TryGetValue(crc, out para) || para == null)
            {
                para            = m_asyncLoadAssetParamPool.Spawn(true);
                para.m_crc      = crc;
                para.m_path     = path;
                para.m_priority = priority;
                //这里应该还少了对Sprite的判定
                m_loadingAssetDict.Add(crc, para);
                m_loadingAssetList[(int)priority].Add(para);
            }
            AsyncCallBack callback = m_asyncCallBackPool.Spawn(true);

            callback.m_resourceObjDealFinished = dealFinished;
            callback.m_param1 = param1;
            callback.m_param2 = param2;
            callback.m_param3 = param3;
            para.m_callbackList.Add(callback);
        }
Ejemplo n.º 4
0
        //GameObject异步加载资源
        public long InstantiateAsync(string path, OnAsyncResourceObjFinished dealFinish, LoadAssetPriority priority,
                                     bool setSceneObject = false, object param1 = null, object param2 = null, object param3 = null,
                                     bool bClear         = true)
        {
            if (string.IsNullOrEmpty(path))
            {
                return(0);
            }
            uint           crc            = CrcHelper.StringToCRC32(path);
            GameObjectItem gameObjectItem = GetGameObjectItemFromPool(crc);

            if (gameObjectItem != null)
            {
                if (setSceneObject)
                {
                    gameObjectItem.Obj.transform.SetParent(m_sceneGos, false);
                }
                if (dealFinish != null)
                {
                    dealFinish(path, gameObjectItem.Obj, param1, param2, param3);
                }
                return(gameObjectItem.Guid);
            }
            long guid = ResourceMgr.Instance.CreateGuid();

            gameObjectItem                    = m_gameObjectItemClassPool.Spawn(true);
            gameObjectItem.Crc                = crc;
            gameObjectItem.SetSceneParent     = setSceneObject;
            gameObjectItem.Clear              = bClear;
            gameObjectItem.DealFinishCallback = dealFinish;
            gameObjectItem.Param1             = param1;
            gameObjectItem.Param2             = param2;
            gameObjectItem.Param3             = param3;
            //调用ResourceManager异步加载接口
            ResourceMgr.Instance.AsyncLoadGameObjectItem(path, gameObjectItem, OnAsyncLoadGameObjectFinish, priority);
            return(guid);
        }