示例#1
0
        private void BeginOperation()
        {
            string path = m_ProvideHandle.Location.InternalId;

            if (File.Exists(path))
            {
                m_RequestOperation            = AssetBundle.LoadFromFileAsync(path, m_Options == null ? 0 : m_Options.Crc);
                m_RequestOperation.completed += LocalRequestOperationCompleted;
            }
            else if (ResourceManagerConfig.ShouldPathUseWebRequest(path))
            {
                var req = CreateWebRequest(m_ProvideHandle.Location);
                req.disposeDownloadHandlerOnDispose = false;
                m_WebRequestQueueOperation          = WebRequestQueue.QueueRequest(req);
                if (m_WebRequestQueueOperation.IsDone)
                {
                    m_RequestOperation            = m_WebRequestQueueOperation.Result;
                    m_RequestOperation.completed += WebRequestOperationCompleted;
                }
                else
                {
                    m_WebRequestQueueOperation.OnComplete += asyncOp =>
                    {
                        m_RequestOperation            = asyncOp;
                        m_RequestOperation.completed += WebRequestOperationCompleted;
                    };
                }
            }
            else
            {
                m_RequestOperation = null;
                m_ProvideHandle.Complete <AssetBundleResource>(null, false, new Exception(string.Format("Invalid path in AssetBundleProvider: '{0}'.", path)));
            }
        }
        public override void Provide(ProvideHandle pi)
        {
            Type t          = pi.Type;
            bool isList     = t.IsGenericType && typeof(IList <>) == t.GetGenericTypeDefinition();
            var  internalId = pi.ResourceManager.TransformInternalId(pi.Location);

            if (t.IsArray || isList)
            {
                object result = null;
                if (t.IsArray)
                {
                    result = ResourceManagerConfig.CreateArrayResult(t, Resources.LoadAll(internalId, t.GetElementType()));
                }
                else
                {
                    result = ResourceManagerConfig.CreateListResult(t, Resources.LoadAll(internalId, t.GetGenericArguments()[0]));
                }

                pi.Complete(result, result != null, null);
            }
            else
            {
                string assetPath = internalId;
                var    i         = assetPath.LastIndexOf('[');
                if (i > 0)
                {
                    var i2 = assetPath.LastIndexOf(']');
                    if (i2 < i)
                    {
                        pi.Complete <AssetBundle>(null, false, new Exception(string.Format("Invalid index format in internal id {0}", assetPath)));
                    }
                    else
                    {
                        var subObjectName = assetPath.Substring(i + 1, i2 - (i + 1));
                        assetPath = assetPath.Substring(0, i);
                        var    objs   = Resources.LoadAll(assetPath, pi.Type);
                        object result = null;
                        foreach (var o in objs)
                        {
                            if (o.name == subObjectName)
                            {
                                if (pi.Type.IsAssignableFrom(o.GetType()))
                                {
                                    result = o;
                                    break;
                                }
                            }
                        }
                        pi.Complete(result, result != null, null);
                    }
                }
                else
                {
                    new InternalOp().Start(pi);
                }
            }
        }
