Skip to content

Commit

Permalink
- Added new way to handle the Settings file, that avoids the need to …
Browse files Browse the repository at this point in the history
…store it in the Assets folder (you can reach the graph settings via ProjectSettings)

- Settings can now also be reverted on a per property basis or altogether
- Removed helper scripts that are not longer needed
- Removed old way to traverse SerializedProperty (was faulty) and extended CreateGenericUI method
  • Loading branch information
Doppelkeks committed Mar 9, 2023
1 parent ef5f358 commit 8007ed6
Show file tree
Hide file tree
Showing 27 changed files with 253 additions and 269 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added tooltips for command panel buttons
- Added "nodeName" field for NodeAttribute so you can customize the nodeName to your liking
### Removed
- Removed Save dialog as it is legacy and not needed
- Removed Save dialog as it is legacy and not needed

## [0.1.6] - 2023-03-09
### Added
- Added new way to handle the Settings file, that avoids the need to store it in the Assets folder (you can reach the graph settings via ProjectSettings)
- Settings can now also be reverted on a per property basis or alltogether
### Removed
- Removed helper scripts that are not longer needed
- Removed old way to traverse SerializedProperty (was faulty) and extended CreateGenericUI method
2 changes: 1 addition & 1 deletion Documentation~
7 changes: 4 additions & 3 deletions Editor/Controllers/GraphController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;
using static NewGraph.GraphSettingsSingleton;

namespace NewGraph {
public class GraphController {
Expand Down Expand Up @@ -325,7 +326,7 @@ private void BuildSearchableMenu() {
Func<bool> defaultEnabledCheck = () => graphView.GetSelectedNodeCount() > 0;
Func<bool> nodeEnabledCheck = () => graphData != null;

searchWindow.StartAddingMenuEntries(GraphSettings.Instance.searchWindowRootHeader);
searchWindow.StartAddingMenuEntries(Settings.searchWindowRootHeader);
// get all types across all assemblies that implement our INode interface
TypeCache.TypeCollection nodeTypes = TypeCache.GetTypesWithAttribute<NodeAttribute>();
foreach (Type nodeType in nodeTypes) {
Expand All @@ -350,13 +351,13 @@ private void BuildSearchableMenu() {

// add to the list of createable nodes
string createNodeLabel = $"{categoryPath}{nodeAttribute.GetName(nodeType)}";
createNodeLabel = (!isUtilityNode ? GraphSettings.Instance.createNodeLabel : GraphSettings.Instance.createUtilityNodeLabel) + createNodeLabel;
createNodeLabel = (!isUtilityNode ? Settings.createNodeLabel : Settings.createUtilityNodeLabel) + createNodeLabel;

searchWindow.AddNodeEntry(createNodeLabel, (obj) => CreateNewNode(nodeType, isUtilityNode));
}
}
searchWindow.ResolveNodeEntries(nodeEnabledCheck);
searchWindow.AddSeparator(GraphSettings.Instance.searchWindowCommandHeader);
searchWindow.AddSeparator(Settings.searchWindowCommandHeader);
searchWindow.AddShortcutEntry(Actions.Frame, SearchTreeEntry.AlwaysEnabled, FrameGraph);
searchWindow.AddShortcutEntry(Actions.Cut, defaultEnabledCheck, OnCut);
searchWindow.AddShortcutEntry(Actions.Copy, defaultEnabledCheck, OnCopy);
Expand Down
15 changes: 8 additions & 7 deletions Editor/Controllers/InspectorController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;
using static NewGraph.GraphSettingsSingleton;

namespace NewGraph {
/// <summary>
Expand Down Expand Up @@ -62,7 +63,7 @@ public InspectorController(VisualElement parent) {
inspectorButton.Add(inspectorButtonImage);
inspectorHeader = inspectorRoot.Q<VisualElement>(nameof(inspectorHeader));

Label startLabel = new Label(GraphSettings.Instance.noGraphLoadedLabel);
Label startLabel = new Label(Settings.noGraphLoadedLabel);
startLabel.AddToClassList(nameof(startLabel));

inspectorHeader.Add(startLabel);
Expand All @@ -87,7 +88,7 @@ private void SetInspectorVisibility(bool visible=true) {
} else {
inspectorContainer.style.visibility = Visibility.Visible;
inspectorHeader.style.visibility = Visibility.Visible;
inspectorRoot.style.minWidth = inspectorRoot.style.maxWidth = GraphSettings.Instance.inspectorWidth;
inspectorRoot.style.minWidth = inspectorRoot.style.maxWidth = Settings.inspectorWidth;
inspectorButtonImage.image = GraphSettings.HideInspectorIcon;
}
}
Expand All @@ -108,20 +109,20 @@ string SelectText(ref int selectedCount, string baseName) {
}

string DoNodeText(ref int selectedCount) {
return SelectText(ref selectedCount, GraphSettings.Instance.node);
return SelectText(ref selectedCount, Settings.node);
}

string DoEdgeText(ref int selectedCount) {
return SelectText(ref selectedCount, GraphSettings.Instance.edge);
return SelectText(ref selectedCount, Settings.edge);
}

if (active && nodeCount == 0 && edgeCount == 0) {
active = false;
} else {
if (nodeCount > 0 && edgeCount > 0) {
multipleNodesSelected.text = $"{DoNodeText(ref nodeCount)} and {DoEdgeText(ref edgeCount)} {GraphSettings.Instance.multipleSelectedMessagePartial}";
multipleNodesSelected.text = $"{DoNodeText(ref nodeCount)} and {DoEdgeText(ref edgeCount)} {Settings.multipleSelectedMessagePartial}";
} else {
multipleNodesSelected.text = $"{(nodeCount > 0 ? DoNodeText(ref nodeCount) : DoEdgeText(ref edgeCount))} {GraphSettings.Instance.multipleSelectedMessagePartial}";
multipleNodesSelected.text = $"{(nodeCount > 0 ? DoNodeText(ref nodeCount) : DoEdgeText(ref edgeCount))} {Settings.multipleSelectedMessagePartial}";
}
}

Expand Down Expand Up @@ -159,7 +160,7 @@ public void SetInspectorContent(VisualElement content, SerializedObject serializ
/// </summary>
private void SettingsChanged() {
if (isInspectorVisible) {
inspectorRoot.style.minWidth = inspectorRoot.style.maxWidth = GraphSettings.Instance.inspectorWidth;
inspectorRoot.style.minWidth = inspectorRoot.style.maxWidth = Settings.inspectorWidth;
}
}

Expand Down
33 changes: 0 additions & 33 deletions Editor/Helpers/ReflectionHelper.cs

This file was deleted.

11 changes: 0 additions & 11 deletions Editor/Helpers/ReflectionHelper.cs.meta

This file was deleted.

73 changes: 0 additions & 73 deletions Editor/Helpers/SerializationHelper.cs

This file was deleted.

11 changes: 0 additions & 11 deletions Editor/Helpers/SerializationHelper.cs.meta

This file was deleted.

56 changes: 35 additions & 21 deletions Editor/Helpers/UIElementsHelper.cs
Original file line number Diff line number Diff line change
@@ -1,39 +1,53 @@
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine.UIElements;

namespace NewGraph {
public static class UIElementsHelper {

public static void CreateGenericUI<T>(SerializedObject serializedObject, VisualElement root, EventCallback<SerializedPropertyChangeEvent> changeCallback = null, bool createGroup = false) {
CreateGenericUI(serializedObject, typeof(T), root, changeCallback, createGroup);
public static PropertyField CreatePropertyFieldWithCallback(SerializedProperty property, EventCallback<SerializedPropertyChangeEvent> changeCallback = null) {
PropertyField propertyField = new PropertyField(property);
if (changeCallback != null) {
propertyField.RegisterValueChangeCallback(changeCallback);
}
return propertyField;
}

public static void CreateGenericUI(SerializedObject serializedObject, Type type, VisualElement root, EventCallback<SerializedPropertyChangeEvent> changeCallback = null, bool createGroup = false) {
List<SerializedProperty> serializedProperties = new List<SerializedProperty>();
SerializationHelper.RetrieveAllSerializedProperties(ref serializedProperties, type, serializedObject);
public static void CreateGenericUI(SerializedObject serializedObject, VisualElement root, EventCallback<SerializedPropertyChangeEvent> changeCallback = null, System.Action<SerializedProperty, VisualElement> CreateAdditionalUI = null) {

Action<SerializedProperty, ScrollView> creationLogic;
if (CreateAdditionalUI != null) {
creationLogic = (prop, scrollView) => {
VisualElement container = new VisualElement();
container.AddToClassList(nameof(container)+nameof(PropertyField));
container.Add(CreatePropertyFieldWithCallback(prop, changeCallback));
CreateAdditionalUI(prop, container);
scrollView.Add(container);
};
} else {
creationLogic = (prop, scrollView) => {
scrollView.Add(CreatePropertyFieldWithCallback(prop, changeCallback));
};
}

void ForEachProperty(ref VisualElement parent) {
foreach (SerializedProperty property in serializedProperties) {
PropertyField propertyField = new PropertyField(property);
if (changeCallback != null) {
propertyField.RegisterValueChangeCallback(changeCallback);
void ForEachProperty(ref ScrollView scrollView) {
SerializedProperty prop = serializedObject.GetIterator();
if (prop.NextVisible(true)) {
do {
if (prop.name != "m_Script") {
creationLogic(prop.Copy(), scrollView);
}
}
parent.Add(propertyField);
while (prop.NextVisible(false));
}
}

if (createGroup) {
VisualElement group = new VisualElement();
ForEachProperty(ref group);
root.Add(group);
group.Bind(serializedObject);
} else {
ForEachProperty(ref root);
root.Bind(serializedObject);
}
ScrollView scrollView = new ScrollView();
scrollView.AddToClassList("propertyList"+nameof(ScrollView));
root.Add(scrollView);
ForEachProperty(ref scrollView);
root.Bind(serializedObject);

}
}
Expand Down
3 changes: 2 additions & 1 deletion Editor/Serialization/PropertyBag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using static NewGraph.GraphSettingsSingleton;

namespace NewGraph {
/// <summary>
Expand Down Expand Up @@ -33,7 +34,7 @@ public class PropertyBag {
private PropertyBag(NodeAttribute nodeAttribute, Type nodeType, SerializedProperty nodeProperty) {
this.nodeType = nodeType;

inputPort = new PortInfo(nodeProperty.propertyPath, nodeType, new PortBaseAttribute(nodeAttribute.inputPortName, nodeAttribute.inputPortCapacity, PortDirection.Input), GraphSettings.Instance.defaultInputName);
inputPort = new PortInfo(nodeProperty.propertyPath, nodeType, new PortBaseAttribute(nodeAttribute.inputPortName, nodeAttribute.inputPortCapacity, PortDirection.Input), Settings.defaultInputName);
InitializeAttributebehaviors();
RetrieveAll(nodeProperty);
}
Expand Down
6 changes: 4 additions & 2 deletions Editor/Settings/GraphSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,24 @@ MonoBehaviour:
m_Name: GraphSettings
m_EditorClassIdentifier:
customStylesheet: {fileID: 0}
basePathToSettingsFile: Project/Tools
searchWindowCommandHeader: Commands
searchWindowRootHeader: Create Nodes
openGraphButtonText: Open Graph
wasBlueprintTransferred: 1
hideInspectorIcon: SceneLoadIn
showInspectorIcon: SceneLoadOut
homeButtonIcon: d_SceneViewCamera@2x
createButtonIcon: d_Toolbar Plus
loadButtonIcon: d_FolderOpened Icon
resetButtonIcon: Refresh@2x
createUtilityNodeLabel: Create Utility
createNodeLabel: Create Node
noGraphLoadedLabel: No graph active!
multipleSelectedMessagePartial: selected. Select a single Node to change any exposed
values.
node: node
edge: edge
edgeWidthSelected: 3
edgeWidthSelected: 4
edgeWidthUnselected: 3
disabledPortColor: {r: 0.27450982, g: 0.27450982, b: 0.27450982, a: 0.27}
portColor: {r: 0.9411765, g: 0.9411765, b: 1, a: 0.95}
Expand All @@ -46,3 +47,4 @@ MonoBehaviour:
graphDocumentIdentifier: a1a3b33cb142d06479dfaa381cc82245
graphStylesheetVariablesIdentifier: a22fe40a267e5824dbde2cea493f40e4
graphStylesheetIdentifier: e2825f280a2499d4587129e0a3716e17
settingsStylesheetIdentifier: 7d7e4dcd278879849b62a784de9bdc3c
Loading

0 comments on commit 8007ed6

Please sign in to comment.