Ejemplo n.º 1
0
    void Request_completed(AsyncOperation obj)
    {
        AssetBundleRequest request = (AssetBundleRequest)obj;
        int reqKey = request.GetHashCode();
        int key    = mRequestKeyForTypeKeyMaping[reqKey];

        if (!mAssetMaping.ContainsKey(key))
        {
            mAssetMaping.Add(key, request.asset);
        }
        else
        {
            mAssetMaping[key] = request.asset;
        }
        OnCallQueue(key);
    }
Ejemplo n.º 2
0
    public int LoadAssetAsync <T>(string sAsset, ResourceMgr.AssetLoadCompleted OnAssetLoadCompleted) where T : UnityEngine.Object
    {
        if (Bundle != null)
        {
            AssetBundleRequest abReq = Bundle.LoadAssetAsync <T>(AssetName(sAsset));
            abReq.completed += (ao) => {
                AssetBundleRequest assetBundleRequest = ao as AssetBundleRequest;
                if (assetBundleRequest != null)
                {
                    OnAssetLoadCompleted(assetBundleRequest.GetHashCode(), assetBundleRequest.asset);
                }
            };

            return(abReq.GetHashCode());
        }
        return(0);
    }
Ejemplo n.º 3
0
    /// <summary>
    /// 请求实例化
    /// </summary>
    /// <param name="_defaultSelfActive">默认激活状态</param>
    /// <param name="_input">输入</param>
    /// <param name="_callback">回调</param>
    /// <param name="_extraParameter">额外参数</param>
    /// <param name="_type">资源类型</param>
    /// <param name="_assetBundle">资源包</param>
    public void RequestInstantiate(bool _defaultSelfActive, IAssetBundleInput _input,
                                   Action <IAssetBundleResult> _callback, object[] _extraParameter, Type _type, AssetBundle _assetBundle)
    {
        int key = _type.GetHashCode();

        if (!mQueueResultCallback.ContainsKey(key))
        {
            mQueueResultCallback.Add(key, new Queue <ResultCallback>());
        }
        mQueueResultCallback[key].Enqueue(new ResultCallback(_defaultSelfActive, _input, _callback, _extraParameter));
        if (!mExecuteQueueResultCallback.ContainsKey(key))
        {
            mExecuteQueueResultCallback.Add(key, false);
        }
        if (mAssetMaping.ContainsKey(key) && mAssetMaping[key] == null)
        {
            mHasRequest.Remove(key);
        }
        if (!mHasRequest.Contains(key))
        {
            mHasRequest.Add(key);
            if (!mFileParameter.isUseAssetBundle)
            {
#if UNITY_EDITOR
                UnityEngine.Object obj = AssetDatabase.LoadAssetAtPath(mFileParameter.assetBundlePath, _type);
                mAssetMaping.Add(key, obj);
                OnCallQueue(key);
#endif
            }
            else if (!mRequestKeyForTypeKeyMaping.ContainsKey(key))
            {
                AssetBundleRequest request = _assetBundle.LoadAssetAsync(_input.config.fileName, _type);
                request.allowSceneActivation = false;
                request.completed           += Request_completed;
                int reqKey = request.GetHashCode();
                mRequestKeyForTypeKeyMaping.Add(reqKey, key);
            }
        }
        else
        {
            OnCallQueue(key);
        }
    }
Ejemplo n.º 4
0
        public override int GetHashCode()
        {
            unchecked
            {
                var hashCode = (AssetBundle != null ? AssetBundle.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ AssetBundleInfo.GetHashCode();
                hashCode = (hashCode * 397) ^ (loadedAssets != null ? loadedAssets.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (LoadRequest != null ? LoadRequest.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (LoadAssetRequest != null ? LoadAssetRequest.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (SceneRequest != null ? SceneRequest.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (UnloadSceneRequest != null ? UnloadSceneRequest.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (int)_status;
#if UNITY_EDITOR
                hashCode = (hashCode * 397) ^ offset;
                hashCode = (hashCode * 397) ^ (history != null ? history.GetHashCode() : 0);
#endif
                hashCode = (hashCode * 397) ^ _userReference;
                hashCode = (hashCode * 397) ^ (References != null ? References.GetHashCode() : 0);
                return(hashCode);
            }
        }