示例#3
0
            public void Start(ProvideHandle provideHandle, TextDataProvider rawProvider, bool ignoreFailures)
            {
                m_PI = provideHandle;
                provideHandle.SetProgressCallback(GetPercentComplete);
                m_Provider       = rawProvider;
                m_IgnoreFailures = ignoreFailures;
                var path = m_PI.ResourceManager.TransformInternalId(m_PI.Location);

                if (File.Exists(path))
                {
#if NET_4_6
                    if (path.Length >= 260)
                    {
                        path = @"\\?\" + path;
                    }
#endif
                    var    text   = File.ReadAllText(path);
                    object result = m_Provider.Convert(m_PI.Type, text);
                    m_PI.Complete(result, result != null, result == null ? new Exception($"Unable to load asset of type {m_PI.Type} from location {m_PI.Location}.") : null);
                }
                else if (ResourceManagerConfig.ShouldPathUseWebRequest(path))
                {
                    UnityWebRequest request = new UnityWebRequest(path, UnityWebRequest.kHttpVerbGET, new DownloadHandlerBuffer(), null);
                    m_RequestQueueOperation = WebRequestQueue.QueueRequest(request);
                    if (m_RequestQueueOperation.IsDone)
                    {
                        m_RequestOperation = m_RequestQueueOperation.Result;
                        if (m_RequestOperation.isDone)
                        {
                            RequestOperation_completed(m_RequestOperation);
                        }
                        else
                        {
                            m_RequestOperation.completed += RequestOperation_completed;
                        }
                    }
                    else
                    {
                        m_RequestQueueOperation.OnComplete += asyncOperation =>
                        {
                            m_RequestOperation            = asyncOperation;
                            m_RequestOperation.completed += RequestOperation_completed;
                        };
                    }
                }
                else
                {
                    Exception exception = null;
                    //Don't log errors when loading from the persistentDataPath since these files are expected to not exist until created
                    if (!m_IgnoreFailures)
                    {
                        exception = new Exception(string.Format("Invalid path in " + nameof(TextDataProvider) + " : '{0}'.", path));
                    }
                    m_PI.Complete <object>(null, m_IgnoreFailures, exception);
                }
            }
            public void Start(ProvideHandle provideHandle, TextDataProvider rawProvider)
            {
                m_PI = provideHandle;
                m_PI.SetWaitForCompletionCallback(WaitForCompletionHandler);
                provideHandle.SetProgressCallback(GetPercentComplete);
                m_Provider = rawProvider;

                // override input options with options from Location if included
                if (m_PI.Location.Data is ProviderLoadRequestOptions providerData)
                {
                    m_IgnoreFailures = providerData.IgnoreFailures;
                    m_Timeout        = providerData.WebRequestTimeout;
                }
                else
                {
                    m_IgnoreFailures = rawProvider.IgnoreFailures;
                    m_Timeout        = 0;
                }

                var path = m_PI.ResourceManager.TransformInternalId(m_PI.Location);

                if (File.Exists(path))
                {
#if NET_4_6
                    if (path.Length >= 260)
                    {
                        path = @"\\?\" + path;
                    }
#endif
                    var    text   = File.ReadAllText(path);
                    object result = ConvertText(text);
                    m_PI.Complete(result, result != null, result == null ? new Exception($"Unable to load asset of type {m_PI.Type} from location {m_PI.Location}.") : null);
                    m_Complete = true;
                }
                else if (ResourceManagerConfig.ShouldPathUseWebRequest(path))
                {
                    SendWebRequest(path);
                }
                else
                {
                    Exception exception = null;
                    //Don't log errors when loading from the persistentDataPath since these files are expected to not exist until created
                    if (m_IgnoreFailures)
                    {
                        m_PI.Complete <object>(null, true, exception);
                        m_Complete = true;
                    }
                    else
                    {
                        exception = new Exception(string.Format("Invalid path in " + nameof(TextDataProvider) + " : '{0}'.", path));
                        m_PI.Complete <object>(null, false, exception);
                        m_Complete = true;
                    }
                }
            }
示例#5
0
            public void Start(ProvideHandle provideHandle)
            {
                provideHandle.SetProgressCallback(ProgressCallback);
                subObjectName      = null;
                m_ProvideHandle    = provideHandle;
                m_RequestOperation = null;
                List <object> deps = new List <object>(); // TODO: garbage. need to pass actual count and reuse the list

                m_ProvideHandle.GetDependencies(deps);
                AssetBundle bundle = LoadBundleFromDependecies(deps);

                if (bundle == null)
                {
                    m_ProvideHandle.Complete <AssetBundle>(null, false, new Exception("Unable to load dependent bundle from location " + m_ProvideHandle.Location));
                }
                else
                {
                    var assetPath = m_ProvideHandle.Location.InternalId;
                    if (m_ProvideHandle.Type.IsArray)
                    {
                        m_RequestOperation = bundle.LoadAssetWithSubAssetsAsync(assetPath, m_ProvideHandle.Type.GetElementType());
                    }
                    else if (m_ProvideHandle.Type.IsGenericType && typeof(IList <>) == m_ProvideHandle.Type.GetGenericTypeDefinition())
                    {
                        m_RequestOperation = bundle.LoadAssetWithSubAssetsAsync(assetPath, m_ProvideHandle.Type.GetGenericArguments()[0]);
                    }
                    else
                    {
                        var i = assetPath.LastIndexOf('[');
                        if (i > 0)
                        {
                            var i2 = assetPath.LastIndexOf(']');
                            if (i2 < i)
                            {
                                m_ProvideHandle.Complete <AssetBundle>(null, false, new Exception(string.Format("Invalid index format in internal id {0}", assetPath)));
                            }
                            else
                            {
                                subObjectName      = assetPath.Substring(i + 1, i2 - (i + 1));
                                assetPath          = assetPath.Substring(0, i);
                                m_RequestOperation = bundle.LoadAssetWithSubAssetsAsync(assetPath, m_ProvideHandle.Type);
                            }
                        }
                        else
                        {
                            m_RequestOperation = bundle.LoadAssetAsync(assetPath, m_ProvideHandle.Type);
                        }
                    }
                    m_RequestOperation.completed += ActionComplete;
                }
            }
