Exemplo n.º 1
0
        protected override float GetCustomRowHeight(int row, TreeViewItem treeViewItem)
        {
            var item = treeViewItem as RecordViewItem;

            var valueNames = masterController.GetValueNames();

            var customRowHeight = 0f;

            for (var i = 0; i < valueNames.Length; i++)
            {
                var valueName = valueNames[i];

                if (!multiColumnHeader.IsColumnVisible(i))
                {
                    continue;
                }

                var valueType = masterController.GetValueType(valueName);

                if (valueType == typeof(string))
                {
                    var value = masterController.GetValue(item.Record, valueName) as string;

                    var hight = EditorRecordFieldUtility.GetTextFieldHight(value);

                    if (customRowHeight < hight)
                    {
                        customRowHeight = hight;

                        if (EditorGUIUtility.singleLineHeight < customRowHeight)
                        {
                            customRowHeight += 4f;
                        }
                    }
                }
            }

            return(RowHight < customRowHeight ? customRowHeight : RowHight);
        }
Exemplo n.º 2
0
        private void DrawFieldGUI(Rect rect, string valueName, object record)
        {
            var current = Event.current;

            var value = masterController.GetValue(record, valueName);

            var valueType = masterController.GetValueType(valueName);

            Action <object> onUpdateValue = x =>
            {
                masterController.UpdateValue(record, valueName, x);

                if (onChangeRecord != null)
                {
                    onChangeRecord.OnNext(Unit.Default);
                }

                RefreshCustomRowHeights();
            };

            var color = masterController.IsChanged(record, valueName) ? EditedColor : Color.white;

            rect.height = EditorGUIUtility.singleLineHeight;

            using (new BackgroundColorScope(color))
            {
                if (EditorRecordFieldUtility.IsArrayType(valueType))
                {
                    var builder = new StringBuilder();

                    if (value != null)
                    {
                        foreach (var item in (IEnumerable)value)
                        {
                            builder.AppendFormat("{0},", item);
                        }
                    }

                    var text = builder.ToString().TrimEnd(',');

                    EditorGUI.LabelField(rect, text, EditorStyles.textField);

                    if (MasterController.CanEdit || !string.IsNullOrEmpty(text))
                    {
                        // メニュー表示と干渉するのでGUILayout.Buttonを使わない.
                        if (rect.Contains(current.mousePosition) && current.type == EventType.MouseDown && current.button == 0)
                        {
                            var mouseRect = new Rect(current.mousePosition, Vector2.one);

                            var arrayFieldPopupWindow = new ArrayFieldPopupWindow();

                            arrayFieldPopupWindow.SetContents(valueType, value);

                            arrayFieldPopupWindow.OnUpdateElementsAsObservable()
                            .Subscribe(x => onUpdateValue(x))
                            .AddTo(lifetimeDisposable.Disposable);

                            PopupWindow.Show(mouseRect, arrayFieldPopupWindow);

                            current.Use();
                        }
                    }
                }
                else
                {
                    if (valueType == typeof(string))
                    {
                        rect.height = EditorRecordFieldUtility.GetTextFieldHight(value as string);
                    }

                    EditorGUI.BeginChangeCheck();

                    try
                    {
                        value = EditorRecordFieldUtility.DrawField(rect, value, valueType);
                    }
                    catch (Exception e)
                    {
                        Debug.LogErrorFormat("Error: {0}\nValueName = {1}\nValueType = {2}\nValue = {3}\n", e.Message, valueName, valueType, value);
                    }

                    if (EditorGUI.EndChangeCheck() && MasterController.CanEdit)
                    {
                        onUpdateValue(value);
                    }
                }
            }

            // 右クリックでメニュー表示.
            if (rect.Contains(current.mousePosition) && current.type == EventType.MouseDown && current.button == 1)
            {
                if (masterController.IsChanged(record, valueName))
                {
                    var menu = new GenericMenu();

                    GenericMenu.MenuFunction onResetMenuClick = () =>
                    {
                        masterController.ResetValue(record, valueName);
                    };

                    menu.AddItem(new GUIContent("Reset"), false, onResetMenuClick);

                    menu.ShowAsContext();

                    GUI.FocusControl(string.Empty);

                    current.Use();
                }
            }
        }