[Unity plugin] Lua Behavior Tree (iv): conditional nodes and Behavior nodes

Source: Internet
Author: User
Tags addchild lua

Conditional node and Behavior node, the design of the two nodes themselves is relatively simple, the project to write the behavior tree node is generally the extension of the two nodes, and the decorator and composite nodes only need to use the built-in is enough.

Their inheritance relationships are as follows:

Conditional->task

Action->task

The code is as follows:

Btaction.lua

1Btaction =bttask:new ();2 3 Localthis =btaction;4 5 functionthis:new ()6     Localn \ {};7     setmetatable(o, self);8Self.__index =Self ;9     returno;Ten End

Btconditional.lua

1Btconditional =bttask:new ();2 3 Localthis =btconditional;4 5 functionthis:new ()6     Localo = {};7     setmetatable(o, self);8Self.__index =Self ;9     returno;Ten End

Btlog.lua

1 --[[2 Reference Behaviordesigner-action-log3 --]]4Btlog =btaction:new ();5 6 Localthis =Btlog;7 8 functionthis:new (text)9     Localo = {};Ten     setmetatable(o, self); OneSelf.__index =Self ; AO.text =text; -     returno; - End the  - functionthis:onupdate () -     Print(self.text); -     returnbttaskstatus.success; + End

Btisnullorempty.lua

1 --[[2 Reference Behaviordesigner-conditional-isnullorempty3 --]]4Btisnullorempty =btconditional:new ();5 6 Localthis =Btisnullorempty;7 8 functionthis:new (text)9     Localo = {};Ten     setmetatable(o, self); OneSelf.__index =Self ; AO.text =text; -     returno; - End the  - functionthis:onupdate () -     if( notSelf.textorSelf.text = ="") Then -         returnbttaskstatus.success; +     Else -         returnbttaskstatus.failure; +     End A End

Testbehaviortree.lua

1Testbehaviortree =btbehaviortree:new ();2 3 Localthis =Testbehaviortree;4 5 functionthis:new ()6     Localo = {};7     setmetatable(o, self);8Self.__index =Self ;9 this:init ();Ten     returno; One End A  - functionThis:init () -     Localsequence =btsequence:new (); the     LocalIsNullOrEmpty = Btisnullorempty:new (""); -     LocalLog = Btlog:new ("This is a empty string"); - Sequence:addchild (isnullorempty); - sequence:addchild (log); + This:pushtask (sequence); - End

The output is as follows:

[Unity plugin] Lua Behavior Tree (iv): conditional nodes and Behavior nodes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.