Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a187a66
preformed the drag creating mechanic here
muwafagelhussein Sep 4, 2019
257d012
called the create drag mechanic here
muwafagelhussein Sep 4, 2019
935cc56
Update NodeEditorAction.cs
muwafagelhussein Sep 4, 2019
8c26042
Un-reverted changes made after 1.7
Siccity Sep 4, 2019
0cf1a0d
update from 1.7
muwafagelhussein Sep 4, 2019
a6f0c97
Update NodeGraphEditor.cs
muwafagelhussein Sep 4, 2019
6657fd4
Add files via upload
muwafagelhussein Sep 4, 2019
5c10727
Done the select feature
muwafagelhussein Sep 4, 2019
e6440bf
Cleanup
Siccity Sep 6, 2019
51a25c2
More cleanup
Siccity Sep 6, 2019
d4345b7
Simplified code
Siccity Sep 6, 2019
9e711f2
Cleanup
Siccity Sep 6, 2019
3b879ed
Add files via upload
muwafagelhussein Jul 4, 2021
358b152
Delete xNode-master directory
muwafagelhussein Jul 10, 2021
da9af2b
Delete Scripts directory
muwafagelhussein Jul 10, 2021
ed720dc
Delete package.json.meta
muwafagelhussein Jul 10, 2021
2f0093e
Delete package.json
muwafagelhussein Jul 10, 2021
6d15b60
Delete Scripts.meta
muwafagelhussein Jul 10, 2021
13d9ece
Delete README.md.meta
muwafagelhussein Jul 10, 2021
d9993ff
Delete README.md
muwafagelhussein Jul 10, 2021
6f3622a
Delete LICENSE.md.meta
muwafagelhussein Jul 10, 2021
5feeae3
Delete LICENSE.md
muwafagelhussein Jul 10, 2021
27943eb
Delete CONTRIBUTING.md.meta
muwafagelhussein Jul 10, 2021
1e6a8ed
Delete CONTRIBUTING.md
muwafagelhussein Jul 10, 2021
1e3d107
Delete .gitignore
muwafagelhussein Jul 10, 2021
e4f49fd
Add files via upload
muwafagelhussein Jul 10, 2021
7ad0198
Delete xNode-master directory
muwafagelhussein Jul 10, 2021
e517cc2
Add files via upload
muwafagelhussein Jul 10, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions .gitignore

This file was deleted.

16 changes: 12 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,22 @@ If you haven't already, join our [Discord channel](https://discord.gg/qgPrHv4)!

## Pull Requests
Try to keep your pull requests relevant, neat, and manageable. If you are adding multiple features, split them into separate PRs.
* Avoid including irellevant whitespace or formatting changes.
* Comment your code.
* Spell check your code / comments
* Use consistent formatting
These are the main points to follow:

1) Use formatting which is consistent with the rest of xNode base (see below)
2) Keep _one feature_ per PR (see below)
3) xNode aims to be compatible with C# 4.x, do not use new language features
4) Avoid including irellevant whitespace or formatting changes
5) Comment your code
6) Spell check your code / comments
7) Use concrete types, not *var*
8) Use english language

## New features
xNode aims to be simple and extendible, not trying to fix all of Unity's shortcomings.

Approved changes might be rejected if bundled with rejected changes, so keep PRs as separate as possible.

If your feature aims to cover something not related to editing nodes, it generally won't be accepted. If in doubt, ask on the Discord channel.

## Coding conventions
Expand Down
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
[![GitHub issues](https://img.shields.io/github/issues/Siccity/xNode.svg)](https://github.com/Siccity/xNode/issues)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/Siccity/xNode/master/LICENSE.md)
[![GitHub Wiki](https://img.shields.io/badge/wiki-available-brightgreen.svg)](https://github.com/Siccity/xNode/wiki)
[![openupm](https://img.shields.io/npm/v/com.github.siccity.xnode?label=openupm&registry_uri=https://package.openupm.com)](https://openupm.com/packages/com.github.siccity.xnode/)

[Downloads](https://github.com/Siccity/xNode/releases) / [Asset Store](http://u3d.as/108S) / [Documentation](https://github.com/Siccity/xNode/wiki)

[Support Me on Ko-fi](https://ko-fi.com/Z8Z5DYWA)
Support xNode on [Ko-fi](https://ko-fi.com/Z8Z5DYWA) or [Patreon](https://www.patreon.com/thorbrigsted)

### xNode
Thinking of developing a node-based plugin? Then this is for you. You can download it as an archive and unpack to a new unity project, or connect it as git submodule.
Expand All @@ -32,7 +33,11 @@ With a minimal footprint, it is ideal as a base for custom state machines, dialo
* [Getting started](https://github.com/Siccity/xNode/wiki/Getting%20Started) - create your very first node node and graph
* [Examples branch](https://github.com/Siccity/xNode/tree/examples) - look at other small projects

### Installation
<details><summary>Instructions</summary>

### Installing with Unity Package Manager
***Via Git URL***
*(Requires Unity version 2018.3.0b7 or above)*

To install this project as a [Git dependency](https://docs.unity3d.com/Manual/upm-git.html) using the Unity Package Manager,
Expand All @@ -46,6 +51,29 @@ You will need to have Git installed and available in your system's PATH.

If you are using [Assembly Definitions](https://docs.unity3d.com/Manual/ScriptCompilationAssemblyDefinitionFiles.html) in your project, you will need to add `XNode` and/or `XNodeEditor` as Assembly Definition References.

***Via OpenUPM***

The package is available on the [openupm registry](https://openupm.com). It's recommended to install it via [openupm-cli](https://github.com/openupm/openupm-cli).

```
openupm add com.github.siccity.xnode
```

### Installing with git
***Via Git Submodule***

To add xNode as a [submodule](https://git-scm.com/book/en/v2/Git-Tools-Submodules) in your existing git project,
run the following git command from your project root:

```
git submodule add git@github.com:Siccity/xNode.git Assets/Submodules/xNode
```

### Installing 'the old way'
If no source control or package manager is available to you, you can simply copy/paste the source files into your assets folder.

</details>

### Node example:
```csharp
// public classes deriving from Node are registered as nodes for use within a graph
Expand Down Expand Up @@ -82,5 +110,10 @@ public class MathNode : Node {
}
```

### Plugins
Plugins are repositories that add functionality to xNode
* [xNodeGroups](https://github.com/Siccity/xNodeGroups): adds resizable groups

### Community
Join the [Discord](https://discord.gg/qgPrHv4 "Join Discord server") server to leave feedback or get support.
Feel free to also leave suggestions/requests in the [issues](https://github.com/Siccity/xNode/issues "Go to Issues") page.
75 changes: 75 additions & 0 deletions Scripts/Editor/GraphAndNodeEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using UnityEditor;
using UnityEngine;
#if ODIN_INSPECTOR
using Sirenix.OdinInspector.Editor;
using Sirenix.Utilities;
using Sirenix.Utilities.Editor;
#endif

namespace XNodeEditor {
/// <summary> Override graph inspector to show an 'Open Graph' button at the top </summary>
[CustomEditor(typeof(XNode.NodeGraph), true)]
#if ODIN_INSPECTOR
public class GlobalGraphEditor : OdinEditor {
public override void OnInspectorGUI() {
if (GUILayout.Button("Edit graph", GUILayout.Height(40))) {
NodeEditorWindow.Open(serializedObject.targetObject as XNode.NodeGraph);
}
base.OnInspectorGUI();
}
}
#else
[CanEditMultipleObjects]
public class GlobalGraphEditor : Editor {
public override void OnInspectorGUI() {
serializedObject.Update();

if (GUILayout.Button("Edit graph", GUILayout.Height(40))) {
NodeEditorWindow.Open(serializedObject.targetObject as XNode.NodeGraph);
}

GUILayout.Space(EditorGUIUtility.singleLineHeight);
GUILayout.Label("Raw data", "BoldLabel");

DrawDefaultInspector();

serializedObject.ApplyModifiedProperties();
}
}
#endif

[CustomEditor(typeof(XNode.Node), true)]
#if ODIN_INSPECTOR
public class GlobalNodeEditor : OdinEditor {
public override void OnInspectorGUI() {
if (GUILayout.Button("Edit graph", GUILayout.Height(40))) {
SerializedProperty graphProp = serializedObject.FindProperty("graph");
NodeEditorWindow w = NodeEditorWindow.Open(graphProp.objectReferenceValue as XNode.NodeGraph);
w.Home(); // Focus selected node
}
base.OnInspectorGUI();
}
}
#else
[CanEditMultipleObjects]
public class GlobalNodeEditor : Editor {
public override void OnInspectorGUI() {
serializedObject.Update();

if (GUILayout.Button("Edit graph", GUILayout.Height(40))) {
SerializedProperty graphProp = serializedObject.FindProperty("graph");
NodeEditorWindow w = NodeEditorWindow.Open(graphProp.objectReferenceValue as XNode.NodeGraph);
w.Home(); // Focus selected node
}

GUILayout.Space(EditorGUIUtility.singleLineHeight);
GUILayout.Label("Raw data", "BoldLabel");

// Now draw the node itself.
DrawDefaultInspector();

serializedObject.ApplyModifiedProperties();
}
}
#endif
}
11 changes: 11 additions & 0 deletions Scripts/Editor/GraphAndNodeEditor.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions Scripts/Editor/GraphRenameFixAssetProcessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using UnityEditor;
using XNode;

namespace XNodeEditor {
/// <summary>
/// This asset processor resolves an issue with the new v2 AssetDatabase system present on 2019.3 and later. When
/// renaming a <see cref="XNode.NodeGraph"/> asset, it appears that sometimes the v2 AssetDatabase will swap which asset
/// is the main asset (present at top level) between the <see cref="XNode.NodeGraph"/> and one of its <see cref="XNode.Node"/>
/// sub-assets. As a workaround until Unity fixes this, this asset processor checks all renamed assets and if it
/// finds a case where a <see cref="XNode.Node"/> has been made the main asset it will swap it back to being a sub-asset
/// and rename the node to the default name for that node type.
/// </summary>
internal sealed class GraphRenameFixAssetProcessor : AssetPostprocessor {
private static void OnPostprocessAllAssets(
string[] importedAssets,
string[] deletedAssets,
string[] movedAssets,
string[] movedFromAssetPaths) {
for (int i = 0; i < movedAssets.Length; i++) {
Node nodeAsset = AssetDatabase.LoadMainAssetAtPath(movedAssets[i]) as Node;

// If the renamed asset is a node graph, but the v2 AssetDatabase has swapped a sub-asset node to be its
// main asset, reset the node graph to be the main asset and rename the node asset back to its default
// name.
if (nodeAsset != null && AssetDatabase.IsMainAsset(nodeAsset)) {
AssetDatabase.SetMainObject(nodeAsset.graph, movedAssets[i]);
AssetDatabase.ImportAsset(movedAssets[i]);

nodeAsset.name = NodeEditorUtilities.NodeDefaultName(nodeAsset.GetType());
EditorUtility.SetDirty(nodeAsset);
}
}
}
}
}
11 changes: 11 additions & 0 deletions Scripts/Editor/GraphRenameFixAssetProcessor.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 47 additions & 12 deletions Scripts/Editor/NodeEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ namespace XNodeEditor {
[CustomNodeEditor(typeof(XNode.Node))]
public class NodeEditor : XNodeEditor.Internal.NodeEditorBase<NodeEditor, NodeEditor.CustomNodeEditorAttribute, XNode.Node> {

private readonly Color DEFAULTCOLOR = new Color32(90, 97, 105, 255);

/// <summary> Fires every whenever a node was modified through the editor </summary>
public static Action<XNode.Node> onUpdateNode;
public readonly static Dictionary<XNode.NodePort, Vector2> portPositions = new Dictionary<XNode.NodePort, Vector2>();

#if ODIN_INSPECTOR
internal static bool inNodeEditor = false;
protected internal static bool inNodeEditor = false;
#endif

public virtual void OnHeaderGUI() {
Expand All @@ -41,17 +39,38 @@ public virtual void OnBodyGUI() {
string[] excludes = { "m_Script", "graph", "position", "ports" };

#if ODIN_INSPECTOR
InspectorUtilities.BeginDrawPropertyTree(objectTree, true);
GUIHelper.PushLabelWidth(84);
objectTree.Draw(true);
try
{
#if ODIN_INSPECTOR_3
objectTree.BeginDraw( true );
#else
InspectorUtilities.BeginDrawPropertyTree(objectTree, true);
#endif
}
catch ( ArgumentNullException )
{
#if ODIN_INSPECTOR_3
objectTree.EndDraw();
#else
InspectorUtilities.EndDrawPropertyTree(objectTree);
#endif
NodeEditor.DestroyEditor(this.target);
return;
}

GUIHelper.PushLabelWidth( 84 );
objectTree.Draw( true );
#if ODIN_INSPECTOR_3
objectTree.EndDraw();
#else
InspectorUtilities.EndDrawPropertyTree(objectTree);
#endif
GUIHelper.PopLabelWidth();
#else

// Iterate through serialized properties and draw them like the Inspector (But with ports)
SerializedProperty iterator = serializedObject.GetIterator();
bool enterChildren = true;
EditorGUIUtility.labelWidth = 84;
while (iterator.NextVisible(enterChildren)) {
enterChildren = false;
if (excludes.Contains(iterator.name)) continue;
Expand All @@ -68,13 +87,11 @@ public virtual void OnBodyGUI() {
serializedObject.ApplyModifiedProperties();

#if ODIN_INSPECTOR
// Call repaint so that the graph window elements respond properly to layout changes coming from Odin
// Call repaint so that the graph window elements respond properly to layout changes coming from Odin
if (GUIHelper.RepaintRequested) {
GUIHelper.ClearRepaintRequest();
window.Repaint();
}
#else
window.Repaint();
#endif

#if ODIN_INSPECTOR
Expand All @@ -96,26 +113,40 @@ public virtual Color GetTint() {
Color color;
if (type.TryGetAttributeTint(out color)) return color;
// Return default color (grey)
else return DEFAULTCOLOR;
else return NodeEditorPreferences.GetSettings().tintColor;
}

public virtual GUIStyle GetBodyStyle() {
return NodeEditorResources.styles.nodeBody;
}

public virtual GUIStyle GetBodyHighlightStyle() {
return NodeEditorResources.styles.nodeHighlight;
}

/// <summary> Override to display custom node header tooltips </summary>
public virtual string GetHeaderTooltip() {
return null;
}

/// <summary> Add items for the context menu when right-clicking this node. Override to add custom menu items. </summary>
public virtual void AddContextMenuItems(GenericMenu menu) {
bool canRemove = true;
// Actions if only one node is selected
if (Selection.objects.Length == 1 && Selection.activeObject is XNode.Node) {
XNode.Node node = Selection.activeObject as XNode.Node;
menu.AddItem(new GUIContent("Move To Top"), false, () => NodeEditorWindow.current.MoveNodeToTop(node));
menu.AddItem(new GUIContent("Rename"), false, NodeEditorWindow.current.RenameSelectedNode);

canRemove = NodeGraphEditor.GetEditor(node.graph, NodeEditorWindow.current).CanRemove(node);
}

// Add actions to any number of selected nodes
menu.AddItem(new GUIContent("Copy"), false, NodeEditorWindow.current.CopySelectedNodes);
menu.AddItem(new GUIContent("Duplicate"), false, NodeEditorWindow.current.DuplicateSelectedNodes);
menu.AddItem(new GUIContent("Remove"), false, NodeEditorWindow.current.RemoveSelectedNodes);

if (canRemove) menu.AddItem(new GUIContent("Remove"), false, NodeEditorWindow.current.RemoveSelectedNodes);
else menu.AddItem(new GUIContent("Remove"), false, null);

// Custom sctions if only one node is selected
if (Selection.objects.Length == 1 && Selection.activeObject is XNode.Node) {
Expand All @@ -128,9 +159,13 @@ public virtual void AddContextMenuItems(GenericMenu menu) {
public void Rename(string newName) {
if (newName == null || newName.Trim() == "") newName = NodeEditorUtilities.NodeDefaultName(target.GetType());
target.name = newName;
OnRename();
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(target));
}

/// <summary> Called after this node's name has changed. </summary>
public virtual void OnRename() { }

[AttributeUsage(AttributeTargets.Class)]
public class CustomNodeEditorAttribute : Attribute,
XNodeEditor.Internal.NodeEditorBase<NodeEditor, NodeEditor.CustomNodeEditorAttribute, XNode.Node>.INodeEditorAttrib {
Expand Down
Loading