コード例 #1
0
        public static T AddService <T>(Composite parent, BehaviorTrees 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    = BehaviorTreesEditorUtility.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);
            }

            AssetCreator.SaveAIAsset();
            return((T)(object)service);
        }
コード例 #2
0
        public static T AddDecorator <T>(Node parent, BehaviorTrees 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    = BehaviorTreesEditorUtility.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);
            }

            AssetCreator.SaveAIAsset();
            return((T)(object)decorator);
        }
コード例 #3
0
        public static T AddNode <T>(Vector2 position, BehaviorTrees 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     = BehaviorTreesEditorUtility.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, BehaviorTreesEditorStyles.NodeNormalWidth, BehaviorTreesEditorStyles.NodeNormalHeight);

            if (EditorUtility.IsPersistent(bt))
            {
                AssetDatabase.AddObjectToAsset(node, bt);
            }

            if (node is BehaviorTrees)
            {
                node.position.width  = 150f;
                node.position.height = 45f;

                Root root = BehaviorTreesEditorUtility.AddNode <Root>(BehaviorTreesEditor.center, node as BehaviorTrees);
                root.Name = "Root";
            }
            else if (node is Wait)
            {
                Wait wait = node as Wait;
                wait.tick    = 0.1f;
                wait.comment = "Wait: 0.1s";
            }

            AssetCreator.SaveAIAsset();
            return((T)(object)node);
        }