public bool OnInspectorGUI()
        {
            Animation anim    = script.GetComponent <Animation>();
            bool      changed = false;

            EditorGUI.indentLevel++;
            foreach (string varName in clipVars)
            {
                AnimationClip val = script.GetFieldValue <AnimationClip>(varName);
                if (anim != null)
                {
                    if (EditorGUILayoutUtil.PopupNullable(varName, ref val, anim.GetAllClips().ToArray()))
                    {
                        script.SetFieldValue(varName, val);
                        changed = true;
                    }
                }
                else
                {
                    if (val != null)
                    {
                        script.SetFieldValue <AnimationClip>(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);
                }
                EditorGUILayoutUtil.ObjectField <UILabel>("Title Label(Prefab)", ref titleLabelPrefab, true, GUILayout.ExpandWidth(false));
                if (EditorGUILayoutUtil.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)
                {
                    EditorGUILayoutUtil.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);
        }
Esempio n. 3
0
        public override void OnHeaderGUI()
        {
            Validate();
            EditorGUILayout.BeginHorizontal();
            if (EditorGUILayoutUtil.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 (EditorGUILayoutUtil.PopupNullable("Panel", ref panelSel, panels, ObjToString.DefaultToString))
            {
                Refresh();
                if (panelSel != null)
                {
                    EditorGUIUtility.PingObject(panelSel);
                    Selection.activeGameObject = panelSel.gameObject;
                }
            }
            EditorGUILayoutUtil.Toggle("Show Active Only", ref showActiveOnly);
            EditorGUILayout.EndHorizontal();
            INGUIAtlas[] atlases = GetAtlases(widgets);
            INGUIFont[]  fonts   = GetFonts(widgets);
            if (EditorGUILayoutUtil.PopupNullable("Select Atlas", ref atlasSel, atlases, ObjToString.DefaultToString))
            {
                if (atlasSel != null)
                {
                    fontSel = null;
                }
            }
            if (EditorGUILayoutUtil.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;
                        EditorUtil.SetDirty(widgets[i]);
                    }
                }
                if (GUILayout.Button("-1 under selection"))
                {
                    for (int i = index; i < widgets.Length; ++i)
                    {
                        widgets[i].depth = widgets[i].depth - 1;
                        EditorUtil.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();
        }