Esempio n. 1
0
    private LoadRequest InternalLoadAsync(string name, System.Type type)
    {
        string localizedObjectName = AssetManager.GetLocalizedObjectName(name, false);

        if (name != localizedObjectName)
        {
            if (GameUtility.Config_UseAssetBundles.Value)
            {
                AssetList.Item itemByPath = AssetManager.AssetList.FindItemByPath(localizedObjectName);
                if (itemByPath != null && itemByPath.Exist)
                {
                    name = localizedObjectName;
                }
            }
            else
            {
                name = localizedObjectName;
            }
        }
        AssetManager.ManagedAsset managedAsset = (AssetManager.ManagedAsset)null;
        bool flag     = true;
        int  hashCode = name.GetHashCode();

        for (int index = this.mLoadingAssets.Count - 1; index >= 0; --index)
        {
            if (this.mLoadingAssets[index].HashCode == hashCode && (object)this.mLoadingAssets[index].AssetType == (object)type && this.mLoadingAssets[index].Name == name)
            {
                return((LoadRequest)this.mLoadingAssets[index].Request_Weak.Target);
            }
        }
        for (int index = this.mAssets.Count - 1; index >= 0; --index)
        {
            managedAsset = this.mAssets[index];
            if (managedAsset.HashCode == hashCode && (object)managedAsset.AssetType == (object)type && managedAsset.Name == name)
            {
                if (managedAsset.Asset.IsAlive && Object.op_Inequality(managedAsset.Asset.Target, (Object)null))
                {
                    return((LoadRequest) new ResourceLoadRequest(managedAsset.Asset.Target));
                }
                this.mAssets.RemoveAt(index);
                flag = false;
                break;
            }
        }
        if (flag)
        {
            managedAsset           = new AssetManager.ManagedAsset();
            managedAsset.Name      = name;
            managedAsset.HashCode  = hashCode;
            managedAsset.AssetType = type;
        }
        AssetList.Item itemByPath1 = AssetManager.AssetList.FindItemByPath(name);
        LoadRequest    loadRequest;

        if (itemByPath1 == null)
        {
            loadRequest = !type.IsSubclassOf(typeof(Texture)) ? (LoadRequest) new ResourceLoadRequest(Resources.LoadAsync(name, type)) : (LoadRequest) new FastLoadRequest((AssetList.Item)null, name, type);
        }
        else if (type.IsSubclassOf(typeof(Texture)))
        {
            loadRequest = (LoadRequest) new FastLoadRequest(itemByPath1, name, type);
        }
        else
        {
            managedAsset.AssetBundles = new List <AssetBundleCache>();
            AssetBundleCache assetBundle = this.OpenAssetBundleAndDependencies(itemByPath1, 1, managedAsset.AssetBundles, 0.0f);
            if (assetBundle == null)
            {
                loadRequest           = (LoadRequest) new ResourceLoadRequest((Object)null);
                managedAsset.HasError = true;
            }
            else
            {
                string withoutExtension = Path.GetFileNameWithoutExtension(name);
                loadRequest = (LoadRequest) new AssetBundleLoadRequest(assetBundle, withoutExtension, type);
            }
        }
        managedAsset.Request_Weak   = new WeakReference((object)loadRequest);
        managedAsset.Request_Strong = loadRequest;
        this.mLoadingAssets.Add(managedAsset);
        return(loadRequest);
    }
Esempio n. 2
0
    public Object InternalLoad(string name, System.Type type)
    {
        AssetManager.ManagedAsset managedAsset = (AssetManager.ManagedAsset)null;
        string localizedObjectName             = AssetManager.GetLocalizedObjectName(name, false);

        if (name != localizedObjectName)
        {
            if (GameUtility.Config_UseAssetBundles.Value)
            {
                AssetList.Item itemByPath = AssetManager.AssetList.FindItemByPath(localizedObjectName);
                if (itemByPath != null && itemByPath.Exist)
                {
                    name = localizedObjectName;
                }
            }
            else
            {
                name = localizedObjectName;
            }
        }
        int hashCode = name.GetHashCode();

        for (int index = this.mLoadingAssets.Count - 1; index >= 0; --index)
        {
            if (this.mLoadingAssets[index].HashCode == hashCode && (object)this.mLoadingAssets[index].AssetType == (object)type && this.mLoadingAssets[index].Name == name)
            {
                managedAsset = this.mLoadingAssets[index];
                this.mLoadingAssets.RemoveAt(index);
                this.mAssets.Add(managedAsset);
                managedAsset.Request_Weak   = new WeakReference((object)managedAsset.Request_Strong);
                managedAsset.Request_Strong = (LoadRequest)null;
                managedAsset.Request        = new WeakReference((object)managedAsset.Request2);
                managedAsset.Request2       = (WeakReference)null;
                break;
            }
        }
        if (managedAsset == null)
        {
            for (int index = this.mAssets.Count - 1; index >= 0; --index)
            {
                managedAsset = this.mAssets[index];
                if (managedAsset.HashCode == hashCode && (object)managedAsset.AssetType == (object)type && managedAsset.Name == name)
                {
                    if (managedAsset.Asset.IsAlive)
                    {
                        Object target = managedAsset.Asset.Target;
                        if (Object.op_Inequality(target, (Object)null))
                        {
                            return(target);
                        }
                    }
                    if (managedAsset.HasError)
                    {
                        return((Object)null);
                    }
                    break;
                }
                managedAsset = (AssetManager.ManagedAsset)null;
            }
        }
        if (managedAsset == null)
        {
            managedAsset           = new AssetManager.ManagedAsset();
            managedAsset.Name      = name;
            managedAsset.AssetType = type;
            managedAsset.HashCode  = hashCode;
            this.mAssets.Add(managedAsset);
        }
        AssetList.Item itemByPath1 = AssetManager.AssetList.FindItemByPath(name);
        if (itemByPath1 == null)
        {
            managedAsset.Asset = AssetManager.ObjectRef <Object> .CreateWeakRef(Resources.Load(name, type));
        }
        else
        {
            AssetBundleCache assetBundleCache = this.OpenAssetBundleAndDependencies(itemByPath1, 0, (List <AssetBundleCache>)null, 0.0f);
            if (assetBundleCache != null)
            {
                string withoutExtension = Path.GetFileNameWithoutExtension(name);
                Object @object          = !type.IsSubclassOf(typeof(Component)) ? assetBundleCache.AssetBundle.LoadAsset(withoutExtension, type) : (Object)((GameObject)assetBundleCache.AssetBundle.LoadAsset(withoutExtension)).GetComponent(type);
                managedAsset.Asset = AssetManager.ObjectRef <Object> .CreateStrongRef(@object);

                managedAsset.Asset = AssetManager.ObjectRef <Object> .CreateWeakRef(@object);
            }
            else
            {
                managedAsset.Asset = AssetManager.ObjectRef <Object> .CreateStrongRef((Object)null);
            }
        }
        managedAsset.HasError = Object.op_Equality(managedAsset.Asset.Target, (Object)null);
        if (managedAsset != null)
        {
            return(managedAsset.Asset.Target);
        }
        return((Object)null);
    }
Esempio n. 3
0
    private void Update()
    {
        bool  flag = true;
        float unscaledDeltaTime = Time.get_unscaledDeltaTime();

        for (int index = this.mAssetBundles.Count - 1; index >= 0; --index)
        {
            this.mAssetBundles[index].NumReferencers = 0;
        }
        for (int index = this.mAssets.Count - 1; index >= 0; --index)
        {
            if (this.mAssets[index].Request_Weak == null || !this.mAssets[index].Request_Weak.IsAlive)
            {
                if (this.mAssets[index].Asset.IsStrong)
                {
                    this.mAssets[index].Asset.MakeWeak();
                }
                else if (!this.mAssets[index].Asset.IsAlive)
                {
                    this.mAssets[index].Drop();
                    this.mAssets.RemoveAt(index);
                }
            }
        }
        for (int index = this.mLoadingAssets.Count - 1; index >= 0; --index)
        {
            LoadRequest requestStrong = this.mLoadingAssets[index].Request_Strong;
            requestStrong.KeepSourceAlive();
            if (requestStrong.isDone)
            {
                Object asset = requestStrong.asset;
                AssetManager.ManagedAsset mLoadingAsset = this.mLoadingAssets[index];
                this.mAssets.Add(mLoadingAsset);
                mLoadingAsset.Asset = AssetManager.ObjectRef <Object> .CreateStrongRef(asset);

                mLoadingAsset.HasError       = Object.op_Equality(asset, (Object)null);
                mLoadingAsset.Request_Weak   = new WeakReference((object)requestStrong);
                mLoadingAsset.Request_Strong = (LoadRequest)null;
                this.mAssets.Add(this.mLoadingAssets[index]);
                this.mLoadingAssets[index].Asset = AssetManager.ObjectRef <Object> .CreateStrongRef(asset);

                this.mLoadingAssets[index].HasError = Object.op_Equality(asset, (Object)null);
                this.mLoadingAssets[index].Request  = new WeakReference((object)requestStrong);
                this.mLoadingAssets[index].Request2 = (WeakReference)null;
                this.mLoadingAssets.RemoveAt(index);
                if (Object.op_Inequality(asset, (Object)null))
                {
                    System.Type type = ((object)asset).GetType();
                    mLoadingAsset.IsIndependent = (object)type == (object)typeof(Texture2D) || type.IsSubclassOf(typeof(Texture2D));
                }
            }
        }
        FastLoadRequest.UpdateAll();
        if (this.mSceneRequests.Count > 0)
        {
            flag = false;
        }
        for (int index = 0; index < this.mSceneRequests.Count; ++index)
        {
            if (this.mSceneRequests[index].isDone)
            {
                this.mSceneRequests.RemoveAt(index--);
            }
        }
        if (!flag)
        {
            return;
        }
        this.UpdateAssetBundles(unscaledDeltaTime);
        this.UnloadUnusedAssetBundles(false, false);
    }