public AssetBundleStateChangedEventArgs(string assetBundleName, AssetBundleDownloadState state, string error = null)
 {
     AssetBundleName = assetBundleName;
     State           = state;
     Error           = error;
     IsRetry         = error != null;
 }
        public Bundle[] GetBundlesInState <T>(AssetBundleDownloadState downloadState) where T : Bundle
        {
            List <Bundle> bundles = new List <Bundle>();

            foreach (KeyValuePair <string, Bundle> item in m_bundleQueue)
            {
                if (item.Value is T && item.Value.state == downloadState)
                {
                    bundles.Add(item.Value);
                }
            }

            return(bundles.ToArray());
        }
        public AssetBundleDownloadState GetOverallStateOfAssetBundles(Bundle[] assetBundles)
        {
            if (assetBundles != null)
            {
                AssetBundleDownloadState state = AssetBundleDownloadState.Loadable;

                for (int i = 0; i < assetBundles.Length; i++)
                {
                    if (assetBundles[i].state < state)
                    {
                        state = assetBundles[i].state;
                    }
                    else if (assetBundles[i].state == AssetBundleDownloadState.Blocked)
                    {
                        return(AssetBundleDownloadState.Blocked);
                    }
                }
                return(state);
            }
            return(AssetBundleDownloadState.Initialising);
        }
Beispiel #4
0
        public void OnAssetBundleStateChanged(AssetBundleStateChangedEventArgs eventArgs)
        {
            if (state != eventArgs.State && !IsBundleLoaded())
            {
                AssetBundleDownloadState oldState = state;
                if (state == AssetBundleDownloadState.NotBundled)
                {
                    Debug.LogError(String.Format("AssetBundle: {0} is not bundled but it's state is changing to {1}", m_assetBundleName, eventArgs.State));
                }
                //isretry is determined from errors in the state
                Debug.Log("State change: " + this + " > " + eventArgs.State + ", " + eventArgs.Error);
                if (eventArgs.IsRetry)
                {
                    downloadRetries++;
                    Debug.Log("OnAssetBundleStateChanged :: " + assetBundleName + " encountered an error. " + downloadRetries + "/3 errors encountered.");
                }
                if (downloadRetries >= 3)
                {
                    Debug.Log("OnAssetBundleStateChanged :: " + assetBundleName + " is assumed to be blocked after 3 retries.");
                    state = AssetBundleDownloadState.Blocked;
                    error = "Attempted download 3 times, failed each time. Stopping";
                    return;
                }
                state = eventArgs.State;
                error = eventArgs.Error;

                if (OnStateChanged != null)
                {
                    OnStateChanged(oldState, state);
                }
                //EventManager<Events>.Instance.TriggerEvent(Events.BundleStateChanged, this);
                if (state == AssetBundleDownloadState.Loadable)
                {
                    m_overrideDownloadPriority = DownloadPriority.Medium;
                    m_downloadPriority         = DownloadPriority.Medium;
                }
            }
        }
        private void AssetBundlesDownloadRequested(Bundle[] bundles)
        {
            AssetBundleDownloadState state = GetOverallStateOfAssetBundles(bundles);

            switch (state)
            {
            case AssetBundleDownloadState.Blocked:
                ShowBlockedStateMessage(bundles);
                break;

            case AssetBundleDownloadState.Queued:
            case AssetBundleDownloadState.Downloading:
            case AssetBundleDownloadState.CRCCheck:
                ShowDownloadingStateMessages(bundles);
                OnBundlesRequestedByUser(bundles);
                break;

            default:
                Debug.LogWarning("User hit play but they are in unhandled asset bundle state. Assuming dodgy internet: bundles are in state: " + state.ToString());
                InitialisingDownloadMessage();
                break;
            }
        }
 public Bundle[] GetBundlesInState <T>(AssetBundleDownloadState downloadState) where T : Bundle
 {
     return(null);
 }