BehaviourNodeGUI NewNode(BTData data) { BehaviourMeta meta = BehaviourModuleManager.GetOrNewInstance().FindBTMeta(data.m_Type, data.m_Name); if (meta == null || (meta.NodeType != EBTNodeType.task && meta.NodeType != EBTNodeType.controller)) { return(null); } BehaviourNodeGUI bnode = new BehaviourNodeGUI(this); bnode.Self = new BehaviourNodeGUI.Decorator(data.m_Id, meta); bnode.Self.ParseData(data.m_JsonData); if (data.m_Services != null) { for (int i = 0; i < data.m_Services.Length; i++) { BTData serv = BehaviourAsset.GetDataById(data.m_Services[i]); if (serv == null) { continue; } BehaviourMeta bm = BehaviourModuleManager.GetOrNewInstance().FindBTMeta(EBTNodeType.service, serv.m_Name); if (bm != null) { BehaviourNodeGUI.Decorator decor = new BehaviourNodeGUI.Decorator(serv.m_Id, bm); decor.ParseData(serv.m_JsonData); bnode.services.Add(decor); } } } if (data.m_Conditions != null) { for (int i = 0; i < data.m_Conditions.Length; i++) { BTData cond = BehaviourAsset.GetDataById(data.m_Conditions[i]); if (cond == null) { continue; } BehaviourMeta bm = BehaviourModuleManager.GetOrNewInstance().FindBTMeta(EBTNodeType.condition, cond.m_Name); if (bm != null) { BehaviourNodeGUI.Decorator decor = new BehaviourNodeGUI.Decorator(cond.m_Id, bm); decor.NotFlag = cond.m_NotFlag; decor.ParseData(cond.m_JsonData); bnode.conditions.Add(decor); } } } Rect r = new Rect(); r.size = bnode.CalculateLocalSize(); r.position = data.m_Pos - Vector2.right * r.size.x * 0.5f; bnode.LocalRect = r; return(bnode); }
public void ShowContext(BehaviourNodeGUI context) { if (EditorApplication.isPlaying || context == null) { return; } List <BehaviourMeta> lst; if (mDecoratorList.Count < 2 || !BehaviourModuleManager.GetOrNewInstance().Decorators.Contains(mDecoratorList[1].BTMeta)) { mMinDecoratorWidth = 200; mDecoratorList.Clear(); lst = BehaviourModuleManager.GetOrNewInstance().Decorators; string category = null; for (int i = 0; i < lst.Count; i++) { MetaUI m = new MetaUI(lst[i]); if (m.BTMeta.Category != category) { category = m.BTMeta.Category; mDropDownMeta = new MetaUI(category); mDecoratorList.Add(mDropDownMeta); } mDecoratorList.Add(m); mMinDecoratorWidth = Mathf.Max(mMinDecoratorWidth, m.Width); } } Mode = EMode.alter_node; Visible = true; Context = context; Rect rect = new Rect(); rect.size = new Vector2(mMinDecoratorWidth + mMinTaskWidth, 270); Vector2 gsize = rect.size * GlobalScale; Vector2 delta = Vector2.zero; if (mWindow.GlobalMousePosition.y + gsize.y > mWindow.RootCanvas.GlobalRect.height) { delta.y = -rect.size.y; } if (mWindow.GlobalMousePosition.x + gsize.x > mWindow.RootCanvas.GlobalRect.width) { delta.x = -rect.size.x; } rect.position = Parent.CalculateLocalPosition(mWindow.GlobalMousePosition) + delta; LocalRect = rect; mWindow.SelectNodes((x) => x == context); mDragEnd = true; }
public static void OnUnityLoaded() { IsInited = false; DevilEditorUtility.ReleaseCache(); titleStyle.alignment = TextAnchor.MiddleCenter; titleStyle.richText = true; titleStyle.fontSize = 13; titleStyle.wordWrap = false; titleStyle.fontStyle = FontStyle.Bold; titleStyle.normal.textColor = Color.green; titleStyle.onHover.textColor = Color.yellow; contentStyle.alignment = TextAnchor.MiddleCenter; contentStyle.richText = true; contentStyle.fontSize = 10; contentStyle.wordWrap = false; contentStyle.fontStyle = FontStyle.Normal; contentStyle.normal.textColor = Color.white; contentStyle.onHover.textColor = Color.white; string txt = "ABCDEFG"; Vector2 size = SizeOfTitle(txt); TitleHeight = size.y; size = SizeOfContent(txt); ContentHeight = size.y; EditorPrefs.SetBool("Devil.Editor.first", false); string[] assets = AssetDatabase.FindAssets("t:script Installizer"); string ends = "/DevilFramework/Editor/Installizer.cs"; foreach (string s in assets) { string path = AssetDatabase.GUIDToAssetPath(s); if (path.EndsWith(ends)) { path = path.Substring(0, path.Length - ends.Length); EditorPrefs.SetString("Devil.Root", path); InstallRoot = path; Debug.Log("Devil Framework install at path: " + path); } } DevilCfg.LoadConfiguration(); BehaviourModuleManager.GetOrNewInstance().Load(); IsInited = true; OnReloaded(); }
public void OnGUI(Rect rect, float scale) { if (BTMeta != null) { QuickGUI.DrawBox(rect, new Color(0.3f, 0.3f, 0.3f), Color.yellow, rect.Contains(Event.current.mousePosition) ? 2 : 0); Rect r = rect; r.size = Vector2.one * (BehaviourNodeGUI.FONT_SIZE * scale); r.position += Vector2.one * (3 * scale); Texture icon = BTMeta.Icon; if (icon != null) { GUI.DrawTexture(r, icon, ScaleMode.ScaleToFit); } r.position = new Vector2(rect.x + r.size.x, rect.y); r.width = rect.width - r.size.x; r.height = TitleSize.y * scale; Installizer.contentStyle.fontStyle = FontStyle.Bold; Installizer.contentStyle.normal.textColor = Color.white; Installizer.contentStyle.fontSize = (int)Mathf.Max(1, BehaviourNodeGUI.SUB_FONT_SIZE * scale); Installizer.contentStyle.alignment = TextAnchor.MiddleCenter; Installizer.contentContent.text = BTMeta.DisplayName; GUI.Label(r, Installizer.contentContent, Installizer.contentStyle); r.y = rect.y + TitleSize.y * scale; r.height = DetailSize.y * scale; r.width = rect.width - 6 * scale; r.x = rect.x + 5 * scale; Installizer.contentStyle.fontStyle = FontStyle.Normal; Installizer.contentStyle.normal.textColor = new Color(0.7f, 0.7f, 0.7f); Installizer.contentStyle.fontSize = (int)Mathf.Max(1, BehaviourNodeGUI.SUB_FONT_SIZE * 0.9f * scale); Installizer.contentStyle.alignment = TextAnchor.MiddleLeft; Installizer.contentContent.text = BTMeta.SubTitle; GUI.Label(r, Installizer.contentContent, Installizer.contentStyle); } else { Color c = BehaviourModuleManager.GetOrNewInstance().GetCategoryColor(Category); QuickGUI.DrawBox(rect, Collaped ? c : new Color(c.r * 0.5f, c.g * 0.5f, c.b * 0.5f), Color.yellow, 0); Installizer.titleStyle.fontSize = (int)Mathf.Max(1, BehaviourNodeGUI.SUB_FONT_SIZE * scale); Installizer.titleStyle.alignment = TextAnchor.MiddleCenter; Installizer.titleContent.text = Category; GUI.Label(rect, Installizer.titleContent, Installizer.titleStyle); } }
public void NewNode(PaintElement context) { if (EditorApplication.isPlaying) { return; } if (mTaskList.Count < 2 || !BehaviourModuleManager.GetOrNewInstance().Composites.Contains(mTaskList[1].BTMeta)) { mTaskList.Clear(); mMinTaskWidth = 200; List <BehaviourMeta> lst; lst = BehaviourModuleManager.GetOrNewInstance().Composites; string category = null; for (int i = 0; i < lst.Count; i++) { MetaUI m = new MetaUI(lst[i]); if (m.BTMeta.Category != category) { category = m.BTMeta.Category; mDropDownMeta = new MetaUI(category); mTaskList.Add(mDropDownMeta); } mTaskList.Add(m); mMinTaskWidth = Mathf.Max(mMinTaskWidth, m.Width); } } Mode = EMode.new_node; Visible = true; Context = context; Rect rect = new Rect(); rect.size = new Vector2(mMinTaskWidth, 270); // 170 + 200 rect.position = Parent.CalculateLocalPosition(mWindow.GlobalMousePosition) - new Vector2(mMinTaskWidth * 0.5f, 0); LocalRect = rect; mDragEnd = true; }
public static void OnBlackboardInspectorGUI(BlackboardAsset asset) { drop = QuickGUI.DrawHeader("Blackboard", "BT", false); if (drop) { QuickGUI.BeginContents(200); scroll = GUILayout.BeginScrollView(scroll, GUILayout.MaxHeight(200)); for (int i = 0; i < asset.m_Properties.Length; i++) { EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("", "OL Minus", GUILayout.Width(20))) { BlackboardAsset.KeyValue[] keys = new BlackboardAsset.KeyValue[asset.m_Properties.Length - 1]; if (i > 0) { System.Array.Copy(asset.m_Properties, 0, keys, 0, i); } if (i < asset.m_Properties.Length - 1) { System.Array.Copy(asset.m_Properties, i + 1, keys, i, keys.Length - i); } asset.m_Properties = keys; EditorUtility.SetDirty(asset); break; } BlackboardAsset.KeyValue key = asset.m_Properties[i]; GUILayout.Label(key.m_Key, GUILayout.Width(140)); GUILayout.Label(key.m_Value, "textfield"); EditorGUILayout.EndHorizontal(); } GUILayout.EndScrollView(); GUILayout.Space(10); if (JDateTime.NowMillies - repeatTip < 2000) { GUILayout.Label("已经存在相同的属性", "flow overlay box"); } EditorGUILayout.BeginHorizontal(); dropIndex = Mathf.Min(dropIndex, BehaviourModuleManager.GetOrNewInstance().SharedTypeNames.Length - 1); if (GUILayout.Button("", "OL Plus", GUILayout.Width(20))) { if (string.IsNullOrEmpty(newName) || asset.HasKey(newName)) { repeatTip = JDateTime.NowMillies; } else { BlackboardAsset.KeyValue[] keys = new BlackboardAsset.KeyValue[asset.m_Properties.Length + 1]; if (keys.Length > 1) { System.Array.Copy(asset.m_Properties, keys, keys.Length - 1); } BlackboardAsset.KeyValue newk = new BlackboardAsset.KeyValue(); newk.m_Key = newName; newk.m_Value = BehaviourModuleManager.GetOrNewInstance().SharedTypeNames[dropIndex]; keys[keys.Length - 1] = newk; asset.m_Properties = keys; EditorUtility.SetDirty(asset); newName = "newVariable"; scroll = Vector2.up * asset.m_Properties.Length * 30; } } newName = GUILayout.TextField(newName ?? "newVariable", GUILayout.Width(140)); dropIndex = EditorGUILayout.Popup(dropIndex, BehaviourModuleManager.GetOrNewInstance().SharedTypeNames); EditorGUILayout.EndHorizontal(); QuickGUI.EndContents(); } }
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); }