Exemplo n.º 1
0
        public bool AssignAsset(string assetGuid, string assetBundleName, string assetBundleVariant)
        {
            if (string.IsNullOrEmpty(assetGuid))
            {
                return(false);
            }

            if (!IsValidAssetBundleName(assetBundleName, assetBundleVariant))
            {
                return(false);
            }

            AssetBundle assetBundle = GetAssetBundle(assetBundleName, assetBundleVariant);

            if (assetBundle == null)
            {
                return(false);
            }

            string assetName = AssetDatabase.GUIDToAssetPath(assetGuid);

            if (string.IsNullOrEmpty(assetName))
            {
                return(false);
            }

            Asset[] assetsInAssetBundle = assetBundle.GetAssets();
            foreach (Asset assetInAssetBundle in assetsInAssetBundle)
            {
                if (assetInAssetBundle.Name == assetName)
                {
                    continue;
                }

                if (assetInAssetBundle.Name.ToLower() == assetName.ToLower())
                {
                    return(false);
                }
            }

            bool isScene = assetName.EndsWith(PostfixOfScene);

            if (isScene && assetBundle.Type == AssetBundleType.Asset || !isScene && assetBundle.Type == AssetBundleType.Scene)
            {
                return(false);
            }

            Asset asset = GetAsset(assetGuid);

            if (asset == null)
            {
                asset = Asset.Create(assetGuid);
                m_Assets.Add(asset.Guid, asset);
            }

            assetBundle.AssignAsset(asset, isScene);

            return(true);
        }
        public Asset[] GetAssets(string assetBundleName, string assetBundleVariant)
        {
            if (!IsValidAssetBundleName(assetBundleName, assetBundleVariant))
            {
                return(new Asset[0]);
            }

            AssetBundle assetBundle = GetAssetBundle(assetBundleName, assetBundleVariant);

            if (assetBundle == null)
            {
                return(new Asset[0]);
            }

            return(assetBundle.GetAssets());
        }
        public bool RemoveAssetBundle(string assetBundleName, string assetBundleVariant)
        {
            if (!IsValidAssetBundleName(assetBundleName, assetBundleVariant))
            {
                return(false);
            }

            AssetBundle assetBundle = GetAssetBundle(assetBundleName, assetBundleVariant);

            if (assetBundle == null)
            {
                return(false);
            }

            Asset[] assets = assetBundle.GetAssets();
            assetBundle.Clear();
            m_AssetBundles.Remove(assetBundle.FullName);
            foreach (Asset asset in assets)
            {
                m_Assets.Remove(asset.Guid);
            }

            return(true);
        }