private void DrawSelectAssetEditor()
        {
            var derivedTypeInfo   = GetDerivedTypeInfo(typeof(UnityEngine.Object));
            var typeName          = m_Node.GetProperty <string>("type", null);
            var selectedTypeIndex = derivedTypeInfo.names.FindIndex(n => n == typeName);
            var typeLabel         = selectedTypeIndex == -1 ? null : derivedTypeInfo.labels[selectedTypeIndex];

            DrawSelectionPopup("Type", typeLabel ?? "Select type...", derivedTypeInfo.labels, selectedIndex =>
            {
                m_Node.SetProperty("type", derivedTypeInfo.names[selectedIndex]);
                propertiesChanged?.Invoke(m_Node);
            });
            if (typeName != null)
            {
                if (selectedTypeIndex != -1)
                {
                    var selectedType  = derivedTypeInfo.types[selectedTypeIndex];
                    var properties    = GetTypePropertyNames(selectedType);
                    var propertyName  = m_Node.GetProperty <string>("field", null);
                    var propertyLabel = properties.FirstOrDefault(p => p.name == propertyName).label;

                    DrawSelectionPopup("Property", propertyLabel ?? "Select property...", properties.Select(p => p.label), selectedIndex =>
                    {
                        m_Node.SetProperty("field", properties[selectedIndex].name);
                        propertiesChanged?.Invoke(m_Node);
                    });
                }
            }
        }
Example #2
0
        public void UpdateNode(SearchExpressionNode ex)
        {
            if (!TryGetNode(ex, out var node))
            {
                return;
            }

            node.title = FormatTitle(ex);

            if (ex.color != Color.clear)
            {
                node.titleContainer.style.backgroundColor = ex.color;
            }

            // Update result port
            if (ex.type == ExpressionType.Value ||
                ex.type == ExpressionType.Provider)
            {
                var outputPort = FindPort(node, "output");
                if (outputPort != null)
                {
                    outputPort.portName = Convert.ToString(ex.value);
                }
            }
            else if (ex.type == ExpressionType.Union)
            {
                UpdateUnionVariables(node);
            }
            else if (ex.type == ExpressionType.Select)
            {
                var outputPort = FindPort(node, "output");
                if (outputPort != null)
                {
                    outputPort.portName = GetSelectNodeOutputPortName(ex);
                }
            }
            else if (ex.type == ExpressionType.Map)
            {
                if (ex.TryGetVariableSource(ExpressionKeyName.X, out var xSource))
                {
                    if (!ex.TryGetProperty(ExpressionKeyName.GroupBy, out string groupBy) || string.IsNullOrEmpty(groupBy))
                    {
                        ex.SetProperty(ExpressionKeyName.GroupBy, GetSelectNodeOutputPortName(xSource).ToLowerInvariant());
                    }
                }

                if (ex.TryGetVariableSource(ExpressionKeyName.Y, out var ySource) && xSource == ySource)
                {
                    ex.SetProperty(nameof(Mapping), (int)Mapping.Table);
                }
            }

            NotifyGraphChanged();
        }
Example #3
0
        private void DrawMapEditor()
        {
            var mapping = (Mapping)m_Node.GetProperty(nameof(Mapping), (int)Mapping.Count);
            var groupBy = m_Node.GetProperty(ExpressionKeyName.GroupBy, "");

            EditorGUI.BeginChangeCheck();
            mapping = (Mapping)EditorGUILayout.EnumPopup(nameof(Mapping), mapping);
            if (m_Node.TryGetVariableSource(ExpressionKeyName.X, out var xSource) && xSource != null && mapping != Mapping.Table)
            {
                groupBy = EditorGUILayout.DelayedTextField("Group By", groupBy);
            }
            else
            {
                GUILayout.Space(20);
            }
            if (EditorGUI.EndChangeCheck())
            {
                m_Node.SetProperty(nameof(Mapping), (int)mapping);
                m_Node.SetProperty(ExpressionKeyName.GroupBy, groupBy);
                propertiesChanged?.Invoke(m_Node);
            }
        }
Example #4
0
        private SearchExpressionNode LoadNodeData(SearchExpressionNode node, IDictionary info)
        {
            if (SJSON.TryGetValue(info, ExpressionField.name, out var name))
            {
                node.name = Convert.ToString(name);
            }

            if (SJSON.TryGetValue(info, ExpressionField.value, out var value))
            {
                node.value = value;
            }

            if (SJSON.TryGetValue(info, ExpressionField.source, out var source))
            {
                if (source is IDictionary nestedSource)
                {
                    node.source = ParseNode(nestedSource);
                }
                else if (node.type == ExpressionType.Provider)
                {
                    node.value = (string)source;
                }
                else if (m_Nodes.TryGetValue((string)source, out var sourceNode))
                {
                    node.source = sourceNode;
                }
                else
                {
                    throw new ExpressionException($"Expression node {node.id} has an invalid source {source}");
                }
            }

            if (SJSON.TryGetValue(info, ExpressionField.position, out var _obj) && _obj is object[] position && position.Length == 2)
            {
                node.position = new Vector2((float)(double)position[0], (float)(double)position[1]);
            }

            if (SJSON.TryGetValue(info, ExpressionField.variables, out var variablesData))
            {
                var variables = (IDictionary)variablesData;
                foreach (var v in variables)
                {
                    var varName     = (string)((DictionaryEntry)v).Key;
                    var valueSource = ((DictionaryEntry)v).Value;
                    if (valueSource == null)
                    {
                        node.AddVariable(varName);
                    }
                    else if (valueSource is IDictionary nestedSource)
                    {
                        node.AddVariable(varName, ParseNode(nestedSource));
                    }
                    else if (valueSource is string && m_Nodes.TryGetValue((string)valueSource, out var sourceNode))
                    {
                        node.AddVariable(varName, sourceNode);
                    }
                    else
                    {
                        throw new ExpressionException(node, $"Expression node {node.id} has an invalid variable {varName} with source {valueSource}");
                    }
                }
            }

            if (SJSON.TryGetValue(info, ExpressionField.properties, out var propertiesData))
            {
                var properties = (IDictionary)propertiesData;
                foreach (var v in properties)
                {
                    var propertyName  = (string)((DictionaryEntry)v).Key;
                    var propertyValue = ((DictionaryEntry)v).Value;
                    node.SetProperty(propertyName, propertyValue);
                }
            }

            return(node);
        }