public override void OnInspectorGUI() { if (GUILayout.Button("Open Editor")) { AIGraph.OpenDialogueGraphWindow(target as ActorAI); } }
public void SetSelections(FilterDelegate <BehaviourNode> select) { mSelection.Clear(); for (int i = 0; i < AIGraph.ElementCount; i++) { var node = AIGraph.GetElement <BehaviourNode>(i); if (node != null) { node.selected = select(node); if (node.selected) { mSelection.Add(node); } } } UpdateSelectionAssets(); if (mSelectionAssets.Count > 0) { Selection.objects = mSelectionAssets.ToArray(); } else if (mAssetBinder != null) { mAssetBinder.SelectTarget(); } }
public void DeleteContext(BehaviourNode node) { if (node == null) { return; } var t = node.GetContext(); if (t != null) { mAssetBinder.targetTree.EditorDeleteNode(t); if (t.Asset is BTNodeAsset) { AddDelayTask(ACT_UPDATE_WIRES, mWires.UpdateWires); } if (node != RootNode && node.GetNode() == null) { AIGraph.RemoveElement(node); } else { node.Resize(); } } }
public Route FindRoute(AIGraph searchGraph, AIGraphNode start, AIGraphNode end, int minAnnotation) { m_minAnnotation = minAnnotation; Route route = new Route(); m_targetPos = end.NodePosition; m_openHeap.Reset(); int maxIterations = 10000; // Pretty lazy, but C# defaults a bool array to false m_closedList = new bool[searchGraph.Nodes.Count]; m_parentList = new int[searchGraph.Nodes.Count]; // No such excuse for ints... m_openHeap.Insert(start, (end.NodePosition - start.NodePosition).magnitude); int iterationCount = 0; while (m_openHeap.HasItems() && m_openHeap.GetTop().NodePosition != end.NodePosition && iterationCount < maxIterations) { UpdateHeap(); iterationCount++; } if (!m_openHeap.HasItems()) { Debug.Log("No route found"); return(route); } if (iterationCount == maxIterations) { Debug.LogWarning("No route found: Max iterations"); } else { // Unwind the route. int currentID = m_parentList[m_openHeap.GetTop().ID]; route.m_routePoints.Add(end); while (currentID != 0) { AIGraphNode node = searchGraph.Nodes[currentID]; route.m_routePoints.Add(node); currentID = m_parentList[currentID]; } route = TrimRoute(route); route.m_routePoints.Reverse(); } return(route); }
public static bool OpenEditor(int instanceId, int line) { ActorAI obj = EditorUtility.InstanceIDToObject(instanceId) as ActorAI; if (obj != null) { AIGraph.OpenDialogueGraphWindow(obj); return(true); } return(false); }
public void PasteSelection() { if (mCopyDo == null) { return; } var pos = mCopyDo.GetSelectionPositin(); mCopyDo.deltaPosition = AIGraph.CalculateLocalPosition(GlobalMousePosition) - pos; DoEdit(mCopyDo); }
public BehaviourNode GetRaycastNode(Vector2 globalPos) { for (int i = AIGraph.ElementCount - 1; i >= 0; i--) { var node = AIGraph.GetElement <BehaviourNode>(i); if (node != null && node.Visible && node.GlobalRect.Contains(globalPos)) { return(node); } } return(null); }
protected override void OnResized() { base.OnResized(); RaycastNode = GetRaycastNode(GlobalMousePosition); for (int i = 0; i < AIGraph.ElementCount; i++) { var bt = AIGraph.GetElement <BehaviourNode>(i); if (bt != null && !bt.cliped && bt != RaycastNode) { bt.DrawComment(false); } } }
public void EditNodes(System.Action <BehaviourNode> callback) { if (callback == null) { return; } for (int i = 0; i < AIGraph.ElementCount; i++) { var node = AIGraph.GetElement <BehaviourNode>(i); if (node != null) { callback(node); } } }
protected override Vector2 GetFocusDeltaPosition() { if (AIGraph.ElementCount == 0) { return(base.GetFocusDeltaPosition()); } var p = new Vector2(); for (int i = 0; i < AIGraph.ElementCount; i++) { p += AIGraph.ElementAt(i).GlobalRect.center; } p /= (float)AIGraph.ElementCount; return(ScaledCanvas.GlobalCentroid - p);// GraphCanvas.GlobalCentroid; }
void UpdateTreeGraph() { mCopyDo = null; AddHistory(mAssetBinder.source); mBindStack.Clear(); mUndoStack.Clear(); AIGraph.ClearElements(); mContextNode = null; RaycastNode = null; RequestChild(null); if (Application.isPlaying) { var bind = mAssetBinder.RuntimeBinder; while (bind != null) { mBindStack.Insert(0, bind); bind = bind.Parent; } } AIGraph.AddElement(RootNode); if (mAssetBinder.targetTree != null) { List <BTNode> datas = new List <BTNode>(); mAssetBinder.targetTree.GetAllNodes(datas); foreach (var t in datas) { if (t.Asset == null) { mAssetBinder.targetTree.EditorDeleteNode(t); continue; } if (t.Asset is BTNodeAsset) { var node = new BTNodeGUI(this, t); AIGraph.AddElement(node); } } } RootNode.Resize(); mWires.UpdateWires(); var runner = TargetRunner; BlackboardMonitor.Visible = runner != null && Application.isPlaying; BlackboardMonitor.Blackboard = runner == null ? null : runner.Blackboard; }
bool InteractCraphClick(EMouseButton btn, Vector2 mousePos) { if (btn == EMouseButton.left) { if (IsRequestParentOrChild && mAssetBinder.targetTree != null) { mContextNode = RaycastNode; mContextPos = AIGraph.CalculateLocalPosition(mousePos); sNodeMenu.Display(this, new Rect(Event.current.mousePosition, Vector2.zero)); } else { ClearSelection(); } return(true); } else if (btn == EMouseButton.right) { if (RaycastNode != null && !mSelection.Contains(RaycastNode)) { ClearSelection(); } mContextNode = RaycastNode; mContextPos = AIGraph.CalculateLocalPosition(mousePos); if (Application.isPlaying) { DisplayDebugMenu(new Rect(Event.current.mousePosition, Vector2.zero)); //EditorUtility.DisplayCustomMenu(new Rect(mousePos, Vector2.zero), mRuntimeMenu, -1, OnRuntimeMenuSelected, null); } else if (IsRequestParentOrChild) { RequestChild(null); } else { DisplayEditMenu(new Rect(Event.current.mousePosition, Vector2.zero)); } return(true); } return(false); }
private bool InteractGraphKeyDown(KeyCode key) { if (key == KeyCode.Delete) { DeleteSelections(); return(true); } else if (key == KeyCode.C && Event.current.control) { CopySelection(); return(true); } else if (!Application.isPlaying && !Event.current.alt && !Event.current.control && !Event.current.shift && mAssetBinder != null && mAssetBinder.targetTree != null) { mContextNode = RaycastNode; mContextPos = AIGraph.CalculateLocalPosition(GlobalMousePosition); sHotkeyMenu.Display(this, new Rect(Event.current.mousePosition, Vector2.zero), key); } return(false); }
//private SerializedObject _serializedObject; //[MenuItem("Graph/AI Graph")] public static void OpenDialogueGraphWindow(ActorAI AI) { AIGraph window = GetWindow <AIGraph>(); window.titleContent = new GUIContent("AI Graph"); window.destAI = AI; window._serializer = AIGraphSerializer.GetInstance(window._graphView); window._serializer.LoadGraph(AI); //window._serializedObject = new SerializedObject(AI); /*foreach(ActorStateNode n in window._graphView.nodes.ToList()) * { * var a = n.Q<Port>(); * var b = a.contentContainer.Q<ObjectField>(); * SerializedObject c; * if(b != null) c = new SerializedObject(b.value); * else { Debug.Log(a.contentContainer.Q<VisualElement>()); } * a.contentContainer.Add(new Foldout()); * //a.contentContainer.Add(new IMGUIContainer()); * }*/ }
void OnEnable() { m_hTarget = this.target as AIGraph; if (m_hTarget.IsEmpty) m_hTarget.Initialize(); }
// Create all the cells of the grid, populate initial blocker counts and link all nodes. public void RebuildGraphs() { m_defaultGraph = new AIGraph(); m_defaultNodes = new AIGraphNode[m_numCellsX][]; m_blockers = new ClearanceBlockers[m_numCellsX][]; // Create the cells for (int x = 0; x < m_numCellsX; x++) { m_defaultNodes[x] = new AIGraphNode[m_numCellsY]; m_blockers[x] = new ClearanceBlockers[m_numCellsY]; for (int y = 0; y < m_numCellsY; y++) { m_defaultNodes[x][y] = m_defaultGraph.AddNode(m_gridStart + (new Vector2(x, y) * m_cellSize)); m_blockers[x][y] = new ClearanceBlockers(); // Iterate the rows down and left, incrementing blocker counts when a blocked cell is encountered. for (int clearance = 1; clearance < MaxClearance; clearance++) { for (int xIndex = 0; xIndex < clearance; xIndex++) { // Check bounds, then blockers if ((x + xIndex) >= m_numCellsX || (y + clearance) >= m_numCellsY || (m_cells[x + xIndex, y + clearance].m_contentsMask & (1 << (int)GridCellContentsType.Wall)) != 0) { m_blockers[x][y].blockerCount[clearance]++; } } for (int yIndex = 0; yIndex < (clearance + 1); yIndex++) { // Check bounds, then blockers if ((x + clearance) >= m_numCellsX || (y + yIndex) >= m_numCellsY || (m_cells[x + clearance, y + yIndex].m_contentsMask & (1 << (int)GridCellContentsType.Wall)) != 0) { m_blockers[x][y].blockerCount[clearance]++; } } } // Re-calculate the annotation for the current cell now that blocker-counts are set. UpdateCellAnnotation(x, y); // If the cell itself is blocked, handle that if ((m_cells[x, y].m_contentsMask & (1 << (int)GridCellContentsType.Wall)) != 0) { m_defaultNodes[x][y].Annotation = 0; m_blockers[x][y].blockerCount[0]++; } } } // Link all the nodes for (int x = 0; x < m_numCellsX; x++) { for (int y = 0; y < m_numCellsY; y++) { if (x > 0) { m_defaultNodes[x][y].NodeLinks.Add(m_defaultNodes[x - 1][y]); } if (x < m_numCellsX - 1) { m_defaultNodes[x][y].NodeLinks.Add(m_defaultNodes[x + 1][y]); } if (y > 0) { m_defaultNodes[x][y].NodeLinks.Add(m_defaultNodes[x][y - 1]); } if (y < m_numCellsY - 1) { m_defaultNodes[x][y].NodeLinks.Add(m_defaultNodes[x][y + 1]); } if (x > 0 && y > 0) { m_defaultNodes[x][y].NodeLinks.Add(m_defaultNodes[x - 1][y - 1]); } if (x < m_numCellsX - 1 && y > 0) { m_defaultNodes[x][y].NodeLinks.Add(m_defaultNodes[x + 1][y - 1]); } if (x > 0 && y < m_numCellsY - 1) { m_defaultNodes[x][y].NodeLinks.Add(m_defaultNodes[x - 1][y + 1]); } if (y < m_numCellsY - 1 && x < m_numCellsX - 1) { m_defaultNodes[x][y].NodeLinks.Add(m_defaultNodes[x + 1][y + 1]); } } } }