bool TryGetFlowNodeOutput(PortAttribute portAttribute, MemberInfo memberInfo, out OutputPortConfig outputPortConfig) { outputPortConfig = new OutputPortConfig(); outputPortConfig.name = portAttribute.Name ?? memberInfo.Name; outputPortConfig.humanName = outputPortConfig.name; outputPortConfig.description = portAttribute.Description; Type type; if (memberInfo.MemberType == MemberTypes.Field) { type = (memberInfo as FieldInfo).FieldType; } else { type = (memberInfo as PropertyInfo).PropertyType; } if (type.Name.StartsWith("OutputPort")) { bool isGenericType = type.IsGenericType; Type genericType = isGenericType ? type.GetGenericArguments()[0] : typeof(void); string prefix; outputPortConfig.type = GetFlowNodePortType(genericType, out prefix, portAttribute); return(true); } return(false); }
/// <summary> 绘制双向接口 </summary> protected void GenerateBothPort(SerializedProperty iterator, PortAttribute attribute, NodePort nodePort, Direction direction) { Port.Capacity capacity = attribute.Capacity == NodePort.PortCapacity.Single ? Port.Capacity.Single : Port.Capacity.Multi; BasePort port = InstantiatePort(Orientation.Horizontal, direction, capacity, nodePort.DataType) as BasePort; port.userData = nodePort; port.name = NodePort.GetBothName(iterator.name, nodePort.Direction); if (!string.IsNullOrEmpty(attribute.PortName)) { port.portName = attribute.PortName; } else { port.portName = iterator.displayName; } if (AttributeCache.TryGetFieldAttribute(NodeData.GetType(), iterator.name, out NodeTooltipAttribute tooltipAttribute)) { port.tooltip = tooltipAttribute.Tooltip; } PortDic[port.name] = port; switch (port.direction) { case Direction.Input: inputContainer.Add(port); break; case Direction.Output: outputContainer.Add(port); port.onConnect += (Edge edge) => { if (GraphView.Inited) { (edge.output.userData as NodePort).Connect(edge.input.userData as NodePort); EditorUtility.SetDirty(NodeData); } }; port.onDisconnect += (Edge edge) => { (edge.output.userData as NodePort).Disconnect(edge.input.userData as NodePort); EditorUtility.SetDirty(NodeData); }; break; } }
NodePortType GetFlowNodePortType(Type type, out string prefix, PortAttribute portAttribute) { prefix = null; if (type == typeof(void)) { return(NodePortType.Void); } if (type == typeof(int)) { return(NodePortType.Int); } if (type == typeof(float)) { return(NodePortType.Float); } if (type == typeof(string)) { switch (portAttribute.StringPortType) { case StringPortType.Sound: prefix = "sound_"; break; case StringPortType.DialogLine: prefix = "dialogline_"; break; case StringPortType.Texture: prefix = "texture_"; break; case StringPortType.Object: prefix = "object_"; break; case StringPortType.File: prefix = "file_"; break; case StringPortType.EquipmentPack: prefix = "equip_"; break; case StringPortType.ReverbPreset: prefix = "reverbpreset_"; break; case StringPortType.GameToken: prefix = "gametoken_"; break; case StringPortType.Material: prefix = "mat_"; break; case StringPortType.Sequence: prefix = "seq_"; break; case StringPortType.Mission: prefix = "mission_"; break; case StringPortType.Animation: prefix = "anim_"; break; case StringPortType.AnimationState: prefix = "animstate_"; break; case StringPortType.AnimationStateEx: prefix = "animstateEx_"; break; case StringPortType.Bone: prefix = "bone_"; break; case StringPortType.Attachment: prefix = "attachment_"; break; case StringPortType.Dialog: prefix = "dialog_"; break; case StringPortType.MaterialParamSlot: prefix = "matparamslot_"; break; case StringPortType.MaterialParamName: prefix = "matparamname_"; break; case StringPortType.MaterialParamCharacterAttachment: prefix = "matparamcharatt_"; break; } return(NodePortType.String); } if (type == typeof(Vec3)) { return(NodePortType.Vec3); } if (type == typeof(Color)) { prefix = "color_"; return(NodePortType.Vec3); // implicit operator takes care of conversion } if (type == typeof(bool)) { return(NodePortType.Bool); } if (type == typeof(EntityId)) { return(NodePortType.EntityId); } if (type == typeof(object)) { return(NodePortType.Any); } throw new ArgumentException("Invalid flownode port type specified!"); }
bool TryGetFlowNodeInput(PortAttribute portAttribute, MethodInfo method, out InputPortConfig inputPortConfig) { string portPrefix = null; object defaultVal = null; inputPortConfig = new InputPortConfig(); if (method.GetParameters().Length > 0) { ParameterInfo parameter = method.GetParameters()[0]; if (parameter.ParameterType.IsEnum) { inputPortConfig.type = NodePortType.Int; var values = Enum.GetValues(parameter.ParameterType); if (values.Length <= 0) { return(false); } defaultVal = values.GetValue(0); inputPortConfig.uiConfig = "enum_int:"; for (int i = 0; i < values.Length; i++) { var value = values.GetValue(i); if (i > 0 && i != inputPortConfig.uiConfig.Length) { inputPortConfig.uiConfig += ","; } inputPortConfig.uiConfig += Enum.GetName(parameter.ParameterType, value) + "=" + (int)value; } } else { inputPortConfig.type = GetFlowNodePortType(parameter.ParameterType, out portPrefix, portAttribute); } if (parameter.IsOptional && defaultVal == null) { defaultVal = parameter.DefaultValue; } else if (defaultVal == null) { switch (inputPortConfig.type) { case NodePortType.Bool: defaultVal = false; break; case NodePortType.EntityId: defaultVal = 0; break; case NodePortType.Float: defaultVal = 0.0f; break; case NodePortType.Int: defaultVal = 0; break; case NodePortType.String: defaultVal = ""; break; case NodePortType.Vec3: defaultVal = Vec3.Zero; break; } } } else { inputPortConfig.type = NodePortType.Void; } string portName = (portAttribute.Name ?? method.Name); if (portPrefix != null) { inputPortConfig.name = portPrefix + portName; } else { inputPortConfig.name = portName; } inputPortConfig.defaultValue = defaultVal; inputPortConfig.description = portAttribute.Description; inputPortConfig.humanName = portAttribute.Name ?? method.Name; return(true); }