public BehaviourNodeGUI AddChild(PaintElement parent, BehaviourMeta meta, Vector2 localPos) { if (parent != null && parent.Parent != TreeCanvas) { return(null); } BehaviourNodeGUI node = new BehaviourNodeGUI(this); node.Self = new BehaviourNodeGUI.Decorator(GenerateId, meta); node.Self.UpdatePropertiesInfo(); Rect r = new Rect(); r.size = node.CalculateLocalSize(); r.position = localPos - Vector2.right * r.size.x * 0.5f; node.LocalRect = r; TreeCanvas.AddElement(node); TreeGraph.AddNode(node); if (parent != null) { TreeGraph.AddPath(0, parent, node); } RebuildExecutionOrder(); return(node); }
public void InitWith(BehaviourTreeRunner runner) { if (EditorApplication.isPlaying) { BindBehaviourTreeEvent(false); } ContextMenu.Hide(); Runner = runner; BehaviourAsset = Runner == null ? (Selection.activeObject as BehaviourTreeAsset) : Runner.SourceAsset; TreeCanvas.ClearElements(); CommentCanvas.ClearElements(); TreeGraph.Clear(); mRootGUI = new BehaviourRootGUI(this); mRootGUI.UpdateLocalData(); TreeCanvas.AddElement(mRootGUI); TreeGraph.AddNode(mRootGUI); if (BehaviourAsset != null) { ImportTreeData(); } ResetIdCounter(); RebuildExecutionOrder(); UpdateStateInfo(); if (EditorApplication.isPlaying) { BindBehaviourTreeEvent(true); } }
void BindBehaviourTreeEvent(bool bind) { if (Runner == null) { return; } if (bind) { Runner.OnBehaviourTreeBegin += OnBehaviourTreeBegin; Runner.OnBehaviourTreeFrame += OnBehaviourTreeFrame; for (int i = 0; i < TreeCanvas.ElementCount; i++) { BehaviourNodeGUI node = TreeCanvas.GetElement <BehaviourNodeGUI>(i); if (node == null) { continue; } node.RuntimeNode = Runner.FindRuntimeNode(node.Self.BTId); } } else { Runner.OnBehaviourTreeBegin -= OnBehaviourTreeBegin; Runner.OnBehaviourTreeFrame -= OnBehaviourTreeFrame; for (int i = 0; i < TreeCanvas.ElementCount; i++) { BehaviourNodeGUI node = TreeCanvas.GetElement <BehaviourNodeGUI>(i); if (node == null) { continue; } node.RuntimeNode = null; } } }
public TreeForm(ProjectManager pm) { InitializeComponent(); treeCanvas1 = new TreeCanvas(pm); elementHost1.Child = treeCanvas1; }
public void Play(TreeCanvas canvas) { if (_controller == null) { _prevPosition = hero.transform.position; FireFxRoot r = new FireFxRoot(); TreeWrap.Init(); TreeEditorFactory.Start(); new TreeToRuntimeComp(canvas, TreeFactory.CreateInstance, r).Transfer(); _controller = new EtFireFxContoller(hero, r) { targetPos = hero.transform.position }; FireFxInfo[] infos = new FireFxInfo[targets.Length]; for (int i = 0; i < targets.Length; i++) { FireFxInfo info = new FireFxInfo(new FireEnemy(targets[i])); if (i == 0) { _controller.mainTargetInfo = info; _controller.targetPos = info.position; _controller.endHostPos = info.position; } infos[i] = info; } _controller.targetInfos = infos; _controller.completeEvent.AddListener(OnComplete); GameTicker.tickerManager.Add(_controller); _controller.Start(); } else { Debug.Log("the current firefx control is running"); } }
public void EditNodes(EditDelegate <BehaviourNodeGUI> editor) { for (int i = 0; i < TreeCanvas.ElementCount; i++) { BehaviourNodeGUI node = TreeCanvas.GetElement <BehaviourNodeGUI>(i); if (node != null) { editor(node); } } }
public void SelectNodes(FilterDelegate <BehaviourNodeGUI> selector) { for (int i = 0; i < TreeCanvas.ElementCount; i++) { BehaviourNodeGUI node = TreeCanvas.GetElement <BehaviourNodeGUI>(i); if (node != null) { node.IsSelected = selector(node); } } }
void ImportTreeData() { for (int i = 0; i < BehaviourAsset.m_Datas.Length; i++) { BehaviourNodeGUI node = NewNode(BehaviourAsset.m_Datas[i]); if (node != null) { TreeGraph.AddNode(node); TreeCanvas.AddElement(node); } } int id = 0; FilterDelegate <PaintElement> filter = (x) => { BehaviourNodeGUI bx = x as BehaviourNodeGUI; return(bx != null && bx.Self.BTId == id); }; for (int i = 0; i < BehaviourAsset.m_Datas.Length; i++) { BTData data = BehaviourAsset.m_Datas[i]; id = data.m_Id; BehaviourNodeGUI gnode = TreeGraph.FindNode(filter) as BehaviourNodeGUI; if (gnode == null) { continue; } int len = data.m_Children == null ? 0 : data.m_Children.Length; for (int j = 0; j < len; j++) { id = data.m_Children[j]; BehaviourNodeGUI gchild = TreeGraph.FindNode(filter) as BehaviourNodeGUI; if (gchild != null) { TreeGraph.AddPath(0, gnode, gchild); } } } id = BehaviourAsset.m_RootNodeId; BehaviourNodeGUI root = TreeGraph.FindNode(filter) as BehaviourNodeGUI; if (root != null) { TreeGraph.AddPath(0, mRootGUI, root); } for (int i = 0; i < BehaviourAsset.m_Comments.Length; i++) { BehaviourCommentGUI comment = new BehaviourCommentGUI(this); comment.Comment = BehaviourAsset.m_Comments[i].m_Comment; comment.LocalRect = BehaviourAsset.m_Comments[i].m_Rect; CommentCanvas.AddElement(comment); } }
private void OnBehaviourTreeFrame(BehaviourTreeRunner btree) { if (btree == Runner) { for (int i = 0; i < TreeCanvas.ElementCount; i++) { BehaviourNodeGUI node = TreeCanvas.GetElement <BehaviourNodeGUI>(i); if (node != null) { node.SyncRuntimeState(btree); } } } }
private static FireFxRoot GetFireSetting(Object t) { TreeWrap.Init(); string path = AssetDatabase.GetAssetPath(t); XDocument doc = XDocument.Load(path); XElement root = doc.Root; string canvasType = StringDataTools.XAttribute(root, "type"); TreeCanvas canvas = TreeEditorFactory.GetCanvas(canvasType); canvas.Read(root); FireFxRoot r = new FireFxRoot(); new TreeToRuntimeComp(canvas, TreeFactory.CreateInstance, r).Transfer(); return(r); }
void ExportTreeData() { List <BTData> nodes = new List <BTData>(); List <PaintElement> children = new List <PaintElement>(); int rootId = 0; for (int i = 0; i < TreeCanvas.ElementCount; i++) { BehaviourNodeGUI bnode = TreeCanvas.GetElement <BehaviourNodeGUI>(i); if (bnode == null) { continue; } if (TreeGraph.GetParent(0, bnode) == mRootGUI) { rootId = bnode.Self.BTId; } BTData data = bnode.ExportNodeData(nodes); children.Clear(); TreeGraph.GetAllChildren(0, bnode, children); GlobalUtil.Sort(children, (x, y) => x.LocalRect.center.x <= y.LocalRect.center.x ? -1 : 1); data.m_Children = new int[children.Count]; for (int j = 0; j < children.Count; j++) { BehaviourNodeGUI child = children[j] as BehaviourNodeGUI; data.m_Children[j] = child == null ? 0 : child.Self.BTId; } } BehaviourAsset.m_RootNodeId = rootId; GlobalUtil.Sort(nodes, (x, y) => x.m_Id - y.m_Id); BehaviourAsset.m_Datas = nodes.ToArray(); BehaviourAsset.m_Sorted = true; BehaviourTreeAsset.Comment[] comments = new BehaviourTreeAsset.Comment[CommentCanvas.ElementCount]; for (int i = 0; i < comments.Length; i++) { comments[i] = new BehaviourTreeAsset.Comment(); BehaviourCommentGUI com = CommentCanvas.GetElement <BehaviourCommentGUI>(i); if (com != null) { comments[i].m_Rect = com.LocalRect; comments[i].m_Comment = com.Comment ?? ""; } } BehaviourAsset.m_Comments = comments; EditorUtility.SetDirty(BehaviourAsset); }
private void TreeContainer_MouseMove(object sender, MouseEventArgs e) { if (!leftMouseDragged) { return; } var position = e.GetPosition(this); var transform = TreeCanvas.RenderTransform as MatrixTransform; var matrix = transform.Matrix; matrix.Translate(position.X - lastMousePos.X, position.Y - lastMousePos.Y); transform.Matrix = matrix; lastMousePos = position; TreeCanvas.UpdateLayout(); }
public static FireFxRoot GetFireSetting(string path) { if (File.Exists(path)) { TreeEditorFactory.Start(); XDocument doc = XDocument.Load(path); XElement root = doc.Root; string canvasType = StringDataTools.XAttribute(root, "type"); TreeCanvas canvas = TreeEditorFactory.GetCanvas(canvasType); canvas.Read(root); FireFxRoot r = new FireFxRoot(); new TreeToRuntimeComp(canvas, TreeFactory.CreateInstance, r).Transfer(); return(r); } GlobalLogger.LogError(string.Format("{0} is not a valid path", path)); return(null); }
private void TreeContainer_MouseWheel(object sender, MouseWheelEventArgs e) { var position = e.GetPosition(TreeCanvas); var transform = TreeCanvas.RenderTransform as MatrixTransform; var matrix = transform.Matrix; var scale = e.Delta >= 0 ? scaleFactor : (1.0 / scaleFactor); var newScaleFactor = matrix.M11 * scale; if (!(newScaleFactor < MaxScale && newScaleFactor > MinScale)) { return; } matrix.ScaleAtPrepend(scale, scale, position.X, position.Y); transform.Matrix = matrix; TreeCanvas.UpdateLayout(); }
bool OnGraphKeyUp(KeyCode key) { if (IsPlaying) { return(false); } if (key == KeyCode.Delete) { List <BehaviourNodeGUI> nodes = new List <BehaviourNodeGUI>(); EditNodes((x) => { if (x.IsSelected) { nodes.Add(x); } }); for (int i = 0; i < nodes.Count; i++) { TreeCanvas.RemoveElement(nodes[i]); TreeGraph.RemoveNode(nodes[i]); } return(true); } if (key == KeyCode.C) { float w = Mathf.Abs(SelectionRect.GlobalRect.width); float dx = SelectionRect.GlobalRect.width < 0 ? -w : 0; float h = Mathf.Abs(SelectionRect.GlobalRect.height); float dy = SelectionRect.GlobalRect.height < 0 ? -h : 0; if (w > 40 && h > 30) { Rect rect = new Rect(SelectionRect.GlobalRect.xMin + dx, SelectionRect.GlobalRect.yMin + dy, w, h); BehaviourCommentGUI comment = new BehaviourCommentGUI(this); comment.LocalRect = CommentCanvas.CalculateLocalRect(rect); CommentCanvas.AddElement(comment); SelectNodes((x) => false); } } return(false); }
public void Grow(TreeCanvas treeCanvas) { this.Grew = true; // Use given canvas for this tree. this.canvas = treeCanvas; }