void OnListElementGUI(Rect rect, int index, bool isactive, bool isfocused) { const float GAP = 5; AssetBundleFilter filter = mConfig.filters[index]; rect.y++; Rect r = rect; r.height = 18; r.width = 100; filter.type = (EnAssetBundleFilter)GUI.Toolbar(r, (int)filter.type, AssetBundleFilter.sType); r.xMin = r.xMax + GAP; r.xMax = rect.xMax - 300; r.width = 200; GUI.enabled = false; filter.path = GUI.TextField(r, filter.path); GUI.enabled = true; r.xMin = r.xMax + GAP; r.width = 50; if (GUI.Button(r, "Select")) { var path = SelectFolder(); if (path != null) { filter.path = path; } } r.xMin = r.xMax + GAP; r.xMax = rect.xMax; filter.filter = GUI.TextField(r, filter.filter); }
void OnGUI() { bool execBuild = false; if (config == null) { config = AssetDatabase.LoadAssetAtPath <AssetBundleBuildConfig>(savePath); if (config == null) { config = new AssetBundleBuildConfig(); } } UpdateStyles(); //tool bar GUILayout.BeginHorizontal(Styles.toolbar); { if (GUILayout.Button("Add", Styles.toolbarButton)) { config.filters.Add(new AssetBundleFilter()); } if (GUILayout.Button("Save", Styles.toolbarButton)) { Save(); } GUILayout.FlexibleSpace(); if (GUILayout.Button("Build", Styles.toolbarButton)) { execBuild = true; } } GUILayout.EndHorizontal(); //context GUILayout.BeginVertical(); //format GUILayout.BeginHorizontal(); { EditorGUILayout.PrefixLabel("DepInfoFileFormat"); config.depInfoFileFormat = (AssetBundleBuildConfig.Format)EditorGUILayout.EnumPopup(config.depInfoFileFormat); } GUILayout.EndHorizontal(); GUILayout.Space(10); for (int i = 0; i < config.filters.Count; i++) { AssetBundleFilter filter = config.filters[i]; GUILayout.BeginHorizontal(); { filter.valid = GUILayout.Toggle(filter.valid, "", GUILayout.ExpandWidth(false)); filter.path = GUILayout.TextField(filter.path, GUILayout.ExpandWidth(true)); if (GUILayout.Button("Select", GUILayout.ExpandWidth(false))) { string dataPath = Application.dataPath; string selectedPath = EditorUtility.OpenFolderPanel("Path", dataPath, ""); if (!string.IsNullOrEmpty(selectedPath)) { if (selectedPath.StartsWith(dataPath)) { filter.path = "Assets/" + selectedPath.Substring(dataPath.Length + 1); } else { ShowNotification(new GUIContent("不能在Assets目录之外!")); } } } filter.filter = GUILayout.TextField(filter.filter, GUILayout.Width(200)); if (GUILayout.Button("X", GUILayout.ExpandWidth(false))) { config.filters.RemoveAt(i); i--; } } GUILayout.EndHorizontal(); } GUILayout.EndVertical(); //set dirty if (GUI.changed) { EditorUtility.SetDirty(config); } if (execBuild) { Build(); } }