示例#6
0
        /// <inheritdoc/>
        public override void Provide(ProvideHandle providerInterface)
        {
            var atlas = providerInterface.GetDependency <SpriteAtlas>(0);

            if (atlas == null)
            {
                providerInterface.Complete <Sprite>(null, false, new System.Exception($"Sprite atlas failed to load for location {providerInterface.Location.PrimaryKey}."));
                return;
            }

            var sprite = atlas.GetSprite(providerInterface.ResourceManager.TransformInternalId(providerInterface.Location));

            providerInterface.Complete(sprite, sprite != null, sprite != null ? null : new System.Exception($"Sprite failed to load for location {providerInterface.Location.PrimaryKey}."));
        }
            void LoadImmediate()
            {
                string assetPath = m_ProvideHandle.Location == null ? string.Empty : m_ProvideHandle.Location.InternalId;

                object result = null;

                if (m_ProvideHandle.Type.IsArray)
                {
                    result = ResourceManagerConfig.CreateArrayResult(m_ProvideHandle.Type, AssetDatabase.LoadAllAssetRepresentationsAtPath(assetPath));
                }
                else if (m_ProvideHandle.Type.IsGenericType && typeof(IList <>) == m_ProvideHandle.Type.GetGenericTypeDefinition())
                {
                    result = ResourceManagerConfig.CreateListResult(m_ProvideHandle.Type, AssetDatabase.LoadAllAssetRepresentationsAtPath(assetPath));
                }
                else
                {
                    var i = assetPath.LastIndexOf('[');
                    if (i > 0)
                    {
                        var i2 = assetPath.LastIndexOf(']');
                        if (i2 < i)
                        {
                            m_ProvideHandle.Complete(result, false, new Exception(string.Format("Invalid index format in internal id {0}", assetPath)));
                        }
                        else
                        {
                            var subObjectName = assetPath.Substring(i + 1, i2 - (i + 1));
                            assetPath = assetPath.Substring(0, i);
                            var objs = AssetDatabase.LoadAllAssetRepresentationsAtPath(assetPath);
                            foreach (var o in objs)
                            {
                                if (o.name == subObjectName)
                                {
                                    if (m_ProvideHandle.Type.IsAssignableFrom(o.GetType()))
                                    {
                                        result = o;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        var obj = AssetDatabase.LoadAssetAtPath(assetPath, m_ProvideHandle.Location.ResourceType);
                        result = obj != null && m_ProvideHandle.Type.IsAssignableFrom(obj.GetType()) ? obj : null;
                    }
                }
                m_ProvideHandle.Complete(result, result != null, null);
            }
            void LoadImmediate()
            {
                string assetPath = m_ProvideHandle.Location == null ? string.Empty : m_ProvideHandle.Location.InternalId;

                object result = null;

                if (m_ProvideHandle.Type.IsArray)
                {
                    result = ResourceManagerConfig.CreateArrayResult(m_ProvideHandle.Type, AssetDatabase.LoadAllAssetRepresentationsAtPath(assetPath));
                }
                else if (m_ProvideHandle.Type.IsGenericType && typeof(IList <>) == m_ProvideHandle.Type.GetGenericTypeDefinition())
                {
                    result = ResourceManagerConfig.CreateListResult(m_ProvideHandle.Type, AssetDatabase.LoadAllAssetRepresentationsAtPath(assetPath));
                }
                else
                {
                    var    mainType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
                    Object obj      = null;
                    if (mainType == typeof(Texture2D) && m_ProvideHandle.Type == typeof(Sprite))
                    {
                        obj = AssetDatabase.LoadAssetAtPath(assetPath, m_ProvideHandle.Type);
                    }
                    else if (mainType == typeof(GameObject) && m_ProvideHandle.Type == typeof(Mesh))
                    {
                        obj = AssetDatabase.LoadAssetAtPath(assetPath, m_ProvideHandle.Type);
                    }
                    else
                    {
                        obj = AssetDatabase.LoadAssetAtPath(assetPath, mainType);
                    }

                    result = obj != null && m_ProvideHandle.Type.IsAssignableFrom(obj.GetType()) ? obj : null;
                }
                m_ProvideHandle.Complete(result, result != null, null);
            }
            public void Start(ProvideHandle provideHandle)
            {
                provideHandle.SetProgressCallback(ProgressCallback);
                subObjectName      = null;
                m_ProvideHandle    = provideHandle;
                m_RequestOperation = null;
                List <object> deps = new List <object>(); // TODO: garbage. need to pass actual count and reuse the list

                m_ProvideHandle.GetDependencies(deps);
                AssetBundle bundle = LoadBundleFromDependecies(deps);

                if (bundle == null)
                {
                    m_ProvideHandle.Complete <AssetBundle>(null, false, new Exception("Unable to load dependent bundle from location " + m_ProvideHandle.Location));
                }
                else
                {
                    var assetPath = m_ProvideHandle.ResourceManager.TransformInternalId(m_ProvideHandle.Location);
                    if (m_ProvideHandle.Type.IsArray)
                    {
                        m_RequestOperation = bundle.LoadAssetWithSubAssetsAsync(assetPath, m_ProvideHandle.Type.GetElementType());
                    }
                    else if (m_ProvideHandle.Type.IsGenericType && typeof(IList <>) == m_ProvideHandle.Type.GetGenericTypeDefinition())
                    {
                        m_RequestOperation = bundle.LoadAssetWithSubAssetsAsync(assetPath, m_ProvideHandle.Type.GetGenericArguments()[0]);
                    }
                    else
                    {
                        if (ResourceManagerConfig.ExtractKeyAndSubKey(assetPath, out string mainPath, out string subKey))
                        {
                            subObjectName      = subKey;
                            m_RequestOperation = bundle.LoadAssetWithSubAssetsAsync(mainPath, m_ProvideHandle.Type);
                        }
示例#10
0
            private void RequestOperation_completed(AsyncOperation op)
            {
                var       webOp     = op as UnityWebRequestAsyncOperation;
                object    result    = null;
                Exception exception = null;

                if (webOp != null)
                {
                    var webReq = webOp.webRequest;
                    if (string.IsNullOrEmpty(webReq.error))
                    {
                        result = m_Provider.Convert(m_PI.Type, webReq.downloadHandler.text);
                    }
                    else
                    {
                        exception = new Exception(string.Format(nameof(TextDataProvider) + " unable to load from url {0}, result='{1}'.", webReq.url, webReq.error));
                    }
                }
                else
                {
                    exception = new Exception(nameof(TextDataProvider) + " unable to load from unknown url.");
                }

                m_PI.Complete(result, result != null || m_IgnoreFailures, exception);
            }
            private void AsyncOperationCompleted(AsyncOperation op)
            {
                var    request = op as ResourceRequest;
                object result  = request != null ? request.asset : null;

                result = result != null && m_ProvideHandle.Type.IsAssignableFrom(result.GetType()) ? result : null;
                m_ProvideHandle.Complete(result, result != null, result == null ? new Exception($"Unable to load asset of type {m_ProvideHandle.Type} from location {m_ProvideHandle.Location}.") : null);
            }
            private void AsyncOperationCompleted(AsyncOperation op)
            {
                var    request = op as ResourceRequest;
                object result  = request != null ? request.asset : null;

                result = result != null && m_PI.Type.IsAssignableFrom(result.GetType()) ? result : null;
                m_PI.Complete(result, result != null, null);
            }
示例#13
0
        /// <inheritdoc/>
        public override void Provide(ProvideHandle providerInterface)
        {
            var atlas = providerInterface.GetDependency <SpriteAtlas>(0);

            if (atlas == null)
            {
                providerInterface.Complete <Sprite>(null, false, new System.Exception($"Sprite atlas failed to load for location {providerInterface.Location.PrimaryKey}."));
                return;
            }

            var key = providerInterface.ResourceManager.TransformInternalId(providerInterface.Location);

            ResourceManagerConfig.ExtractKeyAndSubKey(key, out string mainKey, out string subKey);
            string spriteKey = string.IsNullOrEmpty(subKey) ? mainKey : subKey;
            var    sprite    = atlas.GetSprite(spriteKey);

            providerInterface.Complete(sprite, sprite != null, sprite != null ? null : new System.Exception($"Sprite failed to load for location {providerInterface.Location.PrimaryKey}."));
        }
        /// <inheritdoc/>
        public override void Provide(ProvideHandle providerInterface)
        {
            var atlas = providerInterface.GetDependency <SpriteAtlas>(0);

            if (atlas == null)
            {
                providerInterface.Complete <Sprite>(null, false, new System.Exception(string.Format("Sprite atlas failed to load for location {0}.", providerInterface.Location.PrimaryKey)));
                return;
            }

            var sprite = atlas.GetSprite(providerInterface.Location.InternalId);

            if (sprite == null)
            {
                providerInterface.Complete <Sprite>(null, false, new System.Exception(string.Format("Sprite failed to load for location {0}.", providerInterface.Location.PrimaryKey)));
                return;
            }
            providerInterface.Complete(sprite, sprite != null, null);
        }
            protected void CompleteOperation(string text, Exception exception)
            {
                object result = null;

                if (!string.IsNullOrEmpty(text))
                {
                    result = ConvertText(text);
                }

                m_PI.Complete(result, result != null || m_IgnoreFailures, exception);
                m_Complete = true;
            }
            public void Start(ProvideHandle provideHandle)
            {
                provideHandle.SetProgressCallback(ProgressCallback);
                provideHandle.SetWaitForCompletionCallback(WaitForCompletionHandler);
                subObjectName      = null;
                m_ProvideHandle    = provideHandle;
                m_RequestOperation = null;
                List <object> deps = new List <object>(); // TODO: garbage. need to pass actual count and reuse the list

                m_ProvideHandle.GetDependencies(deps);
                var bundleResource = LoadBundleFromDependecies <IAssetBundleResource>(deps);

                if (bundleResource == null)
                {
                    m_ProvideHandle.Complete <AssetBundle>(null, false, new Exception("Unable to load dependent bundle from location " + m_ProvideHandle.Location));
                }
                else
                {
                    m_AssetBundle = bundleResource.GetAssetBundle();
                    if (m_AssetBundle == null)
                    {
                        m_ProvideHandle.Complete <AssetBundle>(null, false, new Exception("Unable to load dependent bundle from location " + m_ProvideHandle.Location));
                        return;
                    }

                    var assetBundleResource = bundleResource as AssetBundleResource;
                    if (assetBundleResource != null)
                    {
                        m_PreloadRequest = assetBundleResource.GetAssetPreloadRequest();
                    }
                    if (m_PreloadRequest == null || m_PreloadRequest.isDone)
                    {
                        BeginAssetLoad();
                    }
                    else
                    {
                        m_PreloadRequest.completed += operation => BeginAssetLoad();
                    }
                }
            }
        public override void Provide(ProvideHandle pi)
        {
            Type t          = pi.Type;
            bool isList     = t.IsGenericType && typeof(IList <>) == t.GetGenericTypeDefinition();
            var  internalId = pi.ResourceManager.TransformInternalId(pi.Location);

            if (t.IsArray || isList)
            {
                object result = null;
                if (t.IsArray)
                {
                    result = ResourceManagerConfig.CreateArrayResult(t, Resources.LoadAll(internalId, t.GetElementType()));
                }
                else
                {
                    result = ResourceManagerConfig.CreateListResult(t, Resources.LoadAll(internalId, t.GetGenericArguments()[0]));
                }

                pi.Complete(result, result != null, result == null ? new Exception($"Unable to load asset of type {pi.Type} from location {pi.Location}.") : null);
            }
            else
            {
                if (ResourceManagerConfig.ExtractKeyAndSubKey(internalId, out string mainPath, out string subKey))
                {
                    var    objs   = Resources.LoadAll(mainPath, pi.Type);
                    object result = null;
                    foreach (var o in objs)
                    {
                        if (o.name == subKey)
                        {
                            if (pi.Type.IsAssignableFrom(o.GetType()))
                            {
                                result = o;
                                break;
                            }
                        }
                    }
                    pi.Complete(result, result != null, result == null ? new Exception($"Unable to load asset of type {pi.Type} from location {pi.Location}.") : null);
                }
        private void BeginOperation()
        {
            string path = m_ProvideHandle.Location.InternalId;

            if (File.Exists(path))
            {
                m_RequestOperation            = AssetBundle.LoadFromFileAsync(path, m_Options == null ? 0 : m_Options.Crc);
                m_RequestOperation.completed += LocalRequestOperationCompleted;
            }
            else if (path.Contains("://"))
            {
                var req = CreateWebRequest(m_ProvideHandle.Location);
                req.disposeDownloadHandlerOnDispose = false;
                m_RequestOperation            = req.SendWebRequest();
                m_RequestOperation.completed += WebRequestOperationCompleted;
            }
            else
            {
                m_RequestOperation = null;
                m_ProvideHandle.Complete <AssetBundleResource>(null, false, new Exception(string.Format("Invalid path in AssetBundleProvider: '{0}'.", path)));
            }
        }
示例#19
0
            public void Start(ProvideHandle provideHandle, TextDataProvider rawProvider, bool ignoreFailures)
            {
                m_PI = provideHandle;
                provideHandle.SetProgressCallback(GetPercentComplete);
                m_Provider       = rawProvider;
                m_IgnoreFailures = ignoreFailures;
                var path = m_PI.Location.InternalId;

                if (File.Exists(path))
                {
#if NET_4_6
                    if (path.Length >= 260)
                    {
                        path = @"\\?\" + path;
                    }
#endif
                    var    text   = File.ReadAllText(path);
                    object result = m_Provider.Convert(m_PI.Type, text);
                    m_PI.Complete(result, result != null, null);
                }
                else if (ResourceManagerConfig.ShouldPathUseWebRequest(path))
                {
                    m_RequestOperation            = new UnityWebRequest(path, UnityWebRequest.kHttpVerbGET, new DownloadHandlerBuffer(), null).SendWebRequest();
                    m_RequestOperation.completed += RequestOperation_completed;
                }
                else
                {
                    Exception exception = null;
                    //Don't log errors when loading from the persistentDataPath since these files are expected to not exist until created
                    if (!m_IgnoreFailures)
                    {
                        exception = new Exception(string.Format("Invalid path in RawDataProvider: '{0}'.", path));
                    }
                    m_PI.Complete <object>(null, false, exception);
                }
            }
            private void BeginAssetLoad()
            {
                if (m_AssetBundle == null)
                {
                    m_ProvideHandle.Complete <AssetBundle>(null, false, new Exception("Unable to load dependent bundle from location " + m_ProvideHandle.Location));
                }
                else
                {
                    var assetPath = m_ProvideHandle.ResourceManager.TransformInternalId(m_ProvideHandle.Location);
                    if (m_ProvideHandle.Type.IsArray)
                    {
#if !UNITY_2021_1_OR_NEWER
                        if (AsyncOperationHandle.IsWaitingForCompletion)
                        {
                            GetArrayResult(m_AssetBundle.LoadAssetWithSubAssets(assetPath, m_ProvideHandle.Type.GetElementType()));
                            CompleteOperation();
                        }
                        else
#endif
                        m_RequestOperation = m_AssetBundle.LoadAssetWithSubAssetsAsync(assetPath, m_ProvideHandle.Type.GetElementType());
                    }
                    else if (m_ProvideHandle.Type.IsGenericType && typeof(IList <>) == m_ProvideHandle.Type.GetGenericTypeDefinition())
                    {
#if !UNITY_2021_1_OR_NEWER
                        if (AsyncOperationHandle.IsWaitingForCompletion)
                        {
                            GetListResult(m_AssetBundle.LoadAssetWithSubAssets(assetPath, m_ProvideHandle.Type.GetGenericArguments()[0]));
                            CompleteOperation();
                        }
                        else
#endif
                        m_RequestOperation = m_AssetBundle.LoadAssetWithSubAssetsAsync(assetPath, m_ProvideHandle.Type.GetGenericArguments()[0]);
                    }
                    else
                    {
                        if (ResourceManagerConfig.ExtractKeyAndSubKey(assetPath, out string mainPath, out string subKey))
                        {
                            subObjectName = subKey;
#if !UNITY_2021_1_OR_NEWER
                            if (AsyncOperationHandle.IsWaitingForCompletion)
                            {
                                GetAssetSubObjectResult(m_AssetBundle.LoadAssetWithSubAssets(mainPath, m_ProvideHandle.Type));
                                CompleteOperation();
                            }
                            else
#endif
                            m_RequestOperation = m_AssetBundle.LoadAssetWithSubAssetsAsync(mainPath, m_ProvideHandle.Type);
                        }
示例#21
0
            private void ActionComplete(AsyncOperation obj)
            {
                object result = null;

                if (m_RequestOperation != null)
                {
                    if (m_ProvideHandle.Type.IsArray)
                    {
                        result = ResourceManagerConfig.CreateArrayResult(m_ProvideHandle.Type, m_RequestOperation.allAssets);
                    }
                    else if (m_ProvideHandle.Type.IsGenericType && typeof(IList <>) == m_ProvideHandle.Type.GetGenericTypeDefinition())
                    {
                        result = ResourceManagerConfig.CreateListResult(m_ProvideHandle.Type, m_RequestOperation.allAssets);
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(subObjectName))
                        {
                            result = (m_RequestOperation.asset != null && m_ProvideHandle.Type.IsAssignableFrom(m_RequestOperation.asset.GetType())) ? m_RequestOperation.asset : null;
                        }
                        else
                        {
                            if (m_RequestOperation.allAssets != null)
                            {
                                foreach (var o in m_RequestOperation.allAssets)
                                {
                                    if (o.name == subObjectName)
                                    {
                                        if (m_ProvideHandle.Type.IsAssignableFrom(o.GetType()))
                                        {
                                            result = o;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                m_ProvideHandle.Complete(result, result != null, null);
            }
            private void ActionComplete(AsyncOperation obj)
            {
                object result = null;
                Type   t      = m_ProvideHandle.Type;

                if (m_RequestOperation != null)
                {
                    if (t.IsArray)
                    {
                        result = ResourceManagerConfig.CreateArrayResult(t, m_RequestOperation.allAssets);
                    }
                    if (t.IsGenericType && typeof(IList <>) == t.GetGenericTypeDefinition())
                    {
                        result = ResourceManagerConfig.CreateListResult(t, m_RequestOperation.allAssets);
                    }
                    else
                    {
                        result = (m_RequestOperation.asset != null && t.IsAssignableFrom(m_RequestOperation.asset.GetType())) ? m_RequestOperation.asset : null;
                    }
                }
                m_ProvideHandle.Complete(result, result != null, null);
            }
            public void Start(ProvideHandle provideHandle)
            {
                m_ProvideHandle = provideHandle;
                Type t = m_ProvideHandle.Type;


                m_RequestOperation = null;

                List <object> deps = new List <object>(); // TODO: garbage. need to pass actual count and reuse the list

                m_ProvideHandle.GetDependencies(deps);
                AssetBundle bundle = AssetBundleProvider.LoadBundleFromDependecies(deps);

                if (bundle == null)
                {
                    m_ProvideHandle.Complete <AssetBundle>(null, false, new Exception("Unable to load dependent bundle from location " + m_ProvideHandle.Location));
                }
                else
                {
                    if (t.IsArray)
                    {
                        m_RequestOperation = bundle.LoadAssetWithSubAssetsAsync(m_ProvideHandle.Location.InternalId, t.GetElementType());
                    }
                    else if (t.IsGenericType && typeof(IList <>) == t.GetGenericTypeDefinition())
                    {
                        m_RequestOperation = bundle.LoadAssetWithSubAssetsAsync(m_ProvideHandle.Location.InternalId, t.GetGenericArguments()[0]);
                    }
                    else
                    {
                        m_RequestOperation = bundle.LoadAssetAsync(m_ProvideHandle.Location.InternalId, t);
                    }

                    m_RequestOperation.completed += ActionComplete;
                    provideHandle.SetProgressCallback(ProgressCallback);
                }
            }
        public override void Provide(ProvideHandle pi)
        {
            Type t      = pi.Type;
            bool isList = t.IsGenericType && typeof(IList <>) == t.GetGenericTypeDefinition();

            if (t.IsArray || isList)
            {
                object result = null;
                if (t.IsArray)
                {
                    result = ResourceManagerConfig.CreateArrayResult(t, Resources.LoadAll(pi.Location.InternalId, t.GetElementType()));
                }
                else
                {
                    result = ResourceManagerConfig.CreateListResult(t, Resources.LoadAll(pi.Location.InternalId, t.GetGenericArguments()[0]));
                }

                pi.Complete(result, result != null, null);
            }
            else
            {
                new InternalOp().Start(pi);
            }
        }