public static T AddService <T>(Composite parent, BehaviorTree bt) { if (parent == null) { Debug.LogWarning("Can't add a service to the behavior trees, because the behavior trees are null."); return(default(T)); } Service service = ScriptableObject.CreateInstance(typeof(T)) as Service; service.hideFlags = HideFlags.HideInHierarchy; service.Name = BehaviorTreeEditorUtility.GenerateName <T>(); service.tick = 0.1f; service.comment = service.Name + ": tick every 0.1s"; service.parent = parent; parent.services = ArrayUtility.Add <Service>(parent.services, service); if (EditorUtility.IsPersistent(bt)) { AssetDatabase.AddObjectToAsset(service, bt); } AssetDatabase.SaveAssets(); return((T)(object)service); }
public static T AddDecorator <T>(Node parent, BehaviorTree bt) { if (parent == null) { Debug.LogWarning("Can't add a decorator to the behavior trees, because the behavior trees are null."); return(default(T)); } Decorator decorator = ScriptableObject.CreateInstance(typeof(T)) as Decorator; decorator.hideFlags = HideFlags.HideInHierarchy; decorator.Name = BehaviorTreeEditorUtility.GenerateName <T>(); decorator.comment = decorator.Name; decorator.parent = parent; parent.decorators = ArrayUtility.Add <Decorator>(parent.decorators, decorator); if (EditorUtility.IsPersistent(bt)) { AssetDatabase.AddObjectToAsset(decorator, bt); } AssetDatabase.SaveAssets(); return((T)(object)decorator); }
public static T AddNode <T>(Vector2 position, BehaviorTree bt) { if (bt == null) { Debug.LogWarning("Can't add a node to the behavior trees, because the behavior trees are null."); return(default(T)); } Node node = ScriptableObject.CreateInstance(typeof(T)) as Node; node.hideFlags = HideFlags.HideInHierarchy; node.Name = BehaviorTreeEditorUtility.GenerateName <T>(); node.comment = node.Name; node.bt = bt; bt.nodes = ArrayUtility.Add <Node>(bt.nodes, node); node.position = new Rect(position.x, position.y, BehaviorTreeEditorStyles.NodeNormalWidth, BehaviorTreeEditorStyles.NodeNormalHeight); if (EditorUtility.IsPersistent(bt)) { AssetDatabase.AddObjectToAsset(node, bt); } if (node is BehaviorTree) { node.position.width = 150f; node.position.height = 45f; Root root = BehaviorTreeEditorUtility.AddNode <Root>(BehaviorTreeEditor.center, node as BehaviorTree); root.Name = "Root"; } else if (node is Wait) { Wait wait = node as Wait; wait.tick = 0.1f; wait.comment = "Wait: 0.1s"; } AssetDatabase.SaveAssets(); return((T)(object)node); }