예제 #1
0
        private void DrawSourceAssetsMenu()
        {
            HashSet <SourceAsset> selectedSourceAssets = GetSelectedSourceAssets();

            EditorGUI.BeginDisabledGroup(m_SelectedAssetBundle == null || selectedSourceAssets.Count <= 0);
            {
                if (GUILayout.Button(Utility.Text.Format("<< {0}", selectedSourceAssets.Count.ToString()), GUILayout.Width(80f)))
                {
                    foreach (SourceAsset sourceAsset in selectedSourceAssets)
                    {
                        AssignAsset(sourceAsset, m_SelectedAssetBundle);
                    }

                    m_SelectedSourceAssets.Clear();
                    m_CachedSelectedSourceFolders.Clear();
                }
            }
            EditorGUI.EndDisabledGroup();
            EditorGUI.BeginDisabledGroup(selectedSourceAssets.Count <= 0);
            {
                if (GUILayout.Button(Utility.Text.Format("<<< {0}", selectedSourceAssets.Count.ToString()), GUILayout.Width(80f)))
                {
                    int index = 0;
                    int count = selectedSourceAssets.Count;
                    foreach (SourceAsset sourceAsset in selectedSourceAssets)
                    {
                        EditorUtility.DisplayProgressBar("Add AssetBundles", Utility.Text.Format("{0}/{1} processing...", (++index).ToString(), count.ToString()), (float)index / count);
                        int    dotIndex        = sourceAsset.FromRootPath.IndexOf('.');
                        string assetBundleName = dotIndex > 0 ? sourceAsset.FromRootPath.Substring(0, dotIndex) : sourceAsset.FromRootPath;
                        AddAssetBundle(assetBundleName, null, false);
                        AssetBundle assetBundle = m_Controller.GetAssetBundle(assetBundleName, null);
                        if (assetBundle == null)
                        {
                            continue;
                        }

                        AssignAsset(sourceAsset, assetBundle);
                    }

                    EditorUtility.DisplayProgressBar("Add AssetBundles", "Complete processing...", 1f);
                    RefreshAssetBundleTree();
                    EditorUtility.ClearProgressBar();
                    m_SelectedSourceAssets.Clear();
                    m_CachedSelectedSourceFolders.Clear();
                }
            }
            EditorGUI.EndDisabledGroup();
            bool hideAssignedSourceAssets = EditorGUILayout.ToggleLeft("Hide Assigned", m_HideAssignedSourceAssets, GUILayout.Width(100f));

            if (hideAssignedSourceAssets != m_HideAssignedSourceAssets)
            {
                m_HideAssignedSourceAssets = hideAssignedSourceAssets;
                m_CachedSelectedSourceFolders.Clear();
                m_CachedUnselectedSourceFolders.Clear();
                m_CachedAssignedSourceFolders.Clear();
                m_CachedUnassignedSourceFolders.Clear();
            }

            GUILayout.Label(string.Empty);
            if (GUILayout.Button("Clean", GUILayout.Width(80f)))
            {
                EditorUtility.DisplayProgressBar("Clean", "Processing...", 0f);
                CleanAssetBundle();
                EditorUtility.ClearProgressBar();
            }
            if (GUILayout.Button("Save", GUILayout.Width(80f)))
            {
                EditorUtility.DisplayProgressBar("Save", "Processing...", 0f);
                SaveConfiguration();
                EditorUtility.ClearProgressBar();
            }
        }
예제 #2
0
        private void DrawSourceAssetsMenu()
        {
            HashSet <SourceAsset> selectedSourceAssets = GetSelectedSourceAssets();

            EditorGUI.BeginDisabledGroup(m_SelectedAssetBundle == null || selectedSourceAssets.Count <= 0);
            {
                if (GUILayout.Button(string.Format("<< {0}", selectedSourceAssets.Count.ToString()), GUILayout.Width(80f)))
                {
                    foreach (SourceAsset sourceAsset in selectedSourceAssets)
                    {
                        AssignAsset(sourceAsset, m_SelectedAssetBundle);
                    }

                    m_SelectedSourceAssets.Clear();
                    m_CachedSelectedSourceFolders.Clear();
                }
            }
            EditorGUI.EndDisabledGroup();
            EditorGUI.BeginDisabledGroup(selectedSourceAssets.Count <= 0);
            {
                if (GUILayout.Button(string.Format("<<< {0}", selectedSourceAssets.Count.ToString()), GUILayout.Width(80f)))
                {
                    var types = AppDomain.CurrentDomain.GetAssemblies()
                                .SelectMany(a => a.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IAssetBundleSetting))))
                                .ToArray();

                    IAssetBundleSetting[] AssetbundleCls = new IAssetBundleSetting[types.Length];

                    for (int i = 0; i < types.Length; ++i)
                    {
                        System.Type type = types[i];
                        AssetbundleCls[i] = type.Assembly.CreateInstance(type.FullName) as IAssetBundleSetting;
                    }

                    int index = 0;
                    int count = selectedSourceAssets.Count;
                    foreach (SourceAsset sourceAsset in selectedSourceAssets)
                    {
                        EditorUtility.DisplayProgressBar("Add AssetBundles", string.Format("{0}/{1} processing...", (++index).ToString(), count.ToString()), (float)index / count);
                        int    dotIndex           = sourceAsset.FromRootPath.IndexOf('.');
                        string assetBundleName    = dotIndex > 0 ? sourceAsset.FromRootPath.Substring(0, dotIndex) : sourceAsset.FromRootPath;
                        string assetBundleVariant = null;
                        bool   packed             = false;
                        for (int i = 0; i < AssetbundleCls.Length; ++i)
                        {
                            AssetbundleCls[i].GetAssetBundleName(sourceAsset, ref assetBundleName, ref assetBundleVariant);
                            AssetbundleCls[i].GetAssetBundlePacked(sourceAsset, ref packed);
                        }
                        AddAssetBundle(assetBundleName, assetBundleVariant, false);
                        AssetBundle assetBundle = m_Controller.GetAssetBundle(assetBundleName, assetBundleVariant);

                        if (assetBundle == null)
                        {
                            continue;
                        }
                        assetBundle.SetPacked(packed);
                        AssignAsset(sourceAsset, assetBundle);
                    }

                    EditorUtility.DisplayProgressBar("Add AssetBundles", "Complete processing...", 1f);
                    RefreshAssetBundleTree();
                    EditorUtility.ClearProgressBar();
                    m_SelectedSourceAssets.Clear();
                    m_CachedSelectedSourceFolders.Clear();
                }
            }
            EditorGUI.EndDisabledGroup();
            bool hideAssignedSourceAssets = EditorGUILayout.ToggleLeft("Hide Assigned", m_HideAssignedSourceAssets, GUILayout.Width(100f));

            if (hideAssignedSourceAssets != m_HideAssignedSourceAssets)
            {
                m_HideAssignedSourceAssets = hideAssignedSourceAssets;
                m_CachedSelectedSourceFolders.Clear();
                m_CachedUnselectedSourceFolders.Clear();
                m_CachedAssignedSourceFolders.Clear();
                m_CachedUnassignedSourceFolders.Clear();
            }

            GUILayout.Label(string.Empty);
            if (GUILayout.Button("Clean", GUILayout.Width(80f)))
            {
                EditorUtility.DisplayProgressBar("Clean", "Processing...", 0f);
                CleanAssetBundle();
                EditorUtility.ClearProgressBar();
            }
            if (GUILayout.Button("Save", GUILayout.Width(80f)))
            {
                EditorUtility.DisplayProgressBar("Save", "Processing...", 0f);
                SaveConfiguration();
                EditorUtility.ClearProgressBar();
            }
        }