public virtual GUIContent GetNodeName() { FlowNode node = target as FlowNode; string name; var nodeInfo = FlowGraphEditorWindow.GetNodeInfo(node); if (nodeInfo != null) { name = nodeInfo.Name; } else { name = node.GetType().Name; } return(new GUIContent(name, node.GetType().FullName)); }
void Reload() { FlowGraphEditorWindow.ReloadConfig(); }
public override void OnInspectorGUI() { FlowGraphConfig config = target as FlowGraphConfig; using (new GUILayout.HorizontalScope()) { string newTypeName = EditorGUILayout.TextField(typeName ?? ""); if (newTypeName != typeName) { typeName = newTypeName; UpdateType(); } GUI.enabled = type != null; if (GUILayout.Button("Add", GUILayout.ExpandWidth(false))) { var item = config.items.Where(o => o.type == type).FirstOrDefault(); if (item == null) { item = new FlowGraphConfig.IncludeTypeItem() { type = type, }; config.items.Add(item); config.items.Sort(FlowGraphConfig.IncludeTypeItem.Comparer); EditorUtility.SetDirty(config); FlowGraphEditorWindow.ReloadConfig(); typeName = string.Empty; } } GUI.enabled = true; } using (var sv = new GUILayout.ScrollViewScope(scrollPos)) { scrollPos = sv.scrollPosition; for (int i = 0; i < config.items.Count; i++) { var item = config.items[i]; using (new GUILayout.HorizontalScope()) { GUILayout.Label((i + 1).ToString(), GUILayout.Width(20)); if (item.type == null) { GUILayout.Label(item.typeName); } else { GUILayout.Label(item.type.FullName); } } if (Event.current.type == EventType.ContextClick && GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition)) { GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent("Delete " + (i + 1)), false, (o) => { FlowGraphConfig.IncludeTypeItem item1 = (FlowGraphConfig.IncludeTypeItem)o; if (config.items.Remove(item1)) { Repaint(); } }, item); menu.ShowAsContext(); } } } }
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 override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { var dataProperty = property.FindPropertyRelative("data"); var assetDataProperty = property.FindPropertyRelative("assetData"); var dataTypeProperty = property.FindPropertyRelative("dataType"); FlowGraphField.DataType dataType = (FlowGraphField.DataType)dataTypeProperty.intValue; var assetData = assetDataProperty.objectReferenceValue as FlowGraphAsset; float totalHeight = GetPropertyHeight(property, label); Rect rowRect = new Rect(position.x, position.y, position.width, base.GetPropertyHeight(property, label)); var targetObject = property.serializedObject.targetObject; var field = GetGraphField(property); FlowGraphData graphData = null; if (dataType == FlowGraphField.DataType.Asset) { if (assetData) { //FlowGraphEditorWindow.ShowWindow(assetData); graphData = assetData.Graph; } } else { graphData = field.GetFlowGraphData(); } if (graphData != null && graphData.HasDeserializeError) { GUI.color = Color.red; //label.text = "err"; //Debug.Log("has errr"); } //Debug.Log("null:" + (graphData == null)+","+graphData.IsDeserialize+","+graphData.HasDeserializeError); rowRect = EditorGUI.PrefixLabel(rowRect, label); GUI.color = Color.white; if (GUI.Button(new Rect(position.x, position.y, position.width - rowRect.width, rowRect.height), GUIContent.none, "label")) { GenericMenu menu = new GenericMenu(); //menu.AddItem(new GUIContent("Data"), dataType == FlowGraphField.DataType.Data, () => // { // dataType = FlowGraphField.DataType.Data; // assetDataProperty.objectReferenceValue = null; // dataTypeProperty.intValue = (int)dataType; // property.serializedObject.ApplyModifiedProperties(); // }); //menu.AddItem(new GUIContent("Asset"), dataType == FlowGraphField.DataType.Asset, () => //{ // if (graphData != null) // { // if (!EditorUtility.DisplayDialog("confirm clear data", "FlowGraph data not null", "ok", "cancel")) // { // return; // } // } // dataType = FlowGraphField.DataType.Asset; // dataTypeProperty.intValue = (int)dataType; // property.serializedObject.ApplyModifiedProperties(); //}); menu.AddItem(new GUIContent("Copy"), false, () => { copy = field; }); if (copy != null) { menu.AddItem(new GUIContent("Paste"), false, () => { if (copy != null) { Undo.RecordObject(property.serializedObject.targetObject, null); /* if (copy.IsNull) * { * field.AssetData = null; * field.Data = null; * } * else*/ if (copy.IsAssetData) { field.AssetData = copy.AssetData; } else { field.Data = copy.Data; } property.serializedObject.ApplyModifiedProperties(); } }); } else { menu.AddDisabledItem(new GUIContent("Paste")); } //menu.AddItem(new GUIContent("Clear Data"), false, () => //{ // if (EditorUtility.DisplayDialog("Clear data", "Clear FlowGraph data", "ok", "cancel")) // { // Undo.RecordObject(property.serializedObject.targetObject, null); // assetDataProperty.objectReferenceValue = null; // dataType = FlowGraphField.DataType.Null; // dataTypeProperty.intValue = (int)dataType; // property.serializedObject.ApplyModifiedProperties(); // } //}); menu.ShowAsContext(); } rowRect = new Rect(rowRect); int btnWidth = 40; //rowRect.width =rowRect.width -btnWidth; FlowGraphField.DataType newDataType = (FlowGraphField.DataType)EditorGUI.EnumPopup(new Rect(rowRect.x, rowRect.y, 60, rowRect.height), GUIContent.none, dataType); if (newDataType != dataType) { bool cancel = false; if (newDataType == FlowGraphField.DataType.Data) { assetDataProperty.objectReferenceValue = null; } else if (newDataType == FlowGraphField.DataType.Asset) { if (graphData != null && !graphData.IsEmpty) { cancel = !EditorUtility.DisplayDialog("confirm clear data", "FlowGraph data not null", "ok", "cancel"); } } if (!cancel) { dataType = newDataType; dataTypeProperty.intValue = (int)dataType; property.serializedObject.ApplyModifiedProperties(); } } rowRect.xMax -= btnWidth; rowRect.xMin += 60; //if (assetData != null && assetData.Data != null && assetData.Data.HasDeserializeError) // GUI.color = Color.red; if (dataType == FlowGraphField.DataType.Asset) { var newValue = EditorGUI.ObjectField(rowRect, assetData, typeof(FlowGraphAsset), true) as FlowGraphAsset; //GUI.color = Color.white; if (newValue != assetData) { assetData = newValue; if (newValue) { dataType = FlowGraphField.DataType.Asset; } //else //{ // dataType = FlowGraphField.DataType.Data; //} foreach (var target in property.serializedObject.targetObjects) { assetDataProperty.objectReferenceValue = newValue; dataTypeProperty.intValue = (int)dataType; } property.serializedObject.ApplyModifiedProperties(); } } rowRect = new Rect(rowRect); rowRect.xMin = rowRect.xMax; rowRect.width = btnWidth; if (GUI.Button(rowRect, "Edit")) { //if (field != null) //{ // FlowGraphEditorWindow.ShowWindow(property.serializedObject.targetObject, property.propertyPath); //} if (dataType == FlowGraphField.DataType.Asset) { if (assetData) { FlowGraphEditorWindow.ShowWindow(assetData); } } else { graphData = field.GetFlowGraphData(); if (graphData == null || (((graphData.flags & FlowGraphDataFlags.InitializedNew) != FlowGraphDataFlags.InitializedNew) && graphData.IsEmpty)) { Undo.RecordObject(property.serializedObject.targetObject, null); if (graphData == null) { graphData = new FlowGraphData(); field.Data = graphData; } FlowGraphData.InitializedNewGraph(graphData); EditorUtility.SetDirty(property.serializedObject.targetObject); } FlowGraphEditorWindow.ShowWindow(property.serializedObject.targetObject, graphData, property.propertyPath); } } rowRect.y += rowRect.height; using (new GUIDepthScope()) { if (field != null) { var graph = field.GetFlowGraphData(); if (graph != null) { using (var check = new EditorGUI.ChangeCheckScope()) { field.Inputs = DrawVariables(new Rect(0, rowRect.y, position.width, totalHeight - rowRect.y), graph.Variables, field.GetAllOvrrideInputs().ToDictionary(o => o.Name), field.Inputs); if (check.changed) { if (AssetDatabase.IsNativeAsset(property.serializedObject.targetObject)) { EditorUtility.SetDirty(property.serializedObject.targetObject); } else { EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); } } } } } } }