public void Init(List <BehaviourGraphModel> models, BaseBehaviourGraphEditor editor) { foreach (var model in models) { this.DeleteElements(this.graphElements.ToList().Where(element => !(element is BehaviourGraphInspector))); if (model == null) { continue; } model.Entries.Sort(); for (int index = 0; index < model.Entries.Count; index++) { var node = model.Entries[index].CreateNode(this, model.Settings); if (node is IBehaviourGraphNode behaviourGraphNode) { behaviourGraphNode.Model = model; node.RefreshExpandedState(); node.RefreshPorts(); AddElement(node); } } InitVariables(model); FrameAll(); } }
public BehaviourGraphView(BaseBehaviourGraphEditor editor) { SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale); this.AddManipulator(new ContentDragger()); this.AddManipulator(new SelectionDragger()); this.AddManipulator(new ClickSelector()); this.AddManipulator(new RectangleSelector()); this.contentViewContainer.RegisterCallback <GeometryChangedEvent>((evt) => { if (evt.oldRect.width == 0 && evt.oldRect.height == 0) { FrameAll(); } }); SetupSearchWindow(editor); SetupInspector(); this.graphViewChanged += SendPortChangeEvents; this.graphViewChanged += DisposeDeletedElements; this.graphViewChanged += UpdateModel; this.styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>(USS)); this.RegisterCallback <DragUpdatedEvent>((evt) => { var z = DragAndDrop.GetGenericData("DragSelection"); if (z is List <ISelectable> ) { DragAndDrop.visualMode = DragAndDropVisualMode.Generic; } }); this.RegisterCallback <DragPerformEvent>(evt => { if (DragAndDrop.GetGenericData("DragSelection") is List <ISelectable> selectables) { Vector2 offset = new Vector2(0, 0); var pos = evt.mousePosition; foreach (var selectable in selectables) { if (selectable is BlackboardField blackboardField && blackboardField.userData is VariableInfo variableInfo) { var entry = CreateVariable(variableInfo.fieldOffsetInfo, contentViewContainer.WorldToLocal(contentViewContainer.parent.ChangeCoordinatesTo(contentViewContainer.parent, evt.mousePosition)) + offset); variableInfo.model.Entries.Add(entry); var node = entry.CreateNode(this, variableInfo.model.Settings); if (node is IBehaviourGraphNode behaviourGraphNode) { behaviourGraphNode.Model = variableInfo.model; } this.AddElement(node); offset.y += blackboardField.worldBound.height + 2; } } } }); }
private void SetupSearchWindow(BaseBehaviourGraphEditor editor) { searchWindow = ScriptableObject.CreateInstance <BehaviourGraphSearchWindow>(); if (editor.Models?.Count > 0) { searchWindow.models.AddRange(editor.Models); nodeCreationRequest = (context) => { searchWindow.graphView = this; searchWindow.editor = editor; SearchWindow.Open(new SearchWindowContext(context.screenMousePosition), searchWindow); }; } }