Ejemplo n.º 1
0
        private TreeViewItem CreateTreeViewItem(SerializableStateElement element, int depth = 0)
        {
            var item  = new UniReduxTreeModel(Id, element.Name, element.Type, element.Value, element.ObjectType, depth);
            var items =
                element.Children.Select(childrenElement => CreateTreeViewItem(childrenElement, depth + 1)).ToList();

            item.children = items;
            return(item);
        }
Ejemplo n.º 2
0
        private void CellGUI(Rect cellRect, UniReduxTreeModel uniReduxTreeModel, ColumnIndex columnIndex,
                             ref RowGUIArgs args)
        {
            CenterRectUsingSingleLineHeight(ref cellRect);
            switch (columnIndex)
            {
            case ColumnIndex.Id:
                EditorGUI.LabelField(cellRect, $"{uniReduxTreeModel.Element.StateId}", EditorStyles.label);
                break;

            case ColumnIndex.StateName:
                var spaceRect = cellRect;
                spaceRect.x += uniReduxTreeModel.Element.StateDepth * 18f + 20;
                var pass        = $"UniRedux/icon_{uniReduxTreeModel.Element.ObjectType.ToString()}.png";
                var texture     = EditorGUIUtility.Load(pass) as Texture;
                var textureRect = spaceRect;
                textureRect.width = textureRect.height;
                spaceRect.x      += textureRect.width + 5;
                GUI.DrawTexture(textureRect, texture, ScaleMode.ScaleToFit);
                EditorGUI.LabelField(spaceRect, uniReduxTreeModel.Element.StateName, EditorStyles.largeLabel);
                break;

            case ColumnIndex.StateType:

                var curEvent = Event.current;
                var typeName = uniReduxTreeModel.Element.StateType.Name;
                if (cellRect.Contains(curEvent.mousePosition))
                {
                    typeName = uniReduxTreeModel.Element.StateType.FullName;
                }

                EditorGUI.LabelField(cellRect, typeName, EditorStyles.label);
                break;

            case ColumnIndex.StateValue:
                if (uniReduxTreeModel.Element.ObjectType == ObjectType.Array)
                {
                    EditorGUI.LabelField(cellRect, $"{uniReduxTreeModel.Element.StateValue}", EditorStyles.label);
                }
                else if (uniReduxTreeModel.Element.ObjectType == ObjectType.Value)
                {
                    if (uniReduxTreeModel.Element.StateType.IsEnum)
                    {
                        EditorGUI.SelectableLabel(cellRect, $"{uniReduxTreeModel.Element.StateValue}", EditorStyles.popup);
                    }
                    else
                    {
                        switch (Type.GetTypeCode(uniReduxTreeModel.Element.StateType))
                        {
                        case TypeCode.Int32:
                            var intValue = Convert.ToInt32(uniReduxTreeModel.Element.StateValue);
                            EditorGUI.SelectableLabel(cellRect, $"{intValue}", EditorStyles.textField);
                            break;

                        case TypeCode.String:
                            EditorGUI.SelectableLabel(cellRect, $"{uniReduxTreeModel.Element.StateValue}", EditorStyles.textField);
                            break;

                        case TypeCode.Boolean:
                            var  flag       = Convert.ToBoolean(uniReduxTreeModel.Element.StateValue);
                            Rect toggleRect = cellRect;
                            toggleRect.width = 18;
                            using (new BackgroundColorScope(flag ? Color.green : Color.red))
                            {
                                EditorGUI.Toggle(toggleRect, flag, EditorStyles.radioButton);
                            }
                            break;

                        case TypeCode.Double:
                            var doubleValue = Convert.ToDouble(uniReduxTreeModel.Element.StateValue);
                            EditorGUI.SelectableLabel(cellRect, $"{doubleValue}", EditorStyles.textField);
                            break;

                        case TypeCode.DateTime:
                        default:
                            EditorGUI.SelectableLabel(cellRect, $"{uniReduxTreeModel.Element.StateValue}", EditorStyles.textField);
                            break;
                        }
                    }
                }
                break;

            case ColumnIndex.Button:
                if (uniReduxTreeModel.Element.ObjectType != ObjectType.Value && uniReduxTreeModel.children != null && uniReduxTreeModel.children.Count > 0)
                {
                    if (GUI.Button(cellRect, "Open"))
                    {
                        _openNewTreeViewAction(uniReduxTreeModel.Element.StateId);
                    }
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }