summaryrefslogtreecommitdiff
path: root/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/Nodes/StateNode.cs
blob: 2bb7dc03f2be88b41a4eaaf6034b0b13177cc24b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace XNode.Examples.StateGraph {
	public class StateNode : Node {

		[Input] public Empty enter;
		[Output] public Empty exit;

		public void MoveNext() {
			StateGraph fmGraph = graph as StateGraph;

			if (fmGraph.current != this) {
				Debug.LogWarning("Node isn't active");
				return;
			}

			NodePort exitPort = GetOutputPort("exit");

			if (!exitPort.IsConnected) {
				Debug.LogWarning("Node isn't connected");
				return;
			}

			StateNode node = exitPort.Connection.node as StateNode;
			node.OnEnter();
		}

		public void OnEnter() {
			StateGraph fmGraph = graph as StateGraph;
			fmGraph.current = this;
		}

		[Serializable]
		public class Empty { }
	}
}