Exemplo n.º 1
0
        public void AssetDatabaseProvider_LoadAssetAtPath_WhenNotInAssetDatabase_DoesNotThrow()
        {
            var loc = new ResourceLocationBase("name", "id", "providerId", typeof(object));
            ProviderOperation <Object> op = new ProviderOperation <Object>();

            op.Init(m_ResourceManager, null, loc, new AsyncOperationHandle <IList <AsyncOperationHandle> >());
            ProvideHandle handle = new ProvideHandle(m_ResourceManager, op);

            Assert.DoesNotThrow(() => AssetDatabaseProvider.LoadAssetAtPath("doesnotexist", handle));
        }
            public bool Load(long localBandwidth, long remoteBandwidth, float unscaledDeltaTime)
            {
                if (IsDone)
                {
                    return(false);
                }
                var now = m_LastUpdateTime + unscaledDeltaTime;

                if (now > m_LastUpdateTime)
                {
                    m_BytesLoaded   += (long)Math.Ceiling((now - m_LastUpdateTime) * localBandwidth);
                    m_LastUpdateTime = now;
                }
                if (m_BytesLoaded < m_AssetInfo.Size)
                {
                    return(true);
                }
                if (!(Context is IResourceLocation))
                {
                    return(false);
                }
                var    location  = Context as IResourceLocation;
                var    assetPath = m_provideHandle.ResourceManager.TransformInternalId(location);
                object result    = null;

                var pt = m_provideHandle.Type;

                if (pt.IsArray)
                {
                    result = ResourceManagerConfig.CreateArrayResult(pt, AssetDatabaseProvider.LoadAssetsWithSubAssets(assetPath));
                }
                else if (pt.IsGenericType && typeof(IList <>) == pt.GetGenericTypeDefinition())
                {
                    result = ResourceManagerConfig.CreateListResult(pt, AssetDatabaseProvider.LoadAssetsWithSubAssets(assetPath));
                }
                else
                {
                    if (ResourceManagerConfig.ExtractKeyAndSubKey(assetPath, out string mainPath, out string subKey))
                    {
                        var objs = AssetDatabase.LoadAllAssetRepresentationsAtPath(mainPath);
                        foreach (var o in objs)
                        {
                            if (o.name == subKey)
                            {
                                if (pt.IsAssignableFrom(o.GetType()))
                                {
                                    result = o;
                                    break;
                                }
                            }
                        }
                    }
            public bool Load(long localBandwidth, long remoteBandwidth, float unscaledDeltaTime)
            {
                if (IsDone)
                {
                    return(false);
                }
                var now = m_LastUpdateTime + unscaledDeltaTime;

                if (now > m_LastUpdateTime)
                {
                    m_BytesLoaded   += (long)Math.Ceiling((now - m_LastUpdateTime) * localBandwidth);
                    m_LastUpdateTime = now;
                }
                if (m_BytesLoaded < m_AssetInfo.Size)
                {
                    return(true);
                }
                if (!(Context is IResourceLocation))
                {
                    return(false);
                }
                var    location  = Context as IResourceLocation;
                var    assetPath = m_AssetInfo.m_AssetPath;
                object result    = null;

                var pt = m_provideHandle.Type;

                if (pt.IsArray)
                {
                    result = ResourceManagerConfig.CreateArrayResult(pt, AssetDatabaseProvider.LoadAssetsWithSubAssets(assetPath));
                }
                else if (pt.IsGenericType && typeof(IList <>) == pt.GetGenericTypeDefinition())
                {
                    result = ResourceManagerConfig.CreateListResult(pt, AssetDatabaseProvider.LoadAssetsWithSubAssets(assetPath));
                }
                else
                {
                    if (ResourceManagerConfig.ExtractKeyAndSubKey(location.InternalId, out string mainPath, out string subKey))
                    {
                        result = AssetDatabaseProvider.LoadAssetSubObject(assetPath, subKey, pt);
                    }
Exemplo n.º 4
0
 internal static void AddLocations(IList <IResourceLocation> locations, Type type, string keyStr, string internalId)
 {
     if (!string.IsNullOrEmpty(internalId) && !string.IsNullOrEmpty(AssetDatabase.AssetPathToGUID(internalId)))
     {
         if (type == m_SpriteType && AssetDatabase.GetMainAssetTypeAtPath(internalId) == m_SpriteAtlasType)
         {
             locations.Add(new ResourceLocationBase(keyStr, internalId, typeof(AssetDatabaseProvider).FullName, m_SpriteAtlasType));
         }
         else
         {
             foreach (var obj in AssetDatabaseProvider.LoadAssetsWithSubAssets(internalId))
             {
                 var rtt = AddressableAssetUtility.MapEditorTypeToRuntimeType(obj.GetType(), false);
                 if (type.IsAssignableFrom(rtt))
                 {
                     locations.Add(new ResourceLocationBase(keyStr, internalId, typeof(AssetDatabaseProvider).FullName, rtt));
                 }
             }
         }
     }
 }