Beispiel #1
0
        public AssetBundleAnalyzerController(AssetBundleCollection assetBundleCollection)
        {
            m_AssetBundleCollection = (assetBundleCollection != null ? assetBundleCollection : new AssetBundleCollection());
            m_AssetBundleCollection.OnLoadingAssetBundle += delegate(int index, int count) { OnLoadingAssetBundle?.Invoke(index, count); };
            m_AssetBundleCollection.OnLoadingAsset       += delegate(int index, int count) { OnLoadingAsset?.Invoke(index, count); };
            m_AssetBundleCollection.OnLoadCompleted      += delegate() { OnLoadCompleted?.Invoke(); };

            m_DependencyDatas = new Dictionary <string, DependencyData>();
            m_ScatteredAssets = new Dictionary <string, List <Asset> >();
            m_AnalyzedStamps  = new HashSet <Stamp>();
        }
        public bool Load()
        {
            Clear();

            string configurationName = Utility.Path.GetCombinePath(Application.dataPath, ConfigurationName);

            if (!File.Exists(configurationName))
            {
                return(false);
            }

            try
            {
                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.Load(configurationName);
                XmlNode xmlRoot         = xmlDocument.SelectSingleNode("UnityGameFramework");
                XmlNode xmlCollection   = xmlRoot.SelectSingleNode("AssetBundleCollection");
                XmlNode xmlAssetBundles = xmlCollection.SelectSingleNode("AssetBundles");
                XmlNode xmlAssets       = xmlCollection.SelectSingleNode("Assets");

                XmlNodeList xmlNodeList = null;
                XmlNode     xmlNode     = null;
                int         count       = 0;

                xmlNodeList = xmlAssetBundles.ChildNodes;
                count       = xmlNodeList.Count;
                for (int i = 0; i < count; i++)
                {
                    OnLoadingAssetBundle?.Invoke(i, count);
                    xmlNode = xmlNodeList.Item(i);
                    if (xmlNode.Name != "AssetBundle")
                    {
                        continue;
                    }

                    string assetBundleName    = xmlNode.Attributes.GetNamedItem("Name").Value;
                    string assetBundleVariant = xmlNode.Attributes.GetNamedItem("Variant") != null?xmlNode.Attributes.GetNamedItem("Variant").Value : null;

                    int assetBundleLoadType = 0;
                    if (xmlNode.Attributes.GetNamedItem("LoadType") != null)
                    {
                        int.TryParse(xmlNode.Attributes.GetNamedItem("LoadType").Value, out assetBundleLoadType);
                    }
                    bool assetBundlePacked = false;
                    if (xmlNode.Attributes.GetNamedItem("Packed") != null)
                    {
                        bool.TryParse(xmlNode.Attributes.GetNamedItem("Packed").Value, out assetBundlePacked);
                    }

                    if (!AddAssetBundle(assetBundleName, assetBundleVariant, (AssetBundleLoadType)assetBundleLoadType, assetBundlePacked))
                    {
                        string assetBundleFullName = assetBundleVariant != null?string.Format("{0}.{1}", assetBundleName, assetBundleVariant) : assetBundleName;

                        Debug.LogWarning(string.Format("Can not add AssetBundle '{0}'.", assetBundleFullName));
                        continue;
                    }
                }

                xmlNodeList = xmlAssets.ChildNodes;
                count       = xmlNodeList.Count;
                for (int i = 0; i < count; i++)
                {
                    OnLoadingAsset?.Invoke(i, count);
                    xmlNode = xmlNodeList.Item(i);
                    if (xmlNode.Name != "Asset")
                    {
                        continue;
                    }

                    string assetGuid          = xmlNode.Attributes.GetNamedItem("Guid").Value;
                    string assetBundleName    = xmlNode.Attributes.GetNamedItem("AssetBundleName").Value;
                    string assetBundleVariant = xmlNode.Attributes.GetNamedItem("AssetBundleVariant") != null?xmlNode.Attributes.GetNamedItem("AssetBundleVariant").Value : null;

                    if (!AssignAsset(assetGuid, assetBundleName, assetBundleVariant))
                    {
                        string assetBundleFullName = assetBundleVariant != null?string.Format("{0}.{1}", assetBundleName, assetBundleVariant) : assetBundleName;

                        Debug.LogWarning(string.Format("Can not assign asset '{0}' to AssetBundle '{1}'.", assetGuid, assetBundleFullName));
                        continue;
                    }
                }

                OnLoadCompleted?.Invoke();
                return(true);
            }
            catch
            {
                File.Delete(configurationName);
                OnLoadCompleted?.Invoke();
                return(false);
            }
        }
        public AssetBundleEditorController()
        {
            m_AssetBundleCollection = new AssetBundleCollection();
            m_AssetBundleCollection.OnLoadingAssetBundle += delegate(int index, int count) { OnLoadingAssetBundle?.Invoke(index, count); };
            m_AssetBundleCollection.OnLoadingAsset       += delegate(int index, int count) { OnLoadingAsset?.Invoke(index, count); };
            m_AssetBundleCollection.OnLoadCompleted      += delegate() { OnLoadCompleted?.Invoke(); };

            m_SourceAssetSearchPaths         = new List <string>();
            m_SourceAssetSearchRelativePaths = new List <string>();
            m_SourceAssets                 = new Dictionary <string, SourceAsset>();
            m_SourceAssetRoot              = null;
            m_SourceAssetRootPath          = null;
            m_SourceAssetUnionTypeFilter   = null;
            m_SourceAssetUnionLabelFilter  = null;
            m_SourceAssetExceptTypeFilter  = null;
            m_SourceAssetExceptLabelFilter = null;
            m_AssetSorter = AssetSorterType.Path;

            SourceAssetRootPath = DefaultSourceAssetRootPath;
        }