public bool OnInspectorGUI() { Animation anim = script.GetComponent <Animation>(); bool changed = false; EditorGUI.indentLevel++; foreach (string varName in clipVars) { AnimationClip val = ReflectionUtil.GetFieldValue <AnimationClip>(script, varName); if (anim != null) { if (EditorGUIUtil.PopupNullable <AnimationClip>(varName, ref val, anim.GetAllClips().ToArray())) { ReflectionUtil.SetFieldValue(script, varName, val); changed = true; } } else { if (val != null) { ReflectionUtil.SetFieldValue <AnimationClip>(script, varName, null); changed = true; } } } EditorGUI.indentLevel--; if (changed) { EditorUtil.SetDirty(script); } return(changed); }
private bool DrawAddColumn() { showAddColumn = EditorGUILayout.Foldout(showAddColumn, "Add Column"); if (showAddColumn) { if (!grid.isHorizontal) { EditorGUILayout.HelpBox("Currently only Horizontal grid type is supported", MessageType.Warning); return(false); } EditorGUIUtil.ObjectField <UILabel>("Title Label(Prefab)", ref titleLabelPrefab, true, GUILayout.ExpandWidth(false)); if (EditorGUIUtil.PopupNullable <GridStyle>(null, ref currentStyle, gridStyles)) { selectedColumn = null; return(true); } if (GUILayout.Button("Apply")) { grid.totalWidth = currentStyle.width; Vector2 minSize = grid.cellMinSize; minSize.y = currentStyle.rowHeight; grid.cellMinSize = minSize; } if (currentStyle != null) { EditorGUIUtil.PopupNullable <ColumnWidth>(null, ref selectedColumn, currentStyle.columnWidth); GUI.enabled = titleLabelPrefab != null && selectedColumn != null; if (GUILayout.Button("Add")) { int lastCol = GetLastColumn(); for (int r = 1, max = grid.rowHeader; r < max; r++) { UITableCell cell = null; #pragma warning disable 0618 grid.Insert((lastCol + 1) * r - 1, cell); #pragma warning restore 0618 } grid.maxPerLine = Math.Max(lastCol + 1, grid.maxPerLine); grid.InitArray(); grid.columnWidth[lastCol] = selectedColumn.width; grid.SetCell(grid.rowHeader - 1, lastCol, CreateLabel(selectedColumn.name, lastCol + 1)); return(true); } } } return(false); }
public override void OnHeaderGUI() { Validate(); EditorGUILayout.BeginHorizontal(); if (EditorGUIUtil.ObjectField <GameObject>("Root", ref root, true)) { Refresh(); } GUI.enabled = root != null; if (GUILayout.Button("Refresh", GUILayout.ExpandWidth(false))) { Refresh(); } GUI.enabled = true; EditorGUILayout.EndHorizontal(); UIPanel[] panels = root != null?root.GetComponentsInChildren <UIPanel>(true) : new UIPanel[0]; EditorGUILayout.BeginHorizontal(); if (EditorGUIUtil.PopupNullable("Panel", ref panelSel, panels, ObjToString.DefaultToString)) { Refresh(); if (panelSel != null) { EditorGUIUtility.PingObject(panelSel); Selection.activeGameObject = panelSel.gameObject; } } EditorGUIUtil.Toggle("Show Active Only", ref showActiveOnly); EditorGUILayout.EndHorizontal(); UIAtlas[] atlases = GetAtlases(widgets); UIFont[] fonts = GetFonts(widgets); if (EditorGUIUtil.PopupNullable("Select Atlas", ref atlasSel, atlases, ObjToString.DefaultToString)) { if (atlasSel != null) { fontSel = null; } } if (EditorGUIUtil.PopupNullable("Select Font", ref fontSel, fonts, ObjToString.DefaultToString)) { if (fontSel != null) { atlasSel = null; } } EditorGUILayout.BeginHorizontal(); int index = Array.FindIndex(widgets, w => w.gameObject == Selection.activeGameObject); GUI.enabled = index >= 0; if (GUI.enabled) { if (GUILayout.Button("+1 over selection")) { for (int i = 0; i <= index; ++i) { widgets[i].depth = widgets[i].depth + 1; CompatibilityEditor.SetDirty(widgets[i]); } } if (GUILayout.Button("-1 under selection")) { for (int i = index; i < widgets.Length; ++i) { widgets[i].depth = widgets[i].depth - 1; CompatibilityEditor.SetDirty(widgets[i]); } } // TODOM key handling var e = Event.current; if (e.type == EventType.KeyUp) { if (e.keyCode == KeyCode.UpArrow) { index--; if (index >= 0) { Select(widgets[index]); } } else if (e.keyCode == KeyCode.DownArrow) { index++; if (index < widgets.Length) { Select(widgets[index]); } } } } GUI.enabled = true; EditorGUILayout.EndHorizontal(); }