Skip to content

Node API

Antoine Lelievre edited this page Mar 28, 2018 · 2 revisions

Custom node creation using PW:

Here is the base code you will need to implement a new node:

using UnityEditor;

namespace PW
{
	public class PWNodeDebugLog : PWNode {

		public override void OnNodeCreate()
		{
			name = "new node";
		}

		public override void OnNodeGUI()
		{
		}

		public override void OnNodeProcess()
		{
		}

	}
}

⚠️ Important !

All node types must be registered in the allNodeTypeList field in the PWNodeGraph class, if your node type is not in this dictionary, the editor will crash during the graph computing. So just add the type of your node like this:

[System.NonSerializedAttribute]
List< Type > allNodeTypeList = new List< Type > {
	typeof(PWNodeSlider),
	typeof(PWNodeAdd),
	typeof(PWNodeDebugLog),
	...
	typeof(PWNodeYourClass),
}

Function call order

function name description
OnNodeAwake() called once, use it to initialize unserializable datas / temporary datas
OnNodeCreate() just like OnNodeAwake but run just after
OnNodeCreateOnce() run once per instance never recalled.
OnNodeProcess() called to each Node process request (on Layout event / on request of chunkLoader / etc)
OnNodeGUI() called each editor frame to render the node GUI.

Field attributes

name constructors descriptions
PWInput (), (string name) input field, this field will be displayed as an anchor left outside of the window, name is to specify the anchor name (max 4 chars)
PWOutput (), (string name) same as PWInput but in output.
PWOffset (int x, int y), (int y) add a visual offset to decal the anchor position
PWColor (float r, float g, float b), (float r, float g, float b, float a) background color of the anchor
PWMultiple (int min, int max, params Type[] allowedTypes), (int min, params Type[] allowedTypes), (params Type[] allowedTypes) *
PWGeneric (param Type[] allowedTypes) allow multiple types in one variable.
PWMirror (string fieldName) not implemented

Functions

OnNodeCreate: this function will be called when your new node is instantiated.
OnNodeGUI: is used to draw the GUI of your node, here use EditorGUILayout function family.
OnNodeProcess: is called whenever PW needs to generate a chunk of terrain, in this function you can compute everything you want and store the result in PWOutput variables.

Anchors manipulations

All anchor manipulation function takes 2 parameters (+1 optional): propertyName: the name of the target field *: value to set index: optional index for PWMultiple anchors

PWNode function name description
UpdatePropEnabled allow to disable/enable an anchor
UpdatePropName change the name of the anchor
UpdatePropBackgroundColor change the background color of the anchor
UpdatePropVisibility update the visibility of the anchor (VISIBLE, GONE or INVISIBLE)
GetPropLinkCount get the number of links connected to the anchor
GetAnchorRect get the anchor rect postion

PWNode bools

name description
seedHasChanged true when seed just changed
positionHasChanged true when chunk position just changed
chunkSizeHasChanged true when chunk size just changed
inputHasChanged true when an Input was linked to your node
outputHasChanged true when an Output was linked to your node
justReloaded true the first frame after script compilation / play mode / editor mode change (when OnEnable is called).
notifyDataChanged always false, set it to true when you modify an internal property which affect output. (must be called in OnNodeGUI())