翻译来自:http://forums.kleientertainment.com/topic/25850-wots-the-diff-prefabs-components-stategraphs-and-brains/

Wots The Diff?? Prefabs, Components, Stategraphs, And Brains
有啥区别? 预设,组件,状态图,大脑

I understand that there might be some confusion about these four parts of an entity, so here's a brief description of when to use each one.
 我知道一个实体的这四个部分可能会让人困惑,所以接下来我会简述一下什么时候用哪一个。

Prefabs and Components:
预设和组件

These two are the meat and potatoes of any entity in the world and where you'll be spending the most time. There is a simple way to think of the difference:
这两个是,在饥荒世界里,任何实体最基本的组成部分。你会花费大量功夫在它俩上面。它俩最简单的区别就是:
 
Prefabs are what a thing IS.
Components are what a thing DOES.
预设:这个物体是什么
组件:这个物体做什么

Lets look at the firepit as an example. What is it? A firepit! So it becomes a "firepit" prefab. What does it do? Well, it gets built, and it burns, and takes fuel, and can be looked at, and produces light... So we don't make a "firepit" component, instead we have "burnable" component, and "fueled" component, and so forth.
现在举个例子: 火堆,它是什么?火堆!所以它就是一个“预设”。它会做什么?外欧,它能被建造,它能燃烧,它需要燃料,它能被看到,它能产生亮光... 所以,我们不会制作一个“火堆”组件,而是让它拥有“可燃”,“可加燃料”等组件。

So components are where all the work happens, all the logic and data storage. A prefab is an instruction that says, "These are the components to use, and this is how you configure them.
所以,所有的活儿,所有的逻辑和数据,都在组件里发生,在组件里存储。而预设的说明是:拥有组件,可以使用它们,可以配置它们。

"Most prefabs have a main function that basically does just that: attaches all the components and configures them, and for many prefabs this is the entire story, such as the "carrot" prefab.
大多数的预设拥有一个主函数,它基本的工作是:添加各种组件,然后配置它们。大多数预设只做这些就可以了,比如“胡萝卜”预设

The place it gets a little funny is that some components need to be told how to do something. For example, the combat component needs to know, "How do I choose a new target if I lose my target?". If we take a look at the "frog" prefab, we can see that it adds a combat component, and then calls inst.components.combat:SetRetargetFunction(3, retargetfn).
有些组件,比较有意思,它们需要被告诉怎么去做。比如“战斗”组件,它需要被告诉“如果我失去了目标,我该怎么选择新目标?” 如果你看一下“青蛙”预设,你会看到它挂载了一个“战斗”组件,然后调用接口“设置重定向目标”,把“重定向目标”函数传给它。
 
If we look, retargetfn is defined in the prefab, and it's an instruction for the combat component on how to pick a new target. So basically, it's still a configuration of the component. That's all prefabs really do!
我们会发现,接口“重定向目标”函数就定义在“青蛙”预设里,这个函数就是指示“战斗”组件如何选择一个新目标。所以,基本上,这个函数还是算一个配置,来配置“战斗”组件。这就是预设要做的全部事情。
 
Some prefab files define multiple prefabs. Usually these are things with similar components, but different configurations. "staff.lua" contains all the staves. Each one shares a common base, but then has different specialized configurations for each colour of gem.So when you are making your own mods, ask yourself, is this mod a new thing or a new something a thing can do. If you want to make a sword that shoots lightning, you've got a sword (prefab) which can shoot lighting (component). The cool thing about approaching the problem this way is that you can then put your lightning shooter component on a different weapon, or on a hat, or a spider queen, or....!
一些预设文件会定义多个预设。通常,有些实体拥有一致的组件,但组件的配置不同。

Stategraphs and Brains:

These two are a bit fancier and most of the prefabs in the game don't use them at all! This is because, as mentioned, components are really where the hard work is done. But it's worth knowing about them in case they suit your needs.

Stategraphs:

Stategraphs are mainly used for controlling animation and timing. We can look at "SGeyeplant", the stategraph for the Eye Plants that spawn with the Lure Plant, as an example. Its first state is "spawn" which gets played right when the Eye Plant is created. Notice that its "onenter" function plays some animations and plays a sound. It also listens for an "animover" event which gets triggered when the current animation finishes playing, which moves it to the "idle" state. All the idle state does is play the idle animation.Normally that kind of behaviour, "do this thing and when it's done do that thing" is kind of a drudgery to code up, but the stategraph makes it straightforward to handle. We just tell it to go to the "spawn" state and when it's done it will automatically end up idling.

Another interesting example is the "attack" state in SGtentacle. We wanted the tentacles to play sounds and deal damage during the "whipping" part of their animation, which occur at certain frames. So this state sets up a timeline which will do certain things at frames 2, 7, 15, etc. Again, we can set this all up in the stategraph, and then the combat component just says "go to your attack state!" and the timing gets taken care of over here.

Brains:

Brains are the least used of these four elements, because they are the most high-level and generally entities don't needs this level of complexity. Their purpose is for AI and decision-making so only the complicated creatures need this.I'm not going to describe them in detail here, but in a nutshell: Brains use a system called a "behaviour tree" to make decisions. Every now and then it goes to the first item in the tree and checks, "can I do this?" and if not, it goes to the next one, and then next one, and it's children, and their children, until it finds something it can do. Then it does that! So this means things higher in the list have more priority, which lets you do things like make pigs prefer fighting to eating, but to panic when they are on fire even if they were fighting.

Generally each behaviour in the tree boils down to sending instructions to components: components still end up doing all the real "work". So the ChaseAndAttack behaviour, for example, sends instructions to the Locomotor (for movement) and Combat (for attacking) components, and those components handle the details.So as mentioned, most mods will never need to touch brains or stategraphs. But in case you need to modify one, now hopefully you have an idea of what their purpose is.

All in all, I think understanding the prefab/component distinction is critical to getting the most out of Don't Starve modding. If any of this wasn't clear or if you have further questions, please ask below!

游戏《饥荒》开发架构技术分析相关推荐

  1. 【转】网络即时战略游戏软件开发 结构体系分析

    文档下载地址:http://download.csdn.net/detail/wanggan768q/4388056   网络即时战略游戏软件开发 结构体系分析 前言 本人对网络游戏的技术问题一直比较 ...

  2. 网络即时战略游戏软件开发 结构体系分析

    文档下载地址:http://download.csdn.net/detail/wanggan768q/4388056   网络即时战略游戏软件开发 结构体系分析 前言 本人对网络游戏的技术问题一直比较 ...

  3. Spring Cloud Alibaba 分布式微服务高并发数据平台化(中台)思想+多租户saas企业开发架构技术选型和设计方案

    基于Spring Cloud Alibaba 分布式微服务高并发数据平台化(中台)思想+多租户saas设计的企业开发架构,支持源码二次开发.支持其他业务系统集成.集中式应用权限管理.支持拓展其他任意子 ...

  4. 美颜SDK架构技术分析

    美颜SDK发展至今,功能早已不同于往日,相较于开始最基础的美白.磨皮,发展到现在的滤镜.3D面具等各种不同的功能.在这些新兴功能的背后,离不开强大的渲染能力以及美颜算法.那么,一款优质的美颜SDK应该 ...

  5. 抖音SEO排名优化源代码开发搭建技术分析

    抖音seo优化排名获客系统,抖音SEO系统源码开发,思路,给大家日常分享一些抖音seo源码的部署开发,抖音seo程序开发是目前很多开发公司都在搭建的系统.... 一套优秀的抖音seo短视频获客系统,支 ...

  6. 游戏外挂原理和技术分析(关于魔力宝贝)

    先是顺移外挂:         石器和魔力会出现顺移外挂,是因为它的移动消息机制是客户端直接向服务器报告自己新坐标和人物方向,客户端又不是每走一步汇报一次,而是达到一定时间汇报一次,可能是一秒一次吧. ...

  7. C#使用 WebBrowser制作网页游戏辅助工具关键技术分析

    使用WebBrowser控件,实现起来确实很方便,但灵活性差,比不上直接组包发包.对三国风云这款网页游戏来 说,WebBrowser用的好的话理论上可以实现想要的功能(我只实现了整点自动"举 ...

  8. 各种开发架构技术图谱

    这些图谱是别人整理分享的,这里给自己作为笔记记录下.如有原作者链接请告知,谢谢.

  9. 2020最新版C/C++学习路线图--游戏服务器开发重点

    黑马程序员C/C++学习路线图大纲中第六阶段的学习是游戏服务器开发的学习:主要介绍了C/C++学习路线图的游戏服务器开发的学习目标,C/C++学习路线图的游戏服务器开发的市场价值,C/C++学习路线图 ...

最新文章

  1. R语言使用ggradar包可视化基本雷达图(radar chart、蜘蛛图spider plot)、可视化单个数据对象的雷达图、自定义雷达图的线条类型、线条宽度、数据点大小、色彩等
  2. 华为正式发布鸿蒙智慧屏,华为正式发布鸿蒙OS操作系统 智慧屏将率先使用
  3. 网络模块优化方案(1)——封装网络框架
  4. Python基础之:Python中的流程控制
  5. python列表转换成数字_python 字母转成数字Python操作列表的常用方法总结
  6. 计算机类专业权威解读,09计算机考研统考大纲权威解读之操作系统
  7. php mysql 简单留言板_php+mysql 最简单的留言板_PHP教程
  8. python装饰器-简易版
  9. Python3 练习笔记一
  10. win10中plt绘图显示中文
  11. 新人如何使用git加入到团队开发中
  12. C++模板Trait
  13. 普加计划甘特图功能介绍
  14. Faster rcnn 配置时出现bTest Key Error
  15. 在v$lock里找Holder和Waiter
  16. zabbix报错排错大全
  17. 基因组序列genbank格式和fasta格式批量下载
  18. SiamFC++与SiamBAN
  19. kurento API解读
  20. windows7系统出现0x0000003B蓝屏故障的解决方法

热门文章

  1. Python如何判断当前时间是否为夏令时?
  2. 天龙八部网单服务器装备修改,【图文教程】手把手教你修改游戏称号、武器外观!!!...
  3. UNCTF2020 wp
  4. unitoy机器人怎么联网_unitoy智能机器人配网
  5. 英特尔Nick McKeown:5G的意义远超智能手机
  6. OSChina 周三乱弹 ——没见过这么漂亮的女司机啊!
  7. java对象转json jackson_将Jackson对象转换为JSONObject java
  8. 使用wagon-maven-plugin插件自动部署项目
  9. [转]调研报告、论文中参考文献的格式(一)
  10. 智能合约审计之条件竞争