Skip to content

Latest commit

 

History

History

README.md

Node Based

using System;
using OlegHcp.NodeBased;

[Serializable]
public class ExampleNode : Node<ExampleNode>
{
    [UnityEngine.SerializeField]
    private string _text;

    public string Text => _text;
}

using OlegHcp.NodeBased;
using UnityEngine;

[CreateAssetMenu(menuName = nameof(OlegHcp) + "/Graph/" + nameof(ExampleGraph), fileName = nameof(ExampleGraph))]
public class ExampleGraph : Graph<ExampleNode>
{

}

using OlegHcp.NodeBased;
using UnityEngine;

public class Example : MonoBehaviour
{
    [SerializeField]
    private ExampleGraph _graph;

    private void DoSomething()
    {
        ExampleNode node = _graph.RootNode;

        foreach (TransitionInfo<ExampleNode> transition in node)
        {
            if (!transition.Exists)
            {
                Debug.Log(transition.NextNode.Text);
            }
        }
    }
}

Custom Node View

using OlegHcp;
using OlegHcpEditor.NodeBased;
using UnityEditor;
using UnityEngine;

[CustomNodeDrawer(typeof(ExampleNode))]
public class ExampleNodeDrawer : NodeDrawer
{
    protected override float GetHeight(SerializedProperty node)
    {
        return base.GetHeight(node) * 2f + EditorGUIUtility.standardVerticalSpacing;
    }

    protected override Color GetHeaderColor(bool rootNode)
    {
        return rootNode ? Colours.Sky : Colours.Lime;
    }

    protected override void OnGui(SerializedProperty node, float width)
    {
        EditorGUILayout.LabelField("Overridden", "Qwerty");
        GUILayout.Button("Button");
    }
}