├── Editor.meta ├── Editor ├── Blackboard.meta ├── Blackboard │ ├── BlackboardBoolPropertyView.cs │ ├── BlackboardBoolPropertyView.cs.meta │ ├── BlackboardColliderPropertyView.cs │ ├── BlackboardColliderPropertyView.cs.meta │ ├── BlackboardColorPropertyView.cs │ ├── BlackboardColorPropertyView.cs.meta │ ├── BlackboardDoublePropertyView.cs │ ├── BlackboardDoublePropertyView.cs.meta │ ├── BlackboardFieldView.cs │ ├── BlackboardFieldView.cs.meta │ ├── BlackboardFloatPropertyView.cs │ ├── BlackboardFloatPropertyView.cs.meta │ ├── BlackboardGameObjectPropertyView.cs │ ├── BlackboardGameObjectPropertyView.cs.meta │ ├── BlackboardIntPropertyView.cs │ ├── BlackboardIntPropertyView.cs.meta │ ├── BlackboardLayerMaskPropertyView.cs │ ├── BlackboardLayerMaskPropertyView.cs.meta │ ├── BlackboardMaterialPropertyView.cs │ ├── BlackboardMaterialPropertyView.cs.meta │ ├── BlackboardObjectPropertyView.cs │ ├── BlackboardObjectPropertyView.cs.meta │ ├── BlackboardRectIntPropertyView.cs │ ├── BlackboardRectIntPropertyView.cs.meta │ ├── BlackboardRectPropertyView.cs │ ├── BlackboardRectPropertyView.cs.meta │ ├── BlackboardStringPropertyView.cs │ ├── BlackboardStringPropertyView.cs.meta │ ├── BlackboardTransformPropertyView.cs │ ├── BlackboardTransformPropertyView.cs.meta │ ├── BlackboardVector2IntPropertyView.cs │ ├── BlackboardVector2IntPropertyView.cs.meta │ ├── BlackboardVector2PropertyView.cs │ ├── BlackboardVector2PropertyView.cs.meta │ ├── BlackboardVector3IntPropertyView.cs │ ├── BlackboardVector3IntPropertyView.cs.meta │ ├── BlackboardVector3PropertyView.cs │ ├── BlackboardVector3PropertyView.cs.meta │ ├── BlackboardVector4PropertyView.cs │ ├── BlackboardVector4PropertyView.cs.meta │ ├── BlackboardView.cs │ └── BlackboardView.cs.meta ├── Component.meta ├── Component │ ├── VisualGraphMonoBehaviourInspector.cs │ └── VisualGraphMonoBehaviourInspector.cs.meta ├── Graph.meta ├── Graph │ ├── VisualGraphEditor.cs │ ├── VisualGraphEditor.cs.meta │ ├── VisualGraphInspector.cs │ ├── VisualGraphInspector.cs.meta │ ├── VisualGraphSearchWindow.cs │ ├── VisualGraphSearchWindow.cs.meta │ ├── VisualGraphSettings.cs │ ├── VisualGraphSettings.cs.meta │ ├── VisualGraphView.cs │ ├── VisualGraphView.cs.meta │ ├── VisualGraphViewAttributes.cs │ └── VisualGraphViewAttributes.cs.meta ├── Nodes.meta ├── Nodes │ ├── VisualGraphGroupView.cs │ ├── VisualGraphGroupView.cs.meta │ ├── VisualGraphNodeView.cs │ ├── VisualGraphNodeView.cs.meta │ ├── VisualGraphStartNodeView.cs │ └── VisualGraphStartNodeView.cs.meta ├── Ports.meta ├── Ports │ ├── VisualGraphDefaultPortView.cs │ ├── VisualGraphDefaultPortView.cs.meta │ ├── VisualGraphLabelPortView.cs │ ├── VisualGraphLabelPortView.cs.meta │ ├── VisualGraphPortView.cs │ └── VisualGraphPortView.cs.meta ├── Resources.meta ├── Resources │ ├── Node.uss │ ├── Node.uss.meta │ ├── VisualGraphMonoBehaviourInspector.uss │ ├── VisualGraphMonoBehaviourInspector.uss.meta │ ├── VisualGraphStyle.uss │ └── VisualGraphStyle.uss.meta ├── VisualGraphEditorAssembly.asmdef └── VisualGraphEditorAssembly.asmdef.meta ├── LICENSE ├── LICENSE.meta ├── README.md ├── README.md.meta ├── Runtime.meta ├── Runtime ├── Blackboard.meta ├── Blackboard │ ├── AbstractBlackboardProperty.cs │ ├── AbstractBlackboardProperty.cs.meta │ ├── BoolBlackboardProperty.cs │ ├── BoolBlackboardProperty.cs.meta │ ├── ColliderBlackboardProperty.cs │ ├── ColliderBlackboardProperty.cs.meta │ ├── ColorBlackboardProperty.cs │ ├── ColorBlackboardProperty.cs.meta │ ├── DoubleBlackboardProperty.cs │ ├── DoubleBlackboardProperty.cs.meta │ ├── FloatBlackboardProperty.cs │ ├── FloatBlackboardProperty.cs.meta │ ├── GameObjectBlackboardProperty.cs │ ├── GameObjectBlackboardProperty.cs.meta │ ├── IntBlackboardProperty.cs │ ├── IntBlackboardProperty.cs.meta │ ├── LayerMaskBlackboardProperty.cs │ ├── LayerMaskBlackboardProperty.cs.meta │ ├── MaterialBlackboardProperty.cs │ ├── MaterialBlackboardProperty.cs.meta │ ├── ObjectBlackboardProperty.cs │ ├── ObjectBlackboardProperty.cs.meta │ ├── RectBlackboardProperty.cs │ ├── RectBlackboardProperty.cs.meta │ ├── RectIntBlackboardProperty.cs │ ├── RectIntBlackboardProperty.cs.meta │ ├── StringBlackboardProperty.cs │ ├── StringBlackboardProperty.cs.meta │ ├── TransformBlackboardProperty.cs │ ├── TransformBlackboardProperty.cs.meta │ ├── Vector2BlackboardProperty.cs │ ├── Vector2BlackboardProperty.cs.meta │ ├── Vector2IntBlackboardProperty.cs │ ├── Vector2IntBlackboardProperty.cs.meta │ ├── Vector3BlackboardProperty.cs │ ├── Vector3BlackboardProperty.cs.meta │ ├── Vector3IntBlackboardProperty.cs │ ├── Vector3IntBlackboardProperty.cs.meta │ ├── Vector4BlackboardProperty.cs │ └── Vector4BlackboardProperty.cs.meta ├── Component.meta ├── Component │ ├── VisualGraphMonoBehaviour.cs │ └── VisualGraphMonoBehaviour.cs.meta ├── Graph.meta ├── Graph │ ├── VisualGraph.cs │ ├── VisualGraph.cs.meta │ ├── VisualGraphAttributes.cs │ └── VisualGraphAttributes.cs.meta ├── Node.meta ├── Node │ ├── VIsualGraphPort.cs │ ├── VIsualGraphPort.cs.meta │ ├── VisualGraphGroup.cs │ ├── VisualGraphGroup.cs.meta │ ├── VisualGraphNode.cs │ ├── VisualGraphNode.cs.meta │ ├── VisualGraphStartNode.cs │ └── VisualGraphStartNode.cs.meta ├── VisualGraphAssembly.asmdef └── VisualGraphAssembly.asmdef.meta ├── Samples~.meta ├── Samples~ ├── Example.meta ├── Example │ ├── Editor.meta │ ├── Editor │ │ ├── Nodes.meta │ │ ├── Nodes │ │ │ ├── ExampleNodeView.cs │ │ │ ├── ExampleNodeView.cs.meta │ │ │ ├── ExamplePortView.cs │ │ │ └── ExamplePortView.cs.meta │ │ ├── Resources.meta │ │ └── Resources │ │ │ ├── ExampleNodeStyle.uss │ │ │ └── ExampleNodeStyle.uss.meta │ ├── Runtime.meta │ └── Runtime │ │ ├── Graphs.meta │ │ ├── Graphs │ │ ├── Empty Graph.asset │ │ ├── Empty Graph.asset.meta │ │ ├── Simple Graph.asset │ │ └── Simple Graph.asset.meta │ │ ├── Scripts.meta │ │ └── Scripts │ │ ├── ExampleGraph.cs │ │ ├── ExampleGraph.cs.meta │ │ ├── ExampleNode.cs │ │ ├── ExampleNode.cs.meta │ │ ├── ExamplePort.cs │ │ └── ExamplePort.cs.meta ├── FSM.meta └── FSM │ ├── Editor.meta │ ├── Editor │ ├── Ports.meta │ ├── Ports │ │ ├── FSMPortView.cs │ │ └── FSMPortView.cs.meta │ ├── Resources.meta │ └── Resources │ │ ├── LightOffStyle.uss │ │ ├── LightOffStyle.uss.meta │ │ ├── LightOnStyle.uss │ │ └── LightOnStyle.uss.meta │ ├── Runtime.meta │ └── Runtime │ ├── Graphs.meta │ ├── Graphs │ ├── Light FSM Graph.asset │ └── Light FSM Graph.asset.meta │ ├── Scenes.meta │ ├── Scenes │ ├── FSM - VisualGraph.unity │ └── FSM - VisualGraph.unity.meta │ ├── Scripts.meta │ └── Scripts │ ├── Graph.meta │ ├── Graph │ ├── FSM.cs │ ├── FSM.cs.meta │ ├── FSMGraph.cs │ └── FSMGraph.cs.meta │ ├── Nodes.meta │ ├── Nodes │ ├── BaseState.cs │ ├── BaseState.cs.meta │ ├── LightOffState.cs │ ├── LightOffState.cs.meta │ ├── LightOnState.cs │ └── LightOnState.cs.meta │ ├── Ports.meta │ └── Ports │ ├── FSMPort.cs │ └── FSMPort.cs.meta ├── package.json └── package.json.meta /Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a50385eed5d245543b46af23697f3393 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/Blackboard.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 13e5e0c7db5409b42ac225d633777022 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardBoolPropertyView.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using UnityEditor.Experimental.GraphView; 7 | using UnityEngine.UIElements; 8 | using VisualGraphRuntime; 9 | 10 | namespace VisualGraphEditor 11 | { 12 | [BlackboardPropertyType(typeof(BoolBlackboardProperty), "bool")] 13 | public class BlackboardBoolPropertyView : BlackboardFieldView 14 | { 15 | public override void CreateField(BlackboardField field) 16 | { 17 | BoolBlackboardProperty localProperty = (BoolBlackboardProperty)property; 18 | CreatePropertyField(field, localProperty); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardBoolPropertyView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 238b8703d4661be4f8fdaa3e1cb4823f 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardColliderPropertyView.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using UnityEditor.Experimental.GraphView; 7 | using VisualGraphRuntime; 8 | using UnityEngine; 9 | 10 | namespace VisualGraphEditor 11 | { 12 | [BlackboardPropertyType(typeof(ColliderBlackboardProperty), "Collider")] 13 | public class BlackboardColliderPropertyView : BlackboardFieldView 14 | { 15 | public override void CreateField(BlackboardField field) 16 | { 17 | ColliderBlackboardProperty localProperty = (ColliderBlackboardProperty)property; 18 | CreateObjectPropertyField(field, localProperty); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardColliderPropertyView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2954265eb2d1474408d91d66643f5b94 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardColorPropertyView.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using UnityEditor.UIElements; 7 | using UnityEditor.Experimental.GraphView; 8 | using VisualGraphRuntime; 9 | using UnityEngine; 10 | 11 | namespace VisualGraphEditor 12 | { 13 | [BlackboardPropertyType(typeof(ColorBlackboardProperty), "Color")] 14 | public class BlackboardColorPropertyView : BlackboardFieldView 15 | { 16 | public override void CreateField(BlackboardField field) 17 | { 18 | ColorBlackboardProperty localProperty = (ColorBlackboardProperty)property; 19 | CreatePropertyField(field, localProperty); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardColorPropertyView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 364c98a2a63c91c4e9236c3916e08b0c 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardDoublePropertyView.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using UnityEditor.Experimental.GraphView; 7 | using UnityEditor.UIElements; 8 | using VisualGraphRuntime; 9 | 10 | namespace VisualGraphEditor 11 | { 12 | [BlackboardPropertyType(typeof(DoubleBlackboardProperty), "double")] 13 | public class BlackboardDoublePropertyView : BlackboardFieldView 14 | { 15 | public override void CreateField(BlackboardField field) 16 | { 17 | DoubleBlackboardProperty localProperty = (DoubleBlackboardProperty)property; 18 | CreatePropertyField(field, localProperty); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardDoublePropertyView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c6c6fdc5fd5d6c44e8268cdab35d92fc 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardFieldView.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using System; 7 | using UnityEditor; 8 | using UnityEditor.UIElements; 9 | using UnityEditor.Experimental.GraphView; 10 | using UnityEngine.UIElements; 11 | using VisualGraphRuntime; 12 | 13 | namespace VisualGraphEditor 14 | { 15 | /// 16 | /// 17 | /// 18 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] 19 | public class BlackboardPropertyTypeAttribute : Attribute 20 | { 21 | public Type type; 22 | public string menuName; 23 | 24 | /// 25 | /// 26 | /// 27 | /// 28 | public BlackboardPropertyTypeAttribute(Type _type, string _menuName) 29 | { 30 | type = _type; 31 | menuName = _menuName; 32 | } 33 | } 34 | 35 | public abstract class BlackboardFieldView : VisualElement 36 | { 37 | public BlackboardView blackboardView; 38 | protected VisualGraph visualGraph; 39 | public AbstractBlackboardProperty property; 40 | 41 | public Action onRemoveBlackboardProperty; 42 | 43 | public abstract void CreateField(BlackboardField field); 44 | 45 | public void CreateView(VisualGraph visualGraph, AbstractBlackboardProperty property) 46 | { 47 | this.visualGraph = visualGraph; 48 | this.property = property; 49 | 50 | VisualElement rowView = new VisualElement(); 51 | rowView.style.flexDirection = FlexDirection.Row; 52 | 53 | //Type valueType = (Type)property.PropertyType; When we are no type for property 54 | Type valueType = (Type)property.GetType().GetProperty("PropertyType").GetValue(property, null); 55 | 56 | var field = new BlackboardField 57 | { 58 | text = property.Name, 59 | typeText = valueType.Name, 60 | userData = property 61 | }; 62 | rowView.Add(field); 63 | 64 | var deleteButton = new Button(() => onRemoveBlackboardProperty.Invoke(this)) 65 | { 66 | text = "X" 67 | }; 68 | field.Add(deleteButton); 69 | 70 | Add(rowView); 71 | CreateField(field); 72 | } 73 | 74 | public void CreatePropertyField(BlackboardField field, AbstractBlackboardProperty property) 75 | { 76 | BaseField propertyField = Activator.CreateInstance(typeof(ElTy)) as BaseField; 77 | propertyField.label = "Value:"; 78 | propertyField.bindingPath = "abstractData"; 79 | propertyField.Bind(new SerializedObject(property)); 80 | propertyField.ElementAt(0).style.minWidth = 50; 81 | var sa = new BlackboardRow(field, propertyField); 82 | Add(sa); 83 | } 84 | 85 | public void CreateObjectPropertyField(BlackboardField field, AbstractBlackboardProperty property) where Ty : UnityEngine.Object 86 | { 87 | ObjectField propertyField = new ObjectField("Value:"); 88 | propertyField.objectType = typeof(Ty); 89 | propertyField.bindingPath = "abstractData"; 90 | propertyField.Bind(new SerializedObject(property)); 91 | propertyField.ElementAt(0).style.minWidth = 50; 92 | var sa = new BlackboardRow(field, propertyField); 93 | Add(sa); 94 | } 95 | } 96 | } -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardFieldView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6b25614f385f82145992bb28e679bade 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardFloatPropertyView.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using UnityEditor.Experimental.GraphView; 7 | using UnityEditor.UIElements; 8 | using VisualGraphRuntime; 9 | 10 | namespace VisualGraphEditor 11 | { 12 | [BlackboardPropertyType(typeof(FloatBlackboardProperty), "float")] 13 | public class BlackboardFloatPropertyView : BlackboardFieldView 14 | { 15 | public override void CreateField(BlackboardField field) 16 | { 17 | FloatBlackboardProperty localProperty = (FloatBlackboardProperty)property; 18 | CreatePropertyField(field, localProperty); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardFloatPropertyView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 895b3149e870c8844b2c281704aca5e4 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardGameObjectPropertyView.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using UnityEditor.Experimental.GraphView; 7 | using UnityEngine; 8 | using VisualGraphRuntime; 9 | 10 | namespace VisualGraphEditor 11 | { 12 | [BlackboardPropertyType(typeof(GameObjectBlackboardProperty), "GameObject")] 13 | public class BlackboardGameObjectPropertyView : BlackboardFieldView 14 | { 15 | GameObjectBlackboardProperty localProperty; 16 | 17 | public override void CreateField(BlackboardField field) 18 | { 19 | localProperty = (GameObjectBlackboardProperty)property; 20 | CreateObjectPropertyField(field, localProperty); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardGameObjectPropertyView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 016f5a07af0d2294da3180dfa1abddc6 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardIntPropertyView.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using UnityEditor.Experimental.GraphView; 7 | using UnityEditor.UIElements; 8 | using VisualGraphRuntime; 9 | 10 | namespace VisualGraphEditor 11 | { 12 | [BlackboardPropertyType(typeof(IntBlackboardProperty), "int")] 13 | public class BlackboardIntPropertyView : BlackboardFieldView 14 | { 15 | public override void CreateField(BlackboardField field) 16 | { 17 | IntBlackboardProperty localProperty = (IntBlackboardProperty)property; 18 | CreatePropertyField(field, localProperty); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardIntPropertyView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4722bc1516de084428024d7d72c7aa76 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardLayerMaskPropertyView.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using UnityEditor.Experimental.GraphView; 7 | using UnityEditor.UIElements; 8 | using VisualGraphRuntime; 9 | using UnityEngine; 10 | 11 | namespace VisualGraphEditor 12 | { 13 | [BlackboardPropertyType(typeof(LayerMaskBlackboardProperty), "LayerMask")] 14 | public class BlackboardLayerMaskPropertyView : BlackboardFieldView 15 | { 16 | public override void CreateField(BlackboardField field) 17 | { 18 | LayerMaskBlackboardProperty localProperty = (LayerMaskBlackboardProperty)property; 19 | CreatePropertyField(field, localProperty); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardLayerMaskPropertyView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ae5df43c60ef1f04ea53249c67501df0 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardMaterialPropertyView.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using UnityEditor.Experimental.GraphView; 7 | using VisualGraphRuntime; 8 | 9 | namespace VisualGraphEditor 10 | { 11 | [BlackboardPropertyType(typeof(MaterialBlackboardProperty), "Material")] 12 | public class BlackboardMaterialPropertyView : BlackboardFieldView 13 | { 14 | public override void CreateField(BlackboardField field) 15 | { 16 | MaterialBlackboardProperty localProperty = (MaterialBlackboardProperty)property; 17 | CreateObjectPropertyField(field, localProperty); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardMaterialPropertyView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f8a5635bf63bc6a4a839ec33b66c2777 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardObjectPropertyView.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using UnityEditor.Experimental.GraphView; 7 | using VisualGraphRuntime; 8 | 9 | namespace VisualGraphEditor 10 | { 11 | [BlackboardPropertyType(typeof(ObjectBlackboardProperty), "Object")] 12 | public class BlackboardObjectPropertyView : BlackboardFieldView 13 | { 14 | public override void CreateField(BlackboardField field) 15 | { 16 | ObjectBlackboardProperty localProperty = (ObjectBlackboardProperty)property; 17 | CreateObjectPropertyField(field, localProperty); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardObjectPropertyView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 874791cb51ae5324e82bbae521a0b340 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardRectIntPropertyView.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using UnityEditor.Experimental.GraphView; 7 | using UnityEditor.UIElements; 8 | using VisualGraphRuntime; 9 | using UnityEngine; 10 | 11 | namespace VisualGraphEditor 12 | { 13 | [BlackboardPropertyType(typeof(RectIntBlackboardProperty), "RectInt")] 14 | public class BlackboardRectIntPropertyView : BlackboardFieldView 15 | { 16 | public override void CreateField(BlackboardField field) 17 | { 18 | RectIntBlackboardProperty localProperty = (RectIntBlackboardProperty)property; 19 | CreatePropertyField(field, localProperty); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardRectIntPropertyView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7d0fabe799f65a2478aed849ee159446 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardRectPropertyView.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using UnityEditor.Experimental.GraphView; 7 | using UnityEditor.UIElements; 8 | using VisualGraphRuntime; 9 | using UnityEngine; 10 | 11 | namespace VisualGraphEditor 12 | { 13 | [BlackboardPropertyType(typeof(RectBlackboardProperty), "Rect")] 14 | public class BlackboardRectPropertyView : BlackboardFieldView 15 | { 16 | public override void CreateField(BlackboardField field) 17 | { 18 | RectBlackboardProperty localProperty = (RectBlackboardProperty)property; 19 | CreatePropertyField(field, localProperty); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardRectPropertyView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: aae445b138d5db6468aac9c1b196c727 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardStringPropertyView.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using UnityEditor.Experimental.GraphView; 7 | using UnityEngine.UIElements; 8 | using VisualGraphRuntime; 9 | using System; 10 | 11 | namespace VisualGraphEditor 12 | { 13 | [BlackboardPropertyType(typeof(StringBlackboardProperty), "string")] 14 | public class BlackboardStringPropertyView : BlackboardFieldView 15 | { 16 | public override void CreateField(BlackboardField field) 17 | { 18 | StringBlackboardProperty localProperty = (StringBlackboardProperty)property; 19 | CreatePropertyField(field, localProperty); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardStringPropertyView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0546b98d6872819409521c74db6fce2a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardTransformPropertyView.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using UnityEditor.Experimental.GraphView; 7 | using VisualGraphRuntime; 8 | 9 | namespace VisualGraphEditor 10 | { 11 | [BlackboardPropertyType(typeof(TransformBlackboardProperty), "Transform")] 12 | public class BlackboardTransformPropertyView : BlackboardFieldView 13 | { 14 | public override void CreateField(BlackboardField field) 15 | { 16 | TransformBlackboardProperty localProperty = (TransformBlackboardProperty)property; 17 | CreateObjectPropertyField(field, localProperty); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardTransformPropertyView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9d93119fcbcff814db92202ae18cb89c 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardVector2IntPropertyView.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using UnityEditor.UIElements; 7 | using UnityEditor.Experimental.GraphView; 8 | using VisualGraphRuntime; 9 | using UnityEngine; 10 | 11 | namespace VisualGraphEditor 12 | { 13 | [BlackboardPropertyType(typeof(Vector2IntBlackboardProperty), "Vector2Int")] 14 | public class BlackboardVector2IntPropertyView : BlackboardFieldView 15 | { 16 | public override void CreateField(BlackboardField field) 17 | { 18 | Vector2IntBlackboardProperty localProperty = (Vector2IntBlackboardProperty)property; 19 | CreatePropertyField(field, localProperty); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardVector2IntPropertyView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4324ab89aba00ce4bb7820f87e57ace0 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardVector2PropertyView.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using UnityEditor.UIElements; 7 | using UnityEditor.Experimental.GraphView; 8 | using VisualGraphRuntime; 9 | using UnityEngine; 10 | 11 | namespace VisualGraphEditor 12 | { 13 | [BlackboardPropertyType(typeof(Vector2BlackboardProperty), "Vector2")] 14 | public class BlackboardVector2PropertyView : BlackboardFieldView 15 | { 16 | public override void CreateField(BlackboardField field) 17 | { 18 | Vector2BlackboardProperty localProperty = (Vector2BlackboardProperty)property; 19 | CreatePropertyField(field, localProperty); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardVector2PropertyView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4a6c16543eab06940b770efbd631e485 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardVector3IntPropertyView.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using UnityEditor.UIElements; 7 | using UnityEditor.Experimental.GraphView; 8 | using VisualGraphRuntime; 9 | using UnityEngine; 10 | 11 | namespace VisualGraphEditor 12 | { 13 | [BlackboardPropertyType(typeof(Vector3IntBlackboardProperty), "Vector3Int")] 14 | public class BlackboardVector3IntPropertyView : BlackboardFieldView 15 | { 16 | public override void CreateField(BlackboardField field) 17 | { 18 | Vector3IntBlackboardProperty localProperty = (Vector3IntBlackboardProperty)property; 19 | CreatePropertyField(field, localProperty); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardVector3IntPropertyView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9cc977c5e1425ed46800da3cad586b09 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardVector3PropertyView.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using UnityEditor.UIElements; 7 | using UnityEditor.Experimental.GraphView; 8 | using VisualGraphRuntime; 9 | using UnityEngine; 10 | 11 | namespace VisualGraphEditor 12 | { 13 | [BlackboardPropertyType(typeof(Vector3BlackboardProperty), "Vector3")] 14 | public class BlackboardVector3PropertyView : BlackboardFieldView 15 | { 16 | public override void CreateField(BlackboardField field) 17 | { 18 | Vector3BlackboardProperty localProperty = (Vector3BlackboardProperty)property; 19 | CreatePropertyField(field, localProperty); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardVector3PropertyView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2880ada307334ed45b38f1aa62d2c2b5 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardVector4PropertyView.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using UnityEditor.UIElements; 7 | using UnityEditor.Experimental.GraphView; 8 | using VisualGraphRuntime; 9 | using UnityEngine; 10 | 11 | namespace VisualGraphEditor 12 | { 13 | [BlackboardPropertyType(typeof(Vector4BlackboardProperty), "Vector4")] 14 | public class BlackboardVector4PropertyView : BlackboardFieldView 15 | { 16 | public override void CreateField(BlackboardField field) 17 | { 18 | Vector4BlackboardProperty localProperty = (Vector4BlackboardProperty)property; 19 | CreatePropertyField(field, localProperty); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardVector4PropertyView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 78ce97a01dc3d334f94bcfe4b3c95c71 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardView.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Reflection; 9 | using UnityEditor; 10 | using UnityEditor.Experimental.GraphView; 11 | using UnityEngine; 12 | using UnityEngine.UIElements; 13 | using VisualGraphRuntime; 14 | 15 | namespace VisualGraphEditor 16 | { 17 | public class BlackboardView 18 | { 19 | public VisualGraphView visualGraphView; 20 | private VisualGraph visualGraph; 21 | public Blackboard blackboard { get; private set; } 22 | 23 | private Dictionary blackboardFieldTypes = new Dictionary(); 24 | 25 | public BlackboardView() 26 | { 27 | blackboard = new Blackboard(); 28 | blackboard.scrollable = true; 29 | blackboard.windowed = false; 30 | blackboard.Add(new BlackboardSection { title = "Graph Properties" }); 31 | blackboard.addItemRequested = AddItemRequested; 32 | blackboard.editTextRequested = EditTextRequested; 33 | 34 | var assemblies = System.AppDomain.CurrentDomain.GetAssemblies(); 35 | foreach (var assembly in assemblies) 36 | { 37 | var types = assembly.GetTypes(); 38 | foreach (var type in types) 39 | { 40 | if (type.IsSubclassOf(typeof(BlackboardFieldView)) == true && type.IsAbstract == false) 41 | { 42 | BlackboardPropertyTypeAttribute attrib = type.GetCustomAttribute(); 43 | if (attrib != null) 44 | { 45 | blackboardFieldTypes.Add(attrib.type, type); 46 | } 47 | } 48 | } 49 | } 50 | } 51 | public void ClearBlackboard() 52 | { 53 | blackboard.Clear(); 54 | } 55 | 56 | public void SetVisualGraph(VisualGraph visualGraph) 57 | { 58 | blackboard.Clear(); 59 | this.visualGraph = visualGraph; 60 | foreach (var property in visualGraph.BlackboardProperties) 61 | { 62 | if (blackboardFieldTypes.ContainsKey(property.GetType())) 63 | { 64 | AddBlackboardProperty(blackboardFieldTypes[property.GetType()], property); 65 | } 66 | } 67 | } 68 | 69 | public void EditTextRequested(Blackboard blackboard, VisualElement visualElement, string newText) 70 | { 71 | var field = (BlackboardField)visualElement; 72 | var property = (AbstractBlackboardProperty)field.userData; 73 | 74 | if (!string.IsNullOrEmpty(newText) && newText != property.Name) 75 | { 76 | Undo.RecordObject(visualGraph, "Edit Blackboard Text"); 77 | 78 | int count = 0; 79 | string propertyName = newText; 80 | foreach (var boardProperty in visualGraph.BlackboardProperties) 81 | { 82 | if (boardProperty.Name == propertyName) count++; 83 | } 84 | if (count > 0) propertyName += $"({count})"; 85 | 86 | property.Name = propertyName; 87 | field.text = property.Name; 88 | 89 | EditorUtility.SetDirty(visualGraph); 90 | } 91 | } 92 | 93 | void AddItemRequested(Blackboard blackboard) 94 | { 95 | if (visualGraph == null) return; 96 | 97 | var menu = new GenericMenu(); 98 | foreach (var type in blackboardFieldTypes) 99 | { 100 | BlackboardPropertyTypeAttribute attrib = type.Value.GetCustomAttribute(); 101 | if (attrib != null) 102 | { 103 | menu.AddItem(new GUIContent(attrib.menuName), false, () => CreateBlackboardProperty(type.Value)); 104 | } 105 | } 106 | 107 | menu.ShowAsContext(); 108 | } 109 | 110 | void CreateBlackboardProperty(Type type) 111 | { 112 | BlackboardPropertyTypeAttribute attrib = type.GetCustomAttribute(); 113 | 114 | Undo.RecordObject(visualGraph, "Add Blackboard Property"); 115 | 116 | int count = 0; 117 | string propertyName = attrib.menuName; 118 | foreach (var boardProperty in visualGraph.BlackboardProperties) 119 | { 120 | if (boardProperty.Name == propertyName) count++; 121 | } 122 | if (count > 0) propertyName += $"({count})"; 123 | 124 | Type propertyType = attrib.type; 125 | AbstractBlackboardProperty property = Activator.CreateInstance(propertyType) as AbstractBlackboardProperty; 126 | property.name = attrib.type.Name; 127 | property.Name = propertyName; 128 | property.guid = System.Guid.NewGuid().ToString(); 129 | visualGraph.BlackboardProperties.Add(property); 130 | 131 | if (property.name == null || property.name.Trim() == "") property.name = ObjectNames.NicifyVariableName(property.name); 132 | if (!string.IsNullOrEmpty(AssetDatabase.GetAssetPath(visualGraph))) AssetDatabase.AddObjectToAsset(property, visualGraph); 133 | 134 | AddBlackboardProperty(type, property); 135 | 136 | EditorUtility.SetDirty(visualGraph); 137 | AssetDatabase.SaveAssets(); 138 | } 139 | 140 | void OnRemoveBlackboardProperty(BlackboardFieldView field) 141 | { 142 | Undo.RecordObject(visualGraph, "Remove Blackboard Property"); 143 | 144 | visualGraph.BlackboardProperties.Remove(field.property); 145 | blackboard.Remove(field); 146 | 147 | AssetDatabase.RemoveObjectFromAsset(field.property); 148 | Undo.DestroyObjectImmediate(field.property); 149 | 150 | EditorUtility.SetDirty(visualGraph); 151 | } 152 | 153 | void AddBlackboardProperty(Type type, AbstractBlackboardProperty property) 154 | { 155 | BlackboardFieldView propertyView = Activator.CreateInstance(type) as BlackboardFieldView; 156 | propertyView.blackboardView = this; 157 | propertyView.CreateView(visualGraph, property); 158 | propertyView.onRemoveBlackboardProperty += OnRemoveBlackboardProperty; 159 | blackboard.Add(propertyView); 160 | } 161 | } 162 | } -------------------------------------------------------------------------------- /Editor/Blackboard/BlackboardView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3ac0ca09195551d4198287f73d3937df 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Component.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 168fc12cc88ef0344b85b9283b8c1aba 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/Component/VisualGraphMonoBehaviourInspector.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Reflection; 5 | using UnityEditor; 6 | using UnityEditor.UIElements; 7 | using UnityEngine; 8 | using UnityEngine.UIElements; 9 | using VisualGraphRuntime; 10 | 11 | namespace VisualGraphEditor 12 | { 13 | [CustomEditor(typeof(VisualGraphMonoBehaviour<>), true)] 14 | public class VisualGraphMonoBehaviourInspector : Editor 15 | { 16 | private StyleSheet customStyleSheet; 17 | 18 | private void OnEnable() 19 | { 20 | customStyleSheet = Resources.Load("VisualGraphMonoBehaviourInspector"); 21 | } 22 | 23 | public VisualElement CreatePropertyField(AbstractBlackboardProperty property) 24 | { 25 | BaseField propertyField = Activator.CreateInstance(typeof(ElTy)) as BaseField; 26 | propertyField.label = property.Name; 27 | propertyField.bindingPath = "abstractData"; 28 | propertyField.Bind(new SerializedObject(property)); 29 | propertyField.SetEnabled(property.overrideProperty); 30 | propertyField.ElementAt(0).style.minWidth = 50; 31 | return propertyField; 32 | } 33 | 34 | public VisualElement CreateObjectPropertyField(AbstractBlackboardProperty property) where Ty : UnityEngine.Object 35 | { 36 | ObjectField propertyField = new ObjectField(property.Name); 37 | propertyField.objectType = typeof(Ty); 38 | propertyField.bindingPath = "abstractData"; 39 | propertyField.Bind(new SerializedObject(property)); 40 | propertyField.SetEnabled(property.overrideProperty); 41 | return propertyField; 42 | } 43 | 44 | public override VisualElement CreateInspectorGUI() 45 | { 46 | // Because everything in Components is a MonoBehaviour we can get the base type 47 | // If they base type is a generic of type VisualGraphMonoBehaviour<> then we can try and 48 | MethodInfo method = target.GetType().BaseType.GetMethod("UpdateProperties", BindingFlags.Public | BindingFlags.Instance); 49 | method.Invoke(target, null); 50 | 51 | VisualElement rootElement = new VisualElement(); 52 | rootElement.styleSheets.Add(customStyleSheet); 53 | rootElement.style.flexDirection = FlexDirection.Column; 54 | 55 | VisualElement defaultInspector = new VisualElement(); 56 | defaultInspector.AddToClassList("default_inspector"); 57 | UnityEditor.Editor editor = UnityEditor.Editor.CreateEditor(target); 58 | IMGUIContainer inspectorIMGUI = new IMGUIContainer(() => { editor.OnInspectorGUI(); }); 59 | defaultInspector.Add(inspectorIMGUI); 60 | rootElement.Add(defaultInspector); 61 | 62 | //ObjectField propertyField = new ObjectField("Graph"); 63 | //propertyField.objectType = target.GetType().GetField("graph").GetValue(target).GetType(); 64 | //propertyField.bindingPath = "graph"; 65 | //propertyField.Bind(new SerializedObject(target)); 66 | //propertyField.RegisterCallback>( evt => 67 | //{ 68 | // target.GetType().GetField("graph").SetValue(target, evt.newValue); 69 | // MethodInfo method = target.GetType().BaseType.GetMethod("UpdateProperties", BindingFlags.Public | BindingFlags.Instance); 70 | // method.Invoke(target, null); 71 | //}); 72 | //rootElement.Add(propertyField); 73 | 74 | // Because everything in Components is a MonoBehaviour we can get the base type 75 | // If they base type is a generic of type VisualGraphMonoBehaviour<> then we can try and 76 | FieldInfo BlackboardPropertyInfo = target.GetType().BaseType.GetField("BlackboardProperties"); 77 | List BlackboardProperties = BlackboardPropertyInfo.GetValue(target) as List; 78 | 79 | Label blackboardLabel = new Label($"Blackboard Properties: {BlackboardProperties.Count}") { name = "blackboardLabel" }; 80 | rootElement.Add(blackboardLabel); 81 | 82 | foreach (var property in BlackboardProperties) 83 | { 84 | VisualElement blackboardProperty = new VisualElement() { name = "blackboardProperty" }; 85 | blackboardProperty.style.flexDirection = FlexDirection.Row; 86 | 87 | Toggle overwriteField = new Toggle(); 88 | overwriteField.SetValueWithoutNotify(property.overrideProperty); 89 | blackboardProperty.Add(overwriteField); 90 | 91 | //TODO: This is going to get ugly and I don't care at this time..... 92 | // Should look at moving the code generation for each Inspector view into respective classes? 93 | // HACK, HACK, HACKITY, HACK... so ugly need a better solution 94 | VisualElement fieldElement = null; 95 | switch (property) 96 | { 97 | case BoolBlackboardProperty prop: 98 | fieldElement = CreatePropertyField(prop); 99 | break; 100 | case ColliderBlackboardProperty prop: 101 | fieldElement = CreateObjectPropertyField(prop); 102 | break; 103 | case ColorBlackboardProperty prop: 104 | fieldElement = CreatePropertyField(prop); 105 | break; 106 | case DoubleBlackboardProperty prop: 107 | fieldElement = CreatePropertyField(prop); 108 | break; 109 | case FloatBlackboardProperty prop: 110 | fieldElement = CreatePropertyField(prop); 111 | break; 112 | case GameObjectBlackboardProperty prop: 113 | fieldElement = CreateObjectPropertyField(prop); 114 | break; 115 | case IntBlackboardProperty prop: 116 | fieldElement = CreatePropertyField(prop); 117 | break; 118 | case LayerMaskBlackboardProperty prop: 119 | fieldElement = CreatePropertyField(prop); 120 | break; 121 | case MaterialBlackboardProperty prop: 122 | fieldElement = CreateObjectPropertyField(prop); 123 | break; 124 | case ObjectBlackboardProperty prop: 125 | fieldElement = CreateObjectPropertyField(prop); 126 | break; 127 | case RectBlackboardProperty prop: 128 | fieldElement = CreatePropertyField(prop); 129 | break; 130 | case RectIntBlackboardProperty prop: 131 | fieldElement = CreatePropertyField(prop); 132 | break; 133 | case StringBlackboardProperty prop: 134 | fieldElement = CreatePropertyField(prop); 135 | break; 136 | case TransformBlackboardProperty prop: 137 | fieldElement = CreateObjectPropertyField(prop); 138 | break; 139 | case Vector2BlackboardProperty prop: 140 | fieldElement = CreatePropertyField(prop); 141 | break; 142 | case Vector2IntBlackboardProperty prop: 143 | fieldElement = CreatePropertyField(prop); 144 | break; 145 | case Vector3BlackboardProperty prop: 146 | fieldElement = CreatePropertyField(prop); 147 | break; 148 | case Vector3IntBlackboardProperty prop: 149 | fieldElement = CreatePropertyField(prop); 150 | break; 151 | case Vector4BlackboardProperty prop: 152 | fieldElement = CreatePropertyField(prop); 153 | break; 154 | } 155 | 156 | blackboardProperty.Add(fieldElement); 157 | 158 | overwriteField.RegisterCallback>(evt => 159 | { 160 | Undo.RecordObject(target, "VisualGraphMonoBehaviour Changed"); 161 | property.overrideProperty = evt.newValue; 162 | fieldElement.SetEnabled(property.overrideProperty); 163 | }); 164 | 165 | rootElement.Add(blackboardProperty); 166 | } 167 | 168 | return rootElement; 169 | } 170 | } 171 | } -------------------------------------------------------------------------------- /Editor/Component/VisualGraphMonoBehaviourInspector.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 88df514c918cd0e4c854aa640073a015 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Graph.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4a5833e1cbd7c254487991d5179f9d86 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/Graph/VisualGraphEditor.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Reflection; 9 | using UnityEditor; 10 | using UnityEditor.UIElements; 11 | using UnityEngine; 12 | using UnityEngine.UIElements; 13 | using VisualGraphRuntime; 14 | 15 | namespace VisualGraphEditor 16 | { 17 | public sealed class VisualGraphEditor : EditorWindow 18 | { 19 | private Component visualGraphComponent; 20 | private VisualGraphView graphView; 21 | private VisualGraph visualGraph; 22 | private UnityEngine.Object objectSelection; // Used for enter/exit playmode 23 | 24 | /// 25 | /// Create a Visual Graph Window to support a VisualGraph object 26 | /// 27 | /// 28 | /// 29 | public static VisualGraphEditor CreateGraphViewWindow(VisualGraph _visualGraph, bool forceSet = false) 30 | { 31 | var window = GetWindow(); 32 | window.SetVisualGraph(_visualGraph, forceSet); 33 | return window; 34 | } 35 | 36 | /// 37 | /// Create visual elements using Unity GraphView (Experiemental) 38 | /// 39 | private void OnEnable() 40 | { 41 | rootVisualElement.Clear(); 42 | 43 | // Create the GraphView 44 | graphView = new VisualGraphView(this) 45 | { 46 | name = "Visual Graph View", 47 | }; 48 | graphView.StretchToParentSize(); 49 | rootVisualElement.Add(graphView); 50 | 51 | // Add Toolbar to Window 52 | GenerateToolbar(); 53 | graphView.CreateMinimap(this.position.width); 54 | graphView.CreateBlackboard(); 55 | 56 | EditorApplication.playModeStateChanged += LogPlayModeState; 57 | } 58 | 59 | private void OnDisable() 60 | { 61 | EditorApplication.playModeStateChanged -= LogPlayModeState; 62 | } 63 | 64 | private void LogPlayModeState(PlayModeStateChange state) 65 | { 66 | switch(state) 67 | { 68 | case PlayModeStateChange.ExitingEditMode: 69 | objectSelection = Selection.activeObject; 70 | Selection.activeObject = null; 71 | break; 72 | 73 | case PlayModeStateChange.EnteredPlayMode: 74 | Selection.activeObject = objectSelection; 75 | break; 76 | 77 | case PlayModeStateChange.ExitingPlayMode: 78 | objectSelection = Selection.activeObject; 79 | Selection.activeObject = null; 80 | break; 81 | 82 | case PlayModeStateChange.EnteredEditMode: 83 | Selection.activeObject = objectSelection; 84 | break; 85 | } 86 | } 87 | 88 | /// 89 | /// Change the Visual Graph 90 | /// 91 | /// 92 | private void SetVisualGraph(VisualGraph _visualGraph, bool forceSet = false) 93 | { 94 | visualGraph = _visualGraph; 95 | if (visualGraph == null) 96 | { 97 | titleContent = new GUIContent("Empty"); 98 | } 99 | else 100 | { 101 | titleContent = new GUIContent(visualGraph.name); 102 | } 103 | graphView.SetGraph(visualGraph); 104 | } 105 | 106 | /// 107 | /// Window toolbar 108 | /// 109 | private void GenerateToolbar() 110 | { 111 | var toolbar = new Toolbar(); 112 | 113 | ToolbarToggle minimap_toggle = new ToolbarToggle(); 114 | minimap_toggle.text = "Show MiniMap"; 115 | minimap_toggle.SetValueWithoutNotify(true); 116 | minimap_toggle.RegisterCallback>( 117 | (evt) => 118 | { 119 | graphView.Minimap.visible = evt.newValue; 120 | } 121 | ); 122 | toolbar.Add(minimap_toggle); 123 | 124 | ToolbarToggle blackboard_toggle = new ToolbarToggle(); 125 | blackboard_toggle.text = "Show Blackboard"; 126 | blackboard_toggle.SetValueWithoutNotify(true); 127 | blackboard_toggle.RegisterCallback>( 128 | (evt) => 129 | { 130 | graphView.Blackboard.visible = evt.newValue; 131 | } 132 | ); 133 | toolbar.Add(blackboard_toggle); 134 | 135 | rootVisualElement.Add(toolbar); 136 | } 137 | 138 | /// 139 | /// When the GUI changes update the view (this positions the blackboard and minimap) 140 | /// 141 | private void OnGUI() 142 | { 143 | if (graphView != null) 144 | { 145 | graphView.OnGUI(); 146 | } 147 | } 148 | 149 | /// 150 | /// TODO: When this works we can highlight the node that is active great for 151 | /// runtime cases and viewing things like FSM 152 | /// 153 | private void Update() 154 | { 155 | if (Application.isPlaying) 156 | { 157 | if (graphView != null) 158 | { 159 | graphView.Update(); 160 | } 161 | } 162 | } 163 | 164 | /// 165 | /// Handle selection change. This will check the active object to see if it is a 166 | /// VisualGraph Scriptable object. If it is not then it will see if the selected 167 | /// object is a GameObject. If the selection is a GameObject then we iterate over 168 | /// all MonoBehaviour (scripts) to see if one is a has a VisualGraphMonoBehaviour<>. 169 | /// If we find a Component that is a VisualGraphMonoBehaviour<> then we first check 170 | /// if there is an InternalGraph (which is used during runtime) otherwise we will 171 | /// use the Graph itself (needs to change when runtime is invoked in the editor) 172 | /// 173 | void OnSelectionChange() 174 | { 175 | visualGraphComponent = null; 176 | 177 | VisualGraph graph = Selection.activeObject as VisualGraph; 178 | if (graph == null && graphView.activeVisualGraph) 179 | { 180 | SetVisualGraph(null); 181 | } 182 | else if (graph != null && graph != visualGraph) 183 | { 184 | if (!string.IsNullOrEmpty(AssetDatabase.GetAssetPath(graph))) 185 | { 186 | SetVisualGraph(graph); 187 | } 188 | } 189 | else 190 | { 191 | GameObject go = Selection.activeObject as GameObject; 192 | if (go != null) 193 | { 194 | Component[] components = go.GetComponents(typeof(MonoBehaviour)); 195 | foreach (var comp in components) 196 | { 197 | // Because everything in Components is a MonoBehaviour we can get the base type 198 | // If they base type is a generic of type VisualGraphMonoBehaviour<> then we can try and 199 | // get the internal graph (this is for editor runtime). If that doesn't exist use the set graph. 200 | if (comp == null) continue; 201 | 202 | Type t = comp.GetType().BaseType; 203 | if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(VisualGraphMonoBehaviour<>)) 204 | { 205 | graph = (VisualGraph)t.GetField("internalGraph", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(comp); 206 | if (graph != null) 207 | { 208 | visualGraphComponent = comp; 209 | SetVisualGraph(graph); 210 | return; 211 | } 212 | 213 | //graph = (VisualGraph)t.GetField("graph", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(comp); 214 | graph = (VisualGraph)t.GetField("graph").GetValue(comp); 215 | if (graph != null) 216 | { 217 | visualGraphComponent = comp; 218 | SetVisualGraph(graph); 219 | return; 220 | } 221 | } 222 | } 223 | } 224 | } 225 | } 226 | } 227 | } -------------------------------------------------------------------------------- /Editor/Graph/VisualGraphEditor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5afc811b57acbaa4fa9a62b9e4eb3522 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Graph/VisualGraphInspector.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using System.Collections.Generic; 7 | using UnityEditor; 8 | using UnityEditor.Callbacks; 9 | using UnityEngine; 10 | using VisualGraphRuntime; 11 | 12 | namespace VisualGraphEditor 13 | { 14 | [CustomEditor(typeof(VisualGraph), true)] 15 | public class VisualGraphInspector : Editor 16 | { 17 | [OnOpenAssetAttribute(1)] 18 | public static bool OpenVisualGraph(int instanceID, int line) 19 | { 20 | VisualGraph graph = EditorUtility.InstanceIDToObject(instanceID) as VisualGraph; 21 | if (graph != null) 22 | { 23 | VisualGraphEditor.CreateGraphViewWindow(graph, true); 24 | return true; 25 | } 26 | return false; 27 | } 28 | 29 | public override void OnInspectorGUI() 30 | { 31 | EditorGUI.EndDisabledGroup(); 32 | DrawDefaultInspector(); 33 | EditorGUI.EndDisabledGroup(); 34 | 35 | if (GUILayout.Button("Reset")) 36 | { 37 | VisualGraph graph = (VisualGraph)target; 38 | 39 | graph.StartingNode = null; 40 | foreach (var node in graph.Nodes) 41 | { 42 | DestroyImmediate(node, true); 43 | } 44 | graph.Nodes = new List(); 45 | 46 | //graph.Groups.Clear(); 47 | graph.BlackboardProperties.Clear(); 48 | 49 | AssetDatabase.SaveAssets(); 50 | } 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /Editor/Graph/VisualGraphInspector.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7287bbfe496cdaa429c53cb4d4b52f20 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Graph/VisualGraphSearchWindow.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using VisualGraphRuntime; 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Reflection; 10 | using UnityEditor; 11 | using UnityEditor.Experimental.GraphView; 12 | using UnityEngine; 13 | using UnityEngine.UIElements; 14 | 15 | namespace VisualGraphEditor 16 | { 17 | public class VisualGraphSearchWindow : ScriptableObject, ISearchWindowProvider 18 | { 19 | private EditorWindow window; 20 | private VisualGraphView graphView; 21 | private List nodeTypes = new List(); 22 | private Texture2D indentationIcon; 23 | 24 | public void Configure(EditorWindow window, VisualGraphView graphView) 25 | { 26 | this.window = window; 27 | this.graphView = graphView; 28 | 29 | var result = new List(); 30 | var assemblies = System.AppDomain.CurrentDomain.GetAssemblies(); 31 | 32 | DefaultNodeTypeAttribute typeAttrib = graphView.VisualGraph.GetType().GetCustomAttribute(); 33 | foreach (var assembly in assemblies) 34 | { 35 | var types = assembly.GetTypes(); 36 | foreach (var type in types) 37 | { 38 | if (typeAttrib != null && (type.IsAssignableFrom(typeAttrib.type) == true || type.IsSubclassOf(typeAttrib.type)) 39 | && type.IsSubclassOf(typeof(VisualGraphNode)) == true 40 | && type.IsAbstract == false) 41 | { 42 | nodeTypes.Add(type); 43 | } 44 | } 45 | } 46 | 47 | indentationIcon = new Texture2D(1,1); 48 | indentationIcon.SetPixel(0,0,new Color(0,0,0,0)); 49 | indentationIcon.Apply(); 50 | } 51 | 52 | public List CreateSearchTree(SearchWindowContext context) 53 | { 54 | var tree = new List(); 55 | tree.Add(new SearchTreeGroupEntry(new GUIContent("Create Node"), 0)); 56 | //tree.Add(new SearchTreeGroupEntry(new GUIContent("Nodes"), 1)); 57 | 58 | foreach (var type in nodeTypes) 59 | { 60 | string display_name = ""; 61 | if (type.GetCustomAttribute() != null) 62 | { 63 | display_name = type.GetCustomAttribute().name; 64 | } 65 | else 66 | { 67 | display_name = type.Name; 68 | } 69 | 70 | tree.Add(new SearchTreeEntry(new GUIContent(display_name, indentationIcon)) 71 | { 72 | level = 1, 73 | userData = type 74 | }); 75 | } 76 | 77 | //tree.Add(new SearchTreeEntry(new GUIContent("Group", indentationIcon)) 78 | //{ 79 | // level = 1, 80 | // userData = new Group() 81 | //}); 82 | 83 | return tree; 84 | } 85 | 86 | public bool OnSelectEntry(SearchTreeEntry SearchTreeEntry, SearchWindowContext context) 87 | { 88 | var mousePosition = window.rootVisualElement.ChangeCoordinatesTo(window.rootVisualElement.parent, context.screenMousePosition - window.position.position); 89 | var graphMousePosition = graphView.contentViewContainer.WorldToLocal(mousePosition); 90 | switch (SearchTreeEntry.userData) 91 | { 92 | case Type nodeData: 93 | { 94 | graphView.CreateNode(graphMousePosition, nodeData); 95 | return true; 96 | } 97 | //case Group group: 98 | // graphView.CreateGroupBlock(graphMousePosition); 99 | // return true; 100 | } 101 | return false; 102 | } 103 | } 104 | } -------------------------------------------------------------------------------- /Editor/Graph/VisualGraphSearchWindow.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 45d0c0c8ac8fe5c4a8def35beec84973 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Graph/VisualGraphSettings.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEditor; 4 | using UnityEngine; 5 | using VisualGraphRuntime; 6 | 7 | namespace VisualGraphEditor 8 | { 9 | public static class VisualGraphSettings 10 | { 11 | public static bool autoSave = true; 12 | 13 | public static void Save() 14 | { 15 | if (autoSave) 16 | { 17 | AssetDatabase.SaveAssets(); 18 | } 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Editor/Graph/VisualGraphSettings.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9774e0f5f45347a46b7c330c6262c8f7 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Graph/VisualGraphView.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Linq; 9 | using System.Reflection; 10 | using VisualGraphRuntime; 11 | using UnityEditor; 12 | using UnityEditor.Experimental.GraphView; 13 | using UnityEngine; 14 | using UnityEngine.UIElements; 15 | using UnityEditor.UIElements; 16 | using Button = UnityEngine.UIElements.Button; 17 | 18 | namespace VisualGraphEditor 19 | { 20 | public class VisualGraphView : GraphView, IEdgeConnectorListener 21 | { 22 | public VisualGraph VisualGraph { get { return visualGraph; } private set { } } 23 | public MiniMap Minimap { get; private set; } 24 | public BlackboardView BlackboardView { get; private set; } 25 | public Blackboard Blackboard { get { return BlackboardView.blackboard; } private set { } } 26 | 27 | private VisualGraph visualGraph; 28 | private VisualGraphSearchWindow searchWindow; 29 | private VisualGraphEditor editorWindow; 30 | private Orientation orientation; 31 | 32 | // Runtime Type / Editor Type 33 | private Dictionary visualGraphNodeLookup = new Dictionary(); 34 | private Dictionary visualGraphPortLookup = new Dictionary(); 35 | 36 | public bool activeVisualGraph = false; 37 | 38 | public VisualGraphView(VisualGraphEditor editorWindow) 39 | { 40 | this.editorWindow = editorWindow; 41 | 42 | Undo.undoRedoPerformed += OnUndoRedoCallback; 43 | 44 | graphViewChanged = OnGraphChange; 45 | 46 | styleSheets.Add(Resources.Load("VisualGraphStyle")); 47 | SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale); 48 | 49 | this.AddManipulator(new ContentDragger()); 50 | this.AddManipulator(new SelectionDragger()); 51 | this.AddManipulator(new RectangleSelector()); 52 | this.AddManipulator(new FreehandSelector()); 53 | 54 | var grid = new GridBackground(); 55 | Insert(0, grid); 56 | grid.StretchToParentSize(); 57 | 58 | var assemblies = System.AppDomain.CurrentDomain.GetAssemblies(); 59 | foreach (var assembly in assemblies) 60 | { 61 | var types = assembly.GetTypes(); 62 | foreach (var type in types) 63 | { 64 | CustomNodeViewAttribute nodeAttrib = type.GetCustomAttribute(); 65 | if (nodeAttrib != null && nodeAttrib.type.IsAbstract == false) 66 | { 67 | visualGraphNodeLookup.Add(nodeAttrib.type, type); 68 | } 69 | 70 | CustomPortViewAttribute portAttrib = type.GetCustomAttribute(); 71 | if (portAttrib != null && portAttrib.type.IsAbstract == false) 72 | { 73 | visualGraphPortLookup.Add(portAttrib.type, type); 74 | } 75 | } 76 | } 77 | 78 | } 79 | 80 | public void CreateMinimap(float windowWidth) 81 | { 82 | Minimap = new MiniMap { anchored = true }; 83 | Minimap.capabilities &= ~Capabilities.Movable; 84 | Minimap.SetPosition(new Rect(windowWidth - 210, 30, 200, 140)); 85 | Add(Minimap); 86 | } 87 | 88 | public void CreateBlackboard() 89 | { 90 | BlackboardView = new BlackboardView(); 91 | BlackboardView.visualGraphView = this; 92 | Blackboard.SetPosition(new Rect(10, 30, 250, 300)); 93 | Add(BlackboardView.blackboard); 94 | } 95 | 96 | #region View OnGUI/Update 97 | 98 | public void OnGUI() 99 | { 100 | if (Minimap != null) Minimap.SetPosition(new Rect(contentRect.width - 210, 30, 200, 140)); 101 | if (Blackboard != null) Blackboard.SetPosition(new Rect(10, 30, Blackboard.style.width.value.value, Blackboard.style.height.value.value)); 102 | } 103 | 104 | public void Update() 105 | { 106 | nodes.ForEach(nodeView => 107 | { 108 | VisualGraphNode node = nodeView.userData as VisualGraphNode; 109 | if (node != null) 110 | { 111 | if (node.editor_ActiveNode) 112 | { 113 | nodeView.AddToClassList("VisualGraphNodeSelected"); 114 | } 115 | else 116 | { 117 | nodeView.RemoveFromClassList("VisualGraphNodeSelected"); 118 | } 119 | } 120 | }); 121 | } 122 | #endregion 123 | 124 | #region Init the Graph 125 | 126 | public void OnUndoRedoCallback() 127 | { 128 | SetGraph(visualGraph); 129 | } 130 | 131 | /// 132 | /// Load the Visual Graph into the Editor Graph View 133 | /// 134 | /// 135 | public void SetGraph(VisualGraph _visualGraph) 136 | { 137 | // Set the graph to null and clear the edges and nodes before we get going. 138 | visualGraph = null; 139 | DeleteElements(graphElements.ToList()); 140 | DeleteElements(nodes.ToList()); 141 | DeleteElements(edges.ToList()); 142 | activeVisualGraph = false; 143 | BlackboardView.ClearBlackboard(); 144 | 145 | visualGraph = _visualGraph; 146 | if (visualGraph != null) 147 | { 148 | // When the graph is loaded connections need to be remade 149 | visualGraph.InitializeGraph(); 150 | 151 | activeVisualGraph = true; 152 | 153 | GraphOrientationAttribute orientationAttrib = visualGraph.GetType().GetCustomAttribute(); 154 | Debug.Assert(orientationAttrib != null, $"Graph node requires a GraphOrientationAttribute {visualGraph.GetType().Name}"); 155 | orientation = (orientationAttrib.GrapOrientation == GraphOrientationAttribute.Orientation.Horizontal) ? Orientation.Horizontal : Orientation.Vertical; 156 | 157 | BlackboardView.SetVisualGraph(visualGraph); 158 | 159 | searchWindow = ScriptableObject.CreateInstance(); 160 | searchWindow.Configure(editorWindow, this); 161 | nodeCreationRequest = context => SearchWindow.Open(new SearchWindowContext(context.screenMousePosition), searchWindow); 162 | 163 | // If the graph doesn't have a start node it's probably the first time we opened it. This means 164 | // we will create one to get going. 165 | if (visualGraph.StartingNode == null) 166 | { 167 | VisualGraphNode startingNode = Activator.CreateInstance(typeof(VisualGraphStartNode)) as VisualGraphNode; 168 | visualGraph.StartingNode = startingNode; 169 | startingNode.name = "Start"; 170 | startingNode.position = new Vector2(270, 30); 171 | 172 | VisualGraphPort graphPort = startingNode.AddPort("Next", VisualGraphPort.PortDirection.Output); 173 | graphPort.CanBeRemoved = false; 174 | visualGraph.Nodes.Add(startingNode); 175 | 176 | if (startingNode.name == null || startingNode.name.Trim() == "") startingNode.name = UnityEditor.ObjectNames.NicifyVariableName(startingNode.name); 177 | if (!string.IsNullOrEmpty(AssetDatabase.GetAssetPath(visualGraph))) AssetDatabase.AddObjectToAsset(startingNode, visualGraph); 178 | 179 | AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(startingNode)); 180 | } 181 | 182 | // Create all other Nodes for the graph 183 | foreach (var graphNode in visualGraph.Nodes) 184 | { 185 | Node node = AddGraphNode(graphNode); 186 | Vector2 pos = new Vector2(node.style.left.value.value, node.style.top.value.value); 187 | ((VisualGraphNode)node.userData).position = pos; 188 | } 189 | 190 | foreach (VisualGraphNode graphNode in visualGraph.Nodes) 191 | { 192 | foreach (VisualGraphPort graphPort in graphNode.Ports) 193 | { 194 | if (graphPort.Direction == VisualGraphPort.PortDirection.Output) 195 | { 196 | Port port = graphPort.editor_port as Port; 197 | foreach (VisualGraphPort.VisualGraphPortConnection graph_connection in graphPort.Connections) 198 | { 199 | VisualGraphPort other_port = graph_connection.Node.FindPortByGuid(graph_connection.port_guid); 200 | Port other_editor_port = other_port.editor_port as Port; 201 | AddElement(port.ConnectTo(other_editor_port)); 202 | } 203 | } 204 | } 205 | } 206 | 207 | //foreach (var group in visualGraph.Groups) 208 | //{ 209 | // AddGroupBlock(group); 210 | //} 211 | } 212 | } 213 | #endregion 214 | 215 | #region Group Block 216 | 217 | //public void CreateGroupBlock(Vector2 position) 218 | //{ 219 | // Undo.RecordObject(visualGraph, "Create Node"); 220 | // VisualGraphGroup block = new VisualGraphGroup() 221 | // { 222 | // title = "Graph Group", 223 | // position = position 224 | // }; 225 | // visualGraph.Groups.Add(block); 226 | // AddGroupBlock(block); 227 | //} 228 | 229 | //public void AddGroupBlock(VisualGraphGroup graphGroup) 230 | // { 231 | // var group = new VisualGraphGroupView 232 | // { 233 | // autoUpdateGeometry = true, 234 | // title = graphGroup.title, 235 | // userData = graphGroup 236 | // }; 237 | // group.SetPosition(new Rect(graphGroup.position.x, graphGroup.position.y, 300, 200)); 238 | // AddElement(group); 239 | 240 | // HashSet nodes = new HashSet(); 241 | // foreach(var node_guid in graphGroup.node_guids) 242 | // { 243 | // VisualGraphNode node = visualGraph.FindNodeByGuid(node_guid); 244 | // if (node != null) 245 | // { 246 | // nodes.Add(node.graphElement as GraphElement); 247 | // } 248 | // } 249 | // group.CollectElements(nodes, null); 250 | //} 251 | 252 | #endregion 253 | 254 | #region Node Creation 255 | /// 256 | /// Create a node based off the type. Once the node is created it will be added to the Graph and a View 257 | /// node will be created and added 258 | /// 259 | /// 260 | /// 261 | public void CreateNode(Vector2 position, Type nodeType) 262 | { 263 | Undo.RecordObject(visualGraph, "Create Node"); 264 | VisualGraphNode graphNode = visualGraph.AddNode(nodeType); 265 | Undo.RegisterCreatedObjectUndo(graphNode, "Create Node"); 266 | graphNode.position = position; 267 | 268 | if (graphNode.name == null || graphNode.name.Trim() == "") graphNode.name = UnityEditor.ObjectNames.NicifyVariableName(nodeType.Name); 269 | if (!string.IsNullOrEmpty(AssetDatabase.GetAssetPath(visualGraph))) AssetDatabase.AddObjectToAsset(graphNode, visualGraph); 270 | 271 | Node node = AddGraphNode(graphNode); 272 | 273 | AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(graphNode)); 274 | } 275 | 276 | /// 277 | /// Add the node from the graph to the view based off property and attribute settings 278 | /// 279 | /// 280 | /// 281 | private Node AddGraphNode(VisualGraphNode graphNode) 282 | { 283 | // By default we will create all nodes from VisualGraphNodeView 284 | Type visualNodeType = typeof(VisualGraphNodeView); 285 | if (visualGraphNodeLookup.ContainsKey(graphNode.GetType()) == true) 286 | { 287 | visualNodeType = visualGraphNodeLookup[graphNode.GetType()]; 288 | } 289 | 290 | // Create the Node View based off the type, set the class for styling 291 | VisualGraphNodeView node = Activator.CreateInstance(visualNodeType) as VisualGraphNodeView; 292 | node.AddToClassList("VisualGraphNode"); 293 | node.title = GetGraphNodeName(graphNode.GetType()); 294 | node.userData = graphNode; 295 | node.styleSheets.Add(Resources.Load("Node")); 296 | 297 | // The Editor stores a reference to the graph created; 298 | graphNode.graphElement = node; 299 | 300 | // If there are extra Styles apply them 301 | IEnumerable customStyleAttribs = graphNode.GetType().GetCustomAttributes(); 302 | if (customStyleAttribs != null) 303 | { 304 | foreach (var customStyleAttrib in customStyleAttribs) 305 | { 306 | try 307 | { 308 | StyleSheet styleSheet = Resources.Load(customStyleAttrib.style); 309 | if (styleSheet != null) 310 | { 311 | node.styleSheets.Add(styleSheet); 312 | } 313 | else throw new Exception(); 314 | } 315 | catch (Exception ex) 316 | { 317 | Debug.LogWarning($"Style sheet does not exit: {customStyleAttrib.style}"); 318 | } 319 | } 320 | } 321 | 322 | // Get the Port Dynamics. Base class type already has the attribute so this should never fail 323 | NodePortAggregateAttribute dynamicsAttrib = graphNode.GetType().GetCustomAttribute(); 324 | Debug.Assert(dynamicsAttrib != null, $"Graph node requires a NodePortAggregateAttribute {graphNode.GetType().Name}"); 325 | 326 | if (dynamicsAttrib.InputPortAggregate == NodePortAggregateAttribute.PortAggregate.Multiple) 327 | { 328 | // Button for input ports 329 | var button = new Button(() => { CreatePort(node, "Input", VisualGraphPort.PortDirection.Input); }) 330 | { 331 | text = "Add Input" 332 | }; 333 | node.titleButtonContainer.Add(button); 334 | } 335 | if (dynamicsAttrib.OutputPortAggregate == NodePortAggregateAttribute.PortAggregate.Multiple) 336 | { 337 | var button = new Button(() => { CreatePort(node, "Exit", VisualGraphPort.PortDirection.Output); }) 338 | { 339 | text = "Add Exit" 340 | }; 341 | node.titleButtonContainer.Add(button); 342 | } 343 | 344 | // Set the node capabilites. The default View node can be overriden 345 | node.capabilities = node.SetCapabilities(node.capabilities); 346 | node.SetPosition(new Rect(graphNode.position, node.default_size)); 347 | 348 | // Add the needed ports 349 | foreach (var graphPort in graphNode.Ports) 350 | { 351 | AddPort(graphPort, node); 352 | } 353 | 354 | // If there are custom elements or drawing, let the derived node handle this 355 | node.DrawNode(); 356 | 357 | // If the node wants to hide the properties the user must make a View node and set this to false 358 | if (node.ShowNodeProperties) 359 | { 360 | VisualElement divider = new VisualElement(); 361 | divider.style.borderBottomColor = divider.style.borderTopColor = divider.style.borderLeftColor = divider.style.borderRightColor = Color.black; 362 | divider.style.borderBottomWidth = divider.style.borderTopWidth = divider.style.borderLeftWidth = divider.style.borderRightWidth = 0.5f; 363 | node.mainContainer.Add(divider); 364 | 365 | VisualElement node_data = new VisualElement(); 366 | node_data.AddToClassList("node_data"); 367 | node.mainContainer.Add(node_data); 368 | 369 | UnityEditor.Editor editor = UnityEditor.Editor.CreateEditor((VisualGraphNode)node.userData); 370 | IMGUIContainer inspectorIMGUI = new IMGUIContainer(() => { editor.OnInspectorGUI(); }); 371 | node_data.Add(inspectorIMGUI); 372 | } 373 | 374 | // Finally add the element 375 | AddElement(node); 376 | 377 | // Refresh the view 378 | node.RefreshExpandedState(); 379 | node.RefreshPorts(); 380 | 381 | return node; 382 | } 383 | 384 | private string GetGraphNodeName(Type type) 385 | { 386 | string display_name = ""; 387 | if (type.GetCustomAttribute() != null) 388 | { 389 | display_name = type.GetCustomAttribute().name; 390 | } 391 | else 392 | { 393 | display_name = type.Name; 394 | } 395 | return display_name; 396 | } 397 | #endregion 398 | 399 | #region Port Connections 400 | /// 401 | /// Create a port for the given node based off the direction. Once the port is created for the node in the graph 402 | /// a port will be added to the view node 403 | /// 404 | /// 405 | /// 406 | /// 407 | public void CreatePort(Node node, string name, VisualGraphPort.PortDirection direction) 408 | { 409 | VisualGraphNode graphNode = node.userData as VisualGraphNode; 410 | Undo.RecordObject(graphNode, "Add Port to Node"); 411 | 412 | VisualGraphPort graphPort = graphNode.AddPort(name, direction); 413 | AddPort(graphPort, node); 414 | 415 | EditorUtility.SetDirty(visualGraph); 416 | } 417 | 418 | /// 419 | /// Add a port to the view node 420 | /// 421 | /// 422 | /// 423 | private void AddPort(VisualGraphPort graphPort, Node node) 424 | { 425 | VisualGraphNode graphNode = node.userData as VisualGraphNode; 426 | 427 | // Determine the direction of the port (In/Out) 428 | Direction direction = (graphPort.Direction == VisualGraphPort.PortDirection.Input) ? Direction.Input : Direction.Output; 429 | 430 | // Get the capacity of the port (how many connections can this port have) 431 | PortCapacityAttribute capacityAttrib = graphNode.GetType().GetCustomAttribute(); 432 | Debug.Assert(capacityAttrib != null, $"Graph node requires a PortCapacityAttribute {graphNode.GetType().Name}"); 433 | Port.Capacity capacity = Port.Capacity.Single; 434 | if (graphPort.Direction == VisualGraphPort.PortDirection.Input) 435 | { 436 | capacity = (capacityAttrib.InputPortCapacity == PortCapacityAttribute.Capacity.Single) ? Port.Capacity.Single : Port.Capacity.Multi; 437 | } 438 | else 439 | { 440 | capacity = (capacityAttrib.OutputPortCapacity == PortCapacityAttribute.Capacity.Single) ? Port.Capacity.Single : Port.Capacity.Multi; 441 | } 442 | 443 | // Get the data type for the port. 444 | // TODO: can we optimze/change this to be more dynamic? 445 | Type port_type = (graphPort.Direction == VisualGraphPort.PortDirection.Input) ? graphNode.InputType : graphNode.OutputType; 446 | 447 | // Create the port based off supplied information 448 | var port = node.InstantiatePort(orientation, direction, capacity, port_type); 449 | port.portName = "";// Don't set the name this helps with the view. 450 | port.userData = graphPort; 451 | graphPort.editor_port = port; 452 | 453 | // Custom View for ports 454 | NodePortAggregateAttribute portAggregateAttrib = graphNode.GetType().GetCustomAttribute(); 455 | NodePortAggregateAttribute.PortAggregate aggregate = NodePortAggregateAttribute.PortAggregate.None; 456 | if (graphPort.Direction == VisualGraphPort.PortDirection.Input) 457 | { 458 | aggregate = (portAggregateAttrib.InputPortAggregate == NodePortAggregateAttribute.PortAggregate.Single) ? NodePortAggregateAttribute.PortAggregate.Single : NodePortAggregateAttribute.PortAggregate.Multiple; 459 | } 460 | else 461 | { 462 | aggregate = (portAggregateAttrib.OutputPortAggregate == NodePortAggregateAttribute.PortAggregate.Single) ? NodePortAggregateAttribute.PortAggregate.Single : NodePortAggregateAttribute.PortAggregate.Multiple; 463 | } 464 | 465 | VisualGraphPortView graphPortView = null; 466 | if (aggregate == NodePortAggregateAttribute.PortAggregate.Single) 467 | { 468 | graphPortView = Activator.CreateInstance(typeof(VisualGraphLabelPortView)) as VisualGraphLabelPortView; 469 | } 470 | else 471 | { 472 | Type portViewType = null; 473 | visualGraphPortLookup.TryGetValue(graphPort.GetType(), out portViewType); 474 | if (portViewType == null) 475 | { 476 | portViewType = typeof(VisualGraphPortView); 477 | } 478 | graphPortView = Activator.CreateInstance(portViewType) as VisualGraphPortView; 479 | } 480 | graphPortView.CreateView(graphPort); 481 | port.Add(graphPortView); 482 | 483 | // If the user can remove a port add a button 484 | if (graphPort.CanBeRemoved) 485 | { 486 | var deleteButton = new Button(() => RemovePort(node, port)) 487 | { 488 | text = "X" 489 | }; 490 | port.Add(deleteButton); 491 | } 492 | port.AddManipulator(new EdgeConnector(this)); 493 | 494 | // Put the port in the proper container for the view 495 | if (direction == Direction.Input) 496 | { 497 | node.inputContainer.Add(port); 498 | } 499 | else 500 | { 501 | node.outputContainer.Add(port); 502 | } 503 | node.RefreshExpandedState(); 504 | node.RefreshPorts(); 505 | } 506 | 507 | /// 508 | /// Connect the nodes together through the port Connections 509 | /// 510 | /// 511 | /// 512 | public void OnDrop(GraphView graphView, Edge edge) 513 | { 514 | VisualGraphNode graph_input_node = edge.input.node.userData as VisualGraphNode; 515 | VisualGraphNode graph_output_node = edge.output.node.userData as VisualGraphNode; 516 | 517 | Undo.RecordObjects(new UnityEngine.Object[] { graph_input_node, graph_output_node }, "Add Port to Node"); 518 | 519 | VisualGraphPort graph_input_port = edge.input.userData as VisualGraphPort; 520 | VisualGraphPort graph_output_port = edge.output.userData as VisualGraphPort; 521 | 522 | graph_input_port.Connections.Add(new VisualGraphPort.VisualGraphPortConnection() 523 | { 524 | initialized = true, 525 | Node = edge.output.node.userData as VisualGraphNode, 526 | port = graph_output_port, 527 | port_guid = graph_output_port.guid, 528 | node_guid = graph_output_node.guid 529 | }); 530 | graph_output_port.Connections.Add(new VisualGraphPort.VisualGraphPortConnection() 531 | { 532 | initialized = true, 533 | Node = edge.input.node.userData as VisualGraphNode, 534 | port = graph_input_port, 535 | port_guid = graph_input_port.guid, 536 | node_guid = graph_input_node.guid 537 | }); 538 | 539 | EditorUtility.SetDirty(visualGraph); 540 | } 541 | 542 | /// 543 | /// Not needed for default graphing. May be implemented in future versions 544 | /// 545 | /// 546 | /// 547 | public void OnDropOutsidePort(Edge edge, Vector2 position) 548 | { 549 | } 550 | 551 | /// 552 | /// Remove the given port from the node 553 | /// 554 | /// 555 | /// 556 | private void RemovePort(Node node, Port socket) 557 | { 558 | VisualGraphPort socket_port = socket.userData as VisualGraphPort; 559 | List edgeList = edges.ToList(); 560 | foreach (var edge in edgeList) 561 | { 562 | VisualGraphPort graphPort = edge.output.userData as VisualGraphPort; 563 | if (graphPort.guid.Equals(socket_port.guid)) 564 | { 565 | RemoveEdge(edge); 566 | edge.input.Disconnect(edge); 567 | RemoveElement(edge); 568 | } 569 | } 570 | 571 | VisualGraphNode graphNode = node.userData as VisualGraphNode; 572 | 573 | Undo.RecordObject(graphNode, "Remove Port"); 574 | 575 | graphNode.Ports.Remove(socket_port); 576 | 577 | if (socket.direction == Direction.Input) 578 | { 579 | node.inputContainer.Remove(socket); 580 | } 581 | else 582 | { 583 | node.outputContainer.Remove(socket); 584 | } 585 | node.RefreshPorts(); 586 | node.RefreshExpandedState(); 587 | 588 | EditorUtility.SetDirty(visualGraph); 589 | } 590 | 591 | public override List GetCompatiblePorts(Port startPort, NodeAdapter nodeAdapter) 592 | { 593 | var compatiblePorts = new List(); 594 | var startPortView = startPort; 595 | 596 | ports.ForEach((port) => 597 | { 598 | var portView = port; 599 | if (startPortView != portView && startPortView.node != portView.node) 600 | { 601 | compatiblePorts.Add(port); 602 | } 603 | }); 604 | 605 | return compatiblePorts; 606 | } 607 | #endregion 608 | 609 | #region Graph Changes 610 | private GraphViewChange OnGraphChange(GraphViewChange change) 611 | { 612 | // Return from this if we don't have a Visual Graph. This means we are reseting the 613 | // graph 614 | if (visualGraph == null) return change; 615 | 616 | if (change.elementsToRemove != null) 617 | { 618 | foreach (GraphElement element in change.elementsToRemove) 619 | { 620 | if (typeof(Edge).IsInstanceOfType(element) == true) 621 | { 622 | VisualGraphNode graph_input_node = ((Edge)element).input.node.userData as VisualGraphNode; 623 | VisualGraphNode graph_output_node = ((Edge)element).output.node.userData as VisualGraphNode; 624 | Undo.RecordObjects(new UnityEngine.Object[] { graph_input_node, graph_output_node }, "Add Port to Node"); 625 | 626 | RemoveEdge((Edge)element); 627 | } 628 | else if (typeof(Node).IsInstanceOfType(element) == true) 629 | { 630 | RemoveNode((Node)element); 631 | } 632 | //else if (typeof(Group).IsInstanceOfType(element) == true) 633 | //{ 634 | // VisualGraphGroup block = ((Group)element).userData as VisualGraphGroup; 635 | // Undo.RecordObjects(new UnityEngine.Object[] { visualGraph }, "Add Port to Node"); 636 | // visualGraph.Groups.Remove(block); 637 | //} 638 | } 639 | } 640 | 641 | if (change.movedElements != null) 642 | { 643 | List movedNodes = new List(); 644 | foreach (GraphElement element in change.movedElements) 645 | { 646 | if (typeof(Node).IsInstanceOfType(element) == true) 647 | { 648 | movedNodes.Add((VisualGraphNode)element.userData); 649 | } 650 | } 651 | Undo.RecordObjects(movedNodes.ToArray(), "Moved VisualGraphNode"); 652 | 653 | foreach (GraphElement element in change.movedElements) 654 | { 655 | if (typeof(Node).IsInstanceOfType(element) == true) 656 | { 657 | movedNodes.Add((VisualGraphNode)element.userData); 658 | ((VisualGraphNode)element.userData).position = new Vector2(element.style.left.value.value, element.style.top.value.value); 659 | } 660 | } 661 | } 662 | 663 | EditorUtility.SetDirty(visualGraph); 664 | 665 | return change; 666 | } 667 | 668 | private void RemoveNode(Node node) 669 | { 670 | VisualGraphNode graphNode = node.userData as VisualGraphNode; 671 | Undo.RecordObjects(new UnityEngine.Object[] { graphNode, visualGraph }, "Delete Node"); 672 | visualGraph.RemoveNode (graphNode); 673 | Undo.DestroyObjectImmediate(graphNode); 674 | } 675 | 676 | private void RemoveEdge(Edge edge) 677 | { 678 | VisualGraphPort graph_input_port = edge.input.userData as VisualGraphPort; 679 | VisualGraphPort graph_output_port = edge.output.userData as VisualGraphPort; 680 | graph_input_port.RemoveConnectionByPortGuid(graph_output_port.guid); 681 | graph_output_port.RemoveConnectionByPortGuid(graph_input_port.guid); 682 | } 683 | #endregion 684 | } 685 | } -------------------------------------------------------------------------------- /Editor/Graph/VisualGraphView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 44bebb4f9136f9a42bc74d8935d0a8ee 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Graph/VisualGraphViewAttributes.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | 6 | namespace VisualGraphEditor 7 | { 8 | /// 9 | /// 10 | /// 11 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] 12 | public class CustomNodeViewAttribute : Attribute 13 | { 14 | public Type type; 15 | 16 | /// 17 | /// 18 | /// 19 | /// 20 | public CustomNodeViewAttribute(Type type) 21 | { 22 | this.type = type; 23 | } 24 | } 25 | 26 | /// 27 | /// 28 | /// 29 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] 30 | public class CustomPortViewAttribute : Attribute 31 | { 32 | public Type type; 33 | 34 | /// 35 | /// 36 | /// 37 | /// 38 | public CustomPortViewAttribute(Type type) 39 | { 40 | this.type = type; 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /Editor/Graph/VisualGraphViewAttributes.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a96bcfdb050eb8f48aa5ab49b209675d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Nodes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c1b04f799a1cdaf4db7bac9fac87a6a7 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/Nodes/VisualGraphGroupView.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEditor.Experimental.GraphView; 4 | using UnityEngine; 5 | using VisualGraphRuntime; 6 | 7 | namespace VisualGraphEditor 8 | { 9 | public class VisualGraphGroupView : Group 10 | { 11 | protected override void OnElementsAdded(IEnumerable elements) 12 | { 13 | base.OnElementsAdded(elements); 14 | 15 | VisualGraphGroup group = userData as VisualGraphGroup; 16 | foreach(var element in elements) 17 | { 18 | VisualGraphNode node = element.userData as VisualGraphNode; 19 | group.node_guids.Add(node.guid); 20 | } 21 | } 22 | 23 | protected override void OnElementsRemoved(IEnumerable elements) 24 | { 25 | base.OnElementsRemoved(elements); 26 | //VisualGraphGroup group = userData as VisualGraphGroup; 27 | //foreach (var element in elements) 28 | //{ 29 | // VisualGraphNode node = element.userData as VisualGraphNode; 30 | // group.node_guids.Remove(node.guid); 31 | //} 32 | } 33 | 34 | protected override void OnGroupRenamed(string oldName, string newName) 35 | { 36 | base.OnGroupRenamed(oldName, newName); 37 | 38 | VisualGraphGroup group = userData as VisualGraphGroup; 39 | group.title = newName; 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /Editor/Nodes/VisualGraphGroupView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8d2cd0c06399e9f42ad4ca2a2b4699d0 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Nodes/VisualGraphNodeView.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEditor.Experimental.GraphView; 4 | using UnityEngine; 5 | 6 | namespace VisualGraphEditor 7 | { 8 | public class VisualGraphNodeView : Node 9 | { 10 | [HideInInspector] public virtual Vector2 default_size => new Vector2(200, 150); 11 | [HideInInspector] public virtual bool ShowNodeProperties => true; 12 | 13 | public virtual void DrawNode() 14 | { 15 | } 16 | 17 | public virtual Capabilities SetCapabilities(Capabilities capabilities) 18 | { 19 | return capabilities; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Editor/Nodes/VisualGraphNodeView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bd91234aa722c054181e05dbba1f9d56 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Nodes/VisualGraphStartNodeView.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEditor.Experimental.GraphView; 4 | using UnityEngine; 5 | using VisualGraphRuntime; 6 | 7 | namespace VisualGraphEditor 8 | { 9 | [CustomNodeView((typeof(VisualGraphStartNode)))] 10 | public sealed class VisualGraphStartNodeView : VisualGraphNodeView 11 | { 12 | public override bool ShowNodeProperties => false; 13 | 14 | public override Capabilities SetCapabilities(Capabilities capabilities) 15 | { 16 | capabilities &= ~UnityEditor.Experimental.GraphView.Capabilities.Movable; 17 | capabilities &= ~UnityEditor.Experimental.GraphView.Capabilities.Deletable; 18 | return capabilities; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Editor/Nodes/VisualGraphStartNodeView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a2f545839b2112f478785239b3fe6874 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Ports.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ab612bb01c00fd34385d661967cbe24f 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/Ports/VisualGraphDefaultPortView.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.UIElements; 5 | using UnityEditor.UIElements; 6 | using VisualGraphRuntime; 7 | using UnityEditor; 8 | 9 | namespace VisualGraphEditor 10 | { 11 | [CustomPortView(typeof(VisualGraphPort))] 12 | public sealed class VisualGraphDefaultPortView : VisualGraphPortView 13 | { 14 | public override void CreateView(VisualGraphPort port) 15 | { 16 | TextField leftField = new TextField(); 17 | leftField.value = port.Name; 18 | leftField.style.width = 100; 19 | leftField.RegisterCallback>( 20 | (evt) => 21 | { 22 | if (string.IsNullOrEmpty(evt.newValue) == false) 23 | { 24 | port.Name = evt.newValue; 25 | } 26 | } 27 | ); 28 | Add(leftField); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Editor/Ports/VisualGraphDefaultPortView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b14d322c15eeff245bb86b5e96b9a32e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Ports/VisualGraphLabelPortView.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.UIElements; 5 | using VisualGraphRuntime; 6 | 7 | namespace VisualGraphEditor 8 | { 9 | public class VisualGraphLabelPortView : VisualGraphPortView 10 | { 11 | public override void CreateView(VisualGraphPort port) 12 | { 13 | Label field = new Label(port.Name); 14 | Add(field); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Editor/Ports/VisualGraphLabelPortView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a20c41f1e6bde034583cbe24b115de29 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Ports/VisualGraphPortView.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.UIElements; 5 | using VisualGraphRuntime; 6 | 7 | namespace VisualGraphEditor 8 | { 9 | public abstract class VisualGraphPortView : VisualElement 10 | { 11 | public abstract void CreateView(VisualGraphPort port); 12 | } 13 | } -------------------------------------------------------------------------------- /Editor/Ports/VisualGraphPortView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3e5ebc9b2f5427b44b16212969c2bcb6 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Resources.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6f57d508dcae10c44ac58d2f65679e8e 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/Resources/Node.uss: -------------------------------------------------------------------------------- 1 | .VisualGraphNode { 2 | border-radius: 10; 3 | } 4 | 5 | .VisualGraphNodeSelected { 6 | border-radius: 10; 7 | background-color: rgba(128, 128, 196, 1); 8 | } 9 | 10 | #title { 11 | background-color: rgba(64, 64, 64, 1); 12 | } 13 | 14 | #contents { 15 | background-color: rgba(64, 64, 64, 1); 16 | } 17 | 18 | .node_data { 19 | background-color: rgba(64, 64, 64, 1); 20 | border-width: 5; 21 | } 22 | -------------------------------------------------------------------------------- /Editor/Resources/Node.uss.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: de33ade2b9bf6e244a60cb1e3e66b82b 3 | ScriptedImporter: 4 | internalIDToNameTable: [] 5 | externalObjects: {} 6 | serializedVersion: 2 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0} 11 | disableValidation: 0 12 | -------------------------------------------------------------------------------- /Editor/Resources/VisualGraphMonoBehaviourInspector.uss: -------------------------------------------------------------------------------- 1 | #blackboardLabel { 2 | border-top-width: 10; 3 | border-bottom-width: 5; 4 | } 5 | 6 | #blackboardProperty { 7 | border-color: rgba(0, 0, 0, 1); 8 | border-top-width: 1; 9 | padding: 3; 10 | } 11 | -------------------------------------------------------------------------------- /Editor/Resources/VisualGraphMonoBehaviourInspector.uss.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e494e111814971b4291ae0e9fbcd56b7 3 | ScriptedImporter: 4 | internalIDToNameTable: [] 5 | externalObjects: {} 6 | serializedVersion: 2 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0} 11 | disableValidation: 0 12 | -------------------------------------------------------------------------------- /Editor/Resources/VisualGraphStyle.uss: -------------------------------------------------------------------------------- 1 | GridBackground { 2 | --grid-background-color: #282828; 3 | --line-color: rgba(193, 196, 192, 0.1); 4 | --thick-line-color: rgba(193, 196, 192, 0.1); 5 | --spacing: 10; 6 | } -------------------------------------------------------------------------------- /Editor/Resources/VisualGraphStyle.uss.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2eabaa6d7d0399541834a45548246d81 3 | ScriptedImporter: 4 | internalIDToNameTable: [] 5 | externalObjects: {} 6 | serializedVersion: 2 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0} 11 | disableValidation: 0 12 | -------------------------------------------------------------------------------- /Editor/VisualGraphEditorAssembly.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "VisualGraphEditor", 3 | "references": [ 4 | "VisualGraphRuntime" 5 | ], 6 | "optionalUnityReferences": [], 7 | "includePlatforms": [ 8 | "Editor" 9 | ], 10 | "excludePlatforms": [], 11 | "allowUnsafeCode": false, 12 | "overrideReferences": false, 13 | "precompiledReferences": [], 14 | "autoReferenced": true, 15 | "defineConstraints": [], 16 | "versionDefines": [] 17 | } 18 | -------------------------------------------------------------------------------- /Editor/VisualGraphEditorAssembly.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fad92165ed0ff4e46b811fa19404a6f2 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 BusStopStudios 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /LICENSE.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a3c6c87501d394c4493e9b25111e66a3 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Node Based Visual Graph System for Unity 2 | 3 | This graph editor allows you to skip the editor work and create a Node Graph that is customizable. The tool that uses Unity's Experimental GraphView. 4 | 5 | ## Visul Graph Features 6 | * Extensible 7 | * Scriptable Assets that can be used at rumtime through custom behaviour 8 | * Minimap. 9 | * Search window. 10 | * Blackboard that supports most types. 11 | 12 | ## Usage 13 | * VisualGraph generates a starting point for you to create your custom graph 14 | * To start create a script that extends VisualGraphNode. This is either the basic node for your graph or a base node your graph will use. 15 | * You can add the following attributes: [NodeName()] [NodePortAggregate()] [PortCapacity()] [CustomNodeStyle()] 16 | * You can create more node scripts that extend your base node 17 | * Next create a script that extends VisualGraph, add [CreateAssetMenu] and [DefaultNodeType(typeof(YOURBASENODE_YOU_JUST_CREATED))] 18 | * Generate your graph 19 | * It is recommended to extend the VisualGraphMonoBehaviour to create a MonoBehaviour to use in your game 20 | * The VisualGraphMonoBehaviour will create an internal copy of the graph so it does not change the actual ScriptableObject data (at runtime and in the editor) 21 | * Once you have created your VisualGraphMonoBehaviour script add this to a game object. Access the graph by using InternalGraph 22 | * From there you can navigate your graph in your node scripts. 23 | * You can also add Blackboard properties to your graph, if you have added the graph to you MonoBehaviour it will make a copy of the properties 24 | * Properties can be overriden and set which are used at runtime 25 | * There are refresh issues with the properties in the inspector (working on this) 26 | 27 | ## Examples 28 | 29 | ### Basic Example Graph 30 | ![](https://raw.githubusercontent.com/BusStopStudios/Doc/main/Visual-Graph/Example.PNG) 31 | 32 | ### FSM Example 33 | ![](https://raw.githubusercontent.com/BusStopStudios/Doc/main/Visual-Graph/FSM.PNG) 34 | 35 | ![](https://raw.githubusercontent.com/BusStopStudios/Doc/main/Visual-Graph/FSM%20Component.PNG) 36 | 37 | # Bugs 38 | - Inspector does not refresh when blackboard properties change (new, delete, or update) 39 | -------------------------------------------------------------------------------- /README.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1c5a7e6ff6dc0444ba1589694b656c46 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6f86ea4c701b600478b1963d008aabb7 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Blackboard.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: baab5e451877f884d80ce91bfa9110be 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Blackboard/AbstractBlackboardProperty.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using System; 7 | using UnityEngine; 8 | 9 | namespace VisualGraphRuntime 10 | { 11 | /// 12 | /// Base class for all Blackboard Properties 13 | /// 14 | [Serializable] 15 | public abstract class AbstractBlackboardProperty : ScriptableObject 16 | { 17 | [HideInInspector] public bool overrideProperty; // used in the component at runtime 18 | [HideInInspector] public string guid; 19 | public string Name; 20 | 21 | public virtual void Copy(AbstractBlackboardProperty property) 22 | { 23 | guid = property.guid; 24 | Name = property.Name; 25 | } 26 | } 27 | 28 | /// 29 | /// Generic base class for all Blackboard Properties that contain the value 30 | /// 31 | [Serializable] 32 | public abstract class AbstractBlackboardProperty : AbstractBlackboardProperty 33 | { 34 | [SerializeField] [HideInInspector] public T abstractData; 35 | public Type PropertyType => typeof(T); 36 | 37 | public override void Copy(AbstractBlackboardProperty property) 38 | { 39 | base.Copy(property); 40 | 41 | AbstractBlackboardProperty propertyT = property as AbstractBlackboardProperty; 42 | if (propertyT != null) 43 | { 44 | abstractData = propertyT.Value; 45 | } 46 | } 47 | 48 | protected virtual void OnDataChanged() { } 49 | 50 | public virtual T Value 51 | { 52 | get => abstractData; 53 | set 54 | { 55 | abstractData = value; 56 | OnDataChanged(); 57 | } 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /Runtime/Blackboard/AbstractBlackboardProperty.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 941d4258cb0221c4092ec71c0afd3045 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Blackboard/BoolBlackboardProperty.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using System; 7 | using UnityEngine; 8 | 9 | namespace VisualGraphRuntime 10 | { 11 | /// 12 | /// Bool Blackboard property 13 | /// 14 | [Serializable] 15 | public class BoolBlackboardProperty : AbstractBlackboardProperty 16 | { 17 | } 18 | } -------------------------------------------------------------------------------- /Runtime/Blackboard/BoolBlackboardProperty.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c22eacb0334362d4e89994e4a1a0e5ed 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Blackboard/ColliderBlackboardProperty.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using System; 7 | using UnityEngine; 8 | 9 | namespace VisualGraphRuntime 10 | { 11 | /// 12 | /// Collider Blackboard property 13 | /// 14 | [Serializable] 15 | public class ColliderBlackboardProperty : AbstractBlackboardProperty 16 | { 17 | } 18 | } -------------------------------------------------------------------------------- /Runtime/Blackboard/ColliderBlackboardProperty.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: df04a48936abfce4baa779086b6510dc 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Blackboard/ColorBlackboardProperty.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using System; 7 | using UnityEngine; 8 | 9 | namespace VisualGraphRuntime 10 | { 11 | /// 12 | /// Color Blackboard property 13 | /// 14 | [Serializable] 15 | public class ColorBlackboardProperty : AbstractBlackboardProperty 16 | { 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Runtime/Blackboard/ColorBlackboardProperty.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b414e8081c87b0f4d8a0ed6570c7c916 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Blackboard/DoubleBlackboardProperty.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using System; 7 | 8 | namespace VisualGraphRuntime 9 | { 10 | /// 11 | /// double Blackboard property 12 | /// 13 | [Serializable] 14 | public class DoubleBlackboardProperty : AbstractBlackboardProperty 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Runtime/Blackboard/DoubleBlackboardProperty.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9599af1e624e1794e8aa3cd621a7e63e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Blackboard/FloatBlackboardProperty.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using System; 7 | 8 | namespace VisualGraphRuntime 9 | { 10 | /// 11 | /// float Blackboard property 12 | /// 13 | [Serializable] 14 | public class FloatBlackboardProperty : AbstractBlackboardProperty 15 | { 16 | } 17 | } -------------------------------------------------------------------------------- /Runtime/Blackboard/FloatBlackboardProperty.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bd71a48f486cef54b885527933b16c89 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Blackboard/GameObjectBlackboardProperty.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using System; 7 | using UnityEngine; 8 | 9 | namespace VisualGraphRuntime 10 | { 11 | /// 12 | /// GameObject Blackboard property 13 | /// 14 | [Serializable] 15 | public class GameObjectBlackboardProperty : AbstractBlackboardProperty 16 | { 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Runtime/Blackboard/GameObjectBlackboardProperty.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b45a8f6e55846134ca49edb9fe1326b6 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Blackboard/IntBlackboardProperty.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using System; 7 | 8 | namespace VisualGraphRuntime 9 | { 10 | /// 11 | /// int Blackboard property 12 | /// 13 | [Serializable] 14 | public class IntBlackboardProperty : AbstractBlackboardProperty 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Runtime/Blackboard/IntBlackboardProperty.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 613a8ef4221fbc04d844a44fd83b616f 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Blackboard/LayerMaskBlackboardProperty.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using System; 7 | using UnityEngine; 8 | 9 | namespace VisualGraphRuntime 10 | { 11 | /// 12 | /// LayerMask Blackboard property 13 | /// 14 | [Serializable] 15 | public class LayerMaskBlackboardProperty : AbstractBlackboardProperty 16 | { 17 | } 18 | } -------------------------------------------------------------------------------- /Runtime/Blackboard/LayerMaskBlackboardProperty.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 28ea663651b472a4d890c7f4473c1b51 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Blackboard/MaterialBlackboardProperty.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using System; 7 | using UnityEngine; 8 | 9 | namespace VisualGraphRuntime 10 | { 11 | /// 12 | /// Material Blackboard property 13 | /// 14 | [Serializable] 15 | public class MaterialBlackboardProperty : AbstractBlackboardProperty 16 | { 17 | } 18 | } -------------------------------------------------------------------------------- /Runtime/Blackboard/MaterialBlackboardProperty.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8436c1af2d24ebe419ea72497e753a28 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Blackboard/ObjectBlackboardProperty.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using System; 7 | using UnityEngine; 8 | 9 | namespace VisualGraphRuntime 10 | { 11 | /// 12 | /// UnityEngine.Object Blackboard property 13 | /// 14 | [Serializable] 15 | public class ObjectBlackboardProperty : AbstractBlackboardProperty 16 | { 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Runtime/Blackboard/ObjectBlackboardProperty.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5a8c43acc265a6240b814143fd2365b3 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Blackboard/RectBlackboardProperty.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using System; 7 | using UnityEngine; 8 | 9 | namespace VisualGraphRuntime 10 | { 11 | /// 12 | /// Rect Blackboard property 13 | /// 14 | [Serializable] 15 | public class RectBlackboardProperty : AbstractBlackboardProperty 16 | { 17 | } 18 | } -------------------------------------------------------------------------------- /Runtime/Blackboard/RectBlackboardProperty.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2e58d00d341921a4cb6b135fe7d5bf62 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Blackboard/RectIntBlackboardProperty.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using System; 7 | using UnityEngine; 8 | 9 | namespace VisualGraphRuntime 10 | { 11 | /// 12 | /// Rect Blackboard property 13 | /// 14 | [Serializable] 15 | public class RectIntBlackboardProperty : AbstractBlackboardProperty 16 | { 17 | } 18 | } -------------------------------------------------------------------------------- /Runtime/Blackboard/RectIntBlackboardProperty.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e0042553ed1e0f94cae3eea13d31d0f4 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Blackboard/StringBlackboardProperty.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using System; 7 | 8 | namespace VisualGraphRuntime 9 | { 10 | /// 11 | /// string Blackboard property 12 | /// 13 | [Serializable] 14 | public class StringBlackboardProperty : AbstractBlackboardProperty 15 | { 16 | } 17 | } -------------------------------------------------------------------------------- /Runtime/Blackboard/StringBlackboardProperty.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bb8915fb0c3cc0e4098a6b5e20f615f5 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Blackboard/TransformBlackboardProperty.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using System; 7 | using UnityEngine; 8 | 9 | namespace VisualGraphRuntime 10 | { 11 | /// 12 | /// Transform Blackboard property 13 | /// 14 | [Serializable] 15 | public class TransformBlackboardProperty : AbstractBlackboardProperty 16 | { 17 | } 18 | } -------------------------------------------------------------------------------- /Runtime/Blackboard/TransformBlackboardProperty.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: af38f5bcfb88ffa43aa17e77ee4db261 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Blackboard/Vector2BlackboardProperty.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using System; 7 | using UnityEngine; 8 | 9 | namespace VisualGraphRuntime 10 | { 11 | /// 12 | /// Vector2 Blackboard property 13 | /// 14 | [Serializable] 15 | public class Vector2BlackboardProperty : AbstractBlackboardProperty 16 | { 17 | } 18 | } -------------------------------------------------------------------------------- /Runtime/Blackboard/Vector2BlackboardProperty.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3463c2e09a25e6644bb0ece4ddcbe0b7 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Blackboard/Vector2IntBlackboardProperty.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using System; 7 | using UnityEngine; 8 | 9 | namespace VisualGraphRuntime 10 | { 11 | /// 12 | /// Vector2Int Blackboard property 13 | /// 14 | [Serializable] 15 | public class Vector2IntBlackboardProperty : AbstractBlackboardProperty 16 | { 17 | } 18 | } -------------------------------------------------------------------------------- /Runtime/Blackboard/Vector2IntBlackboardProperty.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 144ea7bd1c6ffa24b91b696028f81d37 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Blackboard/Vector3BlackboardProperty.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using System; 7 | using UnityEngine; 8 | 9 | namespace VisualGraphRuntime 10 | { 11 | /// 12 | /// Vector3 Blackboard property 13 | /// 14 | [Serializable] 15 | public class Vector3BlackboardProperty : AbstractBlackboardProperty 16 | { 17 | } 18 | } -------------------------------------------------------------------------------- /Runtime/Blackboard/Vector3BlackboardProperty.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 149500bbf826bac4891c49e55606f06b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Blackboard/Vector3IntBlackboardProperty.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using System; 7 | using UnityEngine; 8 | 9 | namespace VisualGraphRuntime 10 | { 11 | /// 12 | /// Vector3Int Blackboard property 13 | /// 14 | [Serializable] 15 | public class Vector3IntBlackboardProperty : AbstractBlackboardProperty 16 | { 17 | } 18 | } -------------------------------------------------------------------------------- /Runtime/Blackboard/Vector3IntBlackboardProperty.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4e52b9a8781db494b8500aa0bb3a6448 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Blackboard/Vector4BlackboardProperty.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using System; 7 | using UnityEngine; 8 | 9 | namespace VisualGraphRuntime 10 | { 11 | /// 12 | /// Vector3 Blackboard property 13 | /// 14 | [Serializable] 15 | public class Vector4BlackboardProperty : AbstractBlackboardProperty 16 | { 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Runtime/Blackboard/Vector4BlackboardProperty.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bb0de6535871b2f4da0b0841f5b6e859 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Component.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b1f71ae9a5c2d464abe45fbc245e75f7 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Component/VisualGraphMonoBehaviour.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using System; 7 | using System.Collections; 8 | using System.Collections.Generic; 9 | using UnityEngine; 10 | using VisualGraphRuntime; 11 | 12 | namespace VisualGraphRuntime 13 | { 14 | /// 15 | /// Base class for all VisualGraph MonoBehaviours. To create your own behaviour derive from this and 16 | /// complete the generic with what type of VisualGraph your behaviour will use 17 | /// 18 | /// 19 | public class VisualGraphMonoBehaviour : MonoBehaviour where T : VisualGraph 20 | { 21 | /// 22 | /// Internal list of properties. 23 | /// 24 | /// WARNING: Changing this will have undersired results. This list is updated to reflect the properties in the Graph. The 25 | /// inspector will allow you to override settings in the VisualGraph 26 | /// 27 | [SerializeReference] [HideInInspector] public List BlackboardProperties = new List(); 28 | 29 | /// 30 | /// Store a reference to the type of graph we want to use 31 | /// 32 | [SerializeField] private T graph; 33 | 34 | /// 35 | /// To be used at runtime and un editor during play 36 | /// 37 | public T Graph => internalGraph; 38 | private T internalGraph; 39 | 40 | /// 41 | /// On start clone the graph so we don't overwrite the internal SO in the editor 42 | /// and at runtime we have our own version 43 | /// 44 | protected virtual void Start() 45 | { 46 | if (graph == null) 47 | { 48 | Debug.LogWarning($"{name} requires a VisualGraph"); 49 | } 50 | else 51 | { 52 | internalGraph = (T)graph.Clone(); 53 | internalGraph.Init(); 54 | } 55 | 56 | // Override properties in the internalGraph that have been selected in the this 57 | for (int i = 0; i < BlackboardProperties.Count; i++) 58 | { 59 | if (BlackboardProperties[i].overrideProperty == false) continue; 60 | 61 | foreach (var property in internalGraph.BlackboardProperties) 62 | { 63 | if (BlackboardProperties[i].guid == property.guid) 64 | { 65 | property.Copy(BlackboardProperties[i]); 66 | break; 67 | } 68 | } 69 | } 70 | } 71 | 72 | /// 73 | /// Add/Remove any properties to match the VisualGraph 74 | /// 75 | public void UpdateProperties() 76 | { 77 | RemoveMissingProperties(); 78 | AddMissingProperties(); 79 | 80 | // Override properties in the internalGraph that have been selected in the this 81 | for (int i = 0; i < BlackboardProperties.Count; i++) 82 | { 83 | if (BlackboardProperties[i].overrideProperty == true) continue; 84 | 85 | foreach (var property in graph.BlackboardProperties) 86 | { 87 | if (BlackboardProperties[i].guid == property.guid) 88 | { 89 | BlackboardProperties[i].Copy(property); 90 | break; 91 | } 92 | } 93 | } 94 | } 95 | 96 | private void RemoveMissingProperties() 97 | { 98 | // Go through the current list and remove any that may have been removed 99 | for (int i = 0; i < BlackboardProperties.Count; i++) 100 | { 101 | bool found = false; 102 | foreach (var property in graph.BlackboardProperties) 103 | { 104 | if (BlackboardProperties[i].guid == property.guid) 105 | { 106 | found = true; 107 | break; 108 | } 109 | } 110 | if (found == false) 111 | { 112 | BlackboardProperties.RemoveAt(i); 113 | i--; 114 | } 115 | } 116 | } 117 | 118 | private void AddMissingProperties() 119 | { 120 | if (graph != null) 121 | { 122 | // Add any that might be missing 123 | for (int i = 0; i < graph.BlackboardProperties.Count; i++) 124 | { 125 | bool found = false; 126 | foreach (var property in BlackboardProperties) 127 | { 128 | if (graph.BlackboardProperties[i].guid == property.guid) 129 | { 130 | found = true; 131 | break; 132 | } 133 | } 134 | if (found == false) 135 | { 136 | AbstractBlackboardProperty instance = Activator.CreateInstance(graph.BlackboardProperties[i].GetType()) as AbstractBlackboardProperty; 137 | instance.Copy(graph.BlackboardProperties[i]); 138 | BlackboardProperties.Add(instance); 139 | } 140 | } 141 | } 142 | } 143 | } 144 | } -------------------------------------------------------------------------------- /Runtime/Component/VisualGraphMonoBehaviour.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ef055680d3cfe164aaaf3faee6974a52 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Graph.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b1ecacb41e42f5846a76a2cc99f8c40e 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Graph/VisualGraph.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Linq; 9 | using System.Reflection; 10 | using UnityEngine; 11 | 12 | namespace VisualGraphRuntime 13 | { 14 | /// 15 | /// Base class for all VisualGraphs. Derive from this to create your own Graph 16 | /// 17 | [Serializable] 18 | [GraphOrientation()] 19 | public abstract class VisualGraph : ScriptableObject 20 | { 21 | /// 22 | /// Starting node can be found in the Nodes list as well 23 | /// 24 | [HideInInspector] public VisualGraphNode StartingNode; 25 | 26 | /// 27 | /// Internal list of all Nodes 28 | /// 29 | [HideInInspector] public List Nodes = new List(); 30 | 31 | /// 32 | /// Comment Blocks. Not supported at this time 33 | /// 34 | //[HideInInspector] [SerializeField] public List Groups = new List(); 35 | 36 | /// 37 | /// Blackboard properties. Get/Set these through your behaviour 38 | /// 39 | [SerializeReference] [HideInInspector] public List BlackboardProperties = new List(); 40 | 41 | /// 42 | /// Creates a clone of this graph (used for internal graph settings for the MonoBehaviour) 43 | /// 44 | /// 45 | public virtual VisualGraph Clone() 46 | { 47 | VisualGraph clone = Instantiate(this); 48 | for(int i = 0; i < Nodes.Count; i++) 49 | { 50 | VisualGraphNode newNode = Instantiate(Nodes[i]) as VisualGraphNode; 51 | newNode.graph = clone; 52 | clone.Nodes[i] = newNode; 53 | } 54 | 55 | clone.StartingNode = clone.FindNodeByGuid(StartingNode.guid); 56 | clone.InitializeGraph(); 57 | 58 | return clone; 59 | } 60 | 61 | /// 62 | /// Once a graph is cloned Init should be called to ensure your nodes are setup 63 | /// 64 | public virtual void Init() 65 | { 66 | } 67 | 68 | /// 69 | /// Initialize all nodes with new version of graph 70 | /// 71 | public void InitializeGraph() 72 | { 73 | foreach (var node in Nodes) 74 | { 75 | node.graph = this; 76 | foreach (var port in node.Ports) 77 | { 78 | foreach (var connection in port.Connections) 79 | { 80 | if (connection.initialized == false && string.IsNullOrEmpty(connection.node_guid) == false) 81 | { 82 | VisualGraphNode otherNode = FindNodeByGuid(connection.node_guid); 83 | if (otherNode != null) 84 | { 85 | VisualGraphPort otherPort = otherNode.FindPortByGuid(connection.port_guid); 86 | if (otherPort != null) 87 | { 88 | VisualGraphPort.VisualGraphPortConnection otherConnection = otherPort.FindConnectionByNodeGuid(node.guid); 89 | if (otherConnection != null) 90 | { 91 | otherConnection.initialized = true; 92 | otherConnection.Node = node; 93 | otherConnection.port = port; 94 | 95 | connection.initialized = true; 96 | connection.Node = otherNode; 97 | connection.port = otherPort; 98 | } 99 | } 100 | } 101 | } 102 | } 103 | } 104 | } 105 | } 106 | 107 | /// 108 | /// Adds a new node to the graph based off type 109 | /// 110 | /// 111 | /// 112 | public virtual VisualGraphNode AddNode() where T : VisualGraphNode 113 | { 114 | return AddNode(typeof(T)) as T; 115 | } 116 | 117 | /// 118 | /// Adds a new node to the graph based off type 119 | /// 120 | /// 121 | /// 122 | public virtual VisualGraphNode AddNode(Type nodeType) 123 | { 124 | VisualGraphNode graphNode = Activator.CreateInstance(nodeType) as VisualGraphNode; 125 | graphNode.graph = this; 126 | graphNode.Init(); 127 | Nodes.Add(graphNode); 128 | 129 | NodePortAggregateAttribute dynamicsAttrib = graphNode.GetType().GetCustomAttribute(); 130 | Debug.Assert(dynamicsAttrib != null, $"Graph node requires a NodePortAggregateAttribute {graphNode.GetType().Name}"); 131 | 132 | PortCapacityAttribute capacityAttrib = graphNode.GetType().GetCustomAttribute(); 133 | Debug.Assert(capacityAttrib != null, $"Graph node requires a PortCapacityAttribute {graphNode.GetType().Name}"); 134 | 135 | if (dynamicsAttrib.InputPortAggregate != NodePortAggregateAttribute.PortAggregate.None) 136 | { 137 | VisualGraphPort graphPort = graphNode.AddPort("Input", VisualGraphPort.PortDirection.Input); 138 | graphPort.CanBeRemoved = false; 139 | } 140 | 141 | if (dynamicsAttrib.OutputPortAggregate == NodePortAggregateAttribute.PortAggregate.Single) 142 | { 143 | VisualGraphPort graphPort = graphNode.AddPort("Exit", VisualGraphPort.PortDirection.Output); 144 | graphPort.CanBeRemoved = false; 145 | } 146 | 147 | return graphNode; 148 | } 149 | 150 | /// 151 | /// Removes the given node from the graph 152 | /// 153 | /// 154 | public virtual void RemoveNode(VisualGraphNode graphNode) 155 | { 156 | graphNode.ClearConnections(); 157 | Nodes.Remove(graphNode); 158 | if (Application.isPlaying) 159 | { 160 | Destroy(graphNode); 161 | } 162 | } 163 | 164 | /// 165 | /// Find a graph node based off guid 166 | /// 167 | /// 168 | /// 169 | public VisualGraphNode FindNodeByGuid(string guid) 170 | { 171 | return Nodes.Where(n => n.guid.Equals(guid) == true).FirstOrDefault(); 172 | } 173 | 174 | /// 175 | /// Get a Value from the Blackboard based off a string and return true otherwise return false 176 | /// 177 | /// 178 | /// 179 | /// 180 | public bool GetPropertyValue(string propertyName, ref T value) 181 | { 182 | for (int i = 0; i < BlackboardProperties.Count; i++) 183 | { 184 | if (BlackboardProperties[i].Name == propertyName) 185 | { 186 | AbstractBlackboardProperty prop = (AbstractBlackboardProperty)BlackboardProperties[i]; 187 | if (prop != null) 188 | { 189 | value = prop.Value; 190 | return true; 191 | } 192 | } 193 | } 194 | Debug.LogWarning($"Unable to find property {propertyName}"); 195 | return false; 196 | } 197 | } 198 | } -------------------------------------------------------------------------------- /Runtime/Graph/VisualGraph.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 78b3fd9154634ebdb8c8a48960b9a16a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Graph/VisualGraphAttributes.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using System; 7 | 8 | namespace VisualGraphRuntime 9 | { 10 | /// 11 | /// 12 | /// 13 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] 14 | public class NodeNameAttribute : Attribute 15 | { 16 | public string name; 17 | 18 | /// 19 | /// 20 | /// 21 | /// 22 | public NodeNameAttribute(string _name) 23 | { 24 | name = _name; 25 | } 26 | } 27 | 28 | /// 29 | /// 30 | /// 31 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] 32 | public class DefaultNodeTypeAttribute : Attribute 33 | { 34 | public Type type; 35 | 36 | /// 37 | /// 38 | /// 39 | /// 40 | public DefaultNodeTypeAttribute(Type _type) 41 | { 42 | type = _type; 43 | } 44 | } 45 | 46 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] 47 | public class DefaultPortTypeAttribute : Attribute 48 | { 49 | public Type type; 50 | 51 | /// 52 | /// 53 | /// 54 | /// 55 | public DefaultPortTypeAttribute(Type _type) 56 | { 57 | type = _type; 58 | } 59 | } 60 | 61 | /// 62 | /// 63 | /// 64 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] 65 | public class NodePortAggregateAttribute : Attribute 66 | { 67 | public enum PortAggregate 68 | { 69 | None, 70 | Single, 71 | Multiple 72 | }; 73 | public PortAggregate InputPortAggregate = PortAggregate.Single; 74 | public PortAggregate OutputPortAggregate = PortAggregate.Multiple; 75 | 76 | /// 77 | /// 78 | /// 79 | /// 80 | public NodePortAggregateAttribute(PortAggregate InputPortDynamics = PortAggregate.Single, PortAggregate OutputPortDynamics = PortAggregate.Multiple) 81 | { 82 | this.InputPortAggregate = InputPortDynamics; 83 | this.OutputPortAggregate = OutputPortDynamics; 84 | } 85 | } 86 | 87 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] 88 | public class PortCapacityAttribute : Attribute 89 | { 90 | // 91 | // Summary: 92 | // Specify how many edges a port can have connected. 93 | public enum Capacity 94 | { 95 | // 96 | // Summary: 97 | // Port can only have a single connection. 98 | Single = 0, 99 | // 100 | // Summary: 101 | // Port can have multiple connections. 102 | Multi = 1 103 | } 104 | public Capacity InputPortCapacity = Capacity.Multi; 105 | public Capacity OutputPortCapacity = Capacity.Single; 106 | 107 | /// 108 | /// 109 | /// 110 | /// 111 | public PortCapacityAttribute(Capacity InputPortCapacity = Capacity.Multi, Capacity OutputPortCapacity = Capacity.Single) 112 | { 113 | this.InputPortCapacity = InputPortCapacity; 114 | this.OutputPortCapacity = OutputPortCapacity; 115 | } 116 | } 117 | 118 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] 119 | public class GraphOrientationAttribute : Attribute 120 | { 121 | // 122 | // Summary: 123 | // Graph element orientation. 124 | public enum Orientation 125 | { 126 | // Summary: 127 | // Horizontal orientation used for nodes and connections flowing to the left or 128 | // right. 129 | Horizontal = 0, 130 | // 131 | // Summary: 132 | // Vertical orientation used for nodes and connections flowing up or down. 133 | Vertical = 1 134 | } 135 | public Orientation GrapOrientation = Orientation.Horizontal; 136 | 137 | /// 138 | /// 139 | /// 140 | /// 141 | public GraphOrientationAttribute(Orientation GrapOrientation = Orientation.Horizontal) 142 | { 143 | this.GrapOrientation = GrapOrientation; 144 | } 145 | } 146 | 147 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] 148 | public class CustomNodeStyleAttribute : Attribute 149 | { 150 | public string style; 151 | 152 | /// 153 | /// 154 | /// 155 | /// 156 | public CustomNodeStyleAttribute(string style) 157 | { 158 | this.style = style; 159 | } 160 | } 161 | } -------------------------------------------------------------------------------- /Runtime/Graph/VisualGraphAttributes.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 643b055799630fb489746b4e4f769220 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Node.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7ef15f78b3dc02d44b236eecbcf4d532 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Node/VIsualGraphPort.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Linq; 9 | using UnityEngine; 10 | 11 | namespace VisualGraphRuntime 12 | { 13 | /// 14 | /// Node ports for connections 15 | /// 16 | [Serializable] 17 | public class VisualGraphPort 18 | { 19 | /// 20 | /// Port Directions 21 | /// 22 | public enum PortDirection 23 | { 24 | Input, 25 | Output 26 | }; 27 | 28 | /// 29 | /// Port Connections 30 | /// 31 | [Serializable] 32 | public class VisualGraphPortConnection 33 | { 34 | [NonSerialized] public bool initialized; 35 | [NonSerialized] public VisualGraphNode Node; // Node that should contain a port based off the guid 36 | [NonSerialized] public VisualGraphPort port; // This must be set in the OnEnable for the graph cannot be stored 37 | 38 | public string node_guid; // Reference to the port that belongs to the Node 39 | public string port_guid; // Reference to the port that belongs to the Node 40 | } 41 | 42 | // internals 43 | [HideInInspector] public string Name; 44 | [HideInInspector] public PortDirection Direction; 45 | [HideInInspector] public bool CanBeRemoved = true; 46 | [HideInInspector] public string guid; 47 | 48 | /// 49 | /// List of all connections for this port. 50 | /// 51 | [HideInInspector][SerializeField] public List Connections = new List(); 52 | 53 | /// 54 | /// Initialize 55 | /// 56 | public virtual void Init() { } 57 | 58 | /// 59 | /// Finds a Connection by port guid 60 | /// 61 | /// 62 | /// 63 | public VisualGraphPortConnection FindConnectionByPortGuid(string guid) 64 | { 65 | return Connections.Where(c => c.port_guid.Equals(guid) == true).FirstOrDefault(); 66 | } 67 | 68 | /// 69 | /// Finds a Connection by node guid 70 | /// 71 | /// 72 | /// 73 | public VisualGraphPortConnection FindConnectionByNodeGuid(string guid) 74 | { 75 | return Connections.Where(c => c.node_guid.Equals(guid) == true).FirstOrDefault(); 76 | } 77 | 78 | /// 79 | /// Removes the port based off guid 80 | /// 81 | /// 82 | public void RemoveConnectionByPortGuid(string guid) 83 | { 84 | VisualGraphPortConnection connection = Connections.Where(p => p.port_guid.Equals(guid) == true).FirstOrDefault(); 85 | if (connection != null) 86 | { 87 | Connections.Remove(connection); 88 | } 89 | } 90 | 91 | /// 92 | /// Remove all connections the port contains 93 | /// 94 | public void ClearConnections() 95 | { 96 | foreach(VisualGraphPortConnection connection in Connections) 97 | { 98 | if (connection.port != null) 99 | { 100 | connection.port.RemoveConnectionByPortGuid(guid); 101 | } 102 | } 103 | Connections.Clear(); 104 | } 105 | 106 | #region UNITY_EDITOR 107 | #if UNITY_EDITOR 108 | // The Editor Port (easier to link) 109 | public object editor_port; 110 | #endif 111 | #endregion 112 | 113 | } 114 | } -------------------------------------------------------------------------------- /Runtime/Node/VIsualGraphPort.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: be073312f3aaa394db9206d8171bb439 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Node/VisualGraphGroup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace VisualGraphRuntime 6 | { 7 | /// 8 | /// Not supported at this time 9 | /// 10 | [Serializable] 11 | public class VisualGraphGroup 12 | { 13 | public string title; 14 | public Vector2 position; 15 | 16 | public List node_guids = new List(); 17 | } 18 | } -------------------------------------------------------------------------------- /Runtime/Node/VisualGraphGroup.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c454cb3a69274ff985c7401b14143e02 3 | timeCreated: 1584055091 -------------------------------------------------------------------------------- /Runtime/Node/VisualGraphNode.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using System; 7 | using System.Collections.Generic; 8 | using UnityEngine; 9 | using System.Linq; 10 | using System.Reflection; 11 | 12 | namespace VisualGraphRuntime 13 | { 14 | /// 15 | /// Base class for all VisualGraph nodes. Derive from this to create your own nodes. The following attribute 16 | /// can be used to customize your Node (otherwise defaults are used): 17 | /// 18 | /// [NodeName(_name: "NAME OF YOUR NODE, OTHERWISE CLASSNAME IS USED")] 19 | /// OPTIONAL: [NodePortAggregateAttribute(SINGLE OR MULTIPLE INPUT PORTS, SINGLE OR MULTIPLE OUTPUT PORTS)] 20 | /// OPTIONAL: [PortCapacity(SINGLE OR MULTI INPUT CONNECTIONS PER PORT, SINGLE OR MULTI INPUT CONNECTIONS PER PORT)] 21 | /// OPTIONAL: [CustomNodeStyle("USS STYLE")] 22 | /// 23 | [Serializable] 24 | [NodePortAggregate()] 25 | [PortCapacity()] 26 | public abstract class VisualGraphNode : ScriptableObject 27 | { 28 | public IEnumerable Inputs { get { foreach (VisualGraphPort port in Ports) { if (port.Direction == VisualGraphPort.PortDirection.Input) yield return port; } } } 29 | public IEnumerable Outputs { get { foreach (VisualGraphPort port in Ports) { if (port.Direction == VisualGraphPort.PortDirection.Output) yield return port; } } } 30 | 31 | 32 | [HideInInspector][NonSerialized] public VisualGraph graph; 33 | 34 | /// 35 | /// Get the guid for the Node 36 | /// 37 | public string guid { get { return internal_guid; } } 38 | 39 | /// 40 | /// List of all ports that belong to this node (ports can be either in or out 41 | /// 42 | [HideInInspector] [SerializeReference] public List Ports = new List(); 43 | 44 | /// 45 | /// All Nodes have a guid for references 46 | /// 47 | [HideInInspector] [SerializeField] private string internal_guid; 48 | 49 | /// 50 | /// Node Setup 51 | /// 52 | private void OnEnable() 53 | { 54 | if (string.IsNullOrEmpty(internal_guid)) 55 | { 56 | internal_guid = Guid.NewGuid().ToString(); 57 | } 58 | } 59 | 60 | /// 61 | /// Called when created. Use this to add required ports and additional setup 62 | /// 63 | public virtual void Init() 64 | { 65 | } 66 | 67 | public virtual VisualGraphPort AddPort(string name, VisualGraphPort.PortDirection direction) 68 | { 69 | DefaultPortTypeAttribute portAttribute = GetType().GetCustomAttribute(); 70 | Type portType = typeof(VisualGraphPort); 71 | if (portAttribute != null) 72 | { 73 | portType = portAttribute.type; 74 | } 75 | 76 | VisualGraphPort graphPort = Activator.CreateInstance(portType) as VisualGraphPort; 77 | graphPort.Name = name; 78 | graphPort.guid = Guid.NewGuid().ToString(); 79 | graphPort.Direction = direction; 80 | Ports.Add(graphPort); 81 | 82 | return graphPort; 83 | } 84 | 85 | /// 86 | /// Find the first port based off guid Id 87 | /// 88 | /// 89 | /// 90 | public VisualGraphPort FindPortByGuid(string guid) 91 | { 92 | return Ports.Where(p => p.guid.Equals(guid) == true).FirstOrDefault(); 93 | } 94 | 95 | /// 96 | /// Find the first port based off the name. If multiple ports exist the first one will be returned 97 | /// 98 | /// 99 | /// 100 | public VisualGraphPort FindPortByName(string name) 101 | { 102 | return Ports.Where(p => p.Name.Equals(name) == true).FirstOrDefault(); 103 | } 104 | 105 | /// 106 | /// Remove all connections this node has 107 | /// 108 | public void ClearConnections() 109 | { 110 | foreach (VisualGraphPort port in Ports) 111 | { 112 | port.ClearConnections(); 113 | } 114 | } 115 | 116 | #region UNITY_EDITOR 117 | 118 | /// 119 | /// If set the node will highlight in the editor for visual feedback at runtime. It is up to the user to disable 120 | /// other nodes that are active otherwise you will get undesired results in the view. 121 | /// 122 | [HideInInspector] public bool editor_ActiveNode; 123 | 124 | #if UNITY_EDITOR 125 | #region Graph View Editor Values 126 | [HideInInspector] public Vector2 position; 127 | [HideInInspector][NonSerialized] public object graphElement; 128 | #endregion 129 | 130 | public virtual System.Type InputType => typeof(bool); 131 | public virtual System.Type OutputType => typeof(bool); 132 | #endif 133 | #endregion 134 | } 135 | } -------------------------------------------------------------------------------- /Runtime/Node/VisualGraphNode.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7c392018894e4299b2cd6e249b894325 3 | timeCreated: 1574810383 -------------------------------------------------------------------------------- /Runtime/Node/VisualGraphStartNode.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | namespace VisualGraphRuntime 7 | { 8 | /// 9 | /// Start node for the VisualGraph. All Graphs will have this node added at the beginning. 10 | /// Possible future development will remove this and give the option to create one. 11 | /// 12 | [NodePortAggregate(NodePortAggregateAttribute.PortAggregate.None, NodePortAggregateAttribute.PortAggregate.Single)] 13 | [NodeName(_name: "Start")] 14 | public sealed class VisualGraphStartNode : VisualGraphNode 15 | { 16 | } 17 | } -------------------------------------------------------------------------------- /Runtime/Node/VisualGraphStartNode.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ed165b12bb8f4c948932f8ee28821eca 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/VisualGraphAssembly.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "VisualGraphRuntime", 3 | "references": [], 4 | "optionalUnityReferences": [], 5 | "includePlatforms": [], 6 | "excludePlatforms": [], 7 | "allowUnsafeCode": false, 8 | "overrideReferences": false, 9 | "precompiledReferences": [], 10 | "autoReferenced": true, 11 | "defineConstraints": [], 12 | "versionDefines": [] 13 | } 14 | -------------------------------------------------------------------------------- /Runtime/VisualGraphAssembly.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9454a0f97d26bec4686dc94d005a99be 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Samples~.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 09f875e1c1d16fa4e959ae58c4c4aeb9 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/Example.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 39dc42e8825ffb64bbc26937a1b06240 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/Example/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cf6bc48a8271fcf4497aabf36b1fb72e 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/Example/Editor/Nodes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5f20edfb68947ba4eb28b71cf67f6205 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/Example/Editor/Nodes/ExampleNodeView.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEditor.Experimental.GraphView; 4 | using UnityEngine; 5 | using UnityEngine.UIElements; 6 | using VisualGraphEditor; 7 | 8 | /// 9 | /// Example of how you can override the base view node 10 | /// There are few properties to override, most are set through attributes so 11 | /// you don't have to create this node. 12 | /// 13 | /// By using the CustomNodeView, you will see what type runtime type this node will display 14 | /// 15 | [CustomNodeView((typeof(ExampleNode)))] 16 | public sealed class ExampleNodeView : VisualGraphNodeView 17 | { 18 | // For this example the ability to hide/show the properties for the node are 19 | // hidden. Comment this out or set it to true to see the properties 20 | [HideInInspector] public override bool ShowNodeProperties => true; 21 | 22 | public override void DrawNode() 23 | { 24 | base.DrawNode(); 25 | 26 | VisualElement node_data = new VisualElement(); 27 | node_data.style.backgroundColor = Color.blue; 28 | mainContainer.Add(node_data); 29 | 30 | Label example = new Label("Custom Example"); 31 | node_data.Add(example); 32 | 33 | mainContainer.Add(node_data); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Samples~/Example/Editor/Nodes/ExampleNodeView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0fcadf76f993a3949a735c8c82906c23 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Samples~/Example/Editor/Nodes/ExamplePortView.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.UIElements; 5 | using VisualGraphEditor; 6 | using VisualGraphRuntime; 7 | 8 | [CustomPortView(typeof(ExamplePort))] 9 | public sealed class ExamplePortView : VisualGraphPortView 10 | { 11 | public override void CreateView(VisualGraphPort port) 12 | { 13 | Label field = new Label(port.Name); 14 | field.style.width = 100; 15 | Add(field); 16 | } 17 | } -------------------------------------------------------------------------------- /Samples~/Example/Editor/Nodes/ExamplePortView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8c220d7b61d50ce4db0d385a6fa2e356 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Samples~/Example/Editor/Resources.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7e8d1c151c24c7e4a802c2f50db19666 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/Example/Editor/Resources/ExampleNodeStyle.uss: -------------------------------------------------------------------------------- 1 | /* Add a round border to all nodes */ 2 | .VisualGraphNode { 3 | border-radius: 10; 4 | background-color: rgba(196, 196, 196, 1); 5 | } 6 | 7 | /* Change the background color of the title section */ 8 | #title { 9 | background-color: rgba(0, 0, 0, 1); 10 | } -------------------------------------------------------------------------------- /Samples~/Example/Editor/Resources/ExampleNodeStyle.uss.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 83a359ffcf606ac4591b880ea4bb2799 3 | ScriptedImporter: 4 | internalIDToNameTable: [] 5 | externalObjects: {} 6 | serializedVersion: 2 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0} 11 | disableValidation: 0 12 | -------------------------------------------------------------------------------- /Samples~/Example/Runtime.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5b4541600096c5e4baff54df1aa1264f 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/Example/Runtime/Graphs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4974b04c5081d8f4693c44b9598b9307 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/Example/Runtime/Graphs/Empty Graph.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!114 &11400000 4 | MonoBehaviour: 5 | m_ObjectHideFlags: 0 6 | m_CorrespondingSourceObject: {fileID: 0} 7 | m_PrefabInstance: {fileID: 0} 8 | m_PrefabAsset: {fileID: 0} 9 | m_GameObject: {fileID: 0} 10 | m_Enabled: 1 11 | m_EditorHideFlags: 0 12 | m_Script: {fileID: 11500000, guid: a6fde670e7119d9429e3117e89788fe2, type: 3} 13 | m_Name: Empty Graph 14 | m_EditorClassIdentifier: 15 | StartingNode: {fileID: 6750337293623085363} 16 | Nodes: 17 | - {fileID: 6750337293623085363} 18 | BlackboardProperties: [] 19 | --- !u!114 &6750337293623085363 20 | MonoBehaviour: 21 | m_ObjectHideFlags: 0 22 | m_CorrespondingSourceObject: {fileID: 0} 23 | m_PrefabInstance: {fileID: 0} 24 | m_PrefabAsset: {fileID: 0} 25 | m_GameObject: {fileID: 0} 26 | m_Enabled: 1 27 | m_EditorHideFlags: 0 28 | m_Script: {fileID: 11500000, guid: ed165b12bb8f4c948932f8ee28821eca, type: 3} 29 | m_Name: Start 30 | m_EditorClassIdentifier: 31 | graph: {fileID: 0} 32 | Ports: 33 | - id: 0 34 | internal_guid: 7cf0956a-2e04-4d75-ba41-137841489042 35 | editor_ActiveNode: 0 36 | position: {x: 270, y: 30} 37 | references: 38 | version: 1 39 | 00000000: 40 | type: {class: VisualGraphPort, ns: VisualGraphRuntime, asm: VisualGraphRuntime} 41 | data: 42 | Name: Next 43 | Direction: 1 44 | CanBeRemoved: 0 45 | guid: 1057766b-3962-4883-8f34-f0df53e8bba6 46 | Connections: [] 47 | -------------------------------------------------------------------------------- /Samples~/Example/Runtime/Graphs/Empty Graph.asset.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 57fae75b364ff62468a3bf5861470c17 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 11400000 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/Example/Runtime/Graphs/Simple Graph.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!114 &11400000 4 | MonoBehaviour: 5 | m_ObjectHideFlags: 0 6 | m_CorrespondingSourceObject: {fileID: 0} 7 | m_PrefabInstance: {fileID: 0} 8 | m_PrefabAsset: {fileID: 0} 9 | m_GameObject: {fileID: 0} 10 | m_Enabled: 1 11 | m_EditorHideFlags: 0 12 | m_Script: {fileID: 11500000, guid: a6fde670e7119d9429e3117e89788fe2, type: 3} 13 | m_Name: Simple Graph 14 | m_EditorClassIdentifier: 15 | StartingNode: {fileID: 2200814509731714274} 16 | Nodes: 17 | - {fileID: 2200814509731714274} 18 | - {fileID: 3498280319350482697} 19 | BlackboardProperties: [] 20 | --- !u!114 &2200814509731714274 21 | MonoBehaviour: 22 | m_ObjectHideFlags: 0 23 | m_CorrespondingSourceObject: {fileID: 0} 24 | m_PrefabInstance: {fileID: 0} 25 | m_PrefabAsset: {fileID: 0} 26 | m_GameObject: {fileID: 0} 27 | m_Enabled: 1 28 | m_EditorHideFlags: 0 29 | m_Script: {fileID: 11500000, guid: ed165b12bb8f4c948932f8ee28821eca, type: 3} 30 | m_Name: Start 31 | m_EditorClassIdentifier: 32 | graph: {fileID: 0} 33 | Ports: 34 | - id: 0 35 | internal_guid: 53f96e22-e677-403a-b0d3-533c96bd1a7f 36 | editor_ActiveNode: 0 37 | position: {x: 270, y: 30} 38 | references: 39 | version: 1 40 | 00000000: 41 | type: {class: VisualGraphPort, ns: VisualGraphRuntime, asm: VisualGraphRuntime} 42 | data: 43 | Name: Next 44 | Direction: 1 45 | CanBeRemoved: 0 46 | guid: 058a2d76-51a2-4438-b769-e8722584a475 47 | Connections: 48 | - node_guid: 61709656-a018-4032-ba6c-230441f3d6a5 49 | port_guid: 97aec483-afc7-4cff-9103-07abcf282a08 50 | --- !u!114 &3498280319350482697 51 | MonoBehaviour: 52 | m_ObjectHideFlags: 0 53 | m_CorrespondingSourceObject: {fileID: 0} 54 | m_PrefabInstance: {fileID: 0} 55 | m_PrefabAsset: {fileID: 0} 56 | m_GameObject: {fileID: 0} 57 | m_Enabled: 1 58 | m_EditorHideFlags: 0 59 | m_Script: {fileID: 11500000, guid: 9f410bd6e8d523a47b8745e559931533, type: 3} 60 | m_Name: Example Node 61 | m_EditorClassIdentifier: 62 | graph: {fileID: 11400000} 63 | Ports: 64 | - id: 0 65 | - id: 1 66 | - id: 2 67 | - id: 3 68 | - id: 4 69 | internal_guid: 61709656-a018-4032-ba6c-230441f3d6a5 70 | editor_ActiveNode: 0 71 | position: {x: 481, y: 170} 72 | ExampleBool: 0 73 | ExampleInt: 0 74 | ExampleString: 75 | ExampleFloat: 0 76 | ExampleVector: {x: 0, y: 0, z: 0} 77 | references: 78 | version: 1 79 | 00000000: 80 | type: {class: ExamplePort, ns: , asm: Assembly-CSharp} 81 | data: 82 | Name: Input 83 | Direction: 0 84 | CanBeRemoved: 0 85 | guid: 97aec483-afc7-4cff-9103-07abcf282a08 86 | Connections: 87 | - node_guid: 53f96e22-e677-403a-b0d3-533c96bd1a7f 88 | port_guid: 058a2d76-51a2-4438-b769-e8722584a475 89 | 00000001: 90 | type: {class: ExamplePort, ns: , asm: Assembly-CSharp} 91 | data: 92 | Name: Exit 93 | Direction: 1 94 | CanBeRemoved: 1 95 | guid: d2f3d294-80da-4f26-abb5-4c811981b6ee 96 | Connections: [] 97 | 00000002: 98 | type: {class: ExamplePort, ns: , asm: Assembly-CSharp} 99 | data: 100 | Name: Exit 101 | Direction: 1 102 | CanBeRemoved: 1 103 | guid: 18f06172-2afe-41ac-81b8-01f4bb8fcda1 104 | Connections: [] 105 | 00000003: 106 | type: {class: ExamplePort, ns: , asm: Assembly-CSharp} 107 | data: 108 | Name: Exit 109 | Direction: 1 110 | CanBeRemoved: 1 111 | guid: 2b2db6bc-6021-4089-9d8a-b4d06a057790 112 | Connections: [] 113 | 00000004: 114 | type: {class: ExamplePort, ns: , asm: Assembly-CSharp} 115 | data: 116 | Name: Input 117 | Direction: 0 118 | CanBeRemoved: 1 119 | guid: ecd7b3e7-8857-4249-9087-eb0e123f5fe9 120 | Connections: [] 121 | -------------------------------------------------------------------------------- /Samples~/Example/Runtime/Graphs/Simple Graph.asset.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d39aefa9758d45340a054f501a53b036 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 11400000 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/Example/Runtime/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cccb510070dbd14468044a3d0cb73c2d 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/Example/Runtime/Scripts/ExampleGraph.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using UnityEngine; 7 | using VisualGraphRuntime; 8 | 9 | // Ability to create the asset 10 | [CreateAssetMenu] 11 | // Default Node type for this graph 12 | [DefaultNodeType(typeof(ExampleNode))] 13 | public class ExampleGraph : VisualGraph 14 | { 15 | } 16 | -------------------------------------------------------------------------------- /Samples~/Example/Runtime/Scripts/ExampleGraph.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a6fde670e7119d9429e3117e89788fe2 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Samples~/Example/Runtime/Scripts/ExampleNode.cs: -------------------------------------------------------------------------------- 1 | ///------------------------------------------------------------------------------------------------- 2 | // author: William Barry 3 | // date: 2020 4 | // Copyright (c) Bus Stop Studios. 5 | ///------------------------------------------------------------------------------------------------- 6 | using UnityEngine; 7 | using VisualGraphRuntime; 8 | 9 | // Override the default node name (otherwise the name of the class is used) 10 | [NodeName(_name: "Example Node")] 11 | // Override the default settings for how many ports the node will handle 12 | [NodePortAggregateAttribute(NodePortAggregateAttribute.PortAggregate.Multiple, NodePortAggregateAttribute.PortAggregate.Multiple)] 13 | // Override the default settings for the Port Capacity 14 | [PortCapacity(PortCapacityAttribute.Capacity.Multi, PortCapacityAttribute.Capacity.Multi)] 15 | // Custom style sheet for your node 16 | [CustomNodeStyle("ExampleNodeStyle")] 17 | // Default Port to use 18 | [DefaultPortType(typeof(ExamplePort))] 19 | public class ExampleNode : VisualGraphNode 20 | { 21 | public bool ExampleBool; 22 | public int ExampleInt; 23 | public string ExampleString; 24 | public float ExampleFloat; 25 | public Vector3 ExampleVector; 26 | } 27 | -------------------------------------------------------------------------------- /Samples~/Example/Runtime/Scripts/ExampleNode.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9f410bd6e8d523a47b8745e559931533 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Samples~/Example/Runtime/Scripts/ExamplePort.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | using VisualGraphRuntime; 6 | 7 | [Serializable] 8 | public class ExamplePort : VisualGraphPort 9 | { 10 | } 11 | -------------------------------------------------------------------------------- /Samples~/Example/Runtime/Scripts/ExamplePort.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5c93014dad50ee4458031ed017e82880 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Samples~/FSM.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b7e6ccb968f94a04d80c4a9c913bbe40 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/FSM/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6fed7c18f445b754ab7c84f127d25fc7 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/FSM/Editor/Ports.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ec106992c94d7ed458ae94ea7339c93d 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/FSM/Editor/Ports/FSMPortView.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEditor.UIElements; 4 | using UnityEngine; 5 | using UnityEngine.UIElements; 6 | using VisualGraphEditor; 7 | using VisualGraphRuntime; 8 | 9 | [CustomPortView(typeof(FSMPort))] 10 | public class FSMPortView : VisualGraphPortView 11 | { 12 | public override void CreateView(VisualGraphPort port) 13 | { 14 | FSMPort fsmPort = (FSMPort)port; 15 | 16 | EnumField field = new EnumField(FSMPort.State.None); 17 | field.SetValueWithoutNotify(fsmPort.state); 18 | field.RegisterValueChangedCallback(evt=> 19 | { 20 | fsmPort.state = (FSMPort.State)evt.newValue; 21 | }); 22 | Add(field); 23 | } 24 | } -------------------------------------------------------------------------------- /Samples~/FSM/Editor/Ports/FSMPortView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 99bf62bce4aab8b4e979f485e1fdb7bc 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Samples~/FSM/Editor/Resources.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 73ccf5eb7e3a70f419570dd5fa8e74fa 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/FSM/Editor/Resources/LightOffStyle.uss: -------------------------------------------------------------------------------- 1 | #title { 2 | background-color: rgba(128, 0, 255, 1); 3 | } -------------------------------------------------------------------------------- /Samples~/FSM/Editor/Resources/LightOffStyle.uss.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9adf6c99547203448a4b250722e570c6 3 | ScriptedImporter: 4 | internalIDToNameTable: [] 5 | externalObjects: {} 6 | serializedVersion: 2 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0} 11 | disableValidation: 0 12 | -------------------------------------------------------------------------------- /Samples~/FSM/Editor/Resources/LightOnStyle.uss: -------------------------------------------------------------------------------- 1 | #title { 2 | color: rgba(0, 0, 0, 1); 3 | background-color: rgba(196, 196, 196, 1); 4 | } 5 | 6 | #title-label { 7 | color: rgba(0, 0, 0, 1); 8 | } 9 | -------------------------------------------------------------------------------- /Samples~/FSM/Editor/Resources/LightOnStyle.uss.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e74758fa34e2e1f4ab657d1f0a407247 3 | ScriptedImporter: 4 | internalIDToNameTable: [] 5 | externalObjects: {} 6 | serializedVersion: 2 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0} 11 | disableValidation: 0 12 | -------------------------------------------------------------------------------- /Samples~/FSM/Runtime.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5712041f4354162448aa27db41dff2dd 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/FSM/Runtime/Graphs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 591f174635349354cb59210d1f72e2fb 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/FSM/Runtime/Graphs/Light FSM Graph.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!114 &-1236883665489293308 4 | MonoBehaviour: 5 | m_ObjectHideFlags: 0 6 | m_CorrespondingSourceObject: {fileID: 0} 7 | m_PrefabInstance: {fileID: 0} 8 | m_PrefabAsset: {fileID: 0} 9 | m_GameObject: {fileID: 0} 10 | m_Enabled: 1 11 | m_EditorHideFlags: 0 12 | m_Script: {fileID: 11500000, guid: b45a8f6e55846134ca49edb9fe1326b6, type: 3} 13 | m_Name: GameObjectBlackboardProperty 14 | m_EditorClassIdentifier: 15 | overrideProperty: 0 16 | guid: a3d2a5f3-2a8b-4e91-9b7a-b01320a75479 17 | Name: Light 18 | abstractData: {fileID: 0} 19 | --- !u!114 &11400000 20 | MonoBehaviour: 21 | m_ObjectHideFlags: 0 22 | m_CorrespondingSourceObject: {fileID: 0} 23 | m_PrefabInstance: {fileID: 0} 24 | m_PrefabAsset: {fileID: 0} 25 | m_GameObject: {fileID: 0} 26 | m_Enabled: 1 27 | m_EditorHideFlags: 0 28 | m_Script: {fileID: 11500000, guid: 0cac613c2c69d574a8f136683f8f0de0, type: 3} 29 | m_Name: Light FSM Graph 30 | m_EditorClassIdentifier: 31 | StartingNode: {fileID: 6556755584268572760} 32 | Nodes: 33 | - {fileID: 6556755584268572760} 34 | - {fileID: 9062436233233538063} 35 | - {fileID: 7611134317270045205} 36 | BlackboardProperties: 37 | - {fileID: 8484639206423503057} 38 | - {fileID: -1236883665489293308} 39 | currentState: {fileID: 0} 40 | --- !u!114 &6556755584268572760 41 | MonoBehaviour: 42 | m_ObjectHideFlags: 0 43 | m_CorrespondingSourceObject: {fileID: 0} 44 | m_PrefabInstance: {fileID: 0} 45 | m_PrefabAsset: {fileID: 0} 46 | m_GameObject: {fileID: 0} 47 | m_Enabled: 1 48 | m_EditorHideFlags: 0 49 | m_Script: {fileID: 11500000, guid: ed165b12bb8f4c948932f8ee28821eca, type: 3} 50 | m_Name: Start 51 | m_EditorClassIdentifier: 52 | graph: {fileID: 0} 53 | Ports: 54 | - id: 0 55 | internal_guid: a91214cb-c47d-4ffb-85eb-e5d8d46288a4 56 | editor_ActiveNode: 0 57 | position: {x: 270, y: 30} 58 | references: 59 | version: 1 60 | 00000000: 61 | type: {class: VisualGraphPort, ns: VisualGraphRuntime, asm: VisualGraphRuntime} 62 | data: 63 | Name: Next 64 | Direction: 1 65 | CanBeRemoved: 0 66 | guid: 5698114f-5786-4466-907c-83310ce347ca 67 | Connections: 68 | - node_guid: 40a3d9f0-f7c4-41fc-a507-6566b5414efd 69 | port_guid: b119b1f8-877c-4497-ad11-370c8f8fa8f9 70 | --- !u!114 &7611134317270045205 71 | MonoBehaviour: 72 | m_ObjectHideFlags: 0 73 | m_CorrespondingSourceObject: {fileID: 0} 74 | m_PrefabInstance: {fileID: 0} 75 | m_PrefabAsset: {fileID: 0} 76 | m_GameObject: {fileID: 0} 77 | m_Enabled: 1 78 | m_EditorHideFlags: 0 79 | m_Script: {fileID: 11500000, guid: a8b611e4035f82c489ba8981c3e229a7, type: 3} 80 | m_Name: Light On State 81 | m_EditorClassIdentifier: 82 | graph: {fileID: 11400000} 83 | Ports: 84 | - id: 0 85 | - id: 1 86 | internal_guid: cd90c6a0-62a8-4969-8038-ec12be83ae08 87 | editor_ActiveNode: 0 88 | position: {x: 520, y: 397} 89 | fsm: {fileID: 0} 90 | references: 91 | version: 1 92 | 00000000: 93 | type: {class: FSMPort, ns: , asm: Assembly-CSharp} 94 | data: 95 | Name: Input 96 | Direction: 0 97 | CanBeRemoved: 0 98 | guid: 73b44dbc-261c-419b-a4ec-417f34bd12f7 99 | Connections: 100 | - node_guid: 40a3d9f0-f7c4-41fc-a507-6566b5414efd 101 | port_guid: 4d77fdd5-56c1-4d5e-b1e9-99574c89b05c 102 | state: 0 103 | 00000001: 104 | type: {class: FSMPort, ns: , asm: Assembly-CSharp} 105 | data: 106 | Name: Exit 107 | Direction: 1 108 | CanBeRemoved: 1 109 | guid: 4aaed5af-17d9-40aa-9570-d01537353d32 110 | Connections: 111 | - node_guid: 40a3d9f0-f7c4-41fc-a507-6566b5414efd 112 | port_guid: b119b1f8-877c-4497-ad11-370c8f8fa8f9 113 | state: 2 114 | --- !u!114 &8484639206423503057 115 | MonoBehaviour: 116 | m_ObjectHideFlags: 0 117 | m_CorrespondingSourceObject: {fileID: 0} 118 | m_PrefabInstance: {fileID: 0} 119 | m_PrefabAsset: {fileID: 0} 120 | m_GameObject: {fileID: 0} 121 | m_Enabled: 1 122 | m_EditorHideFlags: 0 123 | m_Script: {fileID: 11500000, guid: bd71a48f486cef54b885527933b16c89, type: 3} 124 | m_Name: FloatBlackboardProperty 125 | m_EditorClassIdentifier: 126 | overrideProperty: 0 127 | guid: 63ffe771-c297-4ee0-bac5-00b01242be13 128 | Name: Delay 129 | abstractData: 0.5 130 | --- !u!114 &9062436233233538063 131 | MonoBehaviour: 132 | m_ObjectHideFlags: 0 133 | m_CorrespondingSourceObject: {fileID: 0} 134 | m_PrefabInstance: {fileID: 0} 135 | m_PrefabAsset: {fileID: 0} 136 | m_GameObject: {fileID: 0} 137 | m_Enabled: 1 138 | m_EditorHideFlags: 0 139 | m_Script: {fileID: 11500000, guid: 0de229ea86724a8478b9b558e2c9399f, type: 3} 140 | m_Name: Light Off State 141 | m_EditorClassIdentifier: 142 | graph: {fileID: 11400000} 143 | Ports: 144 | - id: 0 145 | - id: 1 146 | internal_guid: 40a3d9f0-f7c4-41fc-a507-6566b5414efd 147 | editor_ActiveNode: 1 148 | position: {x: 467, y: 84} 149 | fsm: {fileID: 0} 150 | references: 151 | version: 1 152 | 00000000: 153 | type: {class: FSMPort, ns: , asm: Assembly-CSharp} 154 | data: 155 | Name: Input 156 | Direction: 0 157 | CanBeRemoved: 0 158 | guid: b119b1f8-877c-4497-ad11-370c8f8fa8f9 159 | Connections: 160 | - node_guid: a91214cb-c47d-4ffb-85eb-e5d8d46288a4 161 | port_guid: 5698114f-5786-4466-907c-83310ce347ca 162 | - node_guid: cd90c6a0-62a8-4969-8038-ec12be83ae08 163 | port_guid: 4aaed5af-17d9-40aa-9570-d01537353d32 164 | state: 0 165 | 00000001: 166 | type: {class: FSMPort, ns: , asm: Assembly-CSharp} 167 | data: 168 | Name: Exit 169 | Direction: 1 170 | CanBeRemoved: 1 171 | guid: 4d77fdd5-56c1-4d5e-b1e9-99574c89b05c 172 | Connections: 173 | - node_guid: cd90c6a0-62a8-4969-8038-ec12be83ae08 174 | port_guid: 73b44dbc-261c-419b-a4ec-417f34bd12f7 175 | state: 1 176 | -------------------------------------------------------------------------------- /Samples~/FSM/Runtime/Graphs/Light FSM Graph.asset.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1e77de879827f5e4db3fa372b1cae8ff 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 11400000 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/FSM/Runtime/Scenes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 05e168b612517ac48b954f2b4b8b13ce 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/FSM/Runtime/Scenes/FSM - VisualGraph.unity: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!29 &1 4 | OcclusionCullingSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_OcclusionBakeSettings: 8 | smallestOccluder: 5 9 | smallestHole: 0.25 10 | backfaceThreshold: 100 11 | m_SceneGUID: 00000000000000000000000000000000 12 | m_OcclusionCullingData: {fileID: 0} 13 | --- !u!104 &2 14 | RenderSettings: 15 | m_ObjectHideFlags: 0 16 | serializedVersion: 9 17 | m_Fog: 0 18 | m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} 19 | m_FogMode: 3 20 | m_FogDensity: 0.01 21 | m_LinearFogStart: 0 22 | m_LinearFogEnd: 300 23 | m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1} 24 | m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1} 25 | m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1} 26 | m_AmbientIntensity: 1 27 | m_AmbientMode: 0 28 | m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1} 29 | m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0} 30 | m_HaloStrength: 0.5 31 | m_FlareStrength: 1 32 | m_FlareFadeSpeed: 3 33 | m_HaloTexture: {fileID: 0} 34 | m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0} 35 | m_DefaultReflectionMode: 0 36 | m_DefaultReflectionResolution: 128 37 | m_ReflectionBounces: 1 38 | m_ReflectionIntensity: 1 39 | m_CustomReflection: {fileID: 0} 40 | m_Sun: {fileID: 0} 41 | m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1} 42 | m_UseRadianceAmbientProbe: 0 43 | --- !u!157 &3 44 | LightmapSettings: 45 | m_ObjectHideFlags: 0 46 | serializedVersion: 12 47 | m_GIWorkflowMode: 1 48 | m_GISettings: 49 | serializedVersion: 2 50 | m_BounceScale: 1 51 | m_IndirectOutputScale: 1 52 | m_AlbedoBoost: 1 53 | m_EnvironmentLightingMode: 0 54 | m_EnableBakedLightmaps: 1 55 | m_EnableRealtimeLightmaps: 0 56 | m_LightmapEditorSettings: 57 | serializedVersion: 12 58 | m_Resolution: 2 59 | m_BakeResolution: 40 60 | m_AtlasSize: 1024 61 | m_AO: 0 62 | m_AOMaxDistance: 1 63 | m_CompAOExponent: 1 64 | m_CompAOExponentDirect: 0 65 | m_ExtractAmbientOcclusion: 0 66 | m_Padding: 2 67 | m_LightmapParameters: {fileID: 0} 68 | m_LightmapsBakeMode: 1 69 | m_TextureCompression: 1 70 | m_FinalGather: 0 71 | m_FinalGatherFiltering: 1 72 | m_FinalGatherRayCount: 256 73 | m_ReflectionCompression: 2 74 | m_MixedBakeMode: 2 75 | m_BakeBackend: 1 76 | m_PVRSampling: 1 77 | m_PVRDirectSampleCount: 32 78 | m_PVRSampleCount: 512 79 | m_PVRBounces: 2 80 | m_PVREnvironmentSampleCount: 256 81 | m_PVREnvironmentReferencePointCount: 2048 82 | m_PVRFilteringMode: 1 83 | m_PVRDenoiserTypeDirect: 1 84 | m_PVRDenoiserTypeIndirect: 1 85 | m_PVRDenoiserTypeAO: 1 86 | m_PVRFilterTypeDirect: 0 87 | m_PVRFilterTypeIndirect: 0 88 | m_PVRFilterTypeAO: 0 89 | m_PVREnvironmentMIS: 1 90 | m_PVRCulling: 1 91 | m_PVRFilteringGaussRadiusDirect: 1 92 | m_PVRFilteringGaussRadiusIndirect: 5 93 | m_PVRFilteringGaussRadiusAO: 2 94 | m_PVRFilteringAtrousPositionSigmaDirect: 0.5 95 | m_PVRFilteringAtrousPositionSigmaIndirect: 2 96 | m_PVRFilteringAtrousPositionSigmaAO: 1 97 | m_ExportTrainingData: 0 98 | m_TrainingDataDestination: TrainingData 99 | m_LightProbeSampleCountMultiplier: 4 100 | m_LightingDataAsset: {fileID: 0} 101 | m_LightingSettings: {fileID: 0} 102 | --- !u!196 &4 103 | NavMeshSettings: 104 | serializedVersion: 2 105 | m_ObjectHideFlags: 0 106 | m_BuildSettings: 107 | serializedVersion: 2 108 | agentTypeID: 0 109 | agentRadius: 0.5 110 | agentHeight: 2 111 | agentSlope: 45 112 | agentClimb: 0.4 113 | ledgeDropHeight: 0 114 | maxJumpAcrossDistance: 0 115 | minRegionArea: 2 116 | manualCellSize: 0 117 | cellSize: 0.16666667 118 | manualTileSize: 0 119 | tileSize: 256 120 | accuratePlacement: 0 121 | maxJobWorkers: 0 122 | preserveTilesOutsideBounds: 0 123 | debug: 124 | m_Flags: 0 125 | m_NavMeshData: {fileID: 0} 126 | --- !u!1 &1252859649 127 | GameObject: 128 | m_ObjectHideFlags: 0 129 | m_CorrespondingSourceObject: {fileID: 0} 130 | m_PrefabInstance: {fileID: 0} 131 | m_PrefabAsset: {fileID: 0} 132 | serializedVersion: 6 133 | m_Component: 134 | - component: {fileID: 1252859652} 135 | - component: {fileID: 1252859651} 136 | - component: {fileID: 1252859650} 137 | m_Layer: 0 138 | m_Name: Main Camera 139 | m_TagString: Untagged 140 | m_Icon: {fileID: 0} 141 | m_NavMeshLayer: 0 142 | m_StaticEditorFlags: 0 143 | m_IsActive: 1 144 | --- !u!81 &1252859650 145 | AudioListener: 146 | m_ObjectHideFlags: 0 147 | m_CorrespondingSourceObject: {fileID: 0} 148 | m_PrefabInstance: {fileID: 0} 149 | m_PrefabAsset: {fileID: 0} 150 | m_GameObject: {fileID: 1252859649} 151 | m_Enabled: 1 152 | --- !u!20 &1252859651 153 | Camera: 154 | m_ObjectHideFlags: 0 155 | m_CorrespondingSourceObject: {fileID: 0} 156 | m_PrefabInstance: {fileID: 0} 157 | m_PrefabAsset: {fileID: 0} 158 | m_GameObject: {fileID: 1252859649} 159 | m_Enabled: 1 160 | serializedVersion: 2 161 | m_ClearFlags: 1 162 | m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} 163 | m_projectionMatrixMode: 1 164 | m_GateFitMode: 2 165 | m_FOVAxisMode: 0 166 | m_SensorSize: {x: 36, y: 24} 167 | m_LensShift: {x: 0, y: 0} 168 | m_FocalLength: 50 169 | m_NormalizedViewPortRect: 170 | serializedVersion: 2 171 | x: 0 172 | y: 0 173 | width: 1 174 | height: 1 175 | near clip plane: 0.3 176 | far clip plane: 1000 177 | field of view: 60 178 | orthographic: 0 179 | orthographic size: 5 180 | m_Depth: 0 181 | m_CullingMask: 182 | serializedVersion: 2 183 | m_Bits: 4294967295 184 | m_RenderingPath: -1 185 | m_TargetTexture: {fileID: 0} 186 | m_TargetDisplay: 0 187 | m_TargetEye: 3 188 | m_HDR: 1 189 | m_AllowMSAA: 1 190 | m_AllowDynamicResolution: 0 191 | m_ForceIntoRT: 0 192 | m_OcclusionCulling: 1 193 | m_StereoConvergence: 10 194 | m_StereoSeparation: 0.022 195 | --- !u!4 &1252859652 196 | Transform: 197 | m_ObjectHideFlags: 0 198 | m_CorrespondingSourceObject: {fileID: 0} 199 | m_PrefabInstance: {fileID: 0} 200 | m_PrefabAsset: {fileID: 0} 201 | m_GameObject: {fileID: 1252859649} 202 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 203 | m_LocalPosition: {x: -1.6886765, y: -0.0653681, z: -0.39368343} 204 | m_LocalScale: {x: 1, y: 1, z: 1} 205 | m_Children: [] 206 | m_Father: {fileID: 0} 207 | m_RootOrder: 0 208 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 209 | --- !u!114 &1796290082 210 | MonoBehaviour: 211 | m_ObjectHideFlags: 0 212 | m_CorrespondingSourceObject: {fileID: 0} 213 | m_PrefabInstance: {fileID: 0} 214 | m_PrefabAsset: {fileID: 0} 215 | m_GameObject: {fileID: 0} 216 | m_Enabled: 1 217 | m_EditorHideFlags: 0 218 | m_Script: {fileID: 11500000, guid: b45a8f6e55846134ca49edb9fe1326b6, type: 3} 219 | m_Name: 220 | m_EditorClassIdentifier: 221 | overrideProperty: 1 222 | guid: a3d2a5f3-2a8b-4e91-9b7a-b01320a75479 223 | Name: Light 224 | abstractData: {fileID: 2048076127} 225 | --- !u!1 &1853762765 226 | GameObject: 227 | m_ObjectHideFlags: 0 228 | m_CorrespondingSourceObject: {fileID: 0} 229 | m_PrefabInstance: {fileID: 0} 230 | m_PrefabAsset: {fileID: 0} 231 | serializedVersion: 6 232 | m_Component: 233 | - component: {fileID: 1853762767} 234 | - component: {fileID: 1853762766} 235 | m_Layer: 0 236 | m_Name: FSM 237 | m_TagString: Untagged 238 | m_Icon: {fileID: 0} 239 | m_NavMeshLayer: 0 240 | m_StaticEditorFlags: 0 241 | m_IsActive: 1 242 | --- !u!114 &1853762766 243 | MonoBehaviour: 244 | m_ObjectHideFlags: 0 245 | m_CorrespondingSourceObject: {fileID: 0} 246 | m_PrefabInstance: {fileID: 0} 247 | m_PrefabAsset: {fileID: 0} 248 | m_GameObject: {fileID: 1853762765} 249 | m_Enabled: 1 250 | m_EditorHideFlags: 0 251 | m_Script: {fileID: 11500000, guid: fbb655a0a7690ea459502cc5df2dbc8f, type: 3} 252 | m_Name: 253 | m_EditorClassIdentifier: 254 | BlackboardProperties: 255 | - {fileID: 1868841146} 256 | - {fileID: 1796290082} 257 | graph: {fileID: 11400000, guid: 1e77de879827f5e4db3fa372b1cae8ff, type: 2} 258 | --- !u!4 &1853762767 259 | Transform: 260 | m_ObjectHideFlags: 0 261 | m_CorrespondingSourceObject: {fileID: 0} 262 | m_PrefabInstance: {fileID: 0} 263 | m_PrefabAsset: {fileID: 0} 264 | m_GameObject: {fileID: 1853762765} 265 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 266 | m_LocalPosition: {x: 0, y: 0, z: 0} 267 | m_LocalScale: {x: 1, y: 1, z: 1} 268 | m_Children: [] 269 | m_Father: {fileID: 0} 270 | m_RootOrder: 2 271 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 272 | --- !u!114 &1868841146 273 | MonoBehaviour: 274 | m_ObjectHideFlags: 0 275 | m_CorrespondingSourceObject: {fileID: 0} 276 | m_PrefabInstance: {fileID: 0} 277 | m_PrefabAsset: {fileID: 0} 278 | m_GameObject: {fileID: 0} 279 | m_Enabled: 1 280 | m_EditorHideFlags: 0 281 | m_Script: {fileID: 11500000, guid: bd71a48f486cef54b885527933b16c89, type: 3} 282 | m_Name: 283 | m_EditorClassIdentifier: 284 | overrideProperty: 0 285 | guid: 63ffe771-c297-4ee0-bac5-00b01242be13 286 | Name: Delay 287 | abstractData: 0.5 288 | --- !u!1 &2048076127 289 | GameObject: 290 | m_ObjectHideFlags: 0 291 | m_CorrespondingSourceObject: {fileID: 0} 292 | m_PrefabInstance: {fileID: 0} 293 | m_PrefabAsset: {fileID: 0} 294 | serializedVersion: 6 295 | m_Component: 296 | - component: {fileID: 2048076129} 297 | - component: {fileID: 2048076128} 298 | m_Layer: 0 299 | m_Name: Directional Light 300 | m_TagString: Untagged 301 | m_Icon: {fileID: 0} 302 | m_NavMeshLayer: 0 303 | m_StaticEditorFlags: 0 304 | m_IsActive: 1 305 | --- !u!108 &2048076128 306 | Light: 307 | m_ObjectHideFlags: 0 308 | m_CorrespondingSourceObject: {fileID: 0} 309 | m_PrefabInstance: {fileID: 0} 310 | m_PrefabAsset: {fileID: 0} 311 | m_GameObject: {fileID: 2048076127} 312 | m_Enabled: 1 313 | serializedVersion: 10 314 | m_Type: 1 315 | m_Shape: 0 316 | m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1} 317 | m_Intensity: 1 318 | m_Range: 10 319 | m_SpotAngle: 30 320 | m_InnerSpotAngle: 21.80208 321 | m_CookieSize: 10 322 | m_Shadows: 323 | m_Type: 2 324 | m_Resolution: -1 325 | m_CustomResolution: -1 326 | m_Strength: 1 327 | m_Bias: 0.05 328 | m_NormalBias: 0.4 329 | m_NearPlane: 0.2 330 | m_CullingMatrixOverride: 331 | e00: 1 332 | e01: 0 333 | e02: 0 334 | e03: 0 335 | e10: 0 336 | e11: 1 337 | e12: 0 338 | e13: 0 339 | e20: 0 340 | e21: 0 341 | e22: 1 342 | e23: 0 343 | e30: 0 344 | e31: 0 345 | e32: 0 346 | e33: 1 347 | m_UseCullingMatrixOverride: 0 348 | m_Cookie: {fileID: 0} 349 | m_DrawHalo: 0 350 | m_Flare: {fileID: 0} 351 | m_RenderMode: 0 352 | m_CullingMask: 353 | serializedVersion: 2 354 | m_Bits: 4294967295 355 | m_RenderingLayerMask: 1 356 | m_Lightmapping: 4 357 | m_LightShadowCasterMode: 0 358 | m_AreaSize: {x: 1, y: 1} 359 | m_BounceIntensity: 1 360 | m_ColorTemperature: 6570 361 | m_UseColorTemperature: 0 362 | m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0} 363 | m_UseBoundingSphereOverride: 0 364 | m_UseViewFrustumForShadowCasterCull: 1 365 | m_ShadowRadius: 0 366 | m_ShadowAngle: 0 367 | --- !u!4 &2048076129 368 | Transform: 369 | m_ObjectHideFlags: 0 370 | m_CorrespondingSourceObject: {fileID: 0} 371 | m_PrefabInstance: {fileID: 0} 372 | m_PrefabAsset: {fileID: 0} 373 | m_GameObject: {fileID: 2048076127} 374 | m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261} 375 | m_LocalPosition: {x: 0, y: 3, z: 0} 376 | m_LocalScale: {x: 1, y: 1, z: 1} 377 | m_Children: [] 378 | m_Father: {fileID: 0} 379 | m_RootOrder: 1 380 | m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} 381 | -------------------------------------------------------------------------------- /Samples~/FSM/Runtime/Scenes/FSM - VisualGraph.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5107616e558485d4189b5c91a74892d9 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Samples~/FSM/Runtime/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ed0a6b1d73c1d9241a4a731060786a2a 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/FSM/Runtime/Scripts/Graph.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2fe357026de9e6d4ebdf5c9e44ece877 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/FSM/Runtime/Scripts/Graph/FSM.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using VisualGraphRuntime; 5 | 6 | public class FSM : VisualGraphMonoBehaviour 7 | { 8 | void Update() 9 | { 10 | if (Graph != null) 11 | { 12 | Graph.Update(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Samples~/FSM/Runtime/Scripts/Graph/FSM.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fbb655a0a7690ea459502cc5df2dbc8f 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Samples~/FSM/Runtime/Scripts/Graph/FSMGraph.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using UnityEngine; 6 | using VisualGraphRuntime; 7 | 8 | [CreateAssetMenu] 9 | [DefaultNodeType(typeof(BaseState))] 10 | public class FSMGraph : VisualGraph 11 | { 12 | public BaseState currentState; 13 | 14 | public override void Init() 15 | { 16 | Debug.Assert(StartingNode.Outputs.First().Connections.Count != 0, "Starting node needs a connection"); 17 | currentState = (BaseState)StartingNode.Outputs.First().Connections[0].Node; 18 | 19 | foreach(var state in Nodes) 20 | { 21 | BaseState fsmState = state as BaseState; 22 | if (fsmState != null) 23 | { 24 | fsmState.fsm = this; 25 | } 26 | } 27 | 28 | currentState.OnEnter(); 29 | } 30 | 31 | public void Update() 32 | { 33 | if (currentState != null) 34 | { 35 | currentState.OnUpdate(); 36 | } 37 | } 38 | 39 | public void GoToState(FSMPort.State state) 40 | { 41 | if (currentState != null) 42 | { 43 | foreach (var port in currentState.Outputs) 44 | { 45 | FSMPort fsmPort = (FSMPort)port; 46 | if (fsmPort.state == state) 47 | { 48 | // We assume only one connection based off settings 49 | if (port.Connections.Count >= 0) 50 | { 51 | currentState.OnExit(); 52 | currentState = (BaseState)port.Connections[0].Node; 53 | currentState.OnEnter(); 54 | } 55 | } 56 | } 57 | } 58 | 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Samples~/FSM/Runtime/Scripts/Graph/FSMGraph.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0cac613c2c69d574a8f136683f8f0de0 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Samples~/FSM/Runtime/Scripts/Nodes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 52b31af1d80b5fc4988cdf816701b234 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/FSM/Runtime/Scripts/Nodes/BaseState.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using VisualGraphRuntime; 5 | 6 | [DefaultPortType(typeof(FSMPort))] 7 | 8 | public abstract class BaseState : VisualGraphNode 9 | { 10 | [HideInInspector] public FSMGraph fsm; 11 | 12 | public virtual void OnEnter() 13 | { 14 | editor_ActiveNode = true; 15 | } 16 | 17 | public virtual void OnUpdate() 18 | { 19 | } 20 | 21 | public virtual void OnExit() 22 | { 23 | editor_ActiveNode = false; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Samples~/FSM/Runtime/Scripts/Nodes/BaseState.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7014ade7db96fa34fb88206fb9c8da41 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Samples~/FSM/Runtime/Scripts/Nodes/LightOffState.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using VisualGraphRuntime; 5 | 6 | [NodeName(_name: "Light Off")] 7 | [CustomNodeStyle("LightOffStyle")] 8 | public class LightOffState : BaseState 9 | { 10 | float currentDelay = 0.0f; 11 | Light light; 12 | 13 | public override void OnEnter() 14 | { 15 | base.OnEnter(); 16 | 17 | GameObject light_go = null; 18 | fsm.GetPropertyValue("Light", ref light_go); 19 | if (light_go != null) 20 | { 21 | light = light_go.GetComponent(); 22 | if (light != null) 23 | { 24 | light.enabled = false; 25 | } 26 | } 27 | fsm.GetPropertyValue("Delay", ref currentDelay); 28 | } 29 | 30 | public override void OnUpdate() 31 | { 32 | base.OnUpdate(); 33 | 34 | currentDelay -= Time.deltaTime; 35 | if (currentDelay <= 0.0f) 36 | { 37 | fsm.GoToState(FSMPort.State.On); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Samples~/FSM/Runtime/Scripts/Nodes/LightOffState.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0de229ea86724a8478b9b558e2c9399f 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Samples~/FSM/Runtime/Scripts/Nodes/LightOnState.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using VisualGraphRuntime; 5 | 6 | [NodeName(_name: "Light On")] 7 | [CustomNodeStyle("LightOnStyle")] 8 | public class LightOnState : BaseState 9 | { 10 | float currentDelay = 0.0f; 11 | Light light; 12 | 13 | public override void OnEnter() 14 | { 15 | base.OnEnter(); 16 | 17 | GameObject light_go = null; 18 | fsm.GetPropertyValue("Light", ref light_go); 19 | if (light_go != null) 20 | { 21 | light = light_go.GetComponent(); 22 | if (light != null) 23 | { 24 | light.enabled = true; 25 | } 26 | } 27 | fsm.GetPropertyValue("Delay", ref currentDelay); 28 | } 29 | 30 | public override void OnUpdate() 31 | { 32 | base.OnUpdate(); 33 | 34 | currentDelay -= Time.deltaTime; 35 | if (currentDelay <= 0.0f) 36 | { 37 | fsm.GoToState(FSMPort.State.Off); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Samples~/FSM/Runtime/Scripts/Nodes/LightOnState.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a8b611e4035f82c489ba8981c3e229a7 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Samples~/FSM/Runtime/Scripts/Ports.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 214af21e3625cec499581012a44a0149 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/FSM/Runtime/Scripts/Ports/FSMPort.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | using VisualGraphRuntime; 6 | 7 | [Serializable] 8 | public class FSMPort : VisualGraphPort 9 | { 10 | public enum State 11 | { 12 | None, 13 | On, 14 | Off 15 | }; 16 | 17 | public State state = State.None; 18 | } 19 | -------------------------------------------------------------------------------- /Samples~/FSM/Runtime/Scripts/Ports/FSMPort.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c5c4c32229a4d9d4eab8c5eacb9dbdf1 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "busstopstudios.unity.visual-graph", 3 | "version": "0.0.4", 4 | "displayName": "Visual Graph", 5 | "description": "Extension to Unity's GraphView. You can use this to extend Unitys Experimental GraphView to create Graphs that have an entry point to custom nodes.", 6 | "unity": "2020.2", 7 | "unityRelease": "1f1", 8 | "dependencies": { 9 | "com.unity.modules.ui": "1.0.0" 10 | }, 11 | "samples": [ 12 | { 13 | "displayName": "Example", 14 | "description": "Basic example of a graph", 15 | "path": "Samples~/Example" 16 | }, 17 | { 18 | "displayName": "FSM", 19 | "description": "FSM Example that will turn a ligt on and off with blackboard properties", 20 | "path": "Samples~/FSM" 21 | } 22 | ], 23 | "author": "Bus Stop Studios", 24 | "license": "MIT", 25 | "repository": { 26 | "url": "https://github.com/BusStopStudios/unity.visual-graph.git", 27 | "type": "git" 28 | }, 29 | "type": "tool" 30 | } 31 | -------------------------------------------------------------------------------- /package.json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1d9e6bf25aa587e4388f27091e8cb691 3 | PackageManifestImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | --------------------------------------------------------------------------------