public BTInputProperty(BTInputProperty prop) { PropertyName = prop.PropertyName; TypeName = prop.TypeName; InputData = prop.InputData; DefaultValue = prop.DefaultValue; }
void SubmitProperty() { if (mFocusProperty != null && mFocusProperty.ReguexData() && mFocusDecorator != null) { mFocusDecorator.UpdatePropertiesInfo(); } mFocusProperty = null; }
public Decorator(int id, BehaviourMeta meta) { BTId = id; BTMeta = meta; Properties = new BTInputProperty[meta.Properties.Length]; for (int i = 0; i < meta.Properties.Length; i++) { Properties[i] = new BTInputProperty(meta.Properties[i]); } }
public void Hide() { if (mFocusProperty != null && mFocusProperty.ReguexData() && mFocusDecorator != null) { mFocusDecorator.UpdatePropertiesInfo(); } Visible = false; Context = null; Mode = EMode.none; mRaycastProperty = null; mFocusProperty = null; mFocusDecorator = null; mRaycastDecorator = null; mDropDownMeta = null; mSearchContext = ""; }
void OnPropertiesList(Rect r, BehaviourNodeGUI.Decorator decorator, Vector2 tsize, Vector2 dsize) { BTInputProperty[] properties = decorator.Properties; if (properties.Length == 0) { return; } Rect h = new Rect(); h.size = new Vector2(dsize.x - 6 * GlobalScale, dsize.y); h.position = r.position + Vector2.one * 3 * GlobalScale; Installizer.contentStyle.alignment = TextAnchor.MiddleLeft; Installizer.contentStyle.fontSize = (int)Mathf.Max(1, BehaviourNodeGUI.SUB_FONT_SIZE * GlobalScale); bool dirty = false; for (int i = 0; i < properties.Length; i++) { BTInputProperty prop = properties[i]; Installizer.contentContent.text = prop.PropertyName; GUI.Label(h, Installizer.contentContent, Installizer.contentStyle); h.y += dsize.y;// = new Vector2(r.xMin + x0, r.yMin + i * dsize.y); //GUI.Label(h, "", "textfield");// "TL LoopSection"); QuickGUI.DrawBox(h, Color.clear, Color.gray, 1); if (h.Contains(Event.current.mousePosition)) { mRaycastProperty = prop; } if (mFocusProperty == prop) { string str = GUI.TextField(h, prop.InputData, Installizer.contentStyle); dirty |= str != prop.InputData; prop.InputData = str; } else { prop.ReguexData(); GUI.Label(h, prop.IsDefaultValue ? string.Format("<i><color=#a0a0a0>({0})</color></i> {1} ", prop.TypeName, prop.InputData) : prop.InputData, Installizer.contentStyle); } h.y += tsize.y; } if (dirty) { decorator.UpdatePropertiesInfo(); mResizeNode = true; } }
public BehaviourMeta(System.Type target) { //TargetType = target; Name = target.Name; DisplayName = Name; Namespace = target.Namespace; string iconPath = ""; if (target.IsSubclassOf(typeof(BTNodeBase))) { NodeType = EBTNodeType.controller; Category = "Composite"; iconPath = Installizer.InstallRoot + "/DevilFramework/Editor/Icons/composite.png"; } else if (target.IsSubclassOf(typeof(BTTaskBase))) { NodeType = EBTNodeType.task; Category = "Task"; iconPath = Installizer.InstallRoot + "/DevilFramework/Editor/Icons/task.png"; } else if (target.IsSubclassOf(typeof(BTConditionBase))) { NodeType = EBTNodeType.condition; Category = "Condition"; iconPath = Installizer.InstallRoot + "/DevilFramework/Editor/Icons/condition.png"; } else if (target.IsSubclassOf(typeof(BTServiceBase))) { NodeType = EBTNodeType.service; Category = "Service"; iconPath = Installizer.InstallRoot + "/DevilFramework/Editor/Icons/service.png"; } else { NodeType = EBTNodeType.invalid; Category = "Invalid"; } BTCompositeAttribute attr = Ref.GetCustomAttribute <BTCompositeAttribute>(target); if (attr != null) { if (!string.IsNullOrEmpty(attr.Title)) { DisplayName = attr.Title; } if (!string.IsNullOrEmpty(attr.Detail)) { SubTitle = attr.Detail; } if (!string.IsNullOrEmpty(attr.IconPath)) { iconPath = attr.IconPath; } if (!string.IsNullOrEmpty(attr.Category)) { Category = attr.Category; } HideProperty = attr.HideProperty; } FieldInfo[] fields = target.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); List <BTInputProperty> propperties = new List <BTInputProperty>(); for (int i = 0; i < fields.Length; i++) { BTVariableAttribute vatt = Ref.GetCustomAttribute <BTVariableAttribute>(fields[i]); if (vatt != null) { BTInputProperty pro = new BTInputProperty(fields[i], vatt); propperties.Add(pro); } } Icon = DevilEditorUtility.GetTexture(iconPath); Properties = propperties.ToArray(); NotDisplayName = string.Format("<b><color=yellow>NOT</color></b> {0}", DisplayName); SearchName = Name.ToLower() + " " + DisplayName.ToLower(); color = BehaviourModuleManager.GetOrNewInstance().GetCategoryColor(Category); }
public override bool InteractMouseClick(EMouseButton button, Vector2 mousePosition) { if (!Visible) { return(false); } mFocusSearch = mRaycastSearch; if (mRaycastMeta != null && button == EMouseButton.left) { if (mRaycastMeta.IsTitle) { mRaycastMeta.Collaped = !mRaycastMeta.Collaped; } //mDropDownMeta = mRaycastMeta == mDropDownMeta ? null : mRaycastMeta; else { switch (mRaycastMeta.BTMeta.NodeType) { case EBTNodeType.task: case EBTNodeType.controller: mWindow.AddChild(Context, mRaycastMeta.BTMeta, new Vector2(LocalRect.center.x, LocalRect.yMin)); Hide(); return(true); case EBTNodeType.condition: case EBTNodeType.service: BehaviourNodeGUI node = Context as BehaviourNodeGUI; if (node != null) { BehaviourNodeGUI.Decorator decor = node.AddDecorator(mRaycastMeta.BTMeta); if (decor != null && decor.Properties.Length > 0) { //mFocusDecorator = decor; decor.UpdatePropertiesInfo(); } //Hide(); node.Resize(); if (decor == null) { EditorCanvasTip.NewTip("不能添加<color=yellow>" + mRaycastMeta.BTMeta.DisplayName + "</color>", 2) .Show(mWindow.RootCanvas, mWindow.RootCanvas.CalculateLocalPosition(mousePosition - Vector2.up * 20)); } } return(true); default: break; } } } bool act = mFocusProperty == null && mRaycastProperty == null; if (mFocusProperty != mRaycastProperty) { SubmitProperty(); } mFocusProperty = mRaycastProperty; mFocusDecorator = mRaycastDecorator; if (act && mRaycastDecorator != null && mRaycastDecorator.BTMeta.NodeType == EBTNodeType.condition) { mRaycastDecorator.NotFlag = !mRaycastDecorator.NotFlag; } //if (mRaycastDecorator != null && mRaycastDecorator.Properties.Length > 0) //{ // mFocusDecorator = mRaycastDecorator; //} return(Visible); }
void OnContextDecoratorGUI() { mRaycastProperty = null; mRaycastDecorator = null; float l = Mathf.Max(mMinTaskWidth, mMinDecoratorWidth); float w = l + mMinDecoratorWidth; if (w > LocalRect.width) { Rect rect = new Rect(); rect.size = new Vector2(w, LocalRect.height); rect.position = new Vector2(LocalRect.center.x - w * 0.5f, LocalRect.yMin); LocalRect = rect; } Vector2 dsize = new Vector2(l * GlobalScale - 2, BehaviourNodeGUI.SUB_FONT_SIZE * GlobalScale); dsize.y += 5 * GlobalScale; Vector2 tsize = new Vector2(dsize.x, dsize.y * 1.3f); BehaviourNodeGUI node = Context as BehaviourNodeGUI; TextAnchor align = Installizer.contentStyle.alignment; Rect r = new Rect(); r.size = new Vector2(tsize.x, GlobalRect.height); r.position = GlobalRect.position; BeginScroll(r, ref mScrollRectL); // r.size = tsize; r.position = new Vector2(0, mScrollOffsetL); BTInputProperty[] properties; // conditions OnAttachedDecoratorListGUI(ref r, tsize, dsize, node, node.conditions); // self properties = node.Self.Properties; r.size = new Vector2(tsize.x, tsize.y + properties.Length * (tsize.y + dsize.y) + tsize.y); QuickGUI.DrawBox(r, node.Self.BTMeta.color, Color.black); if (r.Contains(Event.current.mousePosition)) { mRaycastDecorator = node.Self; } Rect tmp = new Rect(); Texture icon = node.Self.BTMeta.Icon; if (icon != null) { tmp.size = Vector2.one * tsize.y; tmp.position = new Vector2(r.xMin + 1, r.yMin + 1); GUI.DrawTexture(tmp, icon, ScaleMode.ScaleToFit); } tmp.size = tsize; tmp.position = new Vector2(r.xMin, r.yMin); Installizer.titleStyle.alignment = TextAnchor.MiddleCenter; Installizer.titleStyle.fontSize = (int)Mathf.Max(1, BehaviourNodeGUI.FONT_SIZE * GlobalScale); Installizer.titleContent.text = string.Format("<b>{0}</b>", node.Self.BTMeta.DisplayName); GUI.Label(tmp, Installizer.titleContent, Installizer.titleStyle); tmp.y += tsize.y + 4 * GlobalScale; OnPropertiesList(tmp, node.Self, tsize, dsize); r.y = r.yMax; //services OnAttachedDecoratorListGUI(ref r, tsize, dsize, node, node.services); EndScroll(r.yMax, ref mScrollRectL, ref mScrollOffsetL); Handles.color = Color.gray; Handles.DrawLine(new Vector3(GlobalRect.xMin + tsize.x, GlobalRect.yMin), new Vector3(GlobalRect.xMin + tsize.x, GlobalRect.yMax)); Installizer.contentStyle.alignment = align; }