public void Init() { NodeData.Proto = BTEditor.Instance.GetComponent <BTNodeInfoComponent>().GetNodeMeta(NodeData.Name); string[] arr = NodeData.Proto.style.Split('/'); string style = arr.Length > 0? arr[0] : ""; if (style == "") { switch (NodeData.Classify) { case "装饰节点": style = "green"; break; case "复合节点": style = "blue"; break; case "条件节点": style = "orange"; break; } switch (NodeData.Name) { case "Sequence": style = "blue"; break; case "Selector": style = "green"; break; default: style = "default"; break; } } mBoxTex = BTDesignerUtility.GetTexture(style); mBoxHighLight = BTDesignerUtility.GetTexture("HighLight"); mBoxSelectHighLight = BTDesignerUtility.GetTexture("SelectHighLight"); if (mBoxTex == null) { mBoxTex = BTDesignerUtility.GetTexture("default"); } if (mBoxTex == null) { Log.Info("mBoxTex null " + NodeData.Id); } Width = mBoxTex.width / 2; Height = mBoxTex.height / 2; mLeftConnectTex = BTDesignerUtility.GetTexture("LeftConnect"); mRightConnectTex = BTDesignerUtility.GetTexture("RightConnect"); }
//正在连线 public void DrawConnectingLine() { if (mSelectedNode == null) { return; } Vector2 curPos = Event.current.mousePosition; //MousePosToGraphPos(Event.current.mousePosition); if (mState == State.ConnectLeft) { BTDesignerUtility.DrawConnection(mSelectedNode.LeftPos, curPos); } if (mState == State.ConnectRight) { BTDesignerUtility.DrawConnection(mSelectedNode.RightPos, curPos); } }
public void DrawBackground() { float width = 15f; Texture2D bgTex = BTDesignerUtility.GetTexture("Bg"); GUI.DrawTexture(new Rect(0, 0, mGraphRect.width, mGraphRect.height), bgTex); Texture2D lineTex = BTDesignerUtility.GetTexture("BgLine"); for (int i = 0; i < mGraphRect.width / width; i++) { GUI.DrawTexture(new Rect(width * i, 0, 1f, mGraphRect.height), lineTex); } for (int j = 0; j < mGraphRect.height / width; j++) { GUI.DrawTexture(new Rect(0, width * j, mGraphRect.width, 1f), lineTex); } }
public GUIStyle GetButtonStyle() { GUIStyle style = new GUIStyle() { fontSize = 15, alignment = TextAnchor.MiddleLeft }; GUIStyleState onHoverStyleState = new GUIStyleState() { background = BTDesignerUtility.GetTexture("blue") }; style.hover = onHoverStyleState; GUIStyleState onNormalStyleState = new GUIStyleState(); //onNormalStyleState.textColor = textColor; style.normal = onNormalStyleState; return(style); }
public void Draw() { foreach (NodeDesigner child in this.Children) { //先画子节点,让线条在最低层 BTDesignerUtility.DrawConnection(this.RightPos, child.LeftPos); child.Draw(); } //左链接 Texture2D tex = mLeftConnectTex; Rect rect = new Rect(Pos.x - Width / 2 - tex.width / 6, Pos.y - tex.height / 4, tex.width / 2, tex.height / 2); GUI.DrawTexture(rect, tex); //右链接 if (NodeData.Proto.child_limit > 0) { tex = mRightConnectTex; rect = new Rect(Pos.x + Width / 2 - tex.width / 6 * 2, Pos.y - tex.height / 4.1f, tex.width / 2, tex.height / 2); GUI.DrawTexture(rect, tex); if (NodeData.Children.Count > 0) { if (DesignerData.fold) { GUI.Label(new Rect(Pos.x + Width / 2 - 5f, Pos.y - 9f, tex.width, tex.height), "+"); } else { GUI.Label(new Rect(Pos.x + Width / 2 - 8f, Pos.y - 9f, tex.width, tex.height), "—"); } } } rect = new Rect(Pos.x - Width / 2, Pos.y - Height / 2, Width, Height); GUI.DrawTexture(rect, mBoxTex); if (isSelected) { GUI.DrawTexture(rect, mBoxSelectHighLight); } else if (BTEditor.Instance.IsHighLight(this.NodeData)) { GUI.DrawTexture(rect, mBoxHighLight); } GUIStyle style = new GUIStyle(); style.normal.background = null; style.normal.textColor = new Color(1, 1, 1); style.fontSize = 15; if (!this.isSelected) { style.clipping = TextClipping.Clip; } GUI.Label(new Rect(Pos.x - Width / 2 + 5f, Pos.y - Height / 3, Width - 10f, Height / 2), NodeData.Proto.name, style); style.normal.textColor = new Color(0.8f, 0.8f, 0.8f); style.fontSize = 12; style.wordWrap = true; string deprecatedDesc = NodeData.Proto.isDeprecated? $"({NodeData.Proto.deprecatedDesc})" : ""; GUI.Label(new Rect(Pos.x - Width / 2 + 6f, Pos.y, Width - 12f, Height / 2.1f), NodeData.Desc + deprecatedDesc, style); tex = null; switch (NodeData.NodeDeubgState) { case DebugState.True: tex = BTDesignerUtility.GetTexture("Execute"); break; // case DebugState.False: // tex = BTDesignerUtility.GetTexture("False"); // break; // case DebugState.Error: // tex = BTDesignerUtility.GetTexture("Error"); // break; } if (tex != null) { GUI.DrawTexture(rect, tex); // string time = System.DateTime.Now.ToString(); // GUI.Label(new Rect(Pos.x + Width / 2, Pos.y -20, Width - 12f, Height / 2.1f), time, style); } }
public void DrawMouseIcon(string resName) { GUI.DrawTexture(new Rect(Event.current.mousePosition.x - 10, Event.current.mousePosition.y - 20, 17, 20), BTDesignerUtility.GetTexture(resName)); }