示例#1
0
        public virtual void OnDetailsGUI()
        {
            bool         changed  = false;
            FlowNode     node     = target as FlowNode;
            FlowNodeInfo nodeInfo = FlowGraphEditorWindow.GetNodeInfo(node);

            if (node == null || nodeInfo == null || nodeData.HasDeserializeError)
            {
                using (new GUILayout.HorizontalScope())
                {
                    EditorGUILayout.PrefixLabel("nodeType");

                    //string newValue = ((GUIStyle)"label").LabelEditable(new GUIContent(nodeData.TypeName ?? "", nodeData.TypeName ?? ""));
                    string newType;
                    newType = EditorGUILayout.DelayedTextField(nodeData.TypeName ?? string.Empty);
                    if (nodeData.TypeName != newType)
                    {
                        //Undo.RecordObject(Target, null);
                        nodeData.TypeName = newType;
                        //SetTargetDirty();
                        GUI.changed = true;
                        TryDeserialize();
                    }
                }


                var props = nodeData.Properties;
                if (props != null)
                {
                    foreach (var p in props)
                    {
                        using (new GUILayout.HorizontalScope())
                        {
                            EditorGUILayout.PrefixLabel(new GUIContent(p.field, p.field));

                            if (p.value.Value != null && p.value.TypeCode == SerializableValue.SerializableTypeCode.String)
                            {
                                string strValue = EditorGUILayout.DelayedTextField((string)p.value.Value);
                                if (!object.Equals(strValue, p.value.Value))
                                {
                                    p.value.Value = strValue;
                                    GUI.changed   = true;
                                    TryDeserialize();
                                }
                            }
                            else
                            {
                                if (p.value.Value == null)
                                {
                                    GUILayout.Label("null");
                                }
                                else
                                {
                                    GUILayout.Label(new GUIContent(p.value.Value.ToString(), p.value.Value.ToString()));
                                }
                            }
                        }
                    }
                }

                return;
            }


            if (node != null)
            {
                float maxWidth = GUILayoutUtility.GetRect(0, Screen.width, 0, 0).width;


                FlowGraphEditorWindow.detailsNameStyle.LabelFit(new GUIContent(nodeInfo.Name, nodeInfo.Name), (int)maxWidth);

                FlowGraphEditorWindow.detailsFullNameStyle.LabelFit(new GUIContent(nodeInfo.DisplayFullName, nodeInfo.DisplayFullName), (int)maxWidth);
                //if (nodeInfo.NodeType == NodeType.Value)
                if (nodeInfo.dataMembers != null && nodeInfo.dataMembers.Count > 0)
                {
                    Action <MemberInfo> drawMember = (mInfo) =>
                    {
                        FieldInfo field = mInfo as FieldInfo;
                        if (field != null)
                        {
                            using (new GUILayout.HorizontalScope())
                            {
                                //GUILayout.Label(field.Name, GUILayout.Width(detailsFieldLabelWidth));
                                EditorGUILayout.PrefixLabel(field.Name);
                                object value = field.GetValue(node), newValue;

                                newValue = SerializableValuePropertyDrawer.LayoutValueField(value, field.FieldType);
                                if (!object.Equals(newValue, value))
                                {
                                    Undo.RecordObject(targetObject, null);
                                    field.SetValue(node, newValue);
                                    changed = true;
                                    //SetTargetDirty();
                                    node.OnAfterDeserialize();
                                }
                            }
                            return;
                        }
                        PropertyInfo pInfo = mInfo as PropertyInfo;
                        if (pInfo != null)
                        {
                            using (new GUILayout.HorizontalScope())
                            {
                                EditorGUILayout.PrefixLabel(pInfo.Name);//, GUILayout.Width( detailsFieldLabelWidth)
                                object value = pInfo.GetValue(node, null), newValue;

                                newValue = SerializableValuePropertyDrawer.LayoutValueField(value, pInfo.PropertyType);
                                if (!object.Equals(newValue, value))
                                {
                                    Undo.RecordObject(targetObject, null);
                                    pInfo.SetValue(node, newValue, null);
                                    //SetTargetDirty();
                                    changed = true;
                                }
                            }
                        }
                    };

                    if (nodeInfo.dataMembers != null)
                    {
                        foreach (var m in nodeInfo.dataMembers)
                        {
                            if (m.IsDefined(typeof(HideInInspector), false))
                            {
                                continue;
                            }
                            drawMember(m);
                        }
                    }
                }
            }

            if (changed)
            {
                GUI.changed = true;
            }
        }
        public static List <VariableInfo> DrawVariables(Rect position, IEnumerable <VariableInfo> variables, Dictionary <string, VariableInfo> ovrrideInputs, List <VariableInfo> inputs)
        {
            if (inputs != null)
            {
                for (int i = 0; i < inputs.Count; i++)
                {
                    var input    = inputs[i];
                    var variable = variables.Where(o => o.Name == input.Name).FirstOrDefault();
                    if (variable == null || variable.Type != input.Type)
                    {
                        inputs.RemoveAt(i);
                        i--;
                        GUI.changed = true;
                    }
                }
            }

            Rect rowRect = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);

            GUIStyle labelStyle = new GUIStyle("label");
            //    labelStyle.fontStyle = FontStyle.Bold;

            int inputCount = variables.Where(o => o.IsIn).Count();
            // if (inputCount > 0)
            {
                rowRect.x     = position.x;
                rowRect.width = position.width;
                rowRect.xMin += GUI.depth * GUIDepthScope.Pixels;

                //rowRect = EditorGUI.PrefixLabel(rowRect, new GUIContent("Input"), labelStyle);
                GUI.Label(GUIExtensions.Width(ref rowRect, EditorGUIUtility.labelWidth), new GUIContent("Input"), labelStyle);
                rowRect.y += rowRect.height;
                using (new GUIDepthScope())
                {
                    variables.Where(o => o.IsIn).OrderBy(o => o.Name).Where((variable, index) =>
                    {
                        VariableInfo inVar = null;

                        if (inputs != null)
                        {
                            inVar = inputs.Where(o => o.Name == variable.Name).FirstOrDefault();
                        }

                        if (inVar != null && inVar.Type != variable.Type)
                        {
                            inputs.Remove(inVar);
                            inVar       = null;
                            GUI.changed = true;
                        }


                        rowRect.x     = position.x;
                        rowRect.width = position.width;
                        rowRect.xMin += GUI.depth * GUIDepthScope.Pixels;

                        if (inVar == null)
                        {
                            GUI.color = Color.gray;
                        }
                        else
                        {
                            GUI.color = Color.white;
                        }
                        GUI.Label(GUIExtensions.Width(ref rowRect, variableLabelWidth), new GUIContent(variable.Name));

                        GUI.color = Color.white;

                        var tmpRect = GUIExtensions.Width(ref rowRect, rowRect.width - variableCheckWidth);
                        if (inVar != null)
                        {
                            object newValue2;

                            newValue2 = SerializableValuePropertyDrawer.ValueField(tmpRect, inVar.DefaultValue, inVar.Type);
                            if (!object.Equals(newValue2, inVar.DefaultValue))
                            {
                                inVar.DefaultValue = newValue2;
                                GUI.changed        = true;
                            }
                        }
                        else
                        {
                            GUI.enabled = false;

                            object value = variable.DefaultValue;
                            if (ovrrideInputs.ContainsKey(variable.Name))
                            {
                                value = ovrrideInputs[variable.Name].DefaultValue;
                            }
                            SerializableValuePropertyDrawer.ValueField(tmpRect, value, variable.Type);
                            GUI.enabled = true;
                        }


                        rowRect.xMin += 5f;

                        if (EditorGUI.Toggle(rowRect, inVar != null))
                        {
                            if (inVar == null)
                            {
                                inVar = new VariableInfo(variable.Name, variable.Type, variable.DefaultValue);
                                if (inputs == null)
                                {
                                    inputs = new List <VariableInfo>();
                                }
                                inputs.Add(inVar);
                                GUI.changed = true;
                            }
                        }
                        else
                        {
                            if (inVar != null)
                            {
                                inputs.Remove(inVar);
                                GUI.changed = true;
                            }
                        }

                        rowRect.y = rowRect.yMax;
                        return(false);
                    }).Count();
                }
            }

            int outputCount = variables.Where(o => o.IsOut).Count();

            //     if (outputCount > 0)
            {
                rowRect.x     = position.x;
                rowRect.width = position.width;
                rowRect.xMin += GUI.depth * GUIDepthScope.Pixels;
                //rowRect = EditorGUI.PrefixLabel(rowRect, new GUIContent("Output"), labelStyle);

                GUI.Label(GUIExtensions.Width(ref rowRect, EditorGUIUtility.labelWidth), new GUIContent("Output"), labelStyle);
                rowRect.y += rowRect.height;

                using (new GUIDepthScope())
                {
                    variables.Where(o => o.IsOut).OrderBy(o => o.Name).Where((variable, index) =>
                    {
                        rowRect.x     = position.x;
                        rowRect.width = position.width;
                        rowRect.xMin += GUI.depth * GUIDepthScope.Pixels;

                        GUI.Label(GUIExtensions.Width(ref rowRect, variableLabelWidth), new GUIContent(variable.Name));
                        GUI.Label(rowRect, new GUIContent(FlowNode.GetDisplayValueTypeName(variable.Type), variable.Type.FullName));
                        rowRect.y += rowRect.height;
                        return(false);
                    }).Count();
                }
            }
            return(inputs);
        }