private void AssetBundlePopup(Rect rect, int id, IEnumerable <UnityEngine.Object> assets, bool isVariant) { bool flag; List <string> list = new List <string> { "None", "" }; IEnumerable <string> source = this.GetAssetBundlesFromAssets(assets, isVariant, out flag); string[] collection = !isVariant?AssetDatabase.GetAllAssetBundleNamesWithoutVariant() : AssetDatabase.GetAllAssetBundleVariants(); list.AddRange(collection); list.Add(""); int count = list.Count; list.Add("New..."); int num2 = -1; int num3 = -1; if (!isVariant) { num2 = list.Count; list.Add("Remove Unused Names"); num3 = list.Count; if (source.Count <string>() != 0) { list.Add("Filter Selected Name" + (!flag ? "" : "s")); } } int selected = 0; string str = source.FirstOrDefault <string>(); if (!string.IsNullOrEmpty(str)) { selected = list.IndexOf(str); } EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = flag; selected = EditorGUI.DoPopup(rect, id, selected, EditorGUIUtility.TempContent(list.ToArray()), Styles.popup); EditorGUI.showMixedValue = false; if (EditorGUI.EndChangeCheck()) { if (selected == 0) { this.SetAssetBundleForAssets(assets, null, isVariant); } else if (selected == count) { this.ShowNewAssetBundleField(isVariant); } else if (selected == num2) { AssetDatabase.RemoveUnusedAssetBundleNames(); } else if (selected == num3) { this.FilterSelected(source); } else { this.SetAssetBundleForAssets(assets, list[selected], isVariant); } } }
private void AssetBundlePopup(Rect rect, int id, IEnumerable <UnityEngine.Object> assets, bool isVariant) { List <string> stringList = new List <string>(); stringList.Add("None"); stringList.Add(string.Empty); bool isMixed; IEnumerable <string> bundlesFromAssets = this.GetAssetBundlesFromAssets(assets, isVariant, out isMixed); string[] strArray = !isVariant?AssetDatabase.GetAllAssetBundleNamesWithoutVariant() : AssetDatabase.GetAllAssetBundleVariants(); stringList.AddRange((IEnumerable <string>)strArray); stringList.Add(string.Empty); int count = stringList.Count; stringList.Add("New..."); int num1 = -1; int num2 = -1; if (!isVariant) { num1 = stringList.Count; stringList.Add("Remove Unused Names"); num2 = stringList.Count; if (bundlesFromAssets.Count <string>() != 0) { stringList.Add("Filter Selected Name" + (!isMixed ? string.Empty : "s")); } } int selected = 0; string str = bundlesFromAssets.FirstOrDefault <string>(); if (!string.IsNullOrEmpty(str)) { selected = stringList.IndexOf(str); } EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = isMixed; int index = EditorGUI.DoPopup(rect, id, selected, EditorGUIUtility.TempContent(stringList.ToArray()), AssetBundleNameGUI.Styles.popup); EditorGUI.showMixedValue = false; if (!EditorGUI.EndChangeCheck()) { return; } if (index == 0) { this.SetAssetBundleForAssets(assets, (string)null, isVariant); } else if (index == count) { this.ShowNewAssetBundleField(isVariant); } else if (index == num1) { AssetDatabase.RemoveUnusedAssetBundleNames(); } else if (index == num2) { this.FilterSelected(bundlesFromAssets); } else { this.SetAssetBundleForAssets(assets, stringList[index], isVariant); } }
private void AssetBundlePopup(Rect rect, int id, IEnumerable <Object> assets, bool isVariant) { List <string> displayedOptions = new List <string>(); displayedOptions.Add("None"); displayedOptions.Add(""); // seperator // Anyway to optimize this by caching GetAssetBundleNameFromAssets() and GetAllAssetBundleNames() when they actually change? // As we can change the assetBundle name by script, the UI needs to detect this kind of change. bool mixedValue; IEnumerable <string> assetBundleFromAssets = GetAssetBundlesFromAssets(assets, isVariant, out mixedValue); string[] assetBundles = isVariant ? AssetDatabase.GetAllAssetBundleVariants() : AssetDatabase.GetAllAssetBundleNamesWithoutVariant(); displayedOptions.AddRange(assetBundles); displayedOptions.Add(""); // seperator int newAssetBundleIndex = displayedOptions.Count; displayedOptions.Add("New..."); // These two options are invalid for variant, so skip them for variant. int removeUnusedIndex = -1; int filterSelectedIndex = -1; if (!isVariant) { removeUnusedIndex = displayedOptions.Count; displayedOptions.Add("Remove Unused Names"); filterSelectedIndex = displayedOptions.Count; if (assetBundleFromAssets.Count() != 0) { displayedOptions.Add("Filter Selected Name" + (mixedValue ? "s" : "")); } } int selectedIndex = 0; string firstAssetBundle = assetBundleFromAssets.FirstOrDefault(); if (!String.IsNullOrEmpty(firstAssetBundle)) { selectedIndex = displayedOptions.IndexOf(firstAssetBundle); } EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = mixedValue; selectedIndex = EditorGUI.DoPopup(rect, id, selectedIndex, EditorGUIUtility.TempContent(displayedOptions.ToArray()), Styles.popup); EditorGUI.showMixedValue = false; if (EditorGUI.EndChangeCheck()) { if (selectedIndex == 0) // None { SetAssetBundleForAssets(assets, null, isVariant); } else if (selectedIndex == newAssetBundleIndex) // New... { ShowNewAssetBundleField(isVariant); } else if (selectedIndex == removeUnusedIndex) // Remove Unused Names { AssetDatabase.RemoveUnusedAssetBundleNames(); } else if (selectedIndex == filterSelectedIndex) // Filter Selected Name(s) { FilterSelected(assetBundleFromAssets); } else { SetAssetBundleForAssets(assets, displayedOptions[selectedIndex], isVariant); } } }
private void AssetBundlePopup(Rect rect, int id, IEnumerable <UnityEngine.Object> assets, bool isVariant) { List <string> list = new List <string>(); list.Add("None"); list.Add(string.Empty); bool flag; IEnumerable <string> assetBundlesFromAssets = this.GetAssetBundlesFromAssets(assets, isVariant, out flag); string[] collection = (!isVariant) ? AssetDatabase.GetAllAssetBundleNamesWithoutVariant() : AssetDatabase.GetAllAssetBundleVariants(); list.AddRange(collection); list.Add(string.Empty); int count = list.Count; list.Add("New..."); int num = -1; int num2 = -1; if (!isVariant) { num = list.Count; list.Add("Remove Unused Names"); num2 = list.Count; if (assetBundlesFromAssets.Count <string>() != 0) { list.Add("Filter Selected Name" + ((!flag) ? string.Empty : "s")); } } int num3 = 0; string text = assetBundlesFromAssets.FirstOrDefault <string>(); if (!string.IsNullOrEmpty(text)) { num3 = list.IndexOf(text); } EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = flag; num3 = EditorGUI.DoPopup(rect, id, num3, EditorGUIUtility.TempContent(list.ToArray()), AssetBundleNameGUI.Styles.popup); EditorGUI.showMixedValue = false; if (EditorGUI.EndChangeCheck()) { if (num3 == 0) { this.SetAssetBundleForAssets(assets, null, isVariant); } else { if (num3 == count) { this.ShowNewAssetBundleField(isVariant); } else { if (num3 == num) { AssetDatabase.RemoveUnusedAssetBundleNames(); } else { if (num3 == num2) { this.FilterSelected(assetBundlesFromAssets); } else { this.SetAssetBundleForAssets(assets, list[num3], isVariant); } } } } } }