This repository has been archived by the owner on Oct 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 417
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
#70 Modular Canvas and Traversal behaviours This update streamlines the process of adding new types of canvases with new properties, behaviours, requirements and traversal algorithms to the framework in a modular way. Canvas behaviour can be scripted by controlling many aspects of the canvas and it's modifications. It's also possible to add new ways of traversing these canvases, either similar to the default calculation, a statemachine, a dialogue system, or just a data visualizer, this is now possible without workarounds. This is made possible by having a canvas type specify the basic properties and behaviours and a seperate traversal class manage the traversal of the canvas. Many canvas types could use the same traversal algorithm. WARNING: I seperated the default calculation behaviour from canvas base class, making it a seperate subclass, and NodeCanvas now serves only as a base class. Due to compability with previous save files (which would be broken if NodeCanvas was now abstract) it's now weakly limited (canvases with default type are possible but prohibited). In order to use previous saves, you first have to specify a valid type (any Canvas subclass) after loading. Also note later on NodeCanvas WILL be made abstract and thus older saves will be broken! Included is a Graph Canvas type with seperate (yet empty) traversal behaviour to show how easily canvases can be scripted. Changelog: - NodeCanvas is now the base class for every other canvas type - Added warning and side panel entry to convert canvas if the loaded canvas is of type NodeCanvas (base type). Rest of the framework is also mostly disabled if current canvas is of base type - Added NodeCanvasTraversal base class to add unique traversal algorithms to a specific canvas type - Added various callbacks to NodeCanvas like OnCreate, OnValidate, OnBeforeSavingCanvas, CanAddNode - Added NodeCanvas.CreateCanvas methods to create a canvas - NodeEditor is now completely lifted off the calculation code, API to calculate changed to `nodeCanvas.TraverseAll ()` and `nodeCanvas.OnNodeChange (Node)` - Added Graph canvas example - Fixed warnings in RootGraphNode
- Loading branch information
Showing
32 changed files
with
458 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using UnityEngine; | ||
using System.Collections; | ||
using NodeEditorFramework; | ||
|
||
namespace NodeEditorFramework.Standard | ||
{ | ||
[NodeCanvasType("Graph Canvas")] | ||
public class GraphCanvasType : NodeCanvas | ||
{ | ||
public override string canvasName { get { return "Graph"; } } | ||
|
||
private string rootNodeID { get { return "rootGraphNode"; } } | ||
public RootGraphNode rootNode; | ||
|
||
protected override void OnCreate () | ||
{ | ||
Traversal = new GraphTraversal (this); | ||
rootNode = Node.Create (rootNodeID, Vector2.zero) as RootGraphNode; | ||
} | ||
|
||
private void OnEnable () | ||
{ | ||
// Register to other callbacks | ||
//NodeEditorCallbacks.OnDeleteNode += CheckDeleteNode; | ||
} | ||
|
||
protected override void OnValidate () | ||
{ | ||
if (Traversal == null) | ||
Traversal = new GraphTraversal (this); | ||
if (rootNode == null && (rootNode = nodes.Find ((Node n) => n.GetID == rootNodeID) as RootGraphNode) == null) | ||
rootNode = Node.Create (rootNodeID, Vector2.zero) as RootGraphNode; | ||
} | ||
|
||
public override bool CanAddNode (string nodeID) | ||
{ | ||
//Debug.Log ("Check can add node " + nodeID); | ||
if (nodeID == rootNodeID) | ||
return !nodes.Exists ((Node n) => n.GetID == rootNodeID); | ||
return true; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using NodeEditorFramework; | ||
using UnityEngine; | ||
using System.Collections.Generic; | ||
|
||
namespace NodeEditorFramework.Standard | ||
{ | ||
public class GraphTraversal : NodeCanvasTraversal | ||
{ | ||
GraphCanvasType Canvas; | ||
|
||
public GraphTraversal (GraphCanvasType canvas) : base(canvas) | ||
{ | ||
Canvas = canvas; | ||
} | ||
|
||
/// <summary> | ||
/// Traverse the canvas and evaluate it | ||
/// </summary> | ||
public override void TraverseAll () | ||
{ | ||
RootGraphNode rootNode = Canvas.rootNode; | ||
rootNode.Calculate (); | ||
//Debug.Log ("RootNode is " + rootNode); | ||
} | ||
} | ||
} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using UnityEngine; | ||
using System.Collections; | ||
using NodeEditorFramework; | ||
|
||
namespace NodeEditorFramework.Standard | ||
{ | ||
[NodeCanvasType("Calculation")] | ||
public class CalculationCanvasType : NodeCanvas | ||
{ | ||
public override string canvasName { get { return "Calculation Canvas"; } } | ||
|
||
protected override void OnCreate () | ||
{ | ||
Traversal = new DefaultCanvasCalculator (this); | ||
} | ||
|
||
public void OnEnable () | ||
{ | ||
// Register to other callbacks, f.E.: | ||
//NodeEditorCallbacks.OnDeleteNode += OnDeleteNode; | ||
} | ||
|
||
protected override void OnValidate () | ||
{ | ||
if (Traversal == null) | ||
Traversal = new DefaultCanvasCalculator (this); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.