コード例 #1
0
        private void _UnloadAssetBundleDataWithDepend(int bundleId)
        {
            AssetBundleData bundleData = null;

            if (!m_assetBundleDict.TryGetValue(bundleId, out bundleData))
            {
                return;
            }

            int cur = ResourceMainfest.GetDependFirst(bundleId);

            while (cur != -1)
            {
                int depBundleId = ResourceMainfest.GetDependValue(cur);
                cur = ResourceMainfest.GetDependNext(cur);
                AssetBundleData depBundle = null;
                m_assetBundleDict.TryGetValue(depBundleId, out depBundle);
                if (depBundle != null)
                {
                    depBundle.Release();
                }
            }

            bundleData.Release();
            if (bundleData.Unloadable())
            {
                _UnloadBundleData(bundleData);
            }
        }
コード例 #2
0
        public bool Load()
        {
            BundleState bundleState = ResourceMainfest.GetBundleState((int)Id);

            if (bundleState.bundleId == -1)
            {
                Log.ErrorFormat("[AssetBundleData] bundleState not found bundleId={0}.", Id);
                return(false);
            }

            m_unloadable = !bundleState.canunload && !bundleState.preload;

            string url = ResourceConfig.FormatPath((int)Id, bundleState.export);

            m_assetBundle = AssetBundle.LoadFromFile(url);

            if (m_assetBundle == null)
            {
                Log.ErrorFormat("[AssetBundleData] load asset bundle failed, url={0}", url);
            }
#if ENABLE_PROFILER
            else
            {
                m_assetBundle.name = string.Intern(Id.ToString());
            }
#endif

            return(m_assetBundle != null);
        }
コード例 #3
0
        private void _LoadPreLoadBundle()
        {
            List <BundleState> preLoadList = ResourceMainfest.GetPreloadBundleList();

            for (int i = 0; i < preLoadList.Count; ++i)
            {
                _LoadAssetBundleData(preLoadList[i].bundleId);
            }
        }
コード例 #4
0
        public void Unload(ulong hashID)
        {
            int bundleID = ResourceMainfest.GetBundleID(hashID);

            if (bundleID != -1)
            {
                _UnloadAssetBundleDataWithDepend(bundleID);
            }
        }
コード例 #5
0
 public void Release()
 {
     if (m_refCount == 0)
     {
         string path = ResourceMainfest.GetHashPath(m_id);
         Log.ErrorFormat("[RefCountData] RefCount Error for id={0}, path({1}).", m_id, path == null ? "Unknown" : path);
     }
     m_refCount--;
     m_lastUsedTime = Stopwatch.GetTimestamp();
 }
コード例 #6
0
        private AssetBundleData _LoadAssetBundleDataWithDepend(int bundleId)
        {
            int cur = ResourceMainfest.GetDependFirst(bundleId);

            while (cur != -1)
            {
                int depBundleId = ResourceMainfest.GetDependValue(cur);
                cur = ResourceMainfest.GetDependNext(cur);
                _LoadAssetBundleData(depBundleId);
            }
            return(_LoadAssetBundleData(bundleId));
        }
コード例 #7
0
        public static bool IsBundleExist(string path)
        {
            bool result = false;

            if (Application.isPlaying)
            {
                ulong hash = ResourceHash.FNVHashForPath(path);
                result = ResourceMainfest.IsAssetBundleResource(hash);
            }

            return(result);
        }
コード例 #8
0
        public AssetBundle Load(ulong hashID)
        {
            int bundleID = ResourceMainfest.GetBundleID(hashID);

            if (bundleID == -1)
            {
                return(null);
            }

            AssetBundleData assetBundleData = _LoadAssetBundleDataWithDepend(bundleID);

            return(assetBundleData.GetAssetBundle());
        }
コード例 #9
0
        public Object Load(ulong pathHash, System.Type type)
        {
            ResourceData resourceData = _GetResourceData(pathHash);

            if (resourceData != null)
            {
                Log.Assert(resourceData.type == type);
                resourceData.AddRef();
                return(resourceData.asset);
            }

            Object asset = null;

            if (ResourceMainfest.IsAssetBundleResource(pathHash))
            {
                AssetBundle assetBundle = AssetBundleManager.Instance.Load(pathHash);
                string      name        = ResourceMainfest.GetPathName(pathHash);
                if (assetBundle != null && !string.IsNullOrEmpty(name))
                {
                    asset = assetBundle.LoadAsset(name, type);
                }
                AssetBundleManager.Instance.Unload(pathHash);
            }

            if (asset == null)
            {
                string path = ResourceMainfest.GetHashPath(pathHash);
                if (!string.IsNullOrEmpty(path))
                {
                    asset = Resources.Load(path, type);
                }
            }

            if (asset != null)
            {
                resourceData = new ResourceData(pathHash, type, asset);
                resourceData.AddRef();
                _AddResourceData(resourceData);
            }

            return(asset);
        }
コード例 #10
0
        public override bool TryLoad()
        {
            if (ResourceMainfest.IsAssetBundleResource(Id))
            {
                m_assetBundle = AssetBundleManager.Instance.Load(Id);
            }

            if (m_assetBundle != null)
            {
                string name = ResourceMainfest.GetPathName(Id);
                if (!string.IsNullOrEmpty(name))
                {
                    m_assetBundleRequest = m_assetBundle.LoadAssetAsync(name, m_type);
                    if (m_assetBundleRequest != null)
                    {
                        m_assetBundleRequest.priority = m_priority;
                    }
                }
                if (m_assetBundleRequest == null)
                {
                    return(false);
                }
            }
            else
            {
                string path = ResourceMainfest.GetHashPath(Id);
                if (!string.IsNullOrEmpty(path))
                {
                    m_resourceRequest = Resources.LoadAsync(path, m_type);
                    if (m_resourceRequest != null)
                    {
                        m_resourceRequest.priority = m_priority;
                    }
                }
                if (m_resourceRequest == null)
                {
                    return(false);
                }
            }

            return(base.TryLoad());
        }
コード例 #11
0
        private void _UpdateBundleRef(int bundleId, bool addRef)
        {
            AssetBundleData bundleData = null;

            if (m_assetBundleDict.TryGetValue(bundleId, out bundleData))
            {
                _UpdateBundleDataRef(bundleData, addRef);
            }

            int cur = ResourceMainfest.GetDependFirst(bundleId);

            while (cur != -1)
            {
                int value = ResourceMainfest.GetDependValue(cur);
                cur = ResourceMainfest.GetDependNext(cur);
                if (m_assetBundleDict.TryGetValue(value, out bundleData))
                {
                    _UpdateBundleDataRef(bundleData, addRef);
                }
            }
        }
コード例 #12
0
        public void UnloadUnusedAssets(List <ulong> resHashs)
        {
            for (int i = 0; i < resHashs.Count; ++i)
            {
                int bundleID = ResourceMainfest.GetBundleID(resHashs[i]);
                if (bundleID != -1)
                {
                    _UpdateBundleRef(bundleID, true);
                }
            }

            _UnloadUnloadingAssetBundle(false);

            for (int i = 0; i < resHashs.Count; ++i)
            {
                int bundleID = ResourceMainfest.GetBundleID(resHashs[i]);
                if (bundleID != -1)
                {
                    _UpdateBundleRef(bundleID, false);
                }
            }
        }
コード例 #13
0
 public void ReloadAssetBundle()
 {
     _UnloadUnloadingAssetBundle(true);
     ResourceMainfest.ReloadMainfest();
     _LoadPreLoadBundle();
 }
コード例 #14
0
 public static string HashToPath(ulong pathHash)
 {
     return(ResourceMainfest.GetHashPath(pathHash));
 }
コード例 #15
0
 public static ulong PathToHash(string path)
 {
     return(ResourceMainfest.GetPathHash(path));
 }