├── 1.Overview ├── 1-1.简介.md ├── 1-2.资源内容.md ├── 1-3.最小场景要求.md ├── 1-4.FAQ.md └── media │ ├── 15004513818871.jpg │ ├── 15004623902260.jpg │ ├── 15004625009334.jpg │ └── 15015989276655.jpg ├── 2.Agents ├── 2-1.如何创建角色.md ├── 2-2.角色类.md ├── 2-3.角色能力.md ├── 2-4.动画.md ├── 2-5.AI.md ├── 2-6.武器.md ├── 2-7.装备.md └── media │ ├── 15005163011188.jpg │ ├── 15005175125428.jpg │ ├── 15005223318847.jpg │ ├── 15005234653108.jpg │ ├── 15005318728538.jpg │ ├── 15005426541087.jpg │ ├── 15005429340996.jpg │ ├── 15005439528429.jpg │ ├── 15005453914679.jpg │ ├── 15005659657442.jpg │ ├── 15009134926090.jpg │ ├── 15010347513179.jpg │ ├── 15010533399635.jpg │ ├── 15010648215013.jpg │ ├── 15010663739266.jpg │ ├── 15011218647959.jpg │ ├── 15011223989829.jpg │ ├── 15011225662440.jpg │ ├── 15011248436120.jpg │ └── 15011282424938.jpg ├── 3.General ├── 3-1.创建你自己的游戏.md ├── 3-2.输入.md ├── 3-3.Managers.md ├── 3-4.碰撞.md ├── 3-5.重生.md ├── 3-6.UI.md ├── 3-7.事件.md ├── 3-8.成就.md ├── 3-9.摄像机.md └── media │ ├── 15011432639033.jpg │ ├── 15011436782426.jpg │ ├── 15011514343185.jpg │ ├── 15012114241306.jpg │ ├── 15012273290066.jpg │ ├── 15012325544967.jpg │ ├── 15014710179423.jpg │ ├── 15014817559889.jpg │ ├── 15014825032837.jpg │ ├── 15014835521919.jpg │ ├── 15014985543651.jpg │ ├── 15015540341371.jpg │ ├── 15015582494754.jpg │ └── 15015706225957.jpg └── README.md /1.Overview/1-1.简介.md: -------------------------------------------------------------------------------- 1 | # Corgi Engine 简介 2 | 3 | > 欢迎阅读 Corgi Engine 文档,你可以在这里找到关于如何创造一个平台游戏所需要知道的一切。 4 | 5 | ## 什么是 Corgi Engine? 6 | 7 | Corgi Engine 是一个基于 Unity 的 2D + 2.5D 平台游戏套件,在 [Unity 资源商店](https://www.assetstore.unity3d.com/en/#!/content/26617)中可以找到。它拥有一个**基于非物理引擎(non-physics based)实现的高效的玩家控制器**,并且具备**兼容移动设备**、兼容各种资源等特性。基本上,它就是**你开始着手创建一个 2D 游戏所需的一切**。 8 | 9 | ![Corgi Engine 的启动界面](media/15015989276655.jpg) 10 | 11 | ## 如何开始 12 | 13 | 首先,**你并不需要阅读完所有文档**。Corgi Engine 的创建过程遵循着 Unity 的最佳实践,并且打包了各种帮助内容。如果这不是你的第一个 Unity 项目,尽管按照你的方式进行,在遇到任何不清晰的地方再回到这里查阅即可。 14 | 15 | 也就是说,你可以使用**页面左边的目录**导航到相应的主题,这份文档是一个工具。如果你对源代码本身有疑问,你可能需要查阅 [API 文档](http://corgi-engine-docs.moremountains.com/API/),同时推荐你直接阅读源代码的注释,通常它们就足够解答你可能遇到的很多问题了。 16 | 17 | 如果你想要一份引擎的功能特性列表,或者想知道某些东西引擎是否已经包含在内,你可以访问[这个页面](http://corgi-engine.moremountains.com/),它还包含了更新日志和其他有用的东西。 18 | 19 | 你也可以观看 [YouTube 上的视频教程](https://www.youtube.com/playlist?list=PLl3caEhMYxQEsA5Fbg0M2aB9Q9Z9BTVNS)。 20 | 21 | 如果以上途径都无法帮助你解决问题,你还可以使用[资源商店中的邮件支持链接](https://www.assetstore.unity3d.com/en/#!/content/26617)来获得帮助。 22 | 23 | ------- 24 | 25 | [本页面的 Corgi Engine 官方英文原版链接](http://corgi-engine-docs.moremountains.com/index.html) 26 | 27 | # Introduction to the Corgi Engine 28 | 29 | > **Summary:** Welcome to the Corgi Engine Documentation. Here you'll find everything you need to know to create your own platformer game! 30 | 31 | ## What’s the Corgi Engine? 32 | 33 | The Corgi Engine is a Unity 2D + 2.5D Platformer Kit, available on the [Unity Asset Store](https://www.assetstore.unity3d.com/en/#!/content/26617). It’s a **very fast, non-physics based controller** for your player, plus many other features, described below. It’s **mobile friendly**, works well with other assets, and is basically **everything you need to start creating your own 2D game right now**. 34 | 35 | ![The Corgi Engine's start screen](media/15015989276655.jpg) 36 | 37 | ## Where do I start ? 38 | 39 | First of all, **you don’t have to read all that documentation**. The engine is built with Unity good practices in mind, and is packed with help boxes. So if this is not your first Unity project, you’ll probably be ok on your own. And you can always go back here if something’s not clear. 40 | 41 | That said, you can use the **menu on the left** to get to specific places. This documentation is functional. If you have questions about the code itself, you’ll rather want to have a look at [the API documentation](http://corgi-engine-docs.moremountains.com/API/). It’s also recommended to look at the code’s comments directly, usually they cover pretty much any question you might have. 42 | 43 | If you want a list of features, or are wondering if this or that is included in the engine, you can have a look [at this page](http://corgi-engine.moremountains.com/). It also includes a changelog, and other useful stuff. 44 | 45 | There are also [video tutorials on Youtube](https://www.youtube.com/playlist?list=PLl3caEhMYxQEsA5Fbg0M2aB9Q9Z9BTVNS). 46 | 47 | And if all that doesn’t help, you can always use the **support email link** [on the Asset’s page](https://www.assetstore.unity3d.com/en/#!/content/26617). 48 | 49 | ------- 50 | 51 | -------------------------------------------------------------------------------- /1.Overview/1-2.资源内容.md: -------------------------------------------------------------------------------- 1 | # 资源内容 2 | 3 | > 这个页面描述了引擎包含的资源内容。 4 | 5 | ## 简介 6 | 7 | 当你把 Corgi Engine 的资源包导入到项目中后,在项目视图中会看到 `CorgiEngine` 文件夹,其中包含 4 个子文件夹。我建议保留引擎原来的文件结构,并且**不要修改它的内容**。取而代之,创建另外一个专门的文件夹来保存你的游戏资源。如果你需要修改引擎的源代码,只需要在你自己的类中扩展引擎的类,你可以通过阅读[「扩展 Corgi Engine」](https://github.com/Caizc/corgi-engine-docs/blob/master/3.General/3-1.%E5%88%9B%E5%BB%BA%E4%BD%A0%E8%87%AA%E5%B7%B1%E7%9A%84%E6%B8%B8%E6%88%8F.md)部分内容来了解更多。下图是这 4 个子文件夹的内容大纲和目录结构。 8 | 9 | ![Corgi Engine 的资源内容](media/15004513818871.jpg) 10 | 11 | ## Comon 12 | 13 | 顾名思义,`Common` 包含了实现游戏中移动控制必需的所有脚本和视觉资源,在你的游戏中需要保留这些文件。它主要由以下文件目录构成: 14 | 15 | * **Animations**:所有公共的动画组件,大部分是 GUI 相关 16 | * **Fonts**:各种 GUI 界面上使用的字体都保存在这里 17 | * **Materials**:大部分 Demo 中用到的一些材质,但有特定的几个除外 18 | * **Prefabs**:各个 Demo 关卡中用到的所有 Prefab 19 | * **Resources**:通过代码直接实例化的一些 Prefab 20 | * **Scripts**:引擎的核心部分,也是它最大的价值所在,我们将会详细了解它的细节 21 | * **Sprites**:所有 Demo 公共的 Sprite,同样的,大部分都是 GUI 资源 22 | 23 | `Scripts` 目录包含了所有的引擎脚本。每个 Demo 也都有各自的一些脚本,但都放在各自的目录下。请注意,为了更易于维护和更好的逻辑分离,`MMTools` 的脚本放在了根目录的另一个子目录下。以下是 `Scripts` 中的主要目录: 24 | 25 | * **Agents**:在这里你可以找到所有控制角色动作和行为的脚本,包括射线投射的碰撞控制器(raycast collision controller)、角色能力、AI 脚本以及武器等等 26 | * **Camera**:各种与摄像机、视差相关的脚本 27 | * **Checkpoints**:大部分是与「游戏循环」相关(重生、关卡结束等等)的脚本 28 | * **Environment**:这个目录包含的大部分是处理关卡中物品对象的脚本,包括下落的方块到瞬间传送装置等 29 | * **GUI**:顾名思义,这个目录包含了所有与 GUI 相关的东西:对话窗、暂停界面等 30 | * **Items**:这个目录包含了金币、可捡拾的武器等东西 31 | * **Managers**:包含了所有管理类(所谓「超类」,通常是单例,处理游戏中全局的东西) 32 | * **Sound**:所有声音相关的脚本都放在这里 33 | 34 | ## Demos 35 | 36 | Demos 目录包含了所有引擎中提供的游戏 Demo。它们按照「游戏世界」(universe)来组织目录结构,一个「游戏世界」可能包含一个或多个场景(Scene)。通常每个 Demo 旨在展示**引擎一个或多个特定的方面**, 或者展示如何通过简单的调整或替换美术资源达到你想要的不同效果。 37 | 38 | ### Brobro 39 | 40 | * **BrobroLevel**:一个可以随意摧毁对象的关卡,灵感来源于 `Free Lives` (独立游戏工作室)的 `Broforce` 41 | 42 | ### Corgi 2D 43 | 44 | * **Lava**:一个炎热的关卡 45 | * **Mesa1**:为这个引擎创建的很早期的关卡,包含了几乎所有东西 46 | * **Mesa2**:经典主题的一个变种 47 | * **Mountains**:一个山脉主题的场景,包含风和落叶 48 | * **Sandbox**:一个主要用于快速测试东西的场景,不需要详细研究,它还存在一些问题 49 | 50 | ### Corgi 3D 51 | 52 | * **3D Level**:一个非常基础的 3D 关卡,包含了一些现成的原型方块 53 | 54 | ### Level Selection 55 | 56 | * **LevelSelection**:一个关卡选择的实现示例,包括了路径控制功能 57 | 58 | ### Minimal 59 | 60 | * **FeaturesPlatforms**:一个交互式的 Demo,展示了资源的所有平台相关特性 61 | * **MinimalLevel**:展示了一个单玩家场景的最小要求 62 | * **Minimal4Players**:展示了一个本地多玩家场景的最小要求 63 | 64 | ### Pixel 65 | 66 | * **PixelLevel**:基于像素瓦片(pixelated tile based)的关卡 67 | 68 | ### Super Hipster Bros 69 | 70 | * **HipsterLevel**:一个经典复古的滚屏平台游戏,灵感来源于 `Super Mario Bros` 71 | 72 | ### The Hunt 73 | 74 | * **TheHunt**:一个多玩家的 3D、4 vs 4 关卡,灵感来源于 `Smash Bros` 和 `Towerfall` 以及类似的游戏 75 | 76 | ## MMTools 77 | 78 | `MMTools` 包含了所有在 `More Mountains` 出品的资源中使用到的辅助类(helper)和小类(small class)。有一些类在 Corgi Engine 可能并没有使用到,但我还是建议**不要移除它们**。那些没被用上的资源并不会让你的构建包变大,所以保留它们是较为安全简单的做法。这份文档不会涉及到它们的细节,但它们都有详尽的注释,如果你感兴趣,也可以查阅 API 文档中的相关解析。 79 | 80 | ## InventoryEngine 81 | 82 | 在 Corgi Engine 的 v4.0 版本中有介绍到,Inventory Engine 是 `More Mountains` 完整的装备解决方案。除去这个(通常是)单独的资源,你还是可以使用 Corgi Engine 的专用 Demo 和物件。 83 | 84 | ## UnityStandardAssets 85 | 86 | 在某些 Demo 关卡,Corgi Engine 基于 Unity 标准资源中的 Cinematic Effect 实现了一些火花特效,这些**纯粹出于美化而且是可选的**。值得一提的是它们在某些设备上可能会损害性能,所以请按需安全地移除它们。 87 | 88 | ------- 89 | 90 | [本页面的 Corgi Engine 官方英文原版链接](http://corgi-engine-docs.moremountains.com/contents-of-the-asset.html) 91 | 92 | # Contents of the Asset 93 | 94 | > **Summary:** This page describes the contents of the asset. 95 | 96 | ## Introduction 97 | 98 | When you import the asset into your project, you’ll get a CorgiEngine folder, containing four subfolders. I recommend leaving that folder as it is, and **not modifying its content**. Instead, create a dedicated folder for your game’s assets, and if you need to modify code, just extend the Corgi Engine’s class into one of yours. If you want to know more about that, look at the [“Extending the Corgi Engine” section](http://corgi-engine-docs.moremountains.com/creating-your-own-game.html). Here’s a rundown of the contents of these four folders, and of the general folder structure. 99 | 100 | ![The contents of the asset](media/15004513818871.jpg) 101 | 102 | ## Common 103 | 104 | As the name implies, Common contains all the scripts and visual assets necessary for the mobile controls to work. You’ll want to keep that folder in your game. The main structure is made of the following folders : 105 | 106 | * **Animations** : all the common animations (mostly GUI stuff). 107 | * **Fonts** : the fonts used in the various GUI screens are stored there. 108 | * **Materials** : a few materials used across most demos, but not specific to any. 109 | * **Prefabs** : all the prefabs used throughout the various demo levels. 110 | * **Resources** : the prefabs that are instantiated via code directly. 111 | * **Scripts** : the “core” of the engine, and where most of its value resides. We’ll go over the details in a minute. 112 | * **Sprites** : all the sprites common to all demos. Again, mostly GUI stuff. 113 | 114 | The Scripts folder is where all the engine’s scripts are stored. Each demo may have one or more specific scripts, but otherwise it’s somewhere in there. Note that the MMTools scripts are located in another of the root folders, for easier maintenance and better logic separation. Here are the main Scripts folders : 115 | 116 | * **Agents** : here you’ll find all the scripts that make the characters move and act. From the raycast collision controller, character abilities, to AI scripts and weapons. 117 | * **Camera** : various camera related scripts, parallax stuff, etc. 118 | * **Checkpoints** : Most of the scripts related to the “game cycle” (spawn, end of level, etc.) is in this folder. 119 | * **Environment** : From falling blocks to teleporters, you’ll find in this folder most of the scripts that handle the level’s objects. 120 | * **GUI** : As the name implies, here you’ll find everything GUI related : dialogue boxes, pause screens, etc. 121 | * **Items** : Coins or pickable weapons can be found in this folder. 122 | * **Managers** : All managers (“super” classes, often singletons, that handle global stuff) are in this. 123 | * **Sound** : All sound specific scripts go in there. 124 | 125 | ## Demos 126 | 127 | The Demos folder contains all the demos included in the engine. They’re grouped by “universe”, each universe may contain one or more scene. Usually each demo aims at showcasing **one or more particular aspects of the engine**, or how you can achieve different results with just a few tweaks and different art. 128 | 129 | ### Brobro 130 | 131 | * **BrobroLevel** : A completely destructible level inspired by Free Lives’ Broforce. 132 | 133 | ### Corgi 2D 134 | 135 | * **Lava** : a hot level. 136 | * **Mesa1** : the very first level created for this engine. Includes a little bit of everything. 137 | * **Mesa2** : a variation on a classic theme. 138 | * **Mountains** : a mountain based scene, complete with wind and falling leaves. 139 | * **Sandbox** : a scene mostly used to quickly test stuff. Don’t look at it too hard. It’s got issues. 140 | 141 | ### Corgi 3D 142 | 143 | * **3D Level** : a very basic 3D level, filled with ready-to-use prototyping blocks. 144 | 145 | ### Level Selection 146 | 147 | * **LevelSelection** : an example of an implementation of level selection, complete with path controls. 148 | 149 | ### Minimal 150 | 151 | * **FeaturesPlatforms** : an interactive demo of all the platform related features of the asset. 152 | * **MinimalLevel** : the minimal requirements for a singleplayer scene. 153 | * **Minimal4Players** : the minimal requirements for a local multiplayer scene. 154 | 155 | ### Pixel 156 | 157 | * **PixelLevel** : a pixelated tile based level. 158 | 159 | ### Super Hipster Bros 160 | 161 | * **HipsterLevel** : a classic, retro, sidescrolling platformer, inspired by Super Mario Bros. 162 | 163 | ### The Hunt 164 | 165 | * **TheHunt** : a multiplayer, 3D, 4vs4 level, inspired by Smash Bros and Towerfall and stuff like that. 166 | 167 | ## MMTools 168 | 169 | The MMTools are helpers and small classes used throughout all More Mountains assets. Some of them may not be used in the Corgi Engine, but I’d advise **against removing them**. The unused ones won’t make your build heavier, so it’s just safer and simpler to keep them. This documentation doesn’t cover them in details, but they’re all commented, and explained in the API documentation if you’re interested. 170 | 171 | ## InventoryEngine 172 | 173 | Introduced in v4.0 of the Corgi Engine, the InventoryEngine is More Mountains’ complete inventory solution. In addition to that (usually) separate asset, you also get ready to use items and dedicated Corgi Engine specific demos. 174 | 175 | ## UnityStandardAssets 176 | 177 | The Corgi Engine relies on Unity’s Standard Assets’ Cinematic Effects to give a little sparkle to some of the demo levels. These are **purely cosmetic, and optional**. Note that they’ll also harm performance on certain devices. Feel free to remove them safely. 178 | 179 | ------- 180 | 181 | 182 | -------------------------------------------------------------------------------- /1.Overview/1-3.最小场景要求.md: -------------------------------------------------------------------------------- 1 | # 最小场景要求 2 | 3 | > 这个页面描述了为了让你的引擎跑起来,你的场景中至少需要包含的所有 GameObject。 4 | 5 | ## 简介 6 | 7 | 与大多数 Unity 项目类似,在 Corgi Engine 中,一个关卡由一个场景组成(a level is made of a Scene)。你可以往场景中添加很多东西(梯子,敌人等等),它可以很庞大,也可以很精简,一切都取决于你。但无论你想做什么,引擎都需要一些基本的组件才能够正常运作。Corgi Engine 包含了两个最小场景的示例,这些场景展示了标准情况下的最小组件要求。严格来说,你甚至还可以从中移除更多东西,但当前它们已经是良好的初始场景了。 8 | 9 | ## 最小单玩家场景 10 | 11 | ![最小单玩家场景包含的内容](media/15004623902260.jpg) 12 | 13 | 最小单玩家场景文件在 `CorgiEngine/Demos/Minimal/MinimalLevel` 路径下,它是任何单玩家关卡的一个很好的起点。以下列举了它所包含的对象: 14 | 15 | * **GameManagers**:一个包含了 `GameManager` 和 `SoundManager` 脚本的 GameObject。`GameManager` 脚本负责处理玩家得分、时间尺度(Time Scale)、暂停等,通常是一些全局高层的东西。顾名思义,`SoundManager` 负责声音的播放。请注意,这个 GameObject 并非强制要求的(也就是说游戏还是可以启动),你可以移除它,如果你不想使用这些管理类的话。 16 | 17 | * **UICamera**:同样是可选的,`UICamera` 是一个独立的摄像机,包含一个 `Canvas` 对象,以及各种 GUI 元素,例如血条、分数之类的东西,你可以将你的 GUI 元素放置在这里。 18 | 19 | * **LevelManager**:`LevelManager` 定义了所有游戏角色所需的关卡界限,同时处理玩家角色(Playable Characters)的实例化,以及所有出生/重生机制(当角色死亡时触发)。对于包含有游戏角色的场景来说,这个 GameObject 是强制要求的(不过例如启动界面之类的就不需要)。请确保在 `LevelManager` 的 Inspector 视窗中选择了一个玩家角色。 20 | 21 | * **Camera**:通常需要一个包含 `CameraController` 脚本的摄像机,这个组件被引擎用来追踪你的角色,但你可以把它替换成任何你想要的摄像头。 22 | 23 | * **Level**:场景中至少需要一个平台供角色站立跳跃。 24 | 25 | ## 最小多玩家场景 26 | 27 | ![最小多玩家场景包含的内容](media/15004625009334.jpg) 28 | 29 | 最小多玩家场景文件在 `CorgiEngine/Demos/Minimal/Minimal4Players` 路径下,它是任何多玩家关卡的一个很好的起点。以下列举了它所包含的对象: 30 | 31 | * **InputManagers**:在多玩家场景中,每个玩家角色都需要一个 `InputManager` 组件。 32 | 33 | * **GameManagers**:与单玩家场景中的一样。 34 | 35 | * **MultiplayerUICamera**:一个 `UICamera` 对象,并且它的 `UI Canvas` 组件设置了多玩家专用的布局,它包含了 4 个血条、喷气能量条和玩家名字。当然,你可以(也应该)自定义这些元素来适应特定的游戏主题。 36 | 37 | * **MultiplayerLevelManager**:这个组件负责处理多人游戏的生命周期,处理诸如有一个玩家死亡、只剩一个玩家存活、关卡是否应该重启这样的东西。在大多数情况下,你需要创建自己的 `MultiplayerLevelManager` 来实现自定义的规则逻辑。 38 | 39 | * **MultiplayerCamera**:一个实现多玩家追踪的摄像机,与游戏 `Smash Bros` 中的类似。 40 | 41 | * **Level**:构成关卡场景的平台和物品对象。 42 | 43 | ------- 44 | 45 | [本页面的 Corgi Engine 官方英文原版链接](http://corgi-engine-docs.moremountains.com/minimal-scene-requirements.html) 46 | 47 | # Minimal Scene Requirements 48 | 49 | > **Summary:** This page covers all the gameobjects you need in your scene for the engine to work. 50 | 51 | ## Introduction 52 | 53 | In the Corgi Engine, like in most Unity projects, a level is made of a Scene. You can add lots of stuff to your scene (ladders, enemies, etc.), it can be huge, or very small, **it’s really up to you**. But whatever you do, there are a few elements required for the engine to work. The engine includes two examples of “minimal” scenes. These scenes show the “standard conditions” minimal elements. Technically, you could even remove more stuff, but they act as a good **starting point**. 54 | 55 | ## Minimal Singleplayer Scene 56 | 57 | ![The contents of the singleplayer minimal scene](media/15004623902260.jpg) 58 | 59 | The minimal singleplayer scene can be found in Demos/Minimal/MinimalLevel. It’s a good starting point for any singleplayer level. Here’s what it contains : 60 | 61 | * **GameManagers** : a gameobject containing a GameManager and a SoundManager. The GameManager will handle points, time scale, pause, and generally high level stuff. As its name implies, the SoundManager is in charge of sound playback. Note that this object is not mandatory (meaning the game will still start), you can remove it if you don’t want to use these managers. 62 | * **UICamera** : also optional, the UI camera is a separate camera, complete with a canvas and various GUI stuff like health bar, score, and stuff like that. That’s where you’ll want to put all your GUI elements. 63 | * **LevelManager** : The LevelManager defines the level bounds used by all characters, it also handles the instantiation of the playable character(s), and all the spawn/respawn mechanism (what happens when you die). This one is mandatory for all scenes that contain Characters (you don’t need one for a splash screen for example). Make sure you select a playable Character from the LevelManager’s inspector. 64 | * **Camera** : Usually you’ll want to have a camera with a CameraController, which is the component used by the engine to track your character, but you can replace it with any camera you want. 65 | * **Level** : You’ll need at least a platform for your character to stand on. 66 | 67 | ## Minimal Multiplayer Scene 68 | 69 | ![The contents of the multiplayer minimal scene](media/15004625009334.jpg) 70 | 71 | The minimal singleplayer scene can be found in Demos/Minimal/Minimal4Players. It’s a good starting point for any multiplayer level. Here’s what it contains : 72 | 73 | * **InputManagers** : an InputManager per player is needed for multiplayer scenes. 74 | * **GameManagers** : Same thing as in a singleplayer level. 75 | * **MultiplayerUICamera** : a UICamera, and its UI Canvas, dedicated to multiplayer layout. It contains 4 healthbars and jetpackbars, and the player’s names. Of course you can (and should) customize that to fit your particular game and theme. 76 | * **MultiplayerLevelManager** : this component handles the life cycle of the multiplayer game. What happens when a player dies, have we only one player left standing, should the level restart, stuff like that. In most cases you’ll want to create your own multiplayer level manager, to implement your own rules. 77 | * **MultiplayerCamera** : a camera that allows for the tracking of multiple players, similar to what you’d find in games like Smash Bros. 78 | * **Level** : the platforms and items that make your level 79 | 80 | ------- 81 | 82 | 83 | -------------------------------------------------------------------------------- /1.Overview/1-4.FAQ.md: -------------------------------------------------------------------------------- 1 | # 常见问题 2 | 3 | > 这个页面包括了一些最常见的问题,请在联系技术支持之前阅读这些内容。 4 | 5 | ------- 6 | 7 | [本页面的 Corgi Engine 官方英文原版链接](http://corgi-engine-docs.moremountains.com/faq.html) 8 | 9 | # Frequently Asked Questions 10 | 11 | > **Summary:** This page covers the most frequently asked questions. Please read these before contacting support. 12 | 13 | ## FAQ 14 | 15 | * **Is there a tutorial or something ?** 16 | 17 | Well you’re reading the documentation right now so it’s a good start. There are also video tutorials [over on YouTube](https://www.youtube.com/watch?v=pbosUfdfWWc). Furthermore, the asset includes a [complete documentation](http://corgi-engine-docs.moremountains.com/) of all the classes of the Corgi Engine. Plus, the code is heavily commented, so understanding it shouldn’t be too hard. 18 | 19 | * **When will you release the update X or feature Y ?** 20 | 21 | When it’s done. 22 | 23 | * **Can you develop that feature that I really need ?** 24 | 25 | **I don’t take requests, paid or not.** You can of course express your interest in a new feature, but in the end I’m the one who decides what I do with the Engine. My goal is to create a strong yet generic basis for a platformer game. If your request is very specific (like a grappling hook or a portal gun - although I reckon that’d be pretty fun), it probably won’t make it. 26 | 27 | * **What’s the awesome music I can hear in the demo levels ?** 28 | 29 | That would be The Victory of Buckets and Doors and There is no Way, by [Uniform Motion](http://www.uniformmotion.net/), which is probably the best band ever, check them out. 30 | 31 | * **What are the minimum prefabs I need to start a level from scratch ?** 32 | 33 | I get that one a lot actually, so I’ve included a “minimal demo” scene in the assets. It contains, as the name implies, the only assets you need to get started. 34 | 35 | * **I downloaded the asset and it’s not working / I don’t have all the files** 36 | 37 | First, start by making sure you’re running the **latest current version of Unity**. Then try downloading the asset again. 38 | 39 | * **The asset is not working with my gamepad!** 40 | 41 | Controls have been set up for keyboard and xbox pc gamepad. Obviously including support for every gamepad/configuration would be impossible, so I just went with the most common conf. Luckily for you, this has nothing to do with the Corgi Engine, and is really a **general Unity matter**. You should be able to find the right conf by googling it or on the Unity forums. Key binding is set up in the engine like in any other Unity project, via Edit > Project Settings > Input. 42 | 43 | * **The asset is crashing on my device!** 44 | 45 | My guess is it’s a performance issue. 46 | 47 | * does it work in the editor ? If it works in the editor, your device may not be powerful enough to run it. 48 | 49 | * does the MinimalLevel scene alone work on your tablet ? If it works, your device may not be powerful enough to run larger levels. 50 | 51 | **This is a general Unity performance problem**, nothing really specific to the engine I’m afraid. If you absolutely want to run it on that device, aim for smaller assets, less enemies, stuff like that. Mesa1 level for example does include some very large assets (4096x4096 backgrounds for example), clearly not fit for slow devices. Oh and you may want to disable camera effects like blur or depth of field, they’re not very mobile friendly. 52 | 53 | * **Where can I change the input settings ? I don’t like pressing A to jump!** 54 | 55 | Like in any good Unity project, the settings are defined in the [Input Manager](https://docs.unity3d.com/Manual/class-InputManager.html). You can access it via Edit > Project Settings > Input. 56 | 57 | * **How can I add my own mobile controls, or the ones from that asset I bought ?** 58 | 59 | If you look at the current mobile controls, you’ll see that each button has its various events (button pressed, released, etc…) bound to methods in the InputManager class. As you’ll see, this class is full of simple methods like Jump(), RunStart(), etc… It acts like a remote for your character. If you want to replace the mobile controls included in the asset with your own, you just have to remove these, and bind your new buttons/controls to these InputManager methods. 60 | 61 | * **What programming language is the asset written in ?** 62 | 63 | C# 64 | 65 | * **Am I allowed to use the code in more than one project ? Can I modify the source code or the visual assets ?** 66 | 67 | Once you’ve bought the asset you can do **anything you want with the source code**, you’re just **not allowed to redistribute it** (offer it for free, sell it anywhere, etc). 68 | 69 | You can of course use that code to create commercial games and sell these, just **don’t redistribute the contents of the asset**. And yes you can modify it, use it in more than one project. It’s yours now! 70 | 71 | * **Can I just compile the asset and upload it without changing anything to Google Play, Steam Greenlight or the Apple Store ?** 72 | 73 | Well no you can’t. Although this sounds like a genius masterplan, I’m afraid it’s not legal. Be imaginative, **create your own game**. Of course you can use the asset as a basis, that’s what it’s for. 74 | 75 | * **I really love the asset, is there any way I can help ?** 76 | 77 | Of course, [you could put a nice note or review on the asset on the Asset Store](https://www.assetstore.unity3d.com/#!/content/26617). 78 | 79 | * **Who are you? What is More Mountains?** 80 | 81 | My name is Renaud Forestié, I’m a French game designer from Bordeaux. I also do [illustration](http://reuno.net/) work and **I’m available for freelance work**. I founded [More Mountains](http://moremountains.com/), my creative studio, in 2015, after 15 years spent as a freelance art director and game designer. 82 | 83 | * **Got another question ?** 84 | 85 | Are you sure it’s not answered above ? Then you can [join the discussion](https://forum.unity3d.com/threads/released-corgi-engine-complete-2d-2-5d-platformer-new-v4-0-inventory-ammo-reload.286289/) on the Unity Forum thread, or send me a message using the [support email on the asset’s page](https://www.assetstore.unity3d.com/en/#!/content/26617). Or you can use the form [at the bottom of this page](http://corgi-engine.moremountains.com/). It’s up to you :) 86 | 87 | ------- 88 | 89 | 90 | -------------------------------------------------------------------------------- /1.Overview/media/15004513818871.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Caizc/corgi-engine-docs/21cae88dd5f5430837a23e21afa0b741ec556ce8/1.Overview/media/15004513818871.jpg -------------------------------------------------------------------------------- /1.Overview/media/15004623902260.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Caizc/corgi-engine-docs/21cae88dd5f5430837a23e21afa0b741ec556ce8/1.Overview/media/15004623902260.jpg -------------------------------------------------------------------------------- /1.Overview/media/15004625009334.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Caizc/corgi-engine-docs/21cae88dd5f5430837a23e21afa0b741ec556ce8/1.Overview/media/15004625009334.jpg -------------------------------------------------------------------------------- /1.Overview/media/15015989276655.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Caizc/corgi-engine-docs/21cae88dd5f5430837a23e21afa0b741ec556ce8/1.Overview/media/15015989276655.jpg -------------------------------------------------------------------------------- /2.Agents/2-1.如何创建角色.md: -------------------------------------------------------------------------------- 1 | # 如何创建角色 2 | 3 | > 这个页面说明了在 Corgi Engine 中角色是如何运作的,以及如何创建你自己的角色。 4 | 5 | ## 简介 6 | 7 | ![一个典型的玩家角色,包含了碰撞检测射线和武器炮弹生成原点](media/15005163011188.jpg) 8 | 9 | Corgi Engine 用 **Agent** 这一术语来描述任何类型的角色,包括玩家角色、敌人和 NPC 等等。为了让这些 Agent 正常运作,需要一些[核心的类(core classes)](https://github.com/Caizc/corgi-engine-docs/blob/master/2.Agents/2-2.%E8%A7%92%E8%89%B2%E7%B1%BB.md),如果你想要扩展和创建更多的角色能力,你必须熟悉这些类。 10 | 11 | 同时,这个页面旨在介绍一些**基本概念**,并且帮助你快速地创建角色(基于玩家控制或者 AI)。请注意,这个页面提到的所有信息(同时对整个文档而言)**只对 Corgi Engine v3.0 或以上版本有效**。 12 | 13 | ## 基本概念 14 | 15 | ![在角色对象中一般都会看到这样一堆组件](media/15005175125428.jpg) 16 | 17 | 关于这些角色对象中必不可少的组件,在[另外一个页面](https://github.com/Caizc/corgi-engine-docs/blob/master/2.Agents/2-2.%E8%A7%92%E8%89%B2%E7%B1%BB.md)中会详细探讨,但在这里先做一下**简要说明**。在 Corgi Engine 中,一个 Agent 通常包含这些组件: 18 | 19 | * **BoxCollider2D**:碰撞器(collider)的尺寸用来检测碰撞,同时确定 Agent 在场景中的位置 20 | * **RigidBody2D**:只用来提供与标准物理引擎的基本交互作用(这个组件完全是可选的) 21 | * **CorgiController**:CorgiController 基本上是 Unity 标准物理引擎的替代品,它负责碰撞检测、基础移动(左/右移动)、重力等,它提供了更为紧凑的运动感。不过显然,这个组件不是被设计来作为物理引擎的(虽然它具备了某些物理引擎的功能特性)。 22 | * **Character**:这个是链接其他角色类的核心类,虽说它自身并没有实现太多功能,但确实扮演着核心的作用。在这里你可以定义角色是玩家控制的还是 AI 控制的,以及它是否应该翻转、是否基于模型(model based)等等。同时它也控制运行状态下所有的角色能力。 23 | * **Health**:并非必不可少的组件,但在大部分游戏中,你的 Agent 应该可以被杀死。Health 组件处理伤害、加血/掉血以及死亡。 24 | * **Character Abilities**:至此,前面提到的组件已经提供了大量的能力,但并不真正的显式实现功能,而是交由 `Character Abilities` 组件来实现。Corgi Engine 资源打包了超过 15 种角色能力,从简单的水平移动到复杂的武器使用。它们都是可选的,随你挑选。你当然也可以轻松地创造自定义的能力来创建自己的游戏。 25 | 26 | ## 如何创建一个 Agent? 27 | 28 | 在 Corgi Engine 中有**很多种方式**可以创建一个玩家或 AI 角色,在此我们会涵盖 **3 种推荐的方式**。请注意,如果你更习惯于用别的可以奏效的方式,也是没问题的。 29 | 30 | ![大部分 Corgi Engine 组件都可以通过 AddComponent 菜单来添加(不仅是 Character)](media/15005223318847.jpg) 31 | 32 | ### 自动创建 33 | 34 | 在 Corgi Engine v3.0 版本中介绍过,**Autobuild Character** 功能帮助你在几秒钟之内创建一个新的角色。不过需要注意的是,在完成了初始化设置之后,你还需要设置动画等,但这已经比以往的方式快捷得多了。 35 | 36 | ![「自动创建」按钮](media/15005234653108.jpg) 37 | 38 | 以下阐述了具体步骤: 39 | 40 | 1. 在满足了[最小要求](https://github.com/Caizc/corgi-engine-docs/blob/master/1.Overview/1-3.%E6%9C%80%E5%B0%8F%E5%9C%BA%E6%99%AF%E8%A6%81%E6%B1%82.md)的场景中,添加一个 GameObject。 41 | 2. 首先需要从一个 **GameObject** 出发,无论是新建一个空的 GameObject,使用一个现成的 Prefab,拖拽一个 Sprite 到场景中,或者使用 Model 都可以。 42 | 3. 为 GameObject 添加一个 **Character 组件**。 43 | 4. 在 Character 的 Inspector 视窗底部,点击 **Autobuild Player Character** 或者 **Autobuild AI Character**,这取决于你想要创建的角色类型。 44 | 5. **点击 Play**。如果你创建的是一个 AI 角色,那它现在应该正在场景中走来走去;如果是一个玩家角色,尝试控制它到处走走。恭喜你,你已经创建了一个角色! 45 | 6. 现在你可以调整各种设置,**移除这个角色身上那些你不感兴趣的能力**,或者添加[动画](https://github.com/Caizc/corgi-engine-docs/blob/master/2.Agents/2-4.%E5%8A%A8%E7%94%BB.md)等等。你也可以让它保持现在的样子,**继续制作你的游戏和关卡原型**。 46 | 47 | ### 拷贝 48 | 49 | 另一个创建 Agent 的快捷方式是,**在引擎提供的 Demo 中找一个,作为你的蓝本**。 50 | 51 | ![拷贝一个现成的 Prefab](media/15005318728538.jpg) 52 | 53 | 操作步骤也相当简单: 54 | 55 | 1. 在 Demo 中**找一个你喜欢的 Agent**。 56 | 2. **找到它的 Prefab 的所在位置**(在 Scene 视窗中选中该 Agent,然后在它的 Inspector 视窗的最右上方,在 Prefab 的名字和标签下方有一个 Select 按钮,点击按钮定位到 Prefab 的所在位置)。 57 | 3. **复制这个 Prefab**(Ctrl + D 或者 Cmd + D) 58 | 4. **重命名它**为你的角色的名字 59 | 5. **按照你想要的效果修改它**。也许你只是想替换一些设置,或许修改 Sprite 和动画,从这里开始就都取决于你自己了。 60 | 61 | ### 组件方式 62 | 63 | 你也可以**从头开始创建一个角色**,虽然会花费更长时间,但又何妨呢? 64 | 65 | 1. 首先创建一个**空的 GameObject**。理想情况下,你需要将 Character 部分和视觉资源部分分开来。最好的结构层次可能是将 CorgiController/BoxCollider2D/Character/Abilities 这些组件放置在顶层,然后将视觉资源部分(Sprite、Model 等)嵌套在下一层。 66 | 2. 在 Inspector 视窗的顶部,**设置它的 Tag 为 Player**,如果它是一个玩家角色的话,如果不是那就设置成相应别的标签。Layer 也是同样道理。 67 | 3. 在最顶层的 GameObject 中添加一个 **BoxCollider2D** 组件。调整它的 Size 参数来匹配你的 Sprite/Model 的尺寸。 68 | 4. 添加一个 **CorgiController** 组件。设置各个参数(如果需要帮助,请参照角色类的文档),并且确保设置了各种 Collision Masks 参数(Playform,One Way Platform 等)。 69 | 5. 添加一个 **Character** 组件。检查各个设置以确保它们如你所要。 70 | 6. 添加你想要的角色能力(**Character Abilities**)。最好的方式是通过 Inspector 视窗底部的 AddComponent 按钮来导航并添加这些组件。 71 | 7. 视情况需要,添加 **RigidBody2D/Health/HealthBar** 组件等。 72 | 73 | ------- 74 | 75 | [本页面的 Corgi Engine 官方英文原版链接](http://corgi-engine-docs.moremountains.com/how-to-create-character.html) 76 | 77 | # How to create your own character? 78 | 79 | > **Summary:** This page explains how characters function in the Corgi Engine and how to build your own. 80 | 81 | ## Introduction 82 | 83 | ![A typical playable character, with its collision raycasts and weapon's projectile's spawn origin point](media/15005163011188.jpg) 84 | 85 | “**Agents**” in the CorgiEngine is a term used to describe any kind of characters, whether they’re playable characters, or enemies, NPCs, etc. There are a few [core classes](http://corgi-engine-docs.moremountains.com/character-classes.html) that make these agents work, and that you’ll need to get familiar with if you want to expand and create more character abilities for example. 86 | 87 | In the meantime, this page aims at presenting the **basic concepts** and allowing you to quickly create your own character (player controlled or AI based). Note that all the information on this page (and on that whole documentation for that matter) **only works for Corgi Engine v3.0 or more**. 88 | 89 | ## Base concepts 90 | 91 | ![An example of the stack of components commonly found on Characters](media/15005175125428.jpg) 92 | 93 | [This page](http://corgi-engine-docs.moremountains.com/character-classes.html) goes into more details about the mandatory components of a Character, but here’s a **brief rundown**. An agent in the Corgi Engine usually has these components : 94 | 95 | * **BoxCollider2D** : the collider whose size is used to determine collisions and where in the world the agent is 96 | * **RigidBody2D** : only used to provide basic interactions with standard physics (completely optional) 97 | * **CorgiController** : responsible for collision detection, basic movement (move left / right), gravity, the CorgiController is basically the replacement for Unity’s standard physics. It provides tighter movement and feel. Obviously, and by design, this is not a physics engine. 98 | * **Character** : This is the central class that will link all the others. It doesn’t do much in itself, but really acts as a central point. That’s where you define if the player is an AI or player-controlled, how it should flip, if it’s model based, stuff like that. It’s also the class that will control all character abilities at runtime. 99 | * **Health** : Not mandatory, but in most games your agents will be able to die. The Health component handles damage, health gain/loss, and eventually death. 100 | * **Character Abilities** : So far all the previous components offer lots of possibilities, but don’t really “do” anything visible. That’s what Character Abilities are for. The asset comes packed with more than 15 abilities, from simple ones like HorizontalMovement to more complex ones like weapon handling. They’re all optional, and you can pick whichever you want. You can of course also easily create your own abilities to build your very own game. 101 | 102 | ## How do I create an Agent ? 103 | 104 | There are **many ways** you can create a playable or AI character in the Corgi Engine. Here we’ll cover **the 3 recommended ones**. Note that if you prefer doing differently, as long as it works for you, it’s all fine. 105 | 106 | ![You can use the AddComponent menu to add most Corgi Engine's components (not just Character ones)](media/15005223318847.jpg) 107 | 108 | ### Automatic Creation 109 | 110 | Introduced in Corgi Engine v3.0, the “**Autobuild Character**” feature allows you to create a new character in a few seconds. Note that after that initial setup you’ll still have to setup animations and all that, but it’s a lot faster than it used to be :) 111 | 112 | Here’s how to proceed : 113 | 114 | ![The Autobuild buttons](media/15005234653108.jpg) 115 | 116 | 1. In a scene that meets the [minimal requirements](http://corgi-engine-docs.moremountains.com/minimal-scene-requirements), put a GameObject. 117 | 2. You’ll need a **GameObject** to start with. You can create an empty one, take an existing prefab, drag a Sprite on the scene, or a model, it’s up to you. 118 | 3. Add a **Character component** to that GameObject 119 | 4. At the bottom of the Character’s inspector, press either “**Autobuild Player Character**” or “**Autobuild AI Character**”, depending on what kind of character you’re after. 120 | 5. **Press play**. If you went for an AI character, it should be walking around the scene. If it’s a player character, try moving around. You’ve created a Character! :tada: 121 | 6. You can now fine tune the various settings, **remove the abilities you’re not interested in** for this character, add [animations](http://corgi-engine-docs.moremountains.com/animations), etc. Or you can leave it like that and **start prototyping** the rest of your game and levels. 122 | 123 | ### Copy 124 | 125 | Another fast way to create an agent is to find one you like in the demos, and **create yours from that**. The process for that is quite simple : 126 | 127 | ![Copying an existing prefab](media/15005318728538.jpg) 128 | 129 | 1. **Find an agent you like** in one of the demos. 130 | 2. **Locate its prefab** (select the Agent in Scene View, and in its inspector, at the very top right under the prefab’s name and tag there’s a Select button) 131 | 3. **Duplicate the prefab** (cmd + D) 132 | 4. **Rename it** to whatever you want your Character to be called 133 | 5. **Make the changes you want**. Maybe you’ll just want to replace some settings, maybe you’ll want to change the sprite and animations. It’s up to you from there. 134 | 135 | ### Components approach 136 | 137 | You can also **create a Character from scratch**. It’s longer but why not? 138 | 139 | 1. Start with an **empty gameobject**. Ideally you’ll want to separate the Character part from the visual part. The best possible hierarchy has the CorgiController/BoxCollider2D/Character/Abilities on the top level, and then nests the visual parts (sprite, model, etc). 140 | 2. At the top of the inspector, **set the tag to Player** if it’s a player character, or to anything you prefer if it’s not. Same thing for the layer. 141 | 3. On your top level object, add a **BoxCollider2D**. Adjust its size to match your sprite/model dimensions. 142 | 4. Add a **CorgiController** component. Set the various settings (see the class documentation if you need help with that), and make sure to set the various collision masks (platforms, one ways, etc) 143 | 5. Add a **Character** component. Check the various settings to make sure they’re ok with you. 144 | 6. Add the **Character Abilities** you want (it’s best to use the AddComponent button at the bottom of the inspector for that, and navigate there) 145 | 7. Optionnally, add a **RigidBody2D**, a **Health** component, a **HealthBar** component, etc. 146 | 147 | ------- 148 | 149 | 150 | 151 | -------------------------------------------------------------------------------- /2.Agents/2-2.角色类.md: -------------------------------------------------------------------------------- 1 | # Character 类 2 | 3 | > 这个页面全面讲解了 Character 类,它使用的状态机,以及如何使用它来创建你的角色。 4 | 5 | ## 层级结构和渲染器 6 | 7 | 有各种不同的组装角色对象的方式。首先,最简单的方式是**将所有组件都放置在同一个层级中**。 8 | 9 | ![一个将所有组件都放置在顶层的角色 Prefab 的例子](media/15005426541087.jpg) 10 | 11 | 另外一个方式是**使用嵌套结构**。在大部分 3D 模型或者使用像 Spine 这样的 2D 系统时,对象会拥有一个嵌套的层级结构。**这两种情况 Corgi Engine 都能够处理**,而不会对性能或行为产生任何影响。不过如果你决定使用嵌套的方式,则需要确保你在顶层角色对象的 Inspector 视窗中设置了 Animator 和 Model 参数。 12 | 13 | ![一个具有多层嵌套结构的角色示例(请留意角色的 Inspector 视窗中的 Character Model 是如何设置的)](media/15005429340996.jpg) 14 | 15 | 系统可以兼容各种不同类型的角色,**可以是 2D、3D 的,这取决于你**。Corgi Engine 资源中包括了典型的基于 Sprite 实现的,由 Spine 驱动的,以及 3D 模型实现的角色示例。 16 | 17 | ## Collider 与 RigidBody 18 | 19 | 为了让 Corgi Engine 能够正常运作,你的角色对象上需要有一个 BoxCollider2D 组件(即使它是一个 3D 模型)。Material 设置为空,IsTrigger 设置为 true(勾选之),还要设置 Size 来匹配角色的一部分(可能是整个 Sprite 的大小,但不一定是),以确保你的角色不会穿墙而过,最后把 Offset 的 X 值设置为 0。 20 | 21 | ![典型的 Box Collider 设置,碰撞盒不需要完全匹配 Sprite 的大小](media/15005439528429.jpg) 22 | 23 | 另外,如果你想要在 Corgi Controller 和正规的 Unity 物理引擎之间(试验性的)使用基础的物理交互,你可以往对象添加一个 RigidBody2D 组件。在这种情况下,参照下图的设置即可。 24 | 25 | ![一个角色的 RigidBody2D 组件设置示例](media/15005453914679.jpg) 26 | 27 | ## Corgi Controller 28 | 29 | 创建 Corgi Engine 是为了取代那些基于物理特性的平台游戏,它旨在提供**更为紧凑流畅的游戏体验**,更高效,而且比基于物理特性的实现更易于预测。为此,引擎实现了它自己的「物理特性」:碰撞检测、移动等等。需要明确的是,Corgi Engine 绝对不是一个物理引擎,**它与 Unity 正式的物理引擎没有可比性**,所以如果你计划用它来重新创造一个 Angry Birds,那是不可能成功的。 30 | 31 | Corgi Controller 是这个系统的核心,它是**每一个角色的基础**。它的主要功能是处理碰撞和基础移动。你可以给它添加或设置作用力来使它移动,一般是通过 Character Abilities 中的组件。 32 | 33 | Corgi Engine 通过发射射线(**Raycast**)来处理碰撞,当你运行游戏时,可以在 Scene 视窗中看到它们。它的工作原理从本质上讲就是 Controller 会向它的四周发射一些小射线,像微型激光一样。如果水平的激光击中了物体,那它可能碰到了墙壁或者斜坡。如果竖直的激光击中了物体,那它可能碰到了地面或者天花板。这取决于每一帧应用到对象上的作用力,也取决于射线有没有击中物体,Controller 负责在场景中移动对象,以及在对象穿墙而过之前让它停下来之类的事情。 34 | 35 | 作为角色的核心,Corgi Controller 在 Inspector 视窗中的设置相当重要。在那里你可以规定重力、各种速度参数,以及什么样的斜坡角色可以攀爬(以及攀爬的速度)等等。 36 | 37 | 你还需要规定 **Collision Masks**。Corgi Controller 支持与各种不同的平台交互: 38 | 39 | * 普通平台(regular platforms,Platforms) 40 | * 移动平台(moving platforms) 41 | * 单向平台(one way platforms,可以从它下方跳上去的平台) 42 | * 单向移动平台(one way moving platforms) 43 | 44 | 默认情况下,引擎已经配置好了一系列 Layer,每种类型的平台都分别对应一个:Plaforms,MovingPlatforms,OneWayPlatforms,MovingOneWayPlatforms。如果你增加了更多的 Layer,或者修改了这些 Layer,请确保将这些修改应用到你的角色上。 45 | 46 | 在 Inspector 视窗中你还可以自定义 Raycast,它们的数量事实上取决于你的角色的尺寸大小。调整 Raycast 参数的目标是使用尽可能少的射线(基于性能考虑,虽然现今射线的数量已经不是什么大问题了),但同时射线之间又必须足够紧密,以避免任何平台、敌人或者物品小于两条射线的间距(在这种情况下引擎是无法检测到的)。 47 | 48 | ## Character 关卡界限 49 | 50 | ![SuperHipsterBros Demo 的关卡界限](media/15005659657442.jpg) 51 | 52 | 任何一个关卡都有关卡界限(Level Bounds),可以在 LevelManager 组件中定义它。它是包围着上下左右的不可见线框(事实上在 Scene 视窗中是可见的,左上角写着 Level Bounds 的黄色线框就是它),它规定了**摄像机移动到哪里就会停下来**。通过这个组件,你可以决定当角色碰到边界时会发生什么(通常是无作用、受限制或者死亡)。 53 | 54 | ## Character 55 | 56 | Character 是链接其他类的核心类,虽然它本身并没有做太多事情,但确实起着**核心的作用**。在那里你定义了角色是 AI 控制还是玩家控制,什么时候应该翻转,是否基于模型实现等诸如此类的东西。同时它也是在运行状态下操纵 **Character Abilities** 的类。 57 | 58 | 它是一个非常核心的类,包含在引擎的 v3.0 版本更新中。从它的 Inspector 视窗中你可以定义很多东西。**如果你想创建一个玩家角色,那么 PlayerID 字段将非常重要。**它必须准确匹配到 InputManager 组件中的 PlayerID 字段(InputManager 利用它来得知控制哪个角色)。然后还有一些基本的设置项,例如 Sprite/Mesh 的初始化朝向等。如果 Animator 组件不是放置在角色层级结构的顶层的话,你还可以为它指定一个 Animator。Model 也同样如此(可以是 2D/3D,随你所愿)。 59 | 60 | ## Health 61 | 62 | Health 组件负责处理伤害、加血/掉血,以及死亡和重生。如果你的角色可以受到伤害,该组件则必不可少。有多种方式可以让你从初始血量中加/减血,它还会处理伤害和相关联的效果(视觉上的和碰撞方面等)。 63 | 64 | ## Character Abilities 65 | 66 | 角色的最后一部分(并不是说它不重要)是**角色能力(Character Abilities)**。Corgi Engine 资源中打包了超过 15 种能力,从简单的水平移动到复杂的武器使用。**它们都是可选的**,你可以根据需要选用。你当然也可以轻松地创造自定义的能力来创建你的游戏。可以通过查阅[这个页面](https://github.com/Caizc/corgi-engine-docs/blob/master/2.Agents/2-3.%E8%A7%92%E8%89%B2%E8%83%BD%E5%8A%9B.md)的内容来详细了解 Character Abilities。 67 | 68 | ------- 69 | 70 | [本页面的 Corgi Engine 官方英文原版链接](http://corgi-engine-docs.moremountains.com/character-classes.html) 71 | 72 | # Character Classes 73 | 74 | > **Summary:** This page goes over the Character class, the state machines it uses, and how to use it to create your character. 75 | 76 | ## Hierarchy and renderer 77 | 78 | There are different ways you can choose to assemble your character. The first, and most simple way is to **have everything on the same level** : 79 | 80 | ![An example of a Character prefab with everything at root level](media/15005426541087.jpg) 81 | 82 | The other is to **nest things**. Sometimes, like in most 3D models or when using 2D systems like Spine, is to have a nested hierarchy. **The engine can handle both**, without any impact on performance or behaviour. If you decide to go for the nested way, make sure you set the Animator and Model in the top level’s Character’s inspector. 83 | 84 | ![An example of a character with lots of nested parts. Note how the Character Model is set in the Character inspector](media/15005429340996.jpg) 85 | 86 | The system can work with any kind of character. **It can be 2D, 3D, it’s up to you, really**. The asset includes examples of classic, sprite based characters, Spine powered ones, and 3D models. 87 | 88 | ## Collider and RigidBody 89 | 90 | For the Corgi Controller to work, your character needs to have a BoxCollider2D component on it (even if it’s a 3D model). No material, IsTrigger set to true, the size that matches the parts of your character you don’t want to go through walls (possibly your whole sprite size, but not necessarily), and **an x offset set to zero**. 91 | 92 | ![Typical box collider settings. Your collider doesn't have to match the sprite's size](media/15005439528429.jpg) 93 | 94 | Additionnally, if you want to use the (experimental) basic physics interactions between the Corgi Controller and regular Unity physics, you can add a RigidBody2D to it. In this case, these settings should have you set up : 95 | 96 | ![An example of RigidBody2D settings for your character](media/15005453914679.jpg) 97 | 98 | ## Corgi Controller 99 | 100 | The Corgi Engine was created as an alternative to physics based platformers, aiming to provide a **tighter gameplay**, faster, and more predictable than physics. To do so, the engine implements its own “physics” : collision detection, movement, etc. Note that this is absolutely not a physics engine, this is **not compatible with regular Unity physics**, and if you’re planning on recreating Angry Birds, this will not do the trick. 101 | 102 | The Corgi Controller is at the heart of this system. It’s **the basis for each character**. Its main function is to handle collisions, and basic movement. You’ll be able to add or set forces to it, usually via Character Abilities, which will make it move. 103 | 104 | To handle collisions, the Corgi Controller uses **raycasts**, which you can see in the scene view when playing your game. Basically how it works is that the controller is casting small rays all around itself, like tiny lasers. If a horizontal laser hits something, then we’ve probably hit a wall, or a slope. If a vertical ray hits something, we’ve hit the ground or the ceiling. Depending on the forces being applied every single frame, and based on whether or not the raycasts hit something or not, the controller will move the object around the scene, or make it stop to prevent it from entering a wall for example. 105 | 106 | Being at the center of your character, the Corgi Controller’s inspector settings are quite important. There you’ll be able to define the gravity, various speed factors, what slopes the character can climb (and at what speed). 107 | 108 | You’ll also need to define **Collision Masks**. The Corgi Controller can interact with different types of platforms : 109 | 110 | * regular platforms (Platforms) 111 | * moving platforms 112 | * one way platforms (platforms you can jump on from underneath) 113 | * one way moving platforms 114 | 115 | By default, the engine comes configured with a number of layers, and there’s one for each of these platforms : Plaforms, MovingPlatforms, OneWayPlatforms, MovingOneWayPlatforms respectively. If you add more layers, or change these, make sure to replicate these changes on your characters. 116 | 117 | From the inspector you can also customize the raycasts. Their number really depends on the size of your character. What you’ll want to achieve is **as few raycasts as possible** (for performance reasons, even though raycasts are not really an issue these days), but with raycasts close enough to each other that no platform/enemy/whatever could fit between two raycasts (and in this case wouldn’t be detected by the engine). 118 | 119 | ## Character Level Bounds 120 | 121 | ![The SuperHipsterBros demo level's level bounds](media/15005659657442.jpg) 122 | 123 | Every level has level bounds, defined on the LevelManager. It’s the invisible line to the left/top/right/bottom (actually visible in the scene view, it’s that yellow box with “Level Bounds” written in the top left corner) that defines **where the camera will stop**. Using this component, you can decide what happens to your character when it meets these bounds (usually either nothing, constrain or death). 124 | 125 | ## Character 126 | 127 | This is the central class that will link all the others. It doesn’t do much in itself, but really acts as **a central point**. That’s where you define if the player is an AI or player-controlled, how it should flip, if it’s model based, stuff like that. It’s also the class that will control all **Character Abilities** at runtime. 128 | 129 | It’s a very central class, at the core of the v3.0 update. From its inspector you’ll be able to define a few things. **If it’s a player character, the PlayerID field is very important**. It has to match exactly the one in your InputManager (that’s how the InputManager knows what characters to control). Then there’s basic setup stuff, like what direction your sprite/mesh is facing initially. You can also specify an animator, if your animator isn’t on the top level of your hierarchy. Same thing for the Model (which can be 2D or 3D or whatever you prefer). 130 | 131 | ## Health 132 | 133 | The Health component handles damage, health gain/loss, and eventually death (and rebirth). It’s mandatory if your character can take damage. Its various methods will allow you to remove / add health points from the initial health value, it’ll handle damage and the associated effects (visual and in terms of collisions etc). 134 | 135 | ## Character Abilities 136 | 137 | The last (but not least important) part of your character will be the **Character Abilities**. The asset comes packed with more than 15 abilities, from simple ones like HorizontalMovement to more complex ones like weapon handling. **They’re all optional**, and you can pick whichever you want. You can of course also easily create your own abilities to build your very own game. [You can check this page](http://corgi-engine-docs.moremountains.com/character-abilities.html) for more details about Character Abilities. 138 | 139 | ------- 140 | 141 | 142 | 143 | -------------------------------------------------------------------------------- /2.Agents/2-3.角色能力.md: -------------------------------------------------------------------------------- 1 | # Character Abilities 2 | 3 | > 这个页面全面讲解了引擎中包含的各种角色能力(Character Abilities),以及如何创建自定义的能力。 4 | 5 | ## 一些常识 6 | 7 | Character Abilities 脚本赋予你的角色执行动作的能力,无论跳跃、跑动还是按一个按钮,**都是它在起作用**。在引擎之前的版本中,这些都是由一个单一的脚本—— `CharacterBehaviour` 负责处理的。当在一个小游戏中,你的角色只需要走动和跳跃时,当然不需要过度设计。但当有新的特性不断加入时,这里就会变得难以阅读和维护。相互独立的脚本**让系统更易于扩展**,同时让你更加轻松地创建自定义的能力。 8 | 9 | ## 标准能力 10 | 11 | * **Character HorizontalMovement(水平移动)**:这个组件负责处理基础的左右移动、摩擦力和地面检测。在它的 Inspector 视窗中你可以设定标准的移动速度、走路的速度,以及角色跳跃或下落后碰到地面时使用的效果。 12 | 13 | * **Character Crouch(潜行)**:这个组件负责处理蹲伏和爬行行为。在它的 Inspector 视窗中你可以设定潜行的速度,以及潜行时碰撞盒(Collider)需不需要调整大小(比如让角色能够爬进隧道)。如果需要,确保你设置了新的尺寸大小。 14 | 15 | * **Character Dash(冲撞)**:这个组件让你的角色可以冲撞。在它的 Inspector 视窗中你可以设定冲撞的距离、力度,以及一次冲撞结束后需要冷却多长时间才能开始下一次。 16 | 17 | * **Character Dive(俯冲)**:这个组件让你的角色可以俯冲(通过在空中按下冲撞键 + 向下方向键)。在它的 Inspector 视窗中你可以设定它引起的镜头抖动幅度,以及俯冲的速度有多快。 18 | 19 | * **Character Dangling(摇摆不定)**:如果角色添加了这个组件,当它面对地面上一个坑洞时就会采取摇摆不定的状态(看起来有些紧张犹豫的样子)。这个检测是通过发射射线(Raycast)完成的,在 Inspector 视窗中可以设置射线的原点和长度。 20 | 21 | * **Character Jump(跳跃)**:这个组件负责处理跳跃。在它的 Inspector 视窗中你可以设定以下参数:跳跃的高度,跳跃幅度是否和按下按键的时长成比例,滞空的最小时长(当玩家松开跳跃键之后,角色在下落之前能在空中停留多长时间),跳跃限制,接触地面之前角色可以连跳几次,以及当离开单向平台或移动平台时碰撞(Collision)应该失效多长时间。 22 | 23 | * **Character Run(跑动)**:当跑动键被按下时,这个组件让你的角色可以改变速度(在它的 Inspector 视窗中设定)。 24 | 25 | * **Character Jetpack(喷气背包)**:角色添加了这个组件之后就可以启用一个喷气背包然后在关卡中飞行。在它的 Inspector 视窗中你可以设定喷气时施加的力,使用的粒子系统特效,各种燃料信息,以及可选的当燃料加满时播放的音效。 26 | 27 | * **Character Look Up(向上看)**:这个组件让你的角色在按下向上键且站立在地面时做出往上看的动作。在这种情况下,摄像机向上移动的幅度是在 `CameraController` 的 Inspector 视窗中设定的。 28 | 29 | * **Character Grip(抓握)**:角色添加了这个组件之后就可以抓握关卡中带有 `Grip` 组件的物品了。 30 | 31 | * **Character Wall Clinging(附着在墙壁上)**:角色添加了这个组件之后就可以附着在墙壁上以减缓下落。在它的 Inspector 视窗中你可以设定减缓的系数(`close to 0` : 超级慢,`1` : 正常下落),以及偏差值(用来处理墙壁上的小凹陷)。 32 | 33 | * **Character Walljump(在墙壁上跳跃)**:这个组件让你的角色附着在墙壁上时可以执行一次额外的跳跃。这里你可以设定应用到这次跳跃的力度。 34 | 35 | * **Character Ladder(爬梯子)**:这个组件让你的角色可以爬梯子(带有 `Ladder` 组件的对象)。在它的 Inspector 窗口你可以设置角色爬梯子时的速度。 36 | 37 | * **Character Push(推)**:这个组件让你的角色可以推动那些可以推的物品。这个组件不是必不可少的,没有它你还是可以推动物体,但它让你可以在推东西的时候播放一个专门的推动动画,并且可以重载默认的推动参数。为了让推动动画生效,你需要为可推动的物品添加一个 `Pushable` 组件。 38 | 39 | * **Character Pause(暂停)**:让角色(以及控制它的玩家)可以通过按下暂停键来暂停游戏。 40 | 41 | * **Character SlopeOrientation(斜坡上调整面向)**:角色添加了这个组件之后,模型将垂直于它站立的斜坡坡面。你可以设定它转动的速度,允许的最大和最小角度,武器是否也要跟着转动,以及当它在空中时是否需要重置角度。 42 | 43 | * **Character Button Activation(激活按钮)**:这个组件让你的角色可以与通过按钮驱动的对象交互(对话区域、开关等)。这里没什么需要设置的。 44 | 45 | * **Character Handle Weapon(使用武器)**:这个组件让你的角色可以捡起并使用武器。武器的表现是在 `Weapon` 类中定义的,这个组件只是描述了「手」握武器的行为,而不是武器本身。 46 | 47 | ## 能力概述 48 | 49 | 所以一个能力(Ability)究竟都干了些啥?如果你对代码感兴趣,找到答案最简单的方式就是看一看 `CharacterAbility.cs` 类,所有能力都继承于它。我们来快速地过一遍其中的一些方法: 50 | 51 | * **Initialization**:顾名思义,在这里基类可以获得角色(Character)或者场景(Scene)的一部分,这些东西通常在子能力中会很有用,比如 `Camera`、`CorgiController` 组件、`InputManager` 等等。子能力一般都会通过这个方法来获取到其他组件和初始参数(连跳次数等)。 52 | 53 | * **Animation methods**:使用 `InitializeAnimatorParameters` 方法来注册动画参数,使用 `UpdateAnimator` 方法来更新它们。这里之所以分为两步完成,是为了避免每一帧都要检查各个参数是否存在,这最终会导致性能问题。 54 | 55 | * **HandleInput**:被每一个能力重载,用来检测相关的按键和坐标轴的状态。当某个按键被按下或松开时,这个方法将会调用 Ability 脚本中的另一个方法。 56 | 57 | * **Early/Process/Late Process ability**:这些方法在状态机的每一次更新(Update)中会被调用。 58 | 59 | * **Reset**:这个方法在角色死亡时会被调用,用来重置计数器之类的。 60 | 61 | * **Play/Stop Sfx**:这个方法用来触发能力的音效播放。默认情况下每个能力会有 3 个音效(在每个能力的 Inspector 视窗中设定):一个是能力启用时,一个是能力使用中,一个是能力结束时。你当然可以只使用一个甚至不使用这些音效。如果你创建了自定义的能力,你需要通过调用这些方法来触发音效播放。 62 | 63 | ## 状态机 64 | 65 | Character 组件负责**触发**各种能力(Abilities),这是通过使用**状态机(State Machine)**来实现的。状态机是一种设计模式,本质上它会保存一个当前状态和它的前置状态(如果你对此感到好奇,可以查看源代码或者 API 文档)。默认情况下,一个 Character 使用了两个状态机: 66 | 67 | * **MovementState**:在任何能力脚本中通过 `_movement` 属性访问,它代表了角色当前正在执行的行为。 68 | 69 | * **ConditionState**:在任何能力脚本中通过 `_condition` 属性访问,它保存了角色的当前状态(正常、死亡、暂停等)。 70 | 71 | 它运作的方式是,在一个场景开始时,Character 会初始化所有能力,随后在每一帧中调用它们的 `EarlyProcess`、`Process` 和 `LateProcess` 方法,最后在 `OnDeath` 中重置它们。其他状态机实现中通常只是在 `Update` 方法中调用当前状态下的能力,但这个状态机不是。这样做出于多个原因,但最主要是为了**让系统更易于扩展**,而不用重写所有东西或者修改已存在的类。这意味着每一种能力只负责处理它自身的输入,同时防止对它的方法的侵入(通过检测当前状态是否允许这种侵入,例如你不在地面上是不允许走动的)。引擎中包含的大部分能力都没有使用 `EarlyProcess` 或 `LateProcess`,但你如果需要的话可以利用起来。 72 | 73 | ## 创建自定义能力 74 | 75 | 创建自定义能力最简单的方式是扩展 `CharacterAbility` 类,就像当前引擎中所有能力实现的方式一样。有必要的话就重载方法(确保你在方法开头调用了基类中的方法)。为了测试新的能力,你只需要将它添加到已有的角色中,它就会自动添加到状态机中,然后像其他能力一样被处理。需要时刻留意的是与其他能力之间的交互,你可能想要扩展其他能力来防止或授权某些状态更改。另外,你的能力可能需要新的状态,你可以在 `CharacterState.cs` 中声明这些状态(在 `MovementStates` 枚举或 `CharacterConditions` 枚举中的任何位置增加,顺序无关)。 76 | 77 | 你可以看一下现有的那些角色能力类来获得启发,它们就是你正在尝试创建的,同时也是你最终成果的良好示范。这里有一个我用来创建它们的好模板,因为我发现这些方法就是我最经常重载的那些,确保将其中所有的 `TODO` 都替换成你的东西。 78 | 79 | ```csharp 80 | using UnityEngine; 81 | using System.Collections; 82 | using MoreMountains.Tools; 83 | 84 | namespace MoreMountains.CorgiEngine // you might want to use your own namespace here 85 | { 86 | /// 87 | /// TODO_DESCRIPTION 88 | /// 89 | [AddComponentMenu("Corgi Engine/Character/Abilities/TODO_REPLACE_WITH_ABILITY_NAME")] 90 | public class TODO_NEW_ABILITY_NAME : CharacterAbility 91 | { 92 | /// This method is only used to display a helpbox text 93 | /// at the beginning of the ability's inspector 94 | public override string HelpBoxText() { return "TODO_HELPBOX_TEXT."; } 95 | 96 | [Header("TODO_HEADER")] 97 | /// declare your parameters here 98 | public float randomParameter = 4f; 99 | public bool randomBool; 100 | 101 | /// 102 | /// Here you should initialize our parameters 103 | /// 104 | protected override void Initialization() 105 | { 106 | base.Initialization(); 107 | randomBool = false; 108 | } 109 | 110 | /// 111 | /// Every frame, we check if we're crouched and if we still should be 112 | /// 113 | public override void ProcessAbility() 114 | { 115 | base.ProcessAbility(); 116 | } 117 | 118 | /// 119 | /// Called at the start of the ability's cycle, this is where you'll check for input 120 | /// 121 | protected override void HandleInput() 122 | { 123 | // here as an example we check if we're pressing down 124 | // on our main stick/direction pad/keyboard 125 | if (_inputManager.PrimaryMovement.y < -_inputManager.Threshold.y) 126 | { 127 | DoSomething (); 128 | } 129 | } 130 | 131 | /// 132 | /// If we're pressing down, we check for a few conditions to see if we can perform our action 133 | /// 134 | protected virtual void DoSomething() 135 | { 136 | // if the ability is not permitted 137 | if ( !AbilityPermitted 138 | // or if we're not in our normal stance 139 | || (_condition.CurrentState != CharacterStates.CharacterConditions.Normal) 140 | // or if we're grounded 141 | || (!_controller.State.IsGrounded) 142 | // or if we're gripping 143 | || (_movement.CurrentState == CharacterStates.MovementStates.Gripping) ) 144 | { 145 | // we do nothing and exit 146 | return; 147 | } 148 | 149 | // if we're still here, we display a text log in the console 150 | MMDebug.DebugLogTime("We're doing something yay!"); 151 | } 152 | 153 | /// 154 | /// Adds required animator parameters to the animator parameters list if they exist 155 | /// 156 | protected override void InitializeAnimatorParameters() 157 | { 158 | RegisterAnimatorParameter ("TODO_ANIMATOR_PARAMETER_NAME", AnimatorControllerParameterType.Bool); 159 | } 160 | 161 | /// 162 | /// At the end of the ability's cycle, 163 | /// we send our current crouching and crawling states to the animator 164 | /// 165 | public override void UpdateAnimator() 166 | { 167 | MMAnimator.UpdateAnimatorBool(_animator,"TODO_ANIMATOR_PARAMETER_NAME",(_movement.CurrentState == CharacterStates.MovementStates.Crouching), _character._animatorParameters); 168 | } 169 | } 170 | } 171 | ``` 172 | 173 | ------- 174 | 175 | [本页面的 Corgi Engine 官方英文原版链接](http://corgi-engine-docs.moremountains.com/character-abilities.html) 176 | 177 | # Character Abilities 178 | 179 | > **Summary:** This page goes over the various Character Abilities included in the asset, and how to create your own. 180 | 181 | ## General Information 182 | 183 | The Character Abilities are the scripts that will enable your character to perform actions. Whether it’s jumping, running, or pressing a button, **that’s where it happens**. In previous versions of the engine, this was all handled by a single CharacterBehaviour script. While it’s not necessarily bad design in a small game where your character only does walking and jumping, here it became hard to read and maintain as new features kept being added. Having separated ability scripts also allows for a **much easier extension of the system**. It’ll also make it much easier for you to create your own abilities. 184 | 185 | ## Standard Abilities 186 | 187 | * **Character HorizontalMovement** : This component handles basic left/right movement, friction, and ground hit detection. In its inspector you can define standard movement speed, walk speed, and what effects to use when the character hits the ground after a jump/fall. 188 | 189 | * **Character Crouch** : This component handles crouch and crawl behaviours. In its inspector you can determine the crouch speed, and whether or not the collider should resize when crouched (to crawl into tunnels for example). If it should, make sure you setup its new size. 190 | 191 | * **Character Dash** : This component allows your character to dash. From the inspector you can define the distance the dash should cover, how much force to apply, and the cooldown between the end of a dash and the start of the next one 192 | 193 | * **Character Dive** : This component allows your character to dive (by pressing the dash button + the down direction while in the air). In its inspector you can define how much the camera should shake on impact, and how fast the dive should be. 194 | 195 | * **Character Dangling** : Add this component to a character and it’ll adopt a dangling stance if facing a hole in the ground. The detection is done using a raycast, whose origin and length can be setup from the inspector. 196 | 197 | * **Character Jump** : This component handles jumps. In its inspector you can define the jump height, whether the jump is proportional to the press length or not, the minimum air time (how long a character should stay in the air before being able to go down if the player has released the jump button), jump restrictions, how many jumps the character can perform without touching the ground again, and how long collisions should be disabled when exiting 1-way platforms or moving platforms. 198 | 199 | * **Character Run** : This component allows your character to change speed (defined in its inspector) when pressing the run button 200 | 201 | * **Character Jetpack** : Add this component to a character and it’ll be able to activate a jetpack and fly through the level. From its inspector you can define the force to apply when jetpacking, the particle system to use, various fuel info, and optionnally what sound to play when the jetpack gets fully refueled 202 | 203 | * **Character Look Up** : This component allows your character to look up when pressing up while grounded. How much the camera will move in this situation is defined on the CameraController’s inspector. 204 | 205 | * **Character Grip** : Add this component to a character and it’ll be able to grip level elements that have the Grip component. 206 | 207 | * **Character Wall Clinging** : Add this component to your character and it’ll be able to cling to walls, slowing down its fall. From its inspector you can define the slow factor (close to 0 : super slow, 1 : normal fall) and the tolerance (to account for tiny holes in the wall 208 | 209 | * **Character Walljump** : This component allows your character to perform an extra jump while wall clinging only. Here you can determine the force to apply to that jump 210 | 211 | * **Character Ladder** : This component allows your character to climb ladders (objects with a Ladder component). From its inspector you can set the speed to apply to the character when it’s climbing a ladder. 212 | 213 | * **Character Push** : This component will allow your character to push Pushable blocks. This is not mandatory, you’d be able to push objects without it, but this component will allow you to have a dedicated push animation when pushing, and override default push values. For the animation to work, you’ll need to add a “Pushable” component on your pushable blocks. 214 | 215 | * **Character Pause** : Allows this character (and the player controlling it) to press the pause button to pause the game. 216 | 217 | * **Character SlopeOrientation** : This component, added to a Character, allows you to have your model perpendicular to the slope it’s on. You can define its rotation speed, the min and max angles allowed, whether the weapon should rotate too, and whether or not the angle should reset in the air. 218 | 219 | * **Character Button Activation** : This component allows your character to interact with button powered objects (dialogue zones, switches…). Nothing special to setup here. 220 | 221 | * **Character Handle Weapon** : This component will allow your character to pickup and use weapons. What the weapon will do is defined in the Weapon classes. This just describes the behaviour of the ‘hand’ holding the weapon, not the weapon itself. 222 | 223 | ## Ability overview 224 | 225 | So what does an ability do ? If you’re interested in code, the easiest way to find out is to look at the CharacterAbility.cs class, from which all abilities inherit. It has a few methods, let’s go over the main ones quickly : 226 | 227 | * **Initialization** : as the name implies, that’s where the base class will get parts of the Character or Scene that’ll be regularly useful in children abilities. Stuff like the camera, CorgiController component, input manager, etc. A child ability will typically use this to grab additional components or initialize variables (number of jumps, etc). 228 | * **Animation methods** : InitializeAnimatorParameters and UpdateAnimator : use the first one to register animation parameters, and the second to update them. This is done in two steps to avoid checking for the existence of each parameter every frame, which would end up causing performance issues. 229 | * **HandleInput** : overridden by each ability to check for the state of relevant buttons and axis. If a certain button is pressed/released, this method will call other methods in the ability. 230 | * **Early/Process/Late Process ability** : these methods are called by the state machine at each update. 231 | * **Reset** : this method will be called when the character dies. Useful to reset counters etc. 232 | * **Play/Stop Sfx** : methods used to trigger the abilities sounds. By default each ability comes with 3 sounds (defined per ability in their inspector) : one when it starts, one while it’s used, and one when it stops. You can of course only use one or none of these. If you create your own ability, you’ll need to call these methods to trigger the sounds. 233 | 234 | ## The State Machine 235 | 236 | The Character component is responsible for **triggering** the various abilities. It does so using **state machines**. A StateMachine is a design pattern that will basically store a current state and the previous one (if you’re curious for more, look at the code or API documentation). By default a Character uses two state machines : 237 | 238 | * **MovementState** : accessed via the _movement property from any Ability, it represents the current action the Character is performing. 239 | * **ConditionState** : accessed via the _condition property from any Ability, it stores the current status of the Character (normal, dead, paused, etc). 240 | 241 | The way it works is that at the start of a Scene, the Character will initialize all Abilities, then every frame, call their EarlyProcess, Process and LateProcess methods, and eventually reset them on Death. Other State Machine implementations would usually only call the current state’s ability on Update. This one doesn’t, for a number of reasons, but mostly to make it **easy to extend the system**, without having to rewrite everything or modify existing classes. This means that each ability is responsible for handling its own input, preventing the entry into its methods (by testing if the current state allows it - you can’t walk while not grounded for example). Most abilities included in the engine don’t use EarlyProcess or LateProcess, but it’s still a possibility if you need it. 242 | 243 | ## Create your own ability 244 | 245 | The easiest way to create your own ability is to **extend CharacterAbility**, the same way all abilities in the engine right now do. Override methods (make sure you call the base one at the start then) when needed. To test your new ability, you just have to add it to an existing Character, and it’ll be automatically added to the state machine, and processed like the others. One thing to keep in mind is the interaction with the other abilities. You may want to extend other abilities to prevent or authorize certain state changes. Additionnally, your Ability may require new states. You can declare these in CharacterStates.cs (anywhere in the MovementStates or CharacterConditions enums, the order doesn’t matter). 246 | 247 | For inspiration you can have a look at the current Character Abilities, as **they are exactly what you’re trying to create**, and are good examples of what you can achieve. Here’s a good basis I used to create them, as I found out these methods were the ones I used to override the most. Make sure you replace all the TODOs with your stuff : 248 | 249 | ```csharp 250 | using UnityEngine; 251 | using System.Collections; 252 | using MoreMountains.Tools; 253 | 254 | namespace MoreMountains.CorgiEngine // you might want to use your own namespace here 255 | { 256 | /// 257 | /// TODO_DESCRIPTION 258 | /// 259 | [AddComponentMenu("Corgi Engine/Character/Abilities/TODO_REPLACE_WITH_ABILITY_NAME")] 260 | public class TODO_NEW_ABILITY_NAME : CharacterAbility 261 | { 262 | /// This method is only used to display a helpbox text 263 | /// at the beginning of the ability's inspector 264 | public override string HelpBoxText() { return "TODO_HELPBOX_TEXT."; } 265 | 266 | [Header("TODO_HEADER")] 267 | /// declare your parameters here 268 | public float randomParameter = 4f; 269 | public bool randomBool; 270 | 271 | /// 272 | /// Here you should initialize our parameters 273 | /// 274 | protected override void Initialization() 275 | { 276 | base.Initialization(); 277 | randomBool = false; 278 | } 279 | 280 | /// 281 | /// Every frame, we check if we're crouched and if we still should be 282 | /// 283 | public override void ProcessAbility() 284 | { 285 | base.ProcessAbility(); 286 | } 287 | 288 | /// 289 | /// Called at the start of the ability's cycle, this is where you'll check for input 290 | /// 291 | protected override void HandleInput() 292 | { 293 | // here as an example we check if we're pressing down 294 | // on our main stick/direction pad/keyboard 295 | if (_inputManager.PrimaryMovement.y < -_inputManager.Threshold.y) 296 | { 297 | DoSomething (); 298 | } 299 | } 300 | 301 | /// 302 | /// If we're pressing down, we check for a few conditions to see if we can perform our action 303 | /// 304 | protected virtual void DoSomething() 305 | { 306 | // if the ability is not permitted 307 | if ( !AbilityPermitted 308 | // or if we're not in our normal stance 309 | || (_condition.CurrentState != CharacterStates.CharacterConditions.Normal) 310 | // or if we're grounded 311 | || (!_controller.State.IsGrounded) 312 | // or if we're gripping 313 | || (_movement.CurrentState == CharacterStates.MovementStates.Gripping) ) 314 | { 315 | // we do nothing and exit 316 | return; 317 | } 318 | 319 | // if we're still here, we display a text log in the console 320 | MMDebug.DebugLogTime("We're doing something yay!"); 321 | } 322 | 323 | /// 324 | /// Adds required animator parameters to the animator parameters list if they exist 325 | /// 326 | protected override void InitializeAnimatorParameters() 327 | { 328 | RegisterAnimatorParameter ("TODO_ANIMATOR_PARAMETER_NAME", AnimatorControllerParameterType.Bool); 329 | } 330 | 331 | /// 332 | /// At the end of the ability's cycle, 333 | /// we send our current crouching and crawling states to the animator 334 | /// 335 | public override void UpdateAnimator() 336 | { 337 | MMAnimator.UpdateAnimatorBool(_animator,"TODO_ANIMATOR_PARAMETER_NAME",(_movement.CurrentState == CharacterStates.MovementStates.Crouching), _character._animatorParameters); 338 | } 339 | } 340 | } 341 | ``` 342 | 343 | ------- 344 | 345 | -------------------------------------------------------------------------------- /2.Agents/2-4.动画.md: -------------------------------------------------------------------------------- 1 | # 动画 2 | 3 | > 这个页面讲解了在 Corgi Engine 中如何使用动画。 4 | 5 | ## 简介 6 | 7 | Corgi Engine 包含了很多原型角色,它们都自带了大量的**动画(Animation)**。在各种 Demo 中,你会发现有些角色使用了**精灵图集(Sprite sheet)**,有的使用 **Mecanim 动画系统**,或者 **Spine 骨骼动画**,或者 **3D 的 FBX 格式的动画模型**。你可以随心所欲地选择适合你的技能和需求的动画方式,不过 Corgi Engine 应该已经覆盖了任何你想要采用的方式了。 8 | 9 | 这个页面不会讲解所有关于如何创建动画的知识,Unity 官网上已经有[大量的文档](https://unity3d.com/cn/learn/tutorials/topics/animation)可供查阅。这里会讲解的是动画在 Corgi Engine 中的具体实现,以及它如何帮助你创建优美的动画角色。 10 | 11 | ## 动画控制器 12 | 13 | ![Rectangle 角色的动画控制器(Animator)](media/15009134926090.jpg) 14 | 15 | 大部分情况下,都需要有一个 **Animation Controller** 来设置动画。Corgi Engine 资源中包含了大量的 Animation Controller,我建议使用 `RectangleAnimator` 作为起点来创建自定义的 Animation Controller,由于它包含了所有的动画参数,所以你不需要再自己手动输入它们了。你可以简单地复制一个,然后把动画剪辑拖拽进去,替换原来属于 Rectangle 角色的那些就可以了。 16 | 17 | 角色的 Animator Controller 由两大部分组成:一部分是动画的参数(Animation Parameters),`Character` 和 `Character Abilities` 组件每帧都会更新它们,以映射角色的当前状态;另一部分是一个状态机(State Machine),你可以用它来定义每个动画在什么条件下会被播放,以及动画之间如何转换。 18 | 19 | ![一个动画状态转换的示例](media/15010347513179.jpg) 20 | 21 | 你会发现它的工作流程**非常简单**,由于大部分转换(Transition)都直接基于角色的当前状态,所以最困难的检验各种可能条件的部分,已经由引擎解决了。当然你也可以修改它来创建更加复杂的状态转换,如果那样的效果更好的话。 22 | 23 | ## 动画与脚本 24 | 25 | Corgi Engine 的角色系统已经内建了动画操作接口,所以你不需要再花时间处理这些。每一种能力都已经加载了相应的动画参数。你可以使用 [Unity 内建的方法](https://docs.unity3d.com/Manual/AnimationParameters.html)或者由 Corgi Engine 提供的方法来更新动画参数。做法确实很简单,从任何一个能力中你只需重载两个方法。以喷气背包(Jetpack)能力为例,我们来看一下它是如何使用的吧。 26 | 27 | **InitializeAnimatorParameters**:这个方法中注册了后面会使用到的参数,实际上它只是在检查了参数在 Animator Controller 中确实存在之后,把它放到一个列表中,以避免潜在的运行时错误。如果参数不存在,更新请求(Update Request)则不做任何事情,而不是触发错误。这种机制允许你在多个角色之间共用单一的 Animator,而不用将所有参数拷贝到所有 Animator Contoller 中。这个方法只在 `Initialization` 方法中被调用。 28 | 29 | ```csharp 30 | protected override void InitializeAnimatorParameters() 31 | { 32 | RegisterAnimatorParameter ("Jetpacking", AnimatorControllerParameterType.Bool); 33 | } 34 | ``` 35 | 36 | **UpdateAnimator**:这个方法在每一帧中都会被调用,它会根据动画参数的当前值来更新 Animator 的参数。这个方法应该只包含对 `MMAnimator.UpdateAnimatorBool/Int/Trigger` 方法的调用。 37 | 38 | ```csharp 39 | public override void UpdateAnimator() 40 | { 41 | MMAnimator.UpdateAnimatorBool(_animator,"Jetpacking",(_movement.CurrentState == CharacterStates.MovementStates.Jetpacking),_character._animatorParameters); 42 | } 43 | ``` 44 | 45 | ## 添加新的动画 46 | 47 | 添加一个**新的动画**,你只需要创建它,然后拖拽它到角色的 Animator Controller 中,再创建连接到它的转换(Transition)。如果新动画需要新的参数,确保将它们添加到 Animator Controller 的参数列表中,以及在脚本中使用以上提到的两个方法来注册和更新它们。 48 | 49 | ## 动画参数 50 | 51 | 以下是引擎中已存在的所有动画参数的详细列表: 52 | 53 | | 参数名(Parameter Name) | 能力(Ability) | 类型(Type) | 作用(Role) | 54 | | --- | --- | --- | --- | 55 | | Grounded | Character | Boolean | 当角色与地面接触时为 true | 56 | | Alive | Character | Boolean | 当角色活着时为 true | 57 | | CollidingAbove | Character | Boolean | 当角色碰撞到上方的墙壁时为 true | 58 | | CollidingBelow | Character | Boolean | 当角色碰撞到下方的墙壁时为 true | 59 | | CollidingLeft | Character | Boolean | 当角色碰撞到它左边的墙壁时为 true | 60 | | CollidingRight | Character | Boolean | 当角色碰撞到它右边的墙壁时为 true | 61 | | Idle | Character | Boolean | 当角色处于闲置状态时为 true | 62 | | Activating | CharacterButtonActivation | Boolean | 当角色激活某些东西时为 true | 63 | | Crouching | CharacterCrouch | Boolean | 当角色蹲伏时为 true | 64 | | Crawling | CharacterCrouch | Boolean | 当角色爬行时为 true | 65 | | Dangling | CharacterDangling | Boolean | 当角色犹豫不决时为 true | 66 | | Dashing | CharacterDashing | Boolean | 当角色冲撞时为 true | 67 | | Diving | CharacterDive | Boolean | 当角色俯冲时为 true | 68 | | Gripping | CharacterGrip | Boolean | 当角色抓握某些东西时为 true | 69 | | Speed | CharacterHorizontalMovement | Float | 角色当前的水平速度 | 70 | | xSpeed | Character | Float | 角色当前的水平速度 | 71 | | ySpeed | Character | Float | 角色当前的竖直速度 | 72 | | Walking | CharacterHorizontalMovement | Boolean | 当角色走路时为 true | 73 | | Jetpacking | CharacterJetpack | Boolean | 当角色使用喷气背包时为 true | 74 | | Jumping | CharacterJump | Boolean | 当角色跳跃时为 true | 75 | | DoubleJumping | CharacterJump | Boolean | 当角色进行双段跳跃时为 true | 76 | | HitTheGround | CharacterJump | Boolean | 如果这一帧角色刚好碰到地面则为 true | 77 | | LadderClimbing | CharacterLadder | Boolean | 当角色爬梯子时为 true | 78 | | LadderClimbingSpeedX | CharacterLadder | Float | 当角色在梯子上时的水平速度 | 79 | | LadderClimbingSpeedY | CharacterLadder | Float | 当角色在梯子上时的竖直速度 | 80 | | LookingUp | Character | Boolean | 当角色向上看时为 true | 81 | | Running | CharacterRun | Boolean | 当角色跑动时为 true | 82 | | WallClinging | CharacterWallClinging | Boolean | 当角色附着在墙壁上时为 true | 83 | | WallJumping | CharacterWallJump | Boolean | 当角色从墙壁上跳跃时为 true | 84 | 85 | 除此之外,在 `CharacterHandleWeapon` 组件中你也会发现许多动画参数,在每个武器的 Inspector 视窗中你可以直接设置它们的名称。 86 | 87 | ## Spine 88 | 89 | 如果你想要使用 Spine,可以尝试以下两种方法: 90 | 91 | ...... 92 | 93 | // TODO: 本小节内容暂未翻译 94 | 95 | ------- 96 | 97 | [本页面的 Corgi Engine 官方英文原版链接](http://corgi-engine-docs.moremountains.com/animations.html) 98 | 99 | # Animations 100 | 101 | > **Summary:** This page describes how animations are used in the Corgi Engine. 102 | 103 | ## Introduction 104 | 105 | The Corgi Engine includes a lot of demo characters, and they all come with a number of **animations**. In the various demos, you’ll find some characters animated using **spritesheets**, some using **Mecanim**, **Spine**, or **3D** fbx animated models. It’s really up to you to choose the animation method that fits your skills and needs. But the Engine should have you covered whatever method you decide on. 106 | 107 | This page won’t cover how to create your animations. Unity has a lot of documentation on that, [go check it out](https://unity3d.com/cn/learn/tutorials/topics/animation). It will however cover the specifics of the Corgi Engine and how it’ll help you create nice animated characters. 108 | 109 | ## Animation Controllers 110 | 111 | ![The Rectangle character animator](media/15009134926090.jpg) 112 | 113 | In most cases you’ll need an **Animation Controller** to setup your animations. The asset includes a bunch of these, I’d recommend using the RectangleAnimator one as a starting point for yours as it includes all animation parameters, so you won’t have to enter them all again. You can simply duplicate it, and then drag your animations into it, replacing the Rectangle ones as you go. 114 | 115 | The Animation Controller is made of two big parts : on one side Animation Parameters that will get updated every frame by the Character and Character Abilities scripts to reflect the current state of the character, and on the other a state machine that will allow you to determine in which conditions each animation should be played and how to transition from one to the other. 116 | 117 | ![An example of transition](media/15010347513179.jpg) 118 | 119 | You’ll notice it’s **very simple** in terms of workflow, as most transitions are simply based on the current character’s state, so the hard work of checking the many possible conditions is already done by the engine. Of course you can divert from that and have more complex transitions if that works better for you. 120 | 121 | ## Animation and scripts 122 | 123 | The Corgi Engine’s character system has animation interfaces built-in so you don’t lose time on that. Every ability comes already loaded with corresponding animation parameters. To update animation parameters, you can either use [Unity’s built-in methods](https://docs.unity3d.com/Manual/AnimationParameters.html) or the ones provided with the Corgi Engine. It’s really quite simple, as from any ability you only need to override two methods. Let’s have a look at how it’s used in the Jetpack ability : 124 | 125 | **InitializeAnimatorParameters** : This method “registers” parameters, for later use. Basically it just adds that parameter to a list, after having checked its existence in the Animation Controller, to avoid potential errors at runtime. If that parameter doesn’t exist, update requests will simply do nothing, without triggering errors. This allows you to share a single animator amongst many characters, without having to copy all parameters into all the controllers. This method is only called at Initialization. 126 | 127 | ```csharp 128 | protected override void InitializeAnimatorParameters() 129 | { 130 | RegisterAnimatorParameter ("Jetpacking", AnimatorControllerParameterType.Bool); 131 | } 132 | ``` 133 | 134 | **UpdateAnimator** : This method, called every frame, will update the animator parameters with their current value. In it you should only have calls to MMAnimator.UpdateAnimatorBool/Int/Trigger. 135 | 136 | ```csharp 137 | public override void UpdateAnimator() 138 | { 139 | MMAnimator.UpdateAnimatorBool(_animator,"Jetpacking",(_movement.CurrentState == CharacterStates.MovementStates.Jetpacking),_character._animatorParameters); 140 | } 141 | ``` 142 | 143 | ## Adding new animations 144 | 145 | To add a **new animation**, all you have to do is create it, drag it into your character’s animation controller, and create a transition to it. If it requires new animation parameters, make sure you add them both to your animation controller’s parameters list and register/update them in your script(s) using the above methods. 146 | 147 | ## Animation Parameters 148 | 149 | Here’s a full list of all the animation parameters already in the engine: 150 | 151 | | Parameter Name | Ability | Type | Role | 152 | | --- | --- | --- | --- | 153 | | Grounded | Character | Boolean | True if the character is touching the ground | 154 | | Alive | Character | Boolean | True if the character is currently alive | 155 | | CollidingAbove | Character | Boolean | True if the character is colliding with a wall above | 156 | | CollidingBelow | Character | Boolean | True if the character is colliding with a wall below | 157 | | CollidingLeft | Character | Boolean | True if the character is colliding with a wall on its left | 158 | | CollidingRight | Character | Boolean | True if the character is colliding with a wall on its right | 159 | | Idle | Character | Boolean | n True if the character is currently idle | 160 | | Activating | CharacterButtonActivation | Boolean | True if the character is currently activating something | 161 | | Crouching | CharacterCrouch | Boolean | True if the character is currently crouching | 162 | | Crawling | CharacterCrouch | Boolean | True if the character is currently crawling | 163 | | Dangling | CharacterDangling | Boolean | True if the character is currently dangling | 164 | | Dashing | CharacterDashing | Boolean | True if the character is currently dashing | 165 | | Diving | CharacterDive | Boolean | True if the character is currently diving | 166 | | Gripping | CharacterGrip | Boolean | True if the character is currently gripping to something | 167 | | Speed | CharacterHorizontalMovement | Float | The current horizontal speed of the character | 168 | | xSpeed | Character | Float | The current horizontal speed of the character | 169 | | ySpeed | Character | Float | The current vertical speed of the character | 170 | | Walking | CharacterHorizontalMovement | Boolean | True if the character is currently walking | 171 | | Jetpacking | CharacterJetpack | Boolean | True if the character is currently jetpacking | 172 | | Jumping | CharacterJump | Boolean | True if the character is currently jumping | 173 | | DoubleJumping | CharacterJump | Boolean | True if the character is currently double jumping | 174 | | HitTheGround | CharacterJump | Boolean | True if the character just hit the ground this frame | 175 | | LadderClimbing | CharacterLadder | Boolean | True if the character is currently climbing a ladder | 176 | | LadderClimbingSpeedX | CharacterLadder | Float | The horizontal speed of the character if he’s on a ladder | 177 | | LadderClimbingSpeedY | CharacterLadder | Float | The vertical speed of the character if he’s on a ladder | 178 | | LookingUp | Character | Boolean | True if the character is currently looking up | 179 | | Running | CharacterRun | Boolean | True if the character is currently running | 180 | | WallClinging | CharacterWallClinging | Boolean | True if the character is currently clinging to a wall | 181 | | WallJumping | CharacterWallJump | Boolean | True if the character is currently jumping from a wall | 182 | 183 | In addition to that, you’ll find a number of animation parameters in CharacterHandleWeapon whose name you can set from the inspector of each weapon directly. 184 | 185 | ## Spine 186 | 187 | If you want to use Spine, there are two ways you can go : 188 | 189 | You can “**bake**” your character via the Spine Unity runtime. All the demo playable characters included in the asset use this method, but **I wouldn’t recommend it** for your game. The demo characters are baked because that was the only way to include them without having to add the Spine runtimes. These can’t be distributed by anyone else but Spine, so that was not possible. But baking Spine characters prevents you from using all the cool Spine features. 190 | 191 | The “**best**” way to do is to create/animate your character in Spine, then do File > Export, select .json extension and format, check “create atlas”, go to parameters, set the atlas extension to .atlas.txt, tweak the other settings according to your character, and then export to a folder inside your project. This will create a bunch of Spine related files. You’ll then want to select the SkeletonData file, and drag it into a scene. Select the **SkeletonAnimator** option, and you should see your character on the scene. If that’s not the case, you probably need to select a skin from that new object’s inspector. While you’re at it, select the sorting layer of your choice (Player is the recommended one). You can now drag that object into your hierarchy to create a prefab. 192 | 193 | Now there are two things left to do : add your Character’s components ([see this page for more](http://corgi-engine-docs.moremountains.com/how-to-create-character.html)), and take care of the animator. Spine animators work exactly like regular ones. Select your Character, and go to Window > Animator. There you should see an empty state machine. Start by adding the animation parameters you’ll need from the list above (Idle, Crawling, Crouching, etc…). Then, from the folder with all the exported Spine files, unfold the Controller animator, and drag and drop the required animations into your Animator. The only thing left to do is to create transitions to all these states, and that’s done exactly like for regular animation controllers (see higher in this page). 194 | 195 | ------- 196 | 197 | -------------------------------------------------------------------------------- /2.Agents/2-5.AI.md: -------------------------------------------------------------------------------- 1 | # 人工智能 2 | 3 | > 这个页面讲解了 Corgi Engine 的 AI 脚本如何运作。 4 | 5 | ## 简介 6 | 7 | ![一群 AI 控制的角色在它们的栖息地附近来回走动](media/15010533399635.jpg) 8 | 9 | 目前 Corgi Engine 中包含了一些适用于敌人(或盟友)的**基础 AI 脚本**。你可以向角色添加这些组件(简单地通过角色的 Inspector 视窗底部的 AddComponent 按钮),它就会让角色执行动作**而不需要通过玩家输入**。你需要正确地设置角色,至少为每个 AI 脚本配备必要的组件才能使用它们。每个 AI 脚本可能要求某些特定的能力(Ability),但它们都要求角色上带有 `CorgiController` 组件和 `Character` 组件。你也可以联合它们,比如可以为角色添加 `AI ShootOnSight` 和 `AI Walk` 组件,这样它就能够到处走动并且射击玩家了。**更多的 AI 脚本即将发布**,以帮助你创建更多样化的敌人,不过你随时可以创建自定义的 AI 脚本,这确实很简单而且充满乐趣。 10 | 11 | ## AI ShootOnSight 12 | 13 | 这个组件需要一个 `CharacterHandleWeapon` 组件。它所做的就是向它的左右两边发射射线,定位你在它的 Inspector 视窗中指定的图层(layer)上的目标。如果有物体被这些射线击中,AI 就会用它当前装备的武器来射击它。 14 | 15 | ## AI Walk 16 | 17 | 这个组件需要一个 `CharacterHorizontalMovement` 组件。它让你的 AI 角色能够走动。你可以在它的 Inspector 视窗中指定它所需的行为。据此你可以让它巡逻(随机的走动,并且当碰到墙壁或者坑洞时改变方向),或者锁定目标的走动(walk on sight),也就是说 AI 会搜寻(使用射线)你在它的 Inspector 视窗中指定的图层(layer)上的对象。如果射线击中了这样的对象,角色就会向它移动过去。 18 | 19 | ## Ai Follow 20 | 21 | 这个组件需要一个 `CharacterHorizontalMovement` 组件。向角色添加这个组件会让它追随(或者试着追随)主要玩家角色。如果它带有 `CharacterRun` 组件,在它远离目标的时候它会尝试奔跑。如果它带有 `CharacterJetpack` 组件,它会尝试使用喷气背包来越过障碍物来靠近目标。而如果它带有 `CharacterJump` 组件,它会尝试跳过障碍物。 22 | 23 | ------- 24 | 25 | [本页面的 Corgi Engine 官方英文原版链接](http://corgi-engine-docs.moremountains.com/ai.html) 26 | 27 | # Artificial Intelligence 28 | 29 | > **Summary:** This page describes how the AI scripts of the Corgi Engine work. 30 | 31 | ## Introduction 32 | 33 | ![A bunch of AI controlled characters walking around in their natural habitat.](media/15010533399635.jpg) 34 | 35 | Right now the engine includes a few **basic AI scripts** for your enemies (or friends). These are components you can add to your characters (simply via the AddComponent button at the bottom of the character’s inspector), and it’ll make them perform actions **without the need for input from the player**. To use them, you need to have a Character setup properly, with (at least) the required components for each AI script. Each AI script may require certain particular Abilities, but all of them require that you have a CorgiController and a Character. You can also try combining them : for example you can add AI ShootOnSight and AI Walk to a Character and it’ll be able to walk around and shoot at your player. **More AI scripts are coming soon** to help you create more diverse enemies, but feel free to create your own AI scripts, it’s really easy and fun to do. 36 | 37 | ## AI ShootOnSight 38 | 39 | This component requires a CharacterHandleWeapon component. What it does is cast raycasts to its left and right, targeting the objects on the layers you’ll have specified in its inspector. If one object hits these raycasts, the AI will **shoot at it** using its current equipped weapon. 40 | 41 | ## AI Walk 42 | 43 | This component requires a CharacterHorizontalMovement component. It’ll allow your AI character to walk. You can specify the desired behaviour in its inspector. From there you can have it patrol (walk randomly and change direction when hitting a wall or optionnally a hole), or walk on sight, which means the AI will “look” (using raycasts) for objects on the layers you’ll have specified in its inspector. If a raycast hits such an object, the character will move towards it. 44 | 45 | ## AI Follow 46 | 47 | This component requires a CharacterHorizontalMovement component. Add this script to a Character to make it follow (or try to follow) the main Player character. If it has a CharacterRun component it’ll try to run when far from target. If it has a CharacterJetpack it’ll try to jetpack over obstacles to reach the target, and if it has a CharacterJump component it’ll try to jump over obstacles. 48 | 49 | ------- 50 | 51 | -------------------------------------------------------------------------------- /2.Agents/2-6.武器.md: -------------------------------------------------------------------------------- 1 | # 武器 2 | 3 | > 这个页面讲解了 Corgi Engine 的武器系统背后的机制,以及如何创建和使用自定义的武器。 4 | 5 | ## 简介 6 | 7 | Corgi Engine 包含了一个**通用的武器系统**,让你的角色可以装备武器(基于弹射的、近战的,或者任何你可以想到的),可以切换和使用武器。引擎也包含了一些武器的例子,你可以看一看,在创建自定义的武器时也可以用它们作为基础。 8 | 9 | ## CharacterHandleWeapon 能力组件 10 | 11 | 为了装备和使用武器,角色必须带有一个 **CharacterHandleWeapon** 组件。在它的 Inspector 视窗中,你可以可选地设定角色的初始武器,设定是否可以捡起新的武器,以及指定一个武器附着点(**Weapon Attachment**)。武器附着点是角色身上(或者嵌套在它的 Prefab 中)的一个 `Transform`,让武器可以贴附在上面。如果你没有指定它,武器将会贴附到角色 Prefab 的顶层(root level)。 12 | 13 | **CharacterHandleWeapon** 组件接下来将会检测使用武器按键的变动,如果它被按下或松开,则把信息传递到角色当前装备的武器上。 14 | 15 | ## Weapon 类 16 | 17 | Corgi Engine 中的所有武器都继承自 **Weapon** 类,当然也可以脱离它来创建武器,但引擎中所有的例子都是这么运作的。`Weapon` 类的目标是可以被扩展,并且定义了许多对于所有或大部分武器来说都共用的东西。用它作为基础,你可以创建一切,从霰弹猎枪到火箭筒,甚至一把武士刀或者一把擒拿枪。除了为动画、声音和状态管理提供坚实的基础,它还让你可以在子类中定义使用武器时会发生什么,并且从那里开始构建武器。作为示例,你可以查看弹射武器 **ProjectileWeapon** 和近战武器 **MeleeWeapon** 类,了解如何从这个完全相同的脚本创建出非常不同的武器。 18 | 19 | ## 创建一个武器 20 | 21 | 要创建自定义的武器,你可以重用 `ProjectileWeapon` 和 `MeleeWeapon` 脚本,扩展它们,或者创建自定义的 Weapon 子类。无论如何,你都需要**创建一个武器 Prefab**。为此,你需要一个 GameObject。最基本的,你可以选择创建一个可见的武器或者一个不可见的武器。例如,如果你看一下 `BlueRobot` 敌人角色,会发现它们确实有武器,但你看不见它,它只是一个产生特效和子弹的空 GameObject。反之,`MinimalRocketLauncher` 是可见的,它甚至有两只小手(非常小)。这样当玩家的目标旋转时,武器总是面向正确的方向。所以这些抉择都取决于你想要达到的视觉效果。 22 | 23 | 一旦你有了 Sprite、Model 或者空的 GameObject,只需要为它添加一个 Weapon 脚本(ProjectileWeapon,MeleeWeapon,或者自定义的脚本)。在它的 Inspector 视窗中你可以设定它开火时触发的动画、声音和特效,以及指定当角色翻转时武器应该如何翻转。 24 | 25 | 以下是如何一步步创建一个近战武器的参考: 26 | 27 | * 创建一个空的 GameObject。 28 | * 为它添加一个 `MeleeWeapon` 组件。 29 | 30 | ![一个带有 MeleeWeapon 组件的空 GameObject](media/15010648215013.jpg) 31 | 32 | * 在 `MeleeWeapon` 的 Inspector 视窗中,设置如下参数:`Trigger Mode` 设置为 `Semi auto`,`Damage Area Shape` 设置为 `Rectangle`,`Area Size` 设置为 `{1,1}`,`Area Offset` 设置为 `{2,0}`(所以杀伤区域会在角色的前面激活),`Active Duration` 设置为 `0.2` (这是一个短暂的攻击,例如最基本的打出一拳)。然后设置 `Target Layer Mask` 为 `Platforms` 和 `Enemies`,`Damage Caused` 为 `10`。 33 | * 重命名这个 GameObject 为 `MeleeAttackWeapon`(或者任何你喜欢的)。 34 | * 把这个 GameObject 拖拽到 Hierarchy 视窗中,以此创建一个 Prefab。 35 | * 选择角色,然后拖拽这个新建的 Prefab 到 `Initial Weapon` 属性槽中(或者也可以通过使用脚本中的 `ChangeWeapon` 方法来装备它)。 36 | 37 | ![绑定武器到角色对象上](media/15010663739266.jpg) 38 | 39 | * 就这样,现在你已经有一个可以工作的武器了。按下 `Play`,然后按下 `E` 键(默认),你就可以向周围发起攻击且对敌人或物体造成伤害。但目前为止你在攻击的时候可能还看不到任何效果,所以让我们为攻击绑定一个动画效果。 40 | * 选中角色的 Animator,拖拽攻击动画到它的窗口中,如果攻击动画还没被添加的话。 41 | * 创建一个新的动画参数(点击 Parameters 面板右上角的 + 按钮),在这个例子中我们将它命名为 `RectangleMeleeAttackStart`。 42 | 43 | ![添加一个新的动画参数](media/15011218647959.jpg) 44 | 45 | * 创建一个到该动画的转换(Transition)。你可能需要对它做如下设置(至少要勾选 `Fixed Duration`),但也可以随意调整以适应特定的动画。 46 | 47 | ![添加一个新的转换到攻击动画](media/15011223989829.jpg) 48 | 49 | * 回到武器的 Inspector 视窗,然后在 `Start Animation` 字段填上动画参数名,在这个例子中是 `RectangleMeleeAttackStart`。 50 | 51 | ![绑定新的动画参数到武器中](media/15011225662440.jpg) 52 | 53 | * 再次按下 `Play`,然后用你的武器来攻击,现在你可以看到角色的攻击了。你也可以为攻击中、攻击结束等状态添加其他动画。 54 | 55 | ## 定时(Timing) 56 | 57 | 创建武器的时候,定时(Timing)是必不可少的,因为你需要让武器组件和它的动画完美地同步。所有武器都带有以下两个变量,你可以在武器的 Inspector 视窗中调整: 58 | 59 | * **DelayBeforeUse**:从接收到输入到实际调用 `WeaponUse` 方法的时间间隔,例如开枪、抛掷出斧头等。 60 | * **TimeBetweenUses**:连续两次调用 `WeaponUse` 方法的时间间隔(无论是在自动模式,还是通过连续按下按键),武器在此间隔期间不会「发射」。 61 | 62 | 另外,近战武器还有两个可以使用的变量: 63 | 64 | * **InitialDelay**:`WeaponUse` 方法被调用和杀伤区域(Damage Area)被激活之间的延迟。 65 | * **ActiveDuration**:杀伤区域保持激活状态的时间间隔。 66 | 67 | 最后这两个参数是杀伤区域所特有的,当然,你需要将这些值和 `DelayBeforeUse`/`TimeBetweenUses` 变量的值做同步以避免冲突。 68 | 69 | ## 武器激光瞄准器 70 | 71 | ![运转中的激光瞄准器组件](media/15011248436120.jpg) 72 | 73 | 你可以为武器添加一个 **WeaponLaserSight** 组件,它当然更适用于弹射式的武器,但这并**没有限制**。它会在武器的前面发射一道激光,就像激光瞄准器那样。你可以设置 `Laser Collision Mask` 变量,于是当它碰到墙壁或者平台的时候会停下来。在它的 Inspector 视窗中你也可以定制激光的外观。 74 | 75 | ------- 76 | 77 | [本页面的 Corgi Engine 官方英文原版链接](http://corgi-engine-docs.moremountains.com/weapons.html) 78 | 79 | # Weapons 80 | 81 | > **Summary:** This page describes the mechanics behind the Corgi Engine's weapons, and how to create and use your own weapons. 82 | 83 | ## Introduction 84 | 85 | The Corgi Engine includes a **generic weapon system**, allowing your characters to equip a weapon (projectile based, melee, or whatever you can think of), switch to another one, and use it. The engine also includes a few examples of weapons you can have a look at, and that you can use as a basis when creating your own. 86 | 87 | ## The CharacterHandleWeapon Ability 88 | 89 | To be able to equip and use a weapon, a Character must have a **CharacterHandleWeapon** component. From its inspector you’ll be able to optionally select a weapon for your character to start with, define if it can pickup new ones, and specify a **Weapon Attachment**. This is a transform on your character (or nested inside its prefab) for the weapon to attach to. If you don’t specify one, the weapon will attach to the root level of your prefab. 90 | 91 | What the **CharacterHandleWeapon** component will then do is check for changes on the weapon use button, and if it gets pressed/released, transfer that information to the weapon currently equipped. 92 | 93 | ## The Weapon classes 94 | 95 | All weapons in the Corgi Engine derive from the **Weapon** class. You can of course divert from that, but that’s how all the examples work. The Weapon class is meant to be extended and will define a lot of things common to all or most weapons. Using it as a basis you’ll be able to create everything, from a shotgun to a rocket launcher, but also a katana or a grappling gun. In addition to providing a solid basis for animations, sounds, state management, it allows you to define in your child class what happens when the weapon is used, and build from there. You can look at the **ProjectileWeapon** and **MeleeWeapon** classes for examples of how you can create very different weapons from this very same script. 96 | 97 | ## Creating a weapon 98 | 99 | To create your own weapon, you can either reuse the ProjectileWeapon or MeleeWeapon scripts as they are, extend them, or create your own Weapon child class. In any case, you’ll then need to **create a weapon prefab**. To do so, you’ll need a gameobject. Basically you’ll have the choice to have a visible weapon or an invisible one. For example if you look at the BlueRobot enemies, they do have a weapon, but you don’t see it, it’s just an empty gameobject spawning effects and projectiles. The MinimalRocketLauncher on the other hand is visible, and even includes tiny (very minimal) hands. That way when it rotates as the player aims, the weapon is always facing the right direction. So decide on that depending on the kind of visual result you’re looking for. 100 | 101 | Once you have your sprite, or model, or empty game object, just add your weapon (ProjectileWeapon, MeleeWeapon, or your own) script to it. From its inspector you’ll be able to setup animations, sounds, effects to trigger when firing, and specify how the weapon should flip when the character flips. 102 | 103 | Here’s a step by step creation of a Melee Weapon for reference : 104 | 105 | * create an empty gameobject 106 | * add a MeleeWeapon component to it 107 | 108 | ![Our empty game object with the MeleeWeapon component](media/15010648215013.jpg) 109 | 110 | * in the MeleeWeapon inspector, set the following parameters : Trigger Mode to Semi auto, Damage Area Shape to Rectangle, Area Size to {1,1}, Area Offset to {2,0} (so that the damage area will activate in front of our character), Active Duration to 0.2 (it’s a short attack, a punch basically). Then set the Damage Caused Target Layer mask to Platforms and Enemies, and 10 damage. 111 | * rename this gameobject to MeleeAttackWeapon (or whatever you prefer) 112 | * drag this gameobject into your hierarchy to make a prefab out of it 113 | * select your character, and drag that newly created prefab into its InitialWeapon slot (or you can use the ChangeWeapon method via script to equip it) 114 | 115 | ![Binding the weapon to our character](media/15010663739266.jpg) 116 | 117 | * that’s it, you now have a working weapon. Press play, then E (by default), and you’ll be throwing punches around and damaging enemies/objects. But so far you’re probably not seeing anything when attacking. Let’s bind an animation to that attack. 118 | * select your character’s animator, drag your attack animation into it if it’s not already the case. 119 | * create a new animation parameter (the little + button at the top right corner of the Parameters panel), in our example we’ll call it “RectangleMeleeAttackStart” 120 | 121 | ![Adding a new animation parameter](media/15011218647959.jpg) 122 | 123 | * create a transition to that animation. You’ll probably want it to have the following settings (at least the fixed duration), but feel free to adjust to fit your particular animation. 124 | 125 | ![Adding a new transition to our attack animation](media/15011223989829.jpg) 126 | 127 | * go back to your weapon’s inspector, and fill the StartAnimation field with the name of your animation parameter. In our example “RectangleMeleeAttackStart”. 128 | 129 | ![Binding our new animation parameter to our weapon](media/15011225662440.jpg) 130 | 131 | * press play again, attack with your weapon, you now see your character attacking. You can add other animations, for when the attack is in progress, ending, etc. 132 | 133 | ## Timing 134 | 135 | Timing is essential when creating weapons, as you’ll want to sync your weapon’s component to its animation perfectly. All weapons come with two variables you can tweak directly from the inspector : **DelayBeforeUse** (the time between the input registration and the actual WeaponUse - the shot, axe sling, etc), and **TimeBetweenUses** (the time that needs to pass before you can have another WeaponUse (whether it’s in auto, or via repeated presses, etc). The weapon just won’t “shoot” during that time). 136 | 137 | Additionally, the melee weapons have two more variables you can play with : **InitialDelay** (the delay between the WeaponUse and the activation of the damage area) and **ActiveDuration** (the time during which the damage area will stay active). These 2 last parameters are very specific to damage areas, and of course you’ll want to sync these values with your DelayBeforeUse / TimeBetweenUses to prevent conflicts. 138 | 139 | ## Weapon Laser Sight 140 | 141 | ![The lasersight component in action](media/15011248436120.jpg) 142 | 143 | You can add a **WeaponLaserSight** to your weapon. It’s of course more suited for a projectile weapon but there are **no restrictions**. What it’ll do is that it’ll cast a laser in front of the weapon, like a laser sight would. You can set a collision mask so that the laser stops when meeting a wall or platform. From the inspector you can also customize the appearance of the laser. 144 | 145 | ------- 146 | 147 | 148 | -------------------------------------------------------------------------------- /2.Agents/2-7.装备.md: -------------------------------------------------------------------------------- 1 | # 装备 2 | 3 | > 这个页面讲解了如何为游戏添加装备系统。 4 | 5 | ## The Inventory Engine 6 | 7 | 从 v4.0 版本开始,Corgi Engine 包含了一个**装备引擎(Inventory Engine)**,More Mountain 出品的独立完整的装备解决方案。同时它还打包了 2 个 Demo 场景和一些可用的物品,所以你并不需要担心将它嵌入到另一个项目中,它已经为你的使用做好了设置。 8 | 9 | ![FeaturesWeapons 原型场景中运行中的 Inventory Engine](media/15011282424938.jpg) 10 | 11 | Inventory Engine 的设计旨在简单而灵活,如果你想使用它,建议你阅读它的[专用文档](http://inventory-engine-docs.moremountains.com/)。 12 | 13 | ## Corgi Engine 的相关细节 14 | 15 | Corgi Engine 还包含了一些额外的特性来帮助无缝地使用 Inventory Engine: 16 | 17 | * **CharacterInventory**:一种新的能力(Ability),允许你绑定 3 个装备到你的角色上。你只需要在 Main、Weapon 和 Hotbar Inventory 中填写装备的名字,剩下的引擎会帮你搞定。 18 | 19 | * **FeaturesInventory** 和 **FeaturesWeapons**:2 个专注于装备特性的 Demo 场景,比如捡起物品、装备武器、使用兴奋剂等。能够看到这两个引擎结合的可能性是很棒的。 20 | 21 | ------- 22 | 23 | [本页面的 Corgi Engine 官方英文原版链接](http://corgi-engine-docs.moremountains.com/inventory.html) 24 | 25 | # Inventory 26 | 27 | > **Summary:** This page describes how to add an inventory to your game. 28 | 29 | ## The Inventory Engine 30 | 31 | Starting in v4.0, the Corgi Engine comes with the **Inventory Engine**, More Mountains’ complete and autonomous inventory solution. It also comes packed with 2 demo scenes and ready to use items, so you don’t have to worry about plugging one into the other, it’s already setup for you to use. 32 | 33 | ![The Inventory Engine in action in the FeaturesWeapons demo scene](media/15011282424938.jpg) 34 | 35 | The Inventory Engine is designed to be simple yet flexible, and if you want to use it, it’s recommended that you read [its dedicated documentation](http://inventory-engine-docs.moremountains.com/). 36 | 37 | ## Corgi Engine specifics 38 | 39 | There are a few additions included in the Corgi Engine to make using the Inventory Engine even more seamless : 40 | 41 | * CharacterInventory : a new Ability, that will allow you to bind up to three inventories to your character. You just need to type their names into the main, weapon and hotbar inventories, and the rest is taken care of. 42 | * FeaturesInventory and FeaturesWeapons : two demo scenes focused on inventory features, such as picking items, equipping weapons, using stimpacks, etc. Great to get a quick glance of the possibilities offered by the combination of these two assets. 43 | 44 | ------- 45 | 46 | -------------------------------------------------------------------------------- /2.Agents/media/15005163011188.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Caizc/corgi-engine-docs/21cae88dd5f5430837a23e21afa0b741ec556ce8/2.Agents/media/15005163011188.jpg -------------------------------------------------------------------------------- /2.Agents/media/15005175125428.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Caizc/corgi-engine-docs/21cae88dd5f5430837a23e21afa0b741ec556ce8/2.Agents/media/15005175125428.jpg -------------------------------------------------------------------------------- /2.Agents/media/15005223318847.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Caizc/corgi-engine-docs/21cae88dd5f5430837a23e21afa0b741ec556ce8/2.Agents/media/15005223318847.jpg -------------------------------------------------------------------------------- /2.Agents/media/15005234653108.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Caizc/corgi-engine-docs/21cae88dd5f5430837a23e21afa0b741ec556ce8/2.Agents/media/15005234653108.jpg -------------------------------------------------------------------------------- /2.Agents/media/15005318728538.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Caizc/corgi-engine-docs/21cae88dd5f5430837a23e21afa0b741ec556ce8/2.Agents/media/15005318728538.jpg -------------------------------------------------------------------------------- /2.Agents/media/15005426541087.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Caizc/corgi-engine-docs/21cae88dd5f5430837a23e21afa0b741ec556ce8/2.Agents/media/15005426541087.jpg -------------------------------------------------------------------------------- /2.Agents/media/15005429340996.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Caizc/corgi-engine-docs/21cae88dd5f5430837a23e21afa0b741ec556ce8/2.Agents/media/15005429340996.jpg -------------------------------------------------------------------------------- /2.Agents/media/15005439528429.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Caizc/corgi-engine-docs/21cae88dd5f5430837a23e21afa0b741ec556ce8/2.Agents/media/15005439528429.jpg -------------------------------------------------------------------------------- /2.Agents/media/15005453914679.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Caizc/corgi-engine-docs/21cae88dd5f5430837a23e21afa0b741ec556ce8/2.Agents/media/15005453914679.jpg -------------------------------------------------------------------------------- /2.Agents/media/15005659657442.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Caizc/corgi-engine-docs/21cae88dd5f5430837a23e21afa0b741ec556ce8/2.Agents/media/15005659657442.jpg -------------------------------------------------------------------------------- /2.Agents/media/15009134926090.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Caizc/corgi-engine-docs/21cae88dd5f5430837a23e21afa0b741ec556ce8/2.Agents/media/15009134926090.jpg -------------------------------------------------------------------------------- /2.Agents/media/15010347513179.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Caizc/corgi-engine-docs/21cae88dd5f5430837a23e21afa0b741ec556ce8/2.Agents/media/15010347513179.jpg -------------------------------------------------------------------------------- /2.Agents/media/15010533399635.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Caizc/corgi-engine-docs/21cae88dd5f5430837a23e21afa0b741ec556ce8/2.Agents/media/15010533399635.jpg -------------------------------------------------------------------------------- /2.Agents/media/15010648215013.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Caizc/corgi-engine-docs/21cae88dd5f5430837a23e21afa0b741ec556ce8/2.Agents/media/15010648215013.jpg -------------------------------------------------------------------------------- /2.Agents/media/15010663739266.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Caizc/corgi-engine-docs/21cae88dd5f5430837a23e21afa0b741ec556ce8/2.Agents/media/15010663739266.jpg -------------------------------------------------------------------------------- /2.Agents/media/15011218647959.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Caizc/corgi-engine-docs/21cae88dd5f5430837a23e21afa0b741ec556ce8/2.Agents/media/15011218647959.jpg -------------------------------------------------------------------------------- /2.Agents/media/15011223989829.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Caizc/corgi-engine-docs/21cae88dd5f5430837a23e21afa0b741ec556ce8/2.Agents/media/15011223989829.jpg -------------------------------------------------------------------------------- /2.Agents/media/15011225662440.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Caizc/corgi-engine-docs/21cae88dd5f5430837a23e21afa0b741ec556ce8/2.Agents/media/15011225662440.jpg -------------------------------------------------------------------------------- /2.Agents/media/15011248436120.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Caizc/corgi-engine-docs/21cae88dd5f5430837a23e21afa0b741ec556ce8/2.Agents/media/15011248436120.jpg -------------------------------------------------------------------------------- /2.Agents/media/15011282424938.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Caizc/corgi-engine-docs/21cae88dd5f5430837a23e21afa0b741ec556ce8/2.Agents/media/15011282424938.jpg -------------------------------------------------------------------------------- /3.General/3-1.创建你自己的游戏.md: -------------------------------------------------------------------------------- 1 | # 创建你自己的游戏 2 | 3 | > 这个页面说明了你如何才能在 Corgi Engine 上构建你自己的游戏,以及如何安全地更新(引擎版本)。 4 | 5 | ## 简介 6 | 7 | Corgi Engine 从一开始构建的时候就考虑到了**可扩展性**。当然,你可以简单地使用已有的类,但你也可以创建新的类或者在其基础上继续构建。这个页面提到了几种方式,你可以通过它们为**你自己的游戏**添加内容和功能。 8 | 9 | ## 视觉和声音资源 10 | 11 | 一种非常简单的方式就是**把视觉资源直接替换成你的**。这种方式真的很简单,你只需要定位到文件的位置然后替换成你创作的(资源)。这种方式不需要再多说什么。其中应用了 Unity 的良好实践(你当然可以换别的做法,但如果你想要一些参考的话可以使用这些)。你应该阅读[这个指南](https://docs.unity3d.com/Manual/HOWTO-ArtAssetBestPracticeGuide.html)以确保你的资源在所有平台上都能正确运作,并且让你的项目保持可维护性。 12 | 13 | 如果你不知道 Demo 中**某个 Sprite 文件的位置**,你可以简单地在场景视图(Scene View)中选中那个 Prefab,然后点击它的 `Sprite Renderer` 组件下的 `Sprite` 字段。这样就可以在层级视图(Hierarchy View)中高亮显示该 Sprite 了。接着右键点击该 Sprite,点击 `reveal in Finder`(在 Windows 中是 `show in Explorer`)。现在你需要做的就是把这个文件替换成你的,然后再次按下 `Play`。 14 | 15 | ## 调整已有的组件 16 | 17 | 引擎中的所有组件在创建的时候就已经考虑到了**许多用例**。通常你可以从同样的组件出发,通过它们的 Inspector 视窗调整参数值和选择不同的行为,最后就可以让你的游戏与众不同。在开始编写新的代码之前,可以先看看已有的相似的类,查阅它们的 API 文档,确保无法通过调整一些设置来达到你的目标。 18 | 19 | ## 添加新的类 20 | 21 | 可能简单地添加视觉资源并不足以让你创建你想要的游戏。有时候你会发现必须编写**新的代码**才能够实现你的创意。 22 | 23 | 方法之一就是直接**创建新的类**。或许你想要一个片尾场景(end credits scene),用来展示为你的项目做出贡献的所有人?Corgi Engine 目前还没有这样的组件,也没有任何近似的东西。这就是你需要创建自定义类的典型情况。它不与任何东西相关联,你可以随心所欲地创建你想要的东西。从你自定义的类中,你还是可以访问引擎的其余部分,比如 `LevelManager` 或者 `GameManager`,获取当前角色的引用等等。 24 | 25 | ## 继承 26 | 27 | 有时你会想让已有的类表现得有所不同,可能是墙壁跳跃能力(Walljump Ability)并非如你想要的。即使我希望引擎能够适配所有可能的游戏玩法,但那是不可能的,所以有时候必须做出取舍。但好的一点是,这种情况也被考虑在内了。 28 | 29 | 引擎中的大部分(或许不是全部)方法都被声明为 `virtual`,意味着你可以简单地[重载](https://unity3d.com/cn/learn/tutorials/topics/scripting/overriding)它们来满足你的需求。强烈建议使用[继承](https://unity3d.com/cn/learn/tutorials/topics/scripting/inheritance)和[多态](https://unity3d.com/cn/learn/tutorials/topics/scripting/polymorphism?playlist=17117)以重用和扩展尽可能多的代码。 30 | 31 | 任何情况下我都强烈建议不要修改引擎的任何类,而是**在你的类中扩展引擎的脚本**。这种方式确保你在更新引擎版本的时候不会覆盖掉你的工作成果。 32 | 33 | ------- 34 | 35 | [本页面的 Corgi Engine 官方英文原版链接](http://corgi-engine-docs.moremountains.com/creating-your-own-game.html) 36 | 37 | # Creating your own game 38 | 39 | > **Summary:** This page explains how you can build upon the Corgi Engine to create your own game, and how to update safely. 40 | 41 | ## Introduction 42 | 43 | The Corgi Engine has been built with **extendability** in mind from the start. Of course, you can simply use the existing classes as they are, but you can also create new ones or build on what’s there. This page covers a few of the ways you can add content and functionalities to create **your very own game**. 44 | 45 | ## Visuals and sounds 46 | 47 | A very simple way to go is to just **replace visual assets** with your own. Doing so is pretty easy, as all you have to do is locate the file and replace it with your creations. There’s not much else to say about that. Unity good practices apply (you can divert from that of course, but if you want some reference you can use these). [You should have a look at these guidelines](https://docs.unity3d.com/Manual/HOWTO-ArtAssetBestPracticeGuide.html) that should ensure your assets work as intended on all platforms and that your project remains maintainable. 48 | 49 | If you’re having trouble figuring out **where a particular sprite is located** in the demo files, you can simply select the prefab in the scene view, then click on its sprite renderer’s Sprite field. This will highlight the sprite in the hierarchy view. Then you can simply right click the sprite in the hierarchy view, and click on “reveal in Finder” (or show in Explorer on Windows). All you have to do now is replace this file with your own, and press play again. 50 | 51 | ## Tweaking existing components 52 | 53 | All the components in the asset have been built with **lots of use cases** in mind. From the same component you can usually, via their inspector, tweak values and select different behaviours that in the end will make your game really stand out. Before starting to code something new, maybe have a look at the existing similar classes if there are any, check out their API documentation and make sure you can’t just get what you want via a few changes of settings. 54 | 55 | ## Adding new classes 56 | 57 | Maybe adding simply visuals won’t be enough for you to create that game you want. Sometimes you’ll find that you need **new code** to give life to that idea you have. 58 | 59 | One way to go is to simply **create new classes**. Maybe you want an end credits scene, that would showcase everyone who’s worked on that project of yours? There isn’t such a component in the engine right now, and there isn’t anything remotely close to it in the engine. That’s typically the kind of situation where you’ll want to create your own class. It’s unrelated to anything, and you’re free to do whatever you want. From your own classes you’ll still be able to access the rest of the engine, like LevelManager or GameManager for example, get references to the current Character, etc. 60 | 61 | ## Inheritance 62 | 63 | And sometimes you’ll find that you’ll want some of the existing classes to behave a bit differently. Maybe that walljump ability doesn’t work exactly like you’d want it too. As much as I’d love for the engine to match all possible gameplay styles, that’s just not possible, and sometimes choices have to be made. But the good thing is, that’s been taken into account as well! 64 | 65 | Most, if not all, the methods in the Engine are marked as virtual, which means you can easily [override](https://unity3d.com/cn/learn/tutorials/topics/scripting/overriding) them to suit your own needs. I strongly suggest using [inheritance](https://unity3d.com/cn/learn/tutorials/topics/scripting/inheritance) and [polymorphism](https://unity3d.com/cn/learn/tutorials/topics/scripting/polymorphism?playlist=17117) to reuse and extend as much code as possible. 66 | 67 | In any case, I strongly recommend not modifying any of these, but rather **extend the engine’s scripts into your own classes**. That way you won’t have your work erased when updating to the next version. 68 | 69 | ------- 70 | 71 | 72 | -------------------------------------------------------------------------------- /3.General/3-2.输入.md: -------------------------------------------------------------------------------- 1 | # 输入 2 | 3 | > 这个页面说明了如何在你的游戏中设置输入。 4 | 5 | ## 简介 6 | 7 | 输入是所有游戏的核心,在 Corgi Engine 中也不例外。引擎当前支持移动设备操控(iOS、Android...)、键盘、游戏手柄(初始设置为 Windows Xbox 手柄,但可以重新绑定为其他控制器的键位)以及鼠标。 8 | 9 | ## 默认输入 10 | 11 | 默认的键盘布局被设置为同时支持 4 位玩家。目前对于单玩家游戏来说,这个键位可能并不是特别舒服,请按照你的需求任意重新映射这些按键。不管怎样,这是默认布局: 12 | 13 | ![默认的键盘布局,同时支持 4 位玩家](media/15011432639033.jpg) 14 | 15 | ## 输入设置:如何更改键位绑定? 16 | 17 | ![很多轴](media/15011436782426.jpg) 18 | 19 | 对于键盘和游戏手柄(以及较少程度上的鼠标),键位绑定就像在任何优秀的 Unity 项目中一样,**通过原生的 Input 设置**进行设定。你可以通过顶部菜单 `Edit > Project Settings > Input` 来访问这些设置,这样应该可以打开一个很长的 Axes 列表。如果你之前没有了解过这个面板,可能需要[先阅读一下官方文档](https://docs.unity3d.com/Manual/class-InputManager.html)。 20 | 21 | 目前这个列表相当长,为了支持 4 个玩家而被填满(你想要的话还可以添加更多),并且可以说是一个关键的配置。你可以任意地**编辑这些配置**,根据你的偏好重新绑定键位。 22 | 23 | ## Input Manager 与 GUI 24 | 25 | 通常使用**输入(Input)**来移动屏幕上的角色,无论是通过触摸屏幕还是按下机械按键。Corgi Engine 用 Input Manager 组件来处理输入检测并将其传递给角色。Corgi Engine 的大部分关卡都有一个 UICamera 对象。这个 UICamera Prefab 也有一堆移动控制相关的东西,用来在移动设备上控制玩家角色。为此,同时为了让绑定更加简单,你会发现 InputManager 组件放置在 UICamera Prefab 的顶层。你愿意的话也可以将它放置在单独的 GameObject 上。 26 | 27 | `InputManager` 是一个很长的类,不过如果你细看一下就会发现它并不复杂,只是非常琐碎。它有很多让你能够绑定移动设备控制的方法,以及为每一个登记的按键管理一个小状态机。 28 | 29 | 在它的 Inspector 视窗你可以指定 **Player ID**(阅读下一小节以了解详细信息),无论你使用的是移动设备检测还是强制使用移动设备控制。你也可以决定使用虚拟方向键/十字键或者虚拟操纵杆。最后你可以设置平滑运动的开关(当按下按键时是应该即时移动还是要快速的线性插值?),还有水平和竖直方向的阈值。 30 | 31 | ## Player ID 32 | 33 | ![InputManager 的 PlayerID(右图)必须匹配你要操控的角色中的 PlayerID](media/15011514343185.jpg) 34 | 35 | 这里要理解的一个重要概念就是 **Player ID**。引擎能够从 InputManager 获得输入然后发送给场景中的玩家角色(带有 `Character` 组件且类型设置为 `Player` 的对象)。每一个 InputManager 都有一个 `Player ID` 属性,它会将它的信息发送给所有匹配上 `Player ID` 属性的角色。所以有一些方法可以让它工作: 36 | 37 | * 最普遍的方法是**交给引擎来处理**。添加一个 InputManager 组件到场景中,设置它的 `Player ID` 为 `Player1`。然后在 LevelManager 对象的 Inspector 视窗中,当你添加完角色后(在 Player Prefabs 设置项下面),勾选 `Auto Attribute Player IDs`,接着它就会自动标识玩家角色的 ID 为 `Player1`。如果在一个多玩家关卡中,则会使用 `Player2`、`Player3` 和 `Player4`。当然你也可以添加自定义的 `Player ID`,但以上这些是默认的。 38 | * 你也可以**在 Prefab 上**设置 `Player ID`。例如有一个 Dog 角色,它的 `Player ID` 是 `JoeTheDog`。如果你添加了一个 InputManager 到场景中,并且想设置它的目标为这个 Dog 角色,那么设置它的 `Player ID` 参数为 `JoeTheDog` 即可。按下 Play 按钮,应当就可以控制你的 Dog 角色了。如果由于某些原因你不想使用 LevelManager,又想马上移动场景中的 Prefab 时,使用这种方法就非常好。 39 | 40 | 当调整一个角色的时候,我更多地使用第二种方法。例如我想要修改角色上的跳跃行为,我只需要拷贝该角色的 Prefab,把这个拷贝放到场景中,并且设置它的 `Player ID` 为 `Player1`。然后在 LevelManager 中,将原始的 Prefab 设置为关卡的 Player Prefab。按下 Play 按钮,现在我就可以使用同样的输入控制两个角色(调整前和调整后的)啦。接下来我可以更改其中一个的跳跃设置(甚至用一个新的跳跃脚本替换掉旧的),快速地测试这两个角色,看看这些更改是否提升了游戏体验。 41 | 42 | ## 平台检测是如何工作的? 43 | 44 | 在 InputManager 组件的 Inspector 视窗中,你可以开启或关闭 **Auto Mobile Detection**。 45 | 46 | 如果你展开 UICamera Prefab,会发现它包含了很多东西,最明显的就是方向键(Arrows)、操纵杆(Joystick)和按键(Buttons)这几个画布分组(Canvas Groups)。它们**默认为不可用(Disable)**,以适应更简单的关卡,但你也可以开启或者调整它们。这些(以及其他东西)都是在 GUIManager 组件中绑定的。移动设备检测的工作方式很简单:如果你的目标是移动设备平台(iOS 或者 Android),当你按下 Play 按钮的时候这些操纵组件会显示出来;如果你的目标是其他平台,它们就会**隐藏且变为不可用**。通过 Inspector 视窗,你可以强制设置为任何一种模式。 47 | 48 | ## 虚拟方向键、操纵杆和按钮 49 | 50 | ![方向键的 Touch Axis 组件的 Inspector](media/15012114241306.jpg) 51 | 52 | Corgi Engine 资源中包含了完整功能的十字方向键、操纵杆和一些按钮,当然你也可以将它们混合搭配使用,添加新的按钮、操纵杆等等,以适配你的游戏玩法。 53 | 54 | **移动方向键(Mobile Arrows)**非常简单,只需要将一个 `MMTouchAxis` 组件放置在一个 Rect+CanvasGroup 对象上。接着在它的 Inspector 视窗中设置 `Axis Value`(通常对于左/下为 `-1`,对于右/上为 `1`),然后将它的` Axis Pressed` 事件绑定到 InputManager。操作方法是,拖拽 InputManager(大部分情况下在场景的 UICamera 对象下)到 `Runtime Only` 下方的小方框中,然后选择适当的方法(`SetVerticalMovement`、`SetHorizontalMovement` 或者对应 Secondary 方法)。 55 | 56 | **移动操纵杆(Mobile Joysticks)**甚至更容易设置。只需要添加一个 `MMTouchAxis` 组件到一个 Rect+CanvasGroup 对象上,设定哪个轴是可用的(比如你只想要一个水平方向的操纵杆),`Max Range`(球形柄离原始位置的最大距离),最后再绑定到 InputManager。注意你还需要指定一个目标摄像头(`Target Camera`,通常是场景中的 UICamera)。 57 | 58 | **按钮(Buttons)**的工作方式也一样,但你可以为它们指定 3 种不同的事件:`Button Down`(当它第一次被按下时),`Button Up`(但它被松开时),以及 `Button Pressed`(当它在某一帧被按下时)。这样你就可以在某个按钮松开时让你的 Character Ability 组件(举个例子)调用某个方法了。你不需要绑定所有事件,如果你没有全用到它们的话。 59 | 60 | ## Nice Touch 61 | 62 | Corgi Engine 包含了另一个由 More Mountains 出品的插件:[Nice Touch](https://www.assetstore.unity3d.com/cn/#!/content/65358)。如果你已经有了 Corgi Engine 就不用再买它了!我创建 Nice Touch 是为了提供一个简单快速的输入解决方案。它负责处理键盘、游戏手柄和触摸屏幕输入。除此之外还有很多其他的输入解决方案。有一段时间 Corgi Engine 使用的是 Unity 的标准资源中的 `CrossPlatformInput` 组件。创建 Nice Touch/MMControls 是为了提供一个更简单的替代品,更快捷的设置,而除去那些不必要的设置。你也可以用回自己的组件而不一定要使用这些。 63 | 64 | 你可以在路径 `MMTools/MMControls` 下找到这些脚本,在同一个目录底下还包含了一个测试场景:MMControlsTestScene。你需要在你的游戏中保持这个目录。 65 | 66 | ------- 67 | 68 | [本页面的 Corgi Engine 官方英文原版链接](http://corgi-engine-docs.moremountains.com/input.html) 69 | 70 | # Input 71 | 72 | > **Summary:** This page explains how to setup input in your game. 73 | 74 | ## Introduction 75 | 76 | Input is at the heart of every game. The Corgi Engine is no exception. It currently supports mobile controls (iOS, Android…), keyboard, gamepad (setup for windows xbox pad but feel free to rebind the keys for other controllers), and mouse. 77 | 78 | ## Default Input 79 | 80 | By default the keyboard layout has been created to support 4 simultaneous players. Now that may not be very comfortable for a single player game, feel free to remap the buttons to suit your needs (see the following section). In any case, here is the default layout (click on the image to expand) : 81 | 82 | ![The default keyboard layout, supporting 4 simultaneous players](media/15011432639033.jpg) 83 | 84 | ## Input Settings - How to change key bindings? 85 | 86 | ![That's a lot of axis](media/15011436782426.jpg) 87 | 88 | For keyboard and gamepad (and to a lesser extent mouse), key bindings are defined, like in any good Unity project, **via the native Input settings**. You can access these via the top menu Edit > Project Settings > Input. This should open a quite large list of “axis”. If you’ve never seen this panel before, maybe [have a look at the official documentation first](https://docs.unity3d.com/Manual/class-InputManager.html). 89 | 90 | Now that list is pretty long. That list has been filled to support 4 players (you could add more if you want), and proposes one key configuration. Feel free to **edit each of these** to rebind the keys to your preference. 91 | 92 | ## Input Manager and GUI 93 | 94 | To move your character on screen, you usually use **input**, whether it’s via touch on a screen or by pressing mechanical keys. To handle input detection and pass it to your Character, the Corgi Engine uses an Input Manager. Most levels of the Corgi Engine have a UI Camera in them. This UI Camera prefab also has, nested inside it, a bunch of mobile controls used to control the player when playing on mobile. For that reason, and to make binding easier, you’ll find the InputManager at the top level of the UICamera prefab. You can decide to place it on its own game object if you prefer. 95 | 96 | The Input Manager is quite a long class. If you take a look at it, you’ll see it’s **not too complex**, just very verbose. It has a lot of methods that you’ll be able to bind to your mobile controls, and manages a small state machine for each of the registered buttons. 97 | 98 | From its inspector you’ll be able to specify the **PlayerID** (see the next section for more on that), whether or not you want to use mobile detection or force mobile controls. You can also decide whether you prefer virtual arrows/dpad or virtual joystick. And finally you can set smooth movement on or off (should a press on left be instant or quickly lerped?), and the horizontal and vertical thresholds. 99 | 100 | ## Player ID 101 | 102 | ![Your InputManager's PlayerID (right) must match the one on the Character(s) you want to control](media/15011514343185.jpg) 103 | 104 | One thing here that is **really important** to understand is the **PlayerID** notion. The engine is able to send input from the InputManager to playable characters in the scene (objects with a Character component whose type is set to Player). Each InputManager has a PlayerID attribute, and it’ll send its information **to all characters whose own PlayerID attribute match it**. So there are a few ways this can work : 105 | 106 | * The most common way is to simply **let the engine handle this**. Add an InputManager to your scene, set its PlayerID to “Player1”. Then in the LevelManager, when you add your character, have the “**Auto attribute player IDs**” checkbox checked, and it’ll automatically give the playable character the “Player1” ID. If you are in a multiplayer level use “Player2”, “Player3” and “Player4”. You can add your own of course, but these are the default ones. 107 | * You can also set the PlayerID **on the prefab**. For example you could have a Dog character, whose PlayerID is “JoeTheDog” (why not?). If you add an InputManager to your scene and want it to target that Dog character, set its own PlayerID parameter to “JoeTheDog”. Press play and you should be able to control your Dog character. That method is great if for some reason you don’t want to use the Level Manager and want to instantly move a prefab in the scene. 108 | 109 | I use that second method a lot **when tweaking a character**. Let’s say I want to change the Jump behaviour of my character. I’ll just copy my character’s prefab, put that copy in the scene, set its PlayerID to Player1. Then in the LevelManager I put the original prefab as the Player Prefab. I press play and I’m now controlling two characters with the same input. I can then change the jump settings on one of them (or even add a new Jump script in place of the old one), and **play test both very fast** to see if my changes are improving the gameplay. 110 | 111 | ## How does platform detection work? 112 | 113 | From the InputManager’s inspector you can turn **auto mobile detection** on or off. 114 | 115 | If you unfold the UICamera prefab, you’ll see it contains quite a lot of stuff, and notably Arrows, Joystick and Buttons canvas groups. They’re **disabled by default** to allow for simpler level editions but you can turn them on if you prefer, or to tweak them. These are then bound to the GUIManager component (among other stuff). Mobile detection works in a very simple way : if you’re targeting a mobile platform (iOS or Android), it’ll show the controls when you press play. If you’re targeting another platform, it’ll **hide and disable them**. You can also force one mode or the other from the inspector. 116 | 117 | ## Virtual Arrows, Joysticks and Buttons 118 | 119 | ![The Touch Axis (arrows) inspector](media/15012114241306.jpg) 120 | 121 | The asset comes packed with a fully functional arrow D-pad, a joystick and some buttons, but of course **you can remix all that**, add buttons, add joysticks, etc. to match your own gameplay. 122 | 123 | **Mobile arrows** are very simple, you just need an MMTouchAxis component on a Rect+CanvasGroup object. Then in its inspector you need to set the axis value (usually -1 for left/down or 1 for right/up). Then you need to bind it to your InputManager, simply on the AxisPressed event. To do that, just drag your InputManager (in most cases the UICamera prefab in your scene) onto the little box below “runtime only”, and then select the appropriate method (SetVerticalMovement, SetHorizontalMovement, or their secondary counterparts). 124 | 125 | **Mobile joysticks** are even easier to setup. Just add a MMTouchJoystick component to a Rect+CanvasGroup object, define which axis are enabled (you may want an horizontal only stick for example), the max range (how far the knob can move from its base), and then you bind your input manager to it. Note that you’ll also need to specify a target camera (usually your UICamera). 126 | 127 | **Buttons** work in the same way too, but for them you’ll be able to specify three different events : button down (when it’s pressed for the first time), button up (when it’s released), and button pressed (when it’s being pressed at a certain frame). This will allow you in your Character Abilities (for example) to call certain methods when a button gets released for example. You don’t have to bind all events if you’re not using all of them. 128 | 129 | ## Nice Touch 130 | 131 | The Corgi Engine includes another of More Mountains’ assets : [Nice Touch](https://www.assetstore.unity3d.com/en/#!/content/65358). **Don’t buy it if you already own the Corgi Engine!** I created Nice Touch to provide **a simple and fast input solution**. It handles keyboard, gamepad, mouse, and touch input. There are a lot of other input solutions out there. For a while the Corgi Engine used Unity’s standard assets’ CrossPlatformInput. Nice Touch/MMControls were created to give a simpler alternative, faster to setup, without unnecessary settings. Feel free to not use these and replace them with your own. 132 | 133 | You’ll find these scripts into MMTools/MMControls. That same folder also includes a test scene : MMControlsTestScene. You’ll want to keep that folder in your game. 134 | 135 | ------- 136 | 137 | 138 | -------------------------------------------------------------------------------- /3.General/3-3.Managers.md: -------------------------------------------------------------------------------- 1 | # Managers 2 | 3 | > 这个页面讲解了 Corgi Engine 中包含的各种 Manager,以及如何根据你的需求来调整它们。 4 | 5 | ## 简介 6 | 7 | Corgi Engine 使用 Manager 来作为大量类和组件的**核心引用点**。这些 Manager 会一直存在于你的场景中,它们会记录当前得分、播放中的声音,或者角色重生的位置。 8 | 9 | 其中,在大部分场景中,都会有 Game Manager、Level Manager、Input Manager 和 Sound Manager 一直存在着。通常要把它们放置在空的 GameObject 中。它们在场景中的位置无关紧要,反正它们是不可见的。一个好的习惯就是把它们放置在远离你的关卡物件的地方,以免不小心把它们给删了。 10 | 11 | ## Game Manager 12 | 13 | **Game Manager** 是一个高层次的管理类,负责设置目标帧率、存储得分、处理时间比例(Timescale),以及记录玩家上一次在关卡地图中的位置。大多数情况下,你都**不需要跟它打交道**,只需要保证关卡中存在着一个 Game Manager 即可。如果你想了解更多详细信息,可以查阅 [API 文档](http://corgi-engine-docs.moremountains.com/API/)。 14 | 15 | ## Level Manager 16 | 17 | Level Manager 是很多引擎脚本的引用点,它维护了一张游戏中玩家角色的列表(通常是一个玩家,但也可以有多个)。同时它还负责出生(Spawn)和重生(Respawn),以及记录点(Checkpoint)管理。 18 | 19 | 请留意还有一个 **Multiplayer Level Manager** 也起着类似的作用,但是针对多玩家关卡使用的。 20 | 21 | ![FeaturesPlatforms Demo 场景中的 LevelManager 的 Inspector 视窗](media/15012273290066.jpg) 22 | 23 | 大部分情况下,每个关卡都要有一个 **LevelManager**,它需要放置在单独的 GameObject 中。在它的 Inspector 视窗中你可以(也应当)设置将哪个 Prefab 作为玩家角色。做法是,首先展开 `Player Prefabs` 选项(如果它折叠起来的话),然后从 Project 视窗中拖拽一个 Prefab 到 `Element 0` 字段中。如果是多玩家关卡,则先设置 Player Prefabs 数组的 `Size` 大于 `1`,然后再重复以上过程。关于 `Auto Attribute Player IDs` 复选框,可以查阅 [Input 页面](https://github.com/Caizc/corgi-engine-docs/blob/master/3.General/3-2.%E8%BE%93%E5%85%A5.md)的内容。 24 | 25 | 你还可以设定一个 **Debug Spawn**(从场景视图中拖拽一个,或者点击字段右边的小圆点然后在打开的弹出窗口中选择一个)。这个调试出生点(Debug Spawn)是在编辑器模式(Editor Mode)下玩家角色出生的地方(在调试一个关卡最后部分的时候很有用)。 26 | 27 | 通过 LevelManager 的 Inspector 视窗你还可以设置**关卡的边界(Level Bounds)**。它们是关卡的边界,摄像头的范围不会超过它们,在大部分情况下角色也一样。要设置它,首先设置它的中心位置,然后更改边框的覆盖范围。你应该可以在 Scene 视图中看到这个黄色的边框。 28 | 29 | ## Input Manager 30 | 31 | **Input Manager** 负责处理输入并且将指令发送给玩家角色。[Input 页面](https://github.com/Caizc/corgi-engine-docs/blob/master/3.General/3-2.%E8%BE%93%E5%85%A5.md)给出了更加详细的信息。 32 | 33 | **这个脚本的执行顺序(Execution Order)必须是 -100**,以确保在每次 `Update()` 中都被优先执行,并且避免各种奇怪的副作用,特别是在低帧率的情况下。如果你把 Corgi Engine 导入到一个空的项目中,则应该已经设置好了。你可以通过**点击脚本文件**,然后点击位于脚本 Inspector 视窗右上方的 **Execution Order 按钮**来设定一个脚本的执行顺序。查阅[这个页面](https://docs.unity3d.com/Manual/class-ScriptExecution.html)了解更多细节。 34 | 35 | ## Sound Manager 36 | 37 | 顾名思义,**Sound Manager** 负责管理 Corgi Engine 中的声音播放。当然你也可以通过在代码中使用 Unity 的原生 API 来直接播放声音,但是使用 Sound Manager 可以确保所有声音播放都使用**同样的音量设置**,这样当声音被禁用时它们就不会被播放等等。它通常和 GameManager 脚本放置在同一个 Prefab 对象中。在它的 Inspector 视窗(或者代码)中,你可以设置背景音乐(Music)和音效(SFX)的音量,还有它们各自是否启用。你可以在 [API 文档](http://corgi-engine-docs.moremountains.com/API/)中查阅更多细节,不过你主要会用到以下方法: 38 | 39 | * 播放一段背景音乐(会把之前任何播放中的背景音乐替换掉): 40 | 41 | ```csharp 42 | PlayBackgroundMusic(AudioSource Music); 43 | ``` 44 | 45 | * 播放一段音效。你可以为它指定一个空间位置,以及是否应该循环播放(这种情况下请记得停止它): 46 | 47 | ```csharp 48 | PlaySound(AudioClip sfx, Vector3 location, bool loop=false); 49 | ``` 50 | 51 | ## Loading Scene Manager 52 | 53 | 在 Unity 中,通常当你想切换到另一个场景时(例如在一个菜单界面,或者从一个场景进入下一个),你会使用 **SceneManager API**,而且很可能是 `SceneManager.LoadScene()` 方法。Corgi Engine 有自己的切换场景的 API,不过你要是不喜欢的话完全可以**不用它**。我个人觉得 Unity 的方法没有为玩家提供视觉反馈,然而场景加载在诸如移动设备上需要耗费一段时间,所以只是显示一个黑屏看起来**并不美观**。 54 | 55 | ![Scene 视图中的 LoadingScene](media/15012325544967.jpg) 56 | 57 | 如果你想为玩家提供更好的体验,你可以使用 **Loading Scene Manager**: 58 | 59 | * 它可以在**任何地方**被调用,所以你不需要在场景中放置一个 `LoadingSceneManager` 组件。 60 | * 它负责处理加载(顾名思义),展示一段**动画(Animation)**和一个**进度条(Progress Bar)**。 61 | * 它是完全**可定制的(Customizable)**,只要编辑路径 `Common/LoadingScreen` 场景中的内容。你可以轻易地加入自己的 logo,更改进度条的外观,以及播放的动画等。 62 | * 使用它真的很**简单**。 63 | 64 | 想要在关卡切换的时候使用 LoadingSceneManager API,只需要调用 `LoadingSceneManager.LoadScene(string sceneToLoad)` 方法。传入其中的 string 参数当然必须与你要加载的场景名称**一致**。所以,如果你想加载最小多玩家 Demo 的话,你可以这样使用: 65 | 66 | ```csharp 67 | LoadingSceneManager.LoadScene ("Minimal4Players"); 68 | ``` 69 | 70 | 然后剩下的就交给引擎来搞定吧。 71 | 72 | ## 扩展 Manager 73 | 74 | 如果基于某些原因你想要修改一个 Manager 的行为,最好的方式就是扩展它,这样当你更新插件的时候你就不会丢失已有的更改。扩展一个 Manager 相当简单,你只需要创建一个继承自要修改行为的 Manager 的新的类,就像这样: 75 | 76 | ```csharp 77 | using UnityEngine; 78 | using System.Collections; 79 | using MoreMountains.Tools; 80 | using System.Collections.Generic; 81 | 82 | namespace MoreMountains.CorgiEngine 83 | { 84 | public class NewGameManager : GameManager 85 | { 86 | protected override void Start() 87 | { 88 | base.Start(); 89 | MMDebug.DebugLogTime("new game manager"); 90 | } 91 | public override void Pause() 92 | { 93 | base.Pause(); 94 | MMDebug.DebugLogTime("new game manager pause"); 95 | } 96 | public override void AddPoints(int pointsToAdd) 97 | { 98 | base.AddPoints(pointsToAdd); 99 | MMDebug.DebugLogTime("new game manager add points"); 100 | } 101 | } 102 | } 103 | ``` 104 | 105 | 在这个例子中,一个新的 GameManager 被创建,并且一些方法被重载了。它们只是做了基类所做的事情,然后输出一条 Debug 信息。当然,你应该让它们做更多的事情。你只需要把新的 Manager 放置到场景中的一个对象上,然后移除掉它原来的基类(扩展前的 Manager 脚本)。 106 | 107 | ------- 108 | 109 | [本页面的 Corgi Engine 官方英文原版链接](http://corgi-engine-docs.moremountains.com/managers.html) 110 | 111 | # Managers 112 | 113 | > **Summary:** This page covers the various managers included in the Corgi Engine and how to tweak them to your needs. 114 | 115 | ## Introduction 116 | 117 | The **Corgi Engine** uses managers as **central reference points** for a lot of classes and components. These managers, **always present in your scene**, will remember the current points count, the sounds that are playing, or where to spawn the character. 118 | 119 | There are a few of them, and in most scenes you’ll have a Game, Level, Input and Sound managers present at all time. Usually you’ll want to place them on empty gameobjects. Their position in your scene doesn’t matter, they’re invisible anyway. It’s good practice to put them out of the way of your level so you don’t delete them by accident. 120 | 121 | ## Game Manager 122 | 123 | The **Game Manager** is a high level manager that is responsible for setting the target frame rate, storing the points, handling the timescale, and remembering where on the level map the player was last time. In most cases **you won’t have to interact with it**, but make sure there’s one in your levels. The API documentation is a good place to go to if you want more information about it. 124 | 125 | ## Level Manager 126 | 127 | The **Level Manager** is a reference point for a lot of the engine’s scripts. It maintains a list of player characters in the game (usually one but you could have more if you want). It’s also in charge of spawn and respawn, and checkpoint management. 128 | 129 | Note that there’s also a **Multiplayer Level Manager**, which does pretty much the same thing, but for multiplayer levels. 130 | 131 | ![The LevelManager's inspector from the FeaturesPlatforms demo scene](media/15012273290066.jpg) 132 | 133 | In most cases you’ll want a **LevelManager** in each of your levels. It needs to be on its own gameobject. From its inspector you can (and should) set what prefab to use as the player. To do so, unfold the PlayerPrefabs dropdown if it’s folded, and just drag a prefab from your project view into the Element0 field. If you’re in a multiplayer level, set the size of the PlayerPrefabs array to more than 1 and repeat the process. For more information about the “Auto Attribute Player ID” checkbox, [check out the Input page](http://corgi-engine-docs.moremountains.com/input.html). 134 | 135 | You can also define a **debug spawn** (drag one from the scene view, or click on the little dot at the right of the field and select one from the popup window that will open). This debug spawn will be where your player will spawn while in editor mode (useful to tweak the end of a level for example). 136 | 137 | The level manager’s inspector is also where you’ll be able to set the **level bounds**. They’re the limits of your level, your camera won’t go beyond that, and in most cases neither will your character. To set that up, just set the center’s position, and change the extends of the bounding box. You should see the bounding box in yellow in the scene view. 138 | 139 | ## Input Manager 140 | 141 | The **Input Manager** handles the inputs and sends commands to the player. It’s described in more details [on the Input page](http://corgi-engine-docs.moremountains.com/input.html). 142 | 143 | **This script’s Execution Order MUST be -100**, to make sure it always runs first on each Update(), and avoid weird side effects, especially at low framerates. If you’ve imported the engine into a blank project that should already be the case. You can define a script’s execution order by **clicking on the script’s file** and then clicking on the **Execution Order button** at the bottom right of the script’s inspector. See [this page](https://docs.unity3d.com/Manual/class-ScriptExecution.html) for more details. 144 | 145 | ## Sound Manager 146 | 147 | As its name implies, the **Sound Manager** is in charge of playing sounds in the Corgi Engine. Of course you can play them directly in your code using Unity’s native APIs, but using the Sound Manager will ensure that it’s played using **the same volume settings** as other sounds, that they won’t be played if sound has been disabled, etc. It’s usually found on the same prefab as the GameManager script. From its inspector (or from your code), you’ll be able to set the music and sound effects (Sfx) volume, and whether or not each is active. You can have a look at the [API documentation](http://corgi-engine-docs.moremountains.com/API/) for details, but mostly you’ll be using the following methods : 148 | 149 | **To play a background music** (will replace any previously playing background music) : 150 | 151 | ```csharp 152 | PlayBackgroundMusic(AudioSource Music); 153 | ``` 154 | 155 | **To play a sound effect** - you can specify its position in space, and whether or not it should loop (make sure you stop it in this case) : 156 | 157 | ```csharp 158 | PlaySound(AudioClip sfx, Vector3 location, bool loop=false); 159 | ``` 160 | 161 | ## Loading Scene Manager 162 | 163 | With Unity, usually when you want to go to another scene (in a menu, or to go from one level to the next for example), you’d use the **SceneManager API**, and probably the SceneManager.LoadScene() method. The engine comes with its own scene change API, that you’re completely free **not to use** if you don’t like it. Personnally I think that this method doesn’t provide visual feedback to the player, and scene loading on mobile for example can be a few seconds long, so just having a black screen there **isn’t really good looking**. 164 | 165 | ![The LoadingScene in scene view](media/15012325544967.jpg) 166 | 167 | If you want to provide a better experience to your player, you can use the **Loading Scene Manager** : 168 | 169 | * it can be called from **anywhere**, you don’t have to have a LoadingSceneManager in your scene 170 | * it handles loading (as the name implies), showing an **animation** and a **progress bar** 171 | * it’s completely **customizable**, just edit the Common/LoadingScene scene’s contents. You can easily add your own logo, change the look of the progress bar, what animation is playing, etc. 172 | * it’s pretty **simple** to use 173 | 174 | To use the LoadingSceneManager API, when you want to change level, just call the LoadingSceneManager.LoadScene (string sceneToLoad) method. The string parameter you pass must of course **match** the name of the scene you’re trying to load. So if you were to load the minimal demo multiplayer level for example, you’d use : 175 | 176 | ```csharp 177 | LoadingSceneManager.LoadScene ("Minimal4Players"); 178 | ``` 179 | 180 | And the engine will take care of the rest. 181 | 182 | ## Extending a manager 183 | 184 | If for some reason you want to modify a manager’s behaviour, the best way to do so is to extend it. That way, you won’t lose your changes if you update the asset. Extending a manager is fairly easy. All you have to do is create a new class, that inherits from the manager whose behaviour you want to change, like so : 185 | 186 | ```csharp 187 | using UnityEngine; 188 | using System.Collections; 189 | using MoreMountains.Tools; 190 | using System.Collections.Generic; 191 | 192 | namespace MoreMountains.CorgiEngine 193 | { 194 | public class NewGameManager : GameManager 195 | { 196 | protected override void Start() 197 | { 198 | base.Start(); 199 | MMDebug.DebugLogTime("new game manager"); 200 | } 201 | public override void Pause() 202 | { 203 | base.Pause(); 204 | MMDebug.DebugLogTime("new game manager pause"); 205 | } 206 | public override void AddPoints(int pointsToAdd) 207 | { 208 | base.AddPoints(pointsToAdd); 209 | MMDebug.DebugLogTime("new game manager add points"); 210 | } 211 | } 212 | } 213 | ``` 214 | 215 | In this example, a new GameManager is created, and a few of its methods are overridden. They don’t do much, they just do what the base class does, and then output a debug message. Of course, you could have them do much more. All you have to do then is to place that new manager in your scene on an object, and remove the base one. 216 | 217 | ------- 218 | 219 | -------------------------------------------------------------------------------- /3.General/3-4.碰撞.md: -------------------------------------------------------------------------------- 1 | # 碰撞 2 | 3 | > 这个页面讲解了 Corgi Engine 如何处理碰撞。 4 | 5 | ## 简介 6 | 7 | 创建 Corgi Engine 是为了取代那些基于物理特性的平台游戏,它旨在提供**更为紧凑流畅的游戏体验**,更高效,而且比基于物理特性的实现更易于预测。为此,引擎实现了它自己的「物理特性」:碰撞检测、移动等等。需要明确的是,Corgi Engine 绝对不是一个物理引擎,**它与 Unity 正式的物理引擎没有可比性**,所以如果你计划用它来重新创造一个 Angry Birds,那是不可能成功的。 8 | 9 | Corgi Controller 是这个系统的核心,它是**每一个角色的基础**。它的主要功能是处理碰撞和基础移动。你可以给它添加或设置作用力来使它移动,一般是通过 Character Abilities 中的组件。 10 | 11 | Corgi Engine 通过发射射线(**Raycast**)来处理碰撞,当你运行游戏时,可以在 Scene 视窗中看到它们。它的工作原理从本质上讲就是 Controller 会向它的四周发射一些小射线,像微型激光一样。如果水平的激光击中了物体,那它可能碰到了墙壁或者斜坡。如果竖直的激光击中了物体,那它可能碰到了地面或者天花板。这取决于每一帧应用到对象上的作用力,也取决于射线有没有击中物体,Controller 负责在场景中移动对象,以及在对象穿墙而过之前让它停下来之类的事情。 12 | 13 | 作为角色的核心,Corgi Controller 在 Inspector 视窗中的设置相当重要。在那里你可以规定重力、各种速度参数,以及什么样的斜坡角色可以攀爬(以及攀爬的速度)等等。 14 | 15 | 你还需要规定 **Collision Masks**。Corgi Controller 支持与各种不同的平台交互: 16 | 17 | * 普通平台(regular platforms,Platforms) 18 | * 移动平台(moving platforms) 19 | * 单向平台(one way platforms,可以从它下方跳上去的平台) 20 | * 单向移动平台(one way moving platforms) 21 | 22 | 默认情况下,引擎已经配置好了一系列 Layer,每种类型的平台都分别对应一个:Plaforms,MovingPlatforms,OneWayPlatforms,MovingOneWayPlatforms。如果你增加了更多的 Layer,或者修改了这些 Layer,请确保将这些修改应用到你的角色上。 23 | 24 | 在 Inspector 视窗中你还可以自定义 Raycast,它们的数量事实上取决于你的角色的尺寸大小。调整 Raycast 参数的目标是使用尽可能少的射线(基于性能考虑,虽然现今射线的数量已经不是什么大问题了),但同时射线之间又必须足够紧密,以避免任何平台、敌人或者物品小于两条射线的间距(在这种情况下引擎是无法检测到的)。 25 | 26 | ## Layers 27 | 28 | Corgi Engine 依靠 [Layers](https://docs.unity3d.com/Manual/Layers.html) 来识别某些物体,尤其是平台(Platforms)。Layer 是可以关联到 GameObject 的元数据(metadata),通过 Layer Mask(用来选中 Layer),你可以用它们来实现只往某些层发射射线。请注意,Layers 和 [Sorting Layers](https://unity3d.com/cn/learn/tutorials/topics/2d-game-creation/sorting-layers) 是完全不同的两样东西。在 Corgi Engine 中关于 Sorting Layers 并没有限制或命名约定。 29 | 30 | 以下是引擎中使用到的所有 Layer 的列表。注意只有平台(Platforms)相关的那些是必不可少的: 31 | 32 | * **Platforms**:所有常规的平台物体都应该在这一层中 33 | * **OneWayPlatforms**:应用于所有可以由下方穿越到上方的平台 34 | * **MovingPlatforms**:应用于所有移动的平台(Moving Platforms) 35 | * **MovingOneWayPlatforms**:应用于所有可以由下方穿越到上方的移动平台 36 | 37 | 以下这些 Layer 就不言自明啦(全非必不可少,只是为了整理场景中的东西): 38 | 39 | * **Water** 40 | * **UI** 41 | * **Player** 42 | * **Projectiles** 43 | * **Enemies** 44 | * **NoCollision** 45 | * **Invulnerable** 46 | 47 | ## Tags 48 | 49 | [Tags](https://docs.unity3d.com/Manual/Tags.html) 是可以关联到 GameObject 的元数据(metadata),通过它可以在其他脚本中更容易找到相应的对象。Corgi Engine 曾经依靠 Tags 来找到某些对象(大部分是玩家角色),但从 3.0 版本起就不再依赖 Tags 了。虽然你还是可以在脚本中使用它们,但不需要太过关注。 50 | 51 | ------- 52 | 53 | [本页面的 Corgi Engine 官方英文原版链接](http://corgi-engine-docs.moremountains.com/collisions.html) 54 | 55 | # Collisions 56 | 57 | > **Summary:** This page explains how the Corgi Engine handles collisions. 58 | 59 | ## Introduction 60 | 61 | The Corgi Engine was created as an alternative to physics based platformers, aiming to provide a **tighter gameplay**, faster, and more predictable than physics. To do so, the engine implements its own “physics” : collision detection, movement, etc. Note that this is absolutely not a physics engine, this is **not compatible with regular Unity physics**, and if you’re planning on recreating Angry Birds, this will not do the trick. 62 | 63 | The Corgi Controller is at the heart of this system. It’s **the basis for each character**. Its main function is to handle collisions, and basic movement. You’ll be able to add or set forces to it, usually via Character Abilities, which will make it move. 64 | 65 | To handle collisions, the Corgi Controller uses **raycasts**, which you can see in the scene view when playing your game. Basically how it works is that the controller is casting small rays all around itself, like tiny lasers. If a horizontal laser hits something, then we’ve probably hit a wall, or a slope. If a vertical ray hits something, we’ve hit the ground or the ceiling. Depending on the forces being applied every single frame, and based on whether or not the raycasts hit something or not, the controller will move the object around the scene, or make it stop to prevent it from entering a wall for example. 66 | 67 | Being at the center of your character, the Corgi Controller’s inspector settings are quite important. There you’ll be able to define the gravity, various speed factors, what slopes the character can climb (and at what speed). 68 | 69 | You’ll also need to define **Collision Masks**. The Corgi Controller can interact with different types of platforms : 70 | 71 | * regular platforms (Platforms) 72 | * moving platforms 73 | * one way platforms (platforms you can jump on from underneath) 74 | * one way moving platforms 75 | 76 | By default, the engine comes configured with a number of layers, and there’s one for each of these platforms : Plaforms, MovingPlatforms, OneWayPlatforms, MovingOneWayPlatforms respectively. If you add more layers, or change these, make sure to replicate these changes on your characters. 77 | 78 | From the inspector you can also customize the raycasts. Their number really depends on the size of your character. What you’ll want to achieve is **as few raycasts as possible** (for performance reasons, even though raycasts are not really an issue these days), but with raycasts close enough to each other that no platform/enemy/whatever could fit between two raycasts (and in this case wouldn’t be detected by the engine). 79 | 80 | ## Layers 81 | 82 | The engine relies on [layers](https://docs.unity3d.com/Manual/Layers.html) to identify certain objects, notably platforms. Layers are metadatas you can associate your gameobjects with, and you can then use these to casts rays on certain layers only, via Layer masks (a selection of layers). Note that layers and [sorting layers](https://unity3d.com/cn/learn/tutorials/topics/2d-game-creation/sorting-layers) are completely different things. There are no restrictions or naming conventions regarding sorting layers in the Corgi Engine. 83 | 84 | Here’s a list of all the layers used by the engine. Note that the only mandatory ones are the platform related ones : 85 | 86 | * Platforms : all your “regular” platforms should be in that layer 87 | * OneWayPlatforms : for all your platforms that can be accessed from underneath 88 | * MovingPlatforms : for all your moving platforms 89 | * MovingOneWayPlatforms : for all your moving platforms that can be accessed from underneath 90 | 91 | And these ones are pretty self-explanatory (and not mandatory at all, just used to tidy things up) : 92 | 93 | * Water 94 | * UI 95 | * Player 96 | * Projectiles 97 | * Enemies 98 | * NoCollision 99 | * Invulnerable 100 | 101 | ## Tags 102 | 103 | [Tags](https://docs.unity3d.com/Manual/Tags.html) are metadata you can add to your gameobjects to find them easier from other scripts. The engine used to rely on tags to find certain objects (player characters mostly). Since 3.0 it doesn’t rely on tags at all anymore. Feel free to keep using them in your scripts though, but that’s one less thing to keep an eye on. 104 | 105 | ------- 106 | 107 | 108 | -------------------------------------------------------------------------------- /3.General/3-5.重生.md: -------------------------------------------------------------------------------- 1 | # 重生 2 | 3 | > 这个页面讲解了游戏循环和重生机制。 4 | 5 | ## 重生(Respawn)如何工作? 6 | 7 | 在大部分平台游戏中,角色可以受到伤害,并且在生命值到达零时死亡。在 Corgi Engine 中这也是**默认的行为**。当角色受到伤害时,就开始了相关的一系列复杂的事件: 8 | 9 | * 角色受到 `X` 点伤害,这是 Character 上的 `Health` 组件负责处理的 10 | * 角色失去 `X` 点生命值 11 | * 如果角色的生命值小于等于零,`Health` 组件将调用它的 `Kill()` 方法,并且通知 LevelManager 玩家角色已经死亡 12 | * LevelManager 重置关卡,触发玩家角色和场景中潜在的其他对象的重生 13 | 14 | 重生的实现是通过检查玩家角色最后到达的检查点(Checkpoint),然后将它重置到那个位置,并且重置所有登记到该检查点的对象。对象会自动登记到场景中的检查点。如果你看一下任何一个 Demo 的 LevelManager 组件的 Inspector 视窗,都可以找到一个 `Checkpoint Attribution Axis` 复选框。默认情况下它被设置为 `X` 轴。比如说在一个横版关卡中(类似《超级马里奥》)有 3 个检查点,关卡中的每一个带有 **Autorespawn** 组件的敌人或对象在关卡开始的时候,都会登记到它左边的第一个检查点上。这意味着如果玩家角色在检查点 B 和 C 之间死亡,在它们之间那些可能已经被杀死的敌人都会复活。 15 | 16 | 如果你想要敌人或者对象可以重生,只需要为它们添加一个 **Autorespawn** 组件。 17 | 18 | ## 检查点(Checkpoints) 19 | 20 | ![当游戏运行时,在场景视图中,各个检查点会被一条绿线连接起来](media/15014710179423.jpg) 21 | 22 | 在 Corgi Engine 中创建和放置检查点**超级简单**,你需要做的就是创建一个空的 GameObject,然后为它添加一个 **Checkpoint** 组件,它就会自动地添加一个 **BoxCollider2D** 组件。接着要做的就是调整 BoxCollider2D 组件的尺寸,这个尺寸决定了触发这个检查点的区域大小,确保它足够大以保证角色经过时不会错过。你还可以在 Checkpoint 的 Inspector 视窗中设置朝向,这个方向决定了当角色重生时它会朝向哪个方向。 23 | 24 | 然后把检查点放置到场景中适当的位置,并且添加多几个。最后,你可以在 LevelManager 的 Inspector 视窗中,设定 **Checkpoint Attribution Axis**。如果关卡是横版的,设置它为 `X`;如果关卡是竖版的,设置它为 `Y`。当你按下 Play 按钮之后,在场景视图中会看到所有检查点根据被经过的顺序被一条绿线串联起来。 25 | 26 | ------- 27 | 28 | [本页面的 Corgi Engine 官方英文原版链接](http://corgi-engine-docs.moremountains.com/respawn.html) 29 | 30 | # Respawn 31 | 32 | > **Summary:** This page goes over the game cycle and respawn mechanisms. 33 | 34 | ## How does respawn work? 35 | 36 | In most platform games, your character can take damage, and eventually die if its health reaches zero. In the Corgi Engine that’s also the **default behaviour**. When your character takes damage, a relatively complex chain of events starts : 37 | 38 | * your character takes X damage, this is handled by the Health component of your character 39 | * it loses X health 40 | * if its health goes below zero, the Health component calls its Kill() method and tells the LevelManager that the player is dead 41 | * the LevelManager resets the level, triggering the Respawn of the player and potentially other objects within the scene 42 | 43 | That Respawn is done by checking what checkpoint the player last reached, repositioning the player there, and also respawning all the objects registered to that checkpoint. Objects register automatically to checkpoints in the scene. If you look at any LevelManager in any of the demo scenes for example, you’ll see a “Checkpoint Attribution Axis” checkbox in its inspector. By default it’s set on the X axis. Let’s say you have a horizontal level (think Super Mario), and three checkpoints on it. Every enemy or object in that level with an **Autorespawn** component will, at the start of the level, register to the first checkpoint to its right. Which means that if your character dies between checkpoints B and C, all enemies it may have killed between them will respawn too. 44 | 45 | If you want your enemies or objects to respawn, just put an **Autorespawn** component on them. 46 | 47 | ## Checkpoints 48 | 49 | ![Checkpoints being linked by a green line in scene view while game is running.](media/15014710179423.jpg) 50 | 51 | Creating and placing checkpoints in the Corgi Engine is **extremely simple**. All you have to do is create an empty game object, and add a **Checkpoint component** to it. It should automatically add a **BoxCollider2D** to it. All you have to do then is change the BoxCollider2D’s size. That size will determine the zone that will trigger the checkpoint, make it big enough so that your character won’t miss it. You can also set the facing direction from the Checkpoint component’s inspector. That’s the direction your player character will be facing when respawing. 52 | 53 | You can then position your checkpoint in your scene, and add a few more. One last thing you can do is go to your LevelManager’s inspector, and define the **Checkpoint Attribution Axis**. If your level is horizontal, go for X, if it’s vertical for Y, etc. When you press play, you’ll see all your checkpoints linked by a green line in the order they’ll have to be crossed. 54 | 55 | ------- 56 | 57 | 58 | -------------------------------------------------------------------------------- /3.General/3-6.UI.md: -------------------------------------------------------------------------------- 1 | # 用户界面 2 | 3 | > 这个页面讲解了在 Corgi Engine 中 UI 如何工作。 4 | 5 | ## 简介 6 | 7 | 在专注于游戏玩法的同时,Corgi Engine 也包含了随处可见的用来与玩家沟通的 **GUI** 元素。通常它们只是充当占位符(因为你会用自己的美术资源替换它们),不过理解它们是如何工作的依然很有用处。 8 | 9 | ## UI Camera 10 | 11 | 引擎中的大部分关卡都配有两个[摄像机](https://github.com/Caizc/corgi-engine-docs/blob/master/3.General/3-9.%E6%91%84%E5%83%8F%E6%9C%BA.md):一个普通的 2D 或 3D 摄像机,以及一个 UI 摄像机。后者负责显示游戏的 HUD,以及其他非游戏世界中的视觉元素。如果仔细看一下 UICamera Prefab,会发现它还包含了按钮、方向键、操纵杆和暂停界面等等。所有这些都是由位于 Prefab 顶层的 GUI Manager 组件控制的,它们都绑定到了 GUI Manager 组件的 Inspector 视窗中。 12 | 13 | ## 游戏 HUD 14 | 15 | **HUD** 是 UICamera Prefab 的一部分,它包含了喷气能量条、血条、头像,以及得分、关卡名称和每秒帧数(FPS,Frames per Second)计数器。所有这些都绑定到了 GUI Manager 组件并且通过它的各种方法来更新。你可以随意定制它们的外观、字体等。 16 | 17 | ## 暂停界面 18 | 19 | **暂停界面(Pause Screen)**是 UICamera 的一部分,包含了一个黑色的遮罩层、一些文本和按钮。你当然可以(也应当)定制它们,以适应你自己的按钮和美术风格。为此,只需要展开 UICamera Prefab,定位到 PauseSplash 然后进行更改即可。 20 | 21 | ## 对话窗口 22 | 23 | ![一个简单的对话示例](media/15014817559889.jpg) 24 | 25 | 引擎包含了一个**非常简单的对话系统**,让你可以在关卡中的任何地方显示单向对话或提示信息。只需要定义好一个区域(Zone)就可以使用它。区域是一个具有 BoxCollider2D 的 GameObject,决定了想要激活该区域角色所需处在的位置。最后再给它**添加一个 DialogueZone 组件**。也可以将这个区域对象附加到一个角色上(只需要在 Hierarchy 视图中将它嵌套在角色对象下,它就可以跟随角色到处移动啦)。 26 | 27 | ![一个对话框的 Inspector 视窗](media/15014825032837.jpg) 28 | 29 | 添加了 **DialogueZone** 组件之后,你需要设置它的 Inspector 视窗。有几个与激活(Activation)相关的复选框可以让你设置如何以及何时才能激活对话。可以设置是否显示提示按钮(默认是一个字母 `A` 小图标,可以随意替换)。接着你可以更改对话框的外观,通过调整文本和背景的颜色以及字体等。在 Inspector 视窗的最下方,你可以定义对白。如果对白超过 1 句,它们会**按照顺序**从上往下逐条显示。 30 | 31 | ## 血条(Healthbars) 32 | 33 | ![一个奄奄一息的带血条的机器敌人](media/15014835521919.jpg) 34 | 35 | **血条(Healthbar)**是可以添加到任何一个具有 `Health` 组件的角色上的组件。它可以在角色的上方显示一个代表**当前健康程度**的进度条。设置方法很简单:可以选择使用一个 ProgressBar Prefab 或者交由引擎来绘制它。如果是后者,你可以选择进度条的前景色和背景色、内边距和大小,以及进度条位置离角色中心的偏移值。除此之外,还可以设置它是否**持续可见**,还是只有在它每次受到伤害后的数秒之内可见。 36 | 37 | ------- 38 | 39 | [本页面的 Corgi Engine 官方英文原版链接](http://corgi-engine-docs.moremountains.com/ui.html) 40 | 41 | # User Interface 42 | 43 | > **Summary:** This page describes how UI works in the Corgi Engine. 44 | 45 | ## Introduction 46 | 47 | While primarily focused on gameplay, the Corgi Engine includes **GUI** elements here and there to communicate with the player. Usually meant as placeholders (as you’re likely to replace these with your own art/style), it can still be useful to understand how these work. 48 | 49 | ## UI Camera 50 | 51 | Most levels of the engine feature two [cameras](http://corgi-engine-docs.moremountains.com/cameras.html) : a regular 2D or 3D camera, and a UI Camera. The latter is responsible for displaying the game HUD, and other non-world visual elements. If you look at the UICamera prefab, you’ll see it also contains buttons, arrows, a joystick, a pause splash screen, etc. All these are controlled by the GUI Manager, a component located at the top level of that prefab. Each of these parts are bound to the GUI Manager’s inspector. 52 | 53 | ## Game HUD 54 | 55 | A subpart of the UICamera prefab, the HUD features a jetpack bar, a health bar, an avatar, but also points, level name, and a FPS counter. All that is bound to the GUIManager and updated via its various methods. Feel free to change their look, fonts, etc. 56 | 57 | ## Pause Screen 58 | 59 | The **pause screen** is a subpart of the UICamera, containing a black overlay, some text and a few buttons. You can (and should) of course customize it to feature your own buttons and art style. To do so, all you have to do is unfold the UICamera prefab, locate the PauseSplash part, and make your changes there. 60 | 61 | ## Dialogue Boxes 62 | 63 | ![A very simple dialogue example](media/15014817559889.jpg) 64 | 65 | The engine includes a **very simple dialogue system**, allowing you to display one-way dialogues or tooltips anywhere you want in your levels. To use it, all you need is a zone. A zone is simply a gameobject with a BoxCollider2D on it, determining where the character needs to be for the zone to be activable. Then all you have to do is **add a DialogueZone component** to it. That zone can also be attached to a character (just nest it under your character in your hierarchy and it’ll follow it around). 66 | 67 | ![A look at a Dialogue Box' inspector](media/15014825032837.jpg) 68 | 69 | Once the **DialogueZone** component has been added, all you have to do is setup its inspector. There are a number of activation related checkboxes that will allow you to decide how and when the dialogue can be activated. You can also decide to show a prompt (by default a small “A” icon, feel free to replace it with whatever you want). Then you can change the dialogue box look, by tweaking the text and background color, or the font. At the very bottom of the inspector is where you can define the dialogue lines. If you have more than one, they’ll be displayed **sequentially**, from top to bottom. 70 | 71 | ## Healthbars 72 | 73 | ![An example of a badly damaged robot enemy with a healthbar](media/15014835521919.jpg) 74 | 75 | **Healthbars** are components you can add to any Character with a Health component. It will allow you to display, next to your character, a progress bar showing its **current health level**. It’s pretty simple to setup : you can decide whether you’d rather use a ProgressBar prefab, or just have the engine draw it. In this case you can select a front and back color, decide on a padding and size, and an offset to place the bar relative to your character’s center. Additionnally, you can have it be **always visible**, or only for a number of seconds after each hit taken by the character. 76 | 77 | ------- 78 | 79 | -------------------------------------------------------------------------------- /3.General/3-7.事件.md: -------------------------------------------------------------------------------- 1 | # 事件 2 | 3 | > 这个页面讲解了 Corgi Engine 中的事件系统。 4 | 5 | ## 简介 6 | 7 | 在 v3.1 版本中介绍过,Corgi Engine 自带了**事件管理器(Event Manager)**。事件是由应用中的一个类广播出来的信息,可以被任何一个监听类捕获从而采取行动。我们以关卡中的一个敌人为例。当玩家杀死它之后,可能会增加得分,同时也可以算作取得了某项成就的进展,而且你还得想办法更新 GUI。你当然可以让 `Kill()` 方法直接调用所有这些方法,但它会造成耦合和依赖。另外有时候你并不清楚还需要将敌人死亡的信息通知给其他多少类,于是事件(系统)应运而生。 8 | 9 | 事件是一种**广播**刚刚发生的事实的方法。**任何类都可以监听它**,然后采取适当的行动。事件对于扩展引擎并实现你自己的功能非常有用,而无需修改引擎的基础代码。 10 | 11 | ## MMEventManager 12 | 13 | **MMEventManager** 是一个静态类(意味着不需要把它当作一个组件添加到场景中),它负责事件广播,并且让监听者们知道有事件被触发了。只需要使用这个类就可以触发或监听一个事件。 14 | 15 | 想在任何一个类中触发一个事件都非常简单,只需要调用 `MMEventManager.TriggerEvent(YOUR_EVENT);`。大部分情况下,`YOUR_EVENT` 是一个对该事件的构造器的调用。例如,这里广播了一个名为 `GameStart` 的 `MMGameEvent` 事件到所有监听者: 16 | 17 | ```csharp 18 | MMEventManager.TriggerEvent(new MMGameEvent("GameStart")); 19 | ``` 20 | 21 | **监听事件**会有些麻烦,因为你需要为类添加一些东西才能够正确监听,确保不要遗漏以下步骤中的任何一个! 22 | 23 | **步骤 1:**指定类实现了要监听的事件类型的 `MMEventListener` 接口,这需要在类声明中完成。例如,这是 `MMAchievementDisplayer` 类的声明: 24 | 25 | ```csharp 26 | public class MMAchievementDisplayer : MonoBehaviour, MMEventListener 27 | { 28 | // ... the content of the class goes here 29 | } 30 | ``` 31 | 32 | 你可以看到,这里我们声明了这个类监听 `MMAchievementUnlockedEvent` 事件。 33 | 34 | **步骤 2:**接着要在 `OnEnable` 方法中开始监听事件,然后在 `OnDisable` 方法中停止监听。这实际上是让 `MMEventManager` 知道这个实例想要保持接收任何那种类型的事件被触发的通知。确保同时在 `OnDisable` 方法中停止监听事件,否则 `MMEventManager` 会尝试「联系」这个实例,甚至当它已经不可用或者销毁时,这有可能导致出错。做法很简单: 35 | 36 | ```csharp 37 | void OnEnable() 38 | { 39 | this.MMEventStartListening(); 40 | } 41 | void OnDisable() 42 | { 43 | this.MMEventStopListening(); 44 | } 45 | ``` 46 | 47 | 当然,你需要为监听的每种类型的事件都做以上处理。 48 | 49 | **步骤 3:**最后就是为事件实现 `MMEventListener` 接口: 50 | 51 | ```csharp 52 | public virtual void OnMMEvent(MMAchievementUnlockedEvent achievementUnlockedEvent) 53 | { 54 | // here we start a coroutine that will display our achievement 55 | StartCoroutine(DisplayAchievement (achievementUnlockedEvent.Achievement)); 56 | } 57 | ``` 58 | 59 | 引擎包含了许多使用事件的例子,找出来看看,然后利用事件的潜力来改善你的游戏! 60 | 61 | ## 事件类型 62 | 63 | Corgi Engine 中自带了一些预定义的事件类型,但它们是为了通用于所有类型的事件而被创建的,同时它们也是结构体,所以请按需创建你自定义的事件类型。你可以把以下事件当作范例。引擎中捆绑的事件类型如下: 64 | 65 | * **MMGameEvent:** 66 | 67 | `MMGameEvents` 是一个简单的、多用途的事件,仅由一个 `string` 类型的名称组成。你可以用它来触发那些不需要除了名称之外的其他信息的事件(像「游戏开始」这样的事件)。 68 | 69 | ```csharp 70 | public struct MMGameEvent 71 | { 72 | public string EventName; 73 | public MMGameEvent(string newName) 74 | { 75 | EventName = newName; 76 | } 77 | } 78 | 79 | // trigger one like this (here we're broadcasting a save event): 80 | MMEventManager.TriggerEvent(new MMGameEvent("Save")); 81 | ``` 82 | 83 | * **CorgiEngineEvent:** 84 | 85 | `CorgiEngineEvent` 是 `MMGameEvent` 的替代品,它定义了一个 `CorgiEngineEventTypes` 来取代 `string`。`CorgiEngineEventTypes` 是一个枚举(enum),它避免了使用 `string` 时可能出现错别字而引发的错误。 86 | 87 | ```csharp 88 | public enum CorgiEngineEventTypes 89 | { 90 | LevelStart, 91 | LevelEnd, 92 | PlayerDeath 93 | } 94 | 95 | // trigger one like this 96 | MMEventManager.TriggerEvent(new CorgiEngineEvent(CorgiEngineEventTypes.LevelStart)); 97 | ``` 98 | 99 | * **MMCharacterEvent:** 100 | 101 | 通常在能力(Ability)类中被触发,可以用它来让游戏的其他部分知道一个角色当前正在执行特定的动作。上述的动作在一个枚举中定义。大多数时候使用状态机中的事件已经足够了,但如果你需要更多事件,这也是一个选择。 102 | 103 | ```csharp 104 | public enum MMCharacterEventTypes 105 | { 106 | ButtonActivation, 107 | Jump 108 | } 109 | 110 | // trigger one like this: 111 | MMEventManager.TriggerEvent(new MMCharacterEvent(_character, MMCharacterEventTypes.Jump)); 112 | ``` 113 | 114 | * **PickableItemEvent:** 115 | 116 | 当可拾起的物品被拾起时该事件被触发。 117 | 118 | * **MMDamageTakenEvent:** 119 | 120 | 每次有东西受到伤害时该事件被触发。 121 | 122 | * **MMAchievementUnlockedEvent:** 123 | 124 | 最典型的,当一个成就被解锁时 `MMAchievementUnlockedEvent` 会被触发。它可以被 GUI 捕获然后用于显示成就,同时也可以被用于增加得分等。 125 | 126 | * **MMSfxEvent:** 127 | 128 | `MMSfxEvent` 事件让你可以请求 SoundManager 播放指定的一段声音。显然,你也可以直接使用 `SoundManager.Instance.PlaySound(clipToPlay,transform.position); `,两者都可以达到效果。但事件系统可以让你避免在 SoundManager 丢失的情况下出错的风险。在这种情况下事件还是会被广播出去,但没有东西会拦截它(虽然声音不会被播放,但至少不会出错)。 129 | 130 | ```csharp 131 | // trigger one like this (here we're asking for the playing of a sound set in the achievement displayer's inspector): 132 | MMEventManager.TriggerEvent(new MMSfxEvent (achievement.UnlockedSound)); 133 | ``` 134 | 135 | 再次说明,事件可以是任意类型的结构体,也可以很复杂,所以请随意创建你自己的事件,然后在系统中使用它们。 136 | 137 | ## 状态机 138 | 139 | 状态机(比如说[角色系统](https://github.com/Caizc/corgi-engine-docs/blob/master/2.Agents/2-3.%E8%A7%92%E8%89%B2%E8%83%BD%E5%8A%9B.md)使用的)也可以在**每次状态变化时**自动地触发事件。这特别有用,因为你可以省去手动触发它们的麻烦,只需要专注于实现监听者。这些特有的事件就是 `MMStateChangeEvent`,能够配合任何类型的状态机使用的通用事件。抓取这些事件可以让你知道状态机的目标状态、切换到的新状态以及之前所处的状态。如果你不打算使用事件,可以在 `Character` 组件的 Inspector 视窗中关闭它。 140 | 141 | ```csharp 142 | public struct MMStateChangeEvent where T: struct, IComparable, IConvertible, IFormattable 143 | { 144 | public GameObject Target; 145 | public MMStateMachine TargetStateMachine; 146 | public T NewState; 147 | public T PreviousState; 148 | 149 | public MMStateChangeEvent(MMStateMachine stateMachine) 150 | { 151 | Target = stateMachine.Target; 152 | TargetStateMachine = stateMachine; 153 | NewState = stateMachine.CurrentState; 154 | PreviousState = stateMachine.PreviousState; 155 | } 156 | } 157 | ``` 158 | 159 | ------- 160 | 161 | [本页面的 Corgi Engine 官方英文原版链接](http://corgi-engine-docs.moremountains.com/events.html) 162 | 163 | # Events 164 | 165 | > **Summary:** This page describes the events sytem included in the Corgi Engine. 166 | 167 | ## Introduction 168 | 169 | Introduced in v3.1, the Corgi Engine includes its own **event manager**. Events are messages broadcasted by a class in your application that can be caught by any **listening** class so it can take action. For example, let’s consider an enemy in your level. When your character kills it, it’ll probably increase the score, but also count as progress towards an achievement, and you’ll need to update the GUI somehow. You could of course have your Kill method call all these directly, but it creates **coupling** and **dependencies**. Plus sometimes you don’t know how many other classes you need to inform of that enemy death. That’s where events come in. 170 | 171 | Events are a way for you to **broadcast** the fact that something just happened. **Any class can listen to it**, and take appropriate action. They can be very useful to extend the engine and implement your own features without modifying the base code. 172 | 173 | ## MMEventManager 174 | 175 | The MMEventManager class is a static class (meaning you don’t need to add this as a component in your scenes) that is responsible for event broadcasting, and letting listeners know an event has been triggered. It’s the only class you need to use to trigger or listen to an event. 176 | 177 | Triggering an event, from any class, is extremely simple, you just need to call MMEventManager.TriggerEvent(YOUR_EVENT); In most cases, YOUR_EVENT will be a call to the event’s constructor. For example, here we broadcast an MMGameEvent named GameStart to all our listeners : 178 | 179 | ```csharp 180 | MMEventManager.TriggerEvent(new MMGameEvent("GameStart")); 181 | ``` 182 | 183 | Listening to events can be a bit trickier, as there are a few things you need to add to a class so it can listen properly. Make sure you don’t forget one of these steps! 184 | 185 | **Step 1 :** specify that your class implements the MMEventListener interface for that kind of event. This is done at the top of your class. For example, this is the MMAchievementDisplayer’s declaration : 186 | 187 | ```csharp 188 | public class MMAchievementDisplayer : MonoBehaviour, MMEventListener 189 | { 190 | // ... the content of the class goes here 191 | } 192 | ``` 193 | 194 | As you can see, here we say that this class will listen to MMAchievementUnlockedEvents. 195 | 196 | **Step 2 :** we need to start listening to events on OnEnable, and stop listening to them on OnDisable. This actually lets the MMEventManager know that this instance will want to be kept informed of any events of that type that get triggered. Make sure you also stop listening to events OnDisable, otherwise the MMEventManager may try to “contact” this instance even if it’s been disabled or destroyed, which would cause errors. This is quite simple to do : 197 | 198 | ```csharp 199 | void OnEnable() 200 | { 201 | this.MMEventStartListening(); 202 | } 203 | void OnDisable() 204 | { 205 | this.MMEventStopListening(); 206 | } 207 | ``` 208 | 209 | Of course you’ll want to do that for each type of event you want to listen to. 210 | 211 | **Step 3 :** All that’s left to do is implement the MMEventListener interface for that event : 212 | 213 | ```csharp 214 | public virtual void OnMMEvent(MMAchievementUnlockedEvent achievementUnlockedEvent) 215 | { 216 | // here we start a coroutine that will display our achievement 217 | StartCoroutine(DisplayAchievement (achievementUnlockedEvent.Achievement)); 218 | } 219 | ``` 220 | 221 | The engine contains lots of examples of event uses, check them out, and harness the events potential to improve your own game! 222 | 223 | ## Event Types 224 | 225 | The asset comes with a number of predefined event types, but it’s built to work with any type of event, as long as they’re structs, so feel free to create yours. You can use the following as examples. Bundled with the asset are the following event types : 226 | 227 | **MMGameEvent :** 228 | 229 | MMGameEvents are simple, multi-purpose events, made only of a string name. You can use these to trigger events that don’t require more information than that name (the game starts, stuff like that). 230 | 231 | ```csharp 232 | public struct MMGameEvent 233 | { 234 | public string EventName; 235 | public MMGameEvent(string newName) 236 | { 237 | EventName = newName; 238 | } 239 | } 240 | 241 | // trigger one like this (here we're broadcasting a save event): 242 | MMEventManager.TriggerEvent(new MMGameEvent("Save")); 243 | ``` 244 | 245 | **CorgiEngineEvent :** 246 | 247 | CorgiEngineEvents are an alternative to MMGameEvents. They’re defined by a CorgiEngineEventTypes instead of a string. CorgiEngineEventTypes are defined in an enum. This prevents typo errors you could get with strings. 248 | 249 | ```csharp 250 | public enum CorgiEngineEventTypes 251 | { 252 | LevelStart, 253 | LevelEnd, 254 | PlayerDeath 255 | } 256 | 257 | // trigger one like this 258 | MMEventManager.TriggerEvent(new CorgiEngineEvent(CorgiEngineEventTypes.LevelStart)); 259 | ``` 260 | 261 | **MMCharacterEvent :** 262 | 263 | Usually triggered from within an ability, you can use these to let the rest of your game know that a character has performed a specific action. Said actions are defined in an enum. Most of the time you should be fine with the state machine events, but if you need more, there’s also this option. 264 | 265 | ```csharp 266 | public enum MMCharacterEventTypes 267 | { 268 | ButtonActivation, 269 | Jump 270 | } 271 | 272 | // trigger one like this: 273 | MMEventManager.TriggerEvent(new MMCharacterEvent(_character, MMCharacterEventTypes.Jump)); 274 | ``` 275 | 276 | **PickableItemEvent :** 277 | 278 | Triggered by pickable items when they get picked. 279 | 280 | **MMDamageTakenEvent :** 281 | 282 | Triggered every time something takes damage. 283 | 284 | **MMAchievementUnlockedEvent :** 285 | 286 | MMAchievementUnlockedEvents are typically triggered by an achievement when it’s been unlocked. It can then be caught and used by the GUI to display the achievement, but could also be used to increase score, etc. 287 | 288 | **MMSfxEvent :** 289 | 290 | MMSfxEvent are events that allow you to request the SoundManager to play a specific sound. Admittedly, you could also directly do SoundManager.Instance.PlaySound(clipToPlay,transform.position); Both will work. Events allow you to do that without risking an error in the case of a missing sound manager. The event will just be broacasted, nothing will intercept it (and the sound won’t play, but at least you won’t get an error). 291 | 292 | ```csharp 293 | // trigger one like this (here we're asking for the playing of a sound set in the achievement displayer's inspector): 294 | MMEventManager.TriggerEvent(new MMSfxEvent (achievement.UnlockedSound)); 295 | ``` 296 | 297 | Again, events can be any kind of struct, and quite complex ones too, so feel free to create your own ones and use them with this system. 298 | 299 | ## State Machine 300 | 301 | StateMachines (used [in the Character system for example](http://corgi-engine-docs.moremountains.com/character-abilities.html#the-state-machine)) can also trigger events automatically **every time they change state**. This is particularly useful as it saves you the trouble of triggering them manually, you can just focus on your listeners. These particular events are MMStateChangeEvent, generic events that can work with any kind of state machine. Grabbing the event will allow you to know the state machine’s target, what new state it’s in, and in what state it was previously. If you don’t plan on using events, you can turn them off for a Character via the Character component’s inspector. 302 | 303 | ```csharp 304 | public struct MMStateChangeEvent where T: struct, IComparable, IConvertible, IFormattable 305 | { 306 | public GameObject Target; 307 | public MMStateMachine TargetStateMachine; 308 | public T NewState; 309 | public T PreviousState; 310 | 311 | public MMStateChangeEvent(MMStateMachine stateMachine) 312 | { 313 | Target = stateMachine.Target; 314 | TargetStateMachine = stateMachine; 315 | NewState = stateMachine.CurrentState; 316 | PreviousState = stateMachine.PreviousState; 317 | } 318 | } 319 | ``` 320 | 321 | ------- 322 | 323 | 324 | -------------------------------------------------------------------------------- /3.General/3-8.成就.md: -------------------------------------------------------------------------------- 1 | # 成就 2 | 3 | > 这个页面讲解了如何使用 Corgi Engine 中的成就系统,以及如何为你的游戏定制它。 4 | 5 | ## 简介 6 | 7 | 在 v3.1 版本中介绍过,Corgi Engine 包含了一个简单易用又功能强大的成就系统。它可以设定、触发和保存成就。此外它还非常**模块化**且易于扩展,如果说你要将它接入特定平台的社交 API 的话。 8 | 9 | ## 重置成就 10 | 11 | 关于成就系统首先你要知道**如何重置它**(无论如何它是最常被提及的问题)。可以通过点击在 AchievementList 的 Inspector 视窗中底部的 `Reset Achievements` 按钮,或者通过顶部菜单,点击菜单项 `More Mountains > Reset all achievements` 来重置成就。 12 | 13 | ![More Mountains 顶部菜单](media/15014985543651.jpg) 14 | 15 | ## AchievementList 16 | 17 | 关于成就,第二个重要的事情是知道**如何定义它们**,这是通过一个脚本对象(Scriptable Object)——AchievementList 来完成的。你可以创建一个新的,不过引擎资源中已经有一个可以供你修改了,可以在 `CorgiEngine/Common/Resources/Achievements` 目录下找到它。你可以选中它,然后通过它的 Inspector 视窗修改它的内容。 18 | 19 | ![成就清单](media/15015540341371.jpg) 20 | 21 | 如上图所示,一个成就(Achievement)由 ID(脚本通过它来解锁它)、类型、标题、描述、关联的图片和声音,以及潜在的进度组成。有 2 种类型的成就:简单(`Simple`,类似于完成游戏、找到宝藏等唯一的东西)以及基于进度的(`Progress` Based,例如收集 50 个硬币、死 20 次等)。如果是基于进度的成就,你还需要指定解锁成就所需的进度目标。所有成就都只能解锁一次,当然啦,除非你重置它们。 22 | 23 | ## 解锁成就 24 | 25 | 在你将成就添加到列表(AchievementList)中后,接着就要在代码中让它可以被解锁。这可以在任何类中完成,并且具体在什么地方解锁理所当然地取决于你的游戏和成就。引擎中有一些例子可供你更好地理解它是怎么做的。值得一提的是,本成就系统使用了**事件(Events)**,如果你想要全面了解它是如何工作的,可以[阅读这个页面](https://github.com/Caizc/corgi-engine-docs/blob/master/3.General/3-7.%E4%BA%8B%E4%BB%B6.md)。 26 | 27 | 解锁成就非常简单,可以通过一行代码来解决。将这行代码放在哪里取决于你想要做什么。我建议扩展 `AchievementRules` 类,以将所有成就相关的代码集中到同一个地方,同时让该类监听与它们相关的事件和行为(看看这个类的代码,如果你想知道如何处理的话)。不过如果你喜欢的话也可以在任何地方完成成就的解锁。 28 | 29 | 这里示范了如何解锁一个叫做 `theFirestarter` 的简单成就: 30 | 31 | ```csharp 32 | MMAchievementManager.UnlockAchievement("theFirestarter"); 33 | ``` 34 | 35 | 而这个则是如何增加一个基于进度的成就的当前进度: 36 | 37 | ```csharp 38 | MMAchievementManager.AddProgress ("toInfinityAndBeyond", 1); 39 | ``` 40 | 41 | 当然你可以把 `1` 替换为任何其他值以加快进度。 42 | 43 | ## MMAchievementRules 44 | 45 | 正如前面提到的,目前成就是由 `AchievementRules` 类来触发的。它继承了 `MonoBehaviour` 类,所以在每个有成就被解锁的场景中,你需要把它添加到一个空的 GameObject 对象上。不过成就是全局(Global)的,因此如果你在关卡 A 中解锁了一个成就,就不能在关卡 B 中再次解锁它。即便你不想使用 `AchievementRules` 类,也请确保在游戏开始的时候,在某个管理类(Manager)中添加以下几行代码: 46 | 47 | ```csharp 48 | // we load the list of achievements, stored in a ScriptableObject in our Resources folder. 49 | MMAchievementManager.LoadAchievementList (); 50 | // we load our saved file, to update that list with the saved values. 51 | MMAchievementManager.LoadSavedAchievements (); 52 | ``` 53 | 54 | ## 成就显示 55 | 56 | ![解锁了一个成就时,在屏幕的角落里显示了一个小弹出窗口](media/15015582494754.jpg) 57 | 58 | 引擎包含了一个成就显示组件。要使用它的话,需要给它一个「容器」(Container)。我发现使用 `Vertical Layout Group` 组件作为容器的效果很好,不过你可以使用其他任何东西代替。需要为容器添加一个 `MMAchievementDisplayer` 组件。在它的 Inspector 视窗中,你可以指定当一个成就被解锁时要实例化哪个 Prefab,它会在屏幕上存在多长时间,以及过渡过程应该多快。当然你也可以修改或者创建一个新的 Prefab,以你想要的方式来显示成就。需要为这个 Prefab 添加一个 `MMAchievementDisplayer` 组件,然后再为它绑定 GUI 元素。 59 | 60 | ## 对接 Steam、iOS 等 61 | 62 | 为了避免对外部的代码产生**依赖**,引擎资源中并没有现成的 Steam、Google Play、iOS 或者其他平台相关的接口。不过这个成就系统在创建时就已经考虑到了这种类型的演化,所以你可以轻松的扩展它以及调用必要的方法,因为它们的成就结构体都大同小异。最好的方式是创建一个监听 `MMAchievementUnlockedEvent` 的类(每次有一个成就被解锁时该事件就会被触发),然后再把相应的成就传递给目标平台的社交 API。 63 | 64 | ------- 65 | 66 | [本页面的 Corgi Engine 官方英文原版链接](http://corgi-engine-docs.moremountains.com/achievements.html) 67 | 68 | # Achievements 69 | 70 | > **Summary:** This page describes how to use the achievements system included in the Corgi Engine and customize it to your game. 71 | 72 | ## Introduction 73 | 74 | Introduced in v3.1, the Corgi Engine includes a simple to use yet powerful achievements system. It’ll allow you to define, trigger and save achievements. Plus it’s **very modular** and easy to extend, if you want to plug it to a specific platform’s social API for example. 75 | 76 | ## Resetting Achievements 77 | 78 | The first thing you need to know about the achievement system is **how to reset it** (that’s the most asked question about it anyway). This is done either at the bottom of the Achievement’s list inspector, or via the top menu, by clicking More Mountains > Reset all achievements. : 79 | 80 | ![The More Mountains top menu.](media/15014985543651.jpg) 81 | 82 | ## The Achievement List 83 | 84 | The second important thing to know about achievements is **how to define them**. This is done via a Scriptable Object, the AchievementsList. You can create your own, but there’s already one in the asset that you can modify. You can find it under Common/Resources/Achievements. You can just select it and modify its content via its inspector. 85 | 86 | ![The Achievements List.](media/15015540341371.jpg) 87 | 88 | As you can see on the picture above, an achievement is made of an ID (used to unlock it via your scripts), a type, title, description, associated images and sounds, and potential progress. There are 2 types of achievements : simple (finish the game, find the treasure, unique stuff like that), and progress based ones (collect 50 coins, die 20 times, etc). In the case of progress based ones, you’ll need to specify the target progress needed to unlock the achievement. All achievements can only be unlocked once, unless you reset them of course. 89 | 90 | ## Unlocking achievements 91 | 92 | Once you’ve added an achievement to the list, it’s time to switch to code to make it unlockable. This can be done from any class, and of course where exactly you’ll do it depends on your game and your achievements. There are a few examples in the engine so you can get a better understanding of how it’s done. Note that this achievements system uses **Events**, you may want to [read this page](http://corgi-engine-docs.moremountains.com/events.html) if you want to get a better understanding of how it all works. 93 | 94 | So unlocking achievements is very simple and can be done in a single line of code. Where you put that line of code depends on what you want to do. I’d recommend extending the AchievementRules class so you centralize them all in the same place, and have that class listen to events and act on them (check out this class’ code if you want to know more about how to do it). But you can also do it from anywhere in your code if you prefer. 95 | 96 | Here’s how you unlock a simple achievement called “theFirestarter” (of course you’ll want to replace that with your achievement’s ID) : 97 | 98 | ```csharp 99 | MMAchievementManager.UnlockAchievement("theFirestarter"); 100 | ``` 101 | 102 | And here’s how you add progress to a progress based achievement : 103 | 104 | ```csharp 105 | MMAchievementManager.AddProgress ("toInfinityAndBeyond", 1); 106 | ``` 107 | 108 | Of course you can replace that “1” with any value of your choice to get progress faster. 109 | 110 | ## MMAchievementRules 111 | 112 | As mentioned earlier, right now achievements are triggered by the AchievementRules class. It’s a MonoBehaviour, so you need to add it to an empty GameObject in each of the scenes where you want achievements to be unlocked from. Achievements are global though, so if you unlock one in Level A, you won’t be able to unlock it again in Level B. If you don’t want to use the AchievementRules class though, make sure you add these lines somewhere in a manager at the start of your game : 113 | 114 | ```csharp 115 | // we load the list of achievements, stored in a ScriptableObject in our Resources folder. 116 | MMAchievementManager.LoadAchievementList (); 117 | // we load our saved file, to update that list with the saved values. 118 | MMAchievementManager.LoadSavedAchievements (); 119 | ``` 120 | 121 | ## Achievements Display 122 | 123 | ![Unlocking an achievement displays a small popup in the screen's corner.](media/15015582494754.jpg) 124 | 125 | The asset includes an achievement displayer. To use it, you’ll need to have a container for them. I’ve found that a Vertical Layout Group works quite well, but you can use anything you want. That container will need to have a MMAchievementDisplayer component added to it. From its inspector you’ll be able to specify what prefab to instantiate when an achievement is unlocked, for how long it should remain on screen, and how fast the transition should be. You can of course modify or create a new prefab to display the achievements exactly the way you want. It’ll need an MMAchievementDisplay component added to it so you can bind GUI elements. 126 | 127 | ## Interfacing with Steam, iOS, etc 128 | 129 | To avoid creating **dependencies** to external code, this asset doesn’t include ready-to-use interfaces for Steam, Google Play, iOS or other platforms. But this achievement system has been built with that kind of evolution in mind, so you can easily extend it and call the desired methods, as they all share more or less similar structures for achievements. The best way to do so is to create a new class that listens for MMAchievementUnlockedEvents (these are of course triggered everytime an achievement is unlocked) and pass that achievement to the target social platform’s API. 130 | 131 | ------- 132 | 133 | -------------------------------------------------------------------------------- /3.General/3-9.摄像机.md: -------------------------------------------------------------------------------- 1 | # 摄像机 2 | 3 | > 这个页面讲解了在 Corgi Engine 中如何使用摄像机。 4 | 5 | ## 简介 6 | 7 | 和其他所有 Unity 项目一样,关卡中需要有一个摄像机才能看到东西。Corgi Engine 包含了一些摄像机专用的脚本。要说明的一点是,**你可以在引擎中使用任何摄像机脚本**,或者实现你自己的,或者在提供的脚本上继续构建。关于摄像机**没有什么是强制的**,你可以随意定制。这个页面介绍了主要的脚本以及如何使用它们。 8 | 9 | ## 普通摄像机和 UI 摄像机 10 | 11 | ![在 Hierarchy 视图和 Scene 视图中的 Corgi Engine 的两种摄像机(左边是 UI 摄像机,右边是普通摄像机),以及下方是两种摄像机的单独视图](media/15015706225957.jpg) 12 | 13 | 在 Corgi Engine 的大部分 Demo 场景中,默认情况下你会看到**两个摄像机**:一个普通摄像机(2D、3D、跟随或者不跟随玩家角色等)和一个 UI 摄像机。UICamera 的 `Culling Mask` 被设置为 `UI`,也就是说它只显示被标记为 `UI` 的对象,并且被设置为**叠加(superimpose)**到主摄像机(Main Camera)的显示之上。 14 | 15 | ## CameraController 16 | 17 | `CameraController` 组件**可以被添加到任何摄像机上**(正交 `Orthographic` 或透视 `Perspective`),它让摄像机移动并且尝试跟随玩家角色。默认情况下,它将**以你的主角**(你在场景的 LevelManager 中设置的第一个玩家角色)**为中心**。在它的 Inspector 视窗中,你可以设定一些偏移量,这些偏移量在特定的情况下会被添加到摄像机的位置上。而 `Camera Offset` 则被应用在所有情况下。`Horizontal Look Distance` 在向左或向右移动时被应用,`Manual Up Down Look Distance` 则被应用在向上或向下看时。你还可以设定 `Look Ahead Trigger` 的值来定义移动多长的距离才会触发偏移量的应用。 18 | 19 | 接着你可以通过一些设置项来设定**移动速度(Movement Speed)**和**缩放值(Zoom Values)**。最后你还可以通过勾选一个复选框来自动启用或禁用移动设备上的特效。如果把它禁用,当运行在 **Android** 或 **iOS** 上时,所有添加到摄像头上的标准资源特效都会**被禁用**。 20 | 21 | 引擎资源中还包含了一个**多玩家摄像机控制器(Multiplayer Camera Controller)**。它与单玩家摄像机基本上是一样的,但它会跟随场景中的所有玩家角色。 22 | 23 | ## 像素完美(Pixel Perfect) 24 | 25 | 在 `CameraController` 的 Inspector 视窗中,你还可以设置是否需要一个像素完美的摄像机(Pixel Perfect Camera)。它对于 2D 像素艺术风格的游戏最适合,像素完美的摄像机将禁用缩放,而是根据你在 Inspector 视窗中的设置(你导出的 Sprite 的目标垂直分辨率)和要求的 PPU(Pixels Per Unit)来确定一个新的正交摄像头尺寸(Size)。 26 | 27 | 如果不设置 `Pixel Perfect` 的话,可能会发生 Sprite 没有被正确渲染的情况,因为你的 Sprite 的每一个像素有可能最终并不会整好显示在一个屏幕像素上。你可以执行以下操作来避免这种情况: 28 | 29 | * 根据某个目标垂直分辨率(例如 768px)创建你的资源,然后在 `CameraController` 的 Inspector 视窗中将这个值设置给 `Reference Vertical Resolution`。 30 | * 为每一个 Sprite 设定一个共同的 `PPU` 值(例如 32),然后在 `CameraController` 的 Inspector 视窗中将这个值设置给 `Reference Pixels Per Unit`。 31 | * 在 Sprite 中,设置 `Compression` 为 `None`,`Filter Mode` 为 `Point(no filter)`。 32 | 33 | 你也可以在 Unity 的这篇[博客文章](https://blogs.unity3d.com/cn/2015/06/19/pixel-perfect-2d/)中学习更多关于 Pixel Perfect Camera 的知识。 34 | 35 | ## 视差效果(Parallax) 36 | 37 | Corgi Engine 包含了将视差效果添加到你的游戏中所需的一切。基本上有两种方式可以做到: 38 | 39 | * **3D 视差效果:**最简单的方式是做一个 2.5D 场景,这种方式 Unity 是内建支持的。也就是说你需要一个 3D 场景并且是从左到右移动的。目录 `CorgiEngine/Demos/Corgi3D/3DLevel` 下的 Demo 场景很好的展示了这种情况。**你不需要任何特殊的操作就可以获得视差效果**,只需要将一些元素放置在比你的主平面(角色移动所在的平面)离摄像机更远的地方,然后当你的角色移动(并且摄像机跟随)时它们看起来就会左右移动得**慢一些**。把它们放置在摄像机和你的主平面之间,则当摄像机移动时它们看起来就会移动得**快一些**。 40 | 41 | * **2D 视差效果:**然而要获得类似的 2D 效果,你需要一些 Corgi Engine 脚本的帮助。首先,你需要一个在其顶层带有 `CameraController` 脚本组件的摄像机,你可以自己组装一个,或者从 Minimal Demo 场景中拷贝一个。在摄像机上需要添加一个 `ParallaxCamera` 组件,并且保留勾选它的 `Move Parallax` 复选框。然后添加一个 `ParallaxElement` 组件到场景中任何一个需要与摄像机同步移动的对象上。 42 | 43 | 这里有一些选项需要设置:水平和竖直速度(数值越高移动得越快),以及它移动的方向是否应该与摄像机的相反。大部分情况下,**需要勾选这个复选框**(`Move In Opposite Direction`)。然后你可以按下 Play 按钮,看看效果如何,或者在编辑模式下,直接来回移动摄像机看看这些元素的表现如何。这对于美术人员和关卡设计师来说很有用,他们可以检查当摄像机到达某个位置时某个背景元素所在何处。剩下的就是调整速度参数,以让人产生深度感(impression of depth),如果有超过一个层次的平台的话。例如,如果有 3 个背景元素:一棵树、一座山和一个月亮,设置它们各自的参数为 `0.5`、`0.3` 和 `0.1` 应该会获得很好的深度感。 44 | 45 | 最后需要关注的就是 `LevelBackground` 脚本了。对于 2D 关卡来说很有用,它可以让你把一个 Sprite 「粘」在摄像机上,它会一直跟随着摄像机,通常用于实现天空背景。 46 | 47 | ------- 48 | 49 | [本页面的 Corgi Engine 官方英文原版链接](http://corgi-engine-docs.moremountains.com/cameras.html) 50 | 51 | # Cameras 52 | 53 | > **Summary:** This page explains how to use cameras in the Corgi Engine. 54 | 55 | ## Introduction 56 | 57 | Like for any other Unity project, you’ll need a Camera in your level to see the action. The Corgi Engine includes a few Camera specific scripts. Note that **you can use any Camera script with the asset**, or implement your own, or build on top of the provided scripts. There’s **nothing mandatory here** and you can do whatever you want. This page covers the main scripts and how to use them. 58 | 59 | ## Regular and UI Cameras 60 | 61 | ![The Corgi Engine's two cameras, in the hierarchy view, in the scene view (UI to the left, regular camera to the right), and below both camera's separate previews](media/15015706225957.jpg) 62 | 63 | By default, in most demo scenes of the Corgi Engine, you’ll notice **two cameras** : a regular camera (2D, 3D, following the player or not, etc) and a UI Camera. The UI Camera’s Culling Mask is set on UI, which means it’ll only render UI tagged stuff, and is setup to be **superimposed** over the main camera’s render. 64 | 65 | ## CameraController 66 | 67 | The CameraController component **can be added to any camera** (orthographic or perspective), and it’ll make it move and try to follow the player. By default it’ll **center on your main character** (the first playable Character you’ll set in the scene’s LevelManager). From its inspector, you can define a few offsets, that will be added to this position depending on certain situations. The Camera offset will be applied at all times. The Horizontal Look Distance will be applied when moving left or right. Same thing for the up/down look distance. And you can also define with the LookAheadTrigger value how much you need to move for that offset to apply. 68 | 69 | Then you can define **movement speed** and **zoom values**, with pretty self-explanatory settings. The final thing you can check is a checkbox that will automatically enable or disable effects on mobile. If you set it off, all standard assets effects added to the camera **will be disabled** when running on **Android** or **iOS**. 70 | 71 | The asset also includes a **multiplayer camera controller**. It’s basically the same idea as the single player one, but it’ll track all playable characters in the scene. 72 | 73 | ## Pixel Perfect 74 | 75 | From the CameraController’s inspector, you’ll also be able to set whether or not you want a pixel perfect camera. Most suited for 2D pixel art games, the pixel perfect camera will disable zoom, and instead determine a new orthographic camera size based on your settings in the inspector (the target vertical resolution at which for which you produced your sprites) and your desired PPU (pixels per unit) value. 76 | 77 | Without this PixelPerfect setting, it can happen that a sprite is not rendered correctly, as each pixel of your sprite might not end up on one rounded screen pixel. To avoid this, here are a few things you can do : 78 | 79 | * Create your assets for a target vertical resolution (768px for example), and set that value as your Reference Vertical Resolution in the CameraController’s inspector. 80 | * For each of your sprites, define a common PPU value (32 for example), and set that value as your Reference Pixels Per Unit value in the CameraController’s inspector. 81 | * On your sprites, set compression to None, and Filter Mode to Point (no filter). 82 | 83 | You can also learn more about Pixel Perfect cameras in Unity [in this blog post](https://blogs.unity3d.com/cn/2015/06/19/pixel-perfect-2d/). 84 | 85 | ## Parallax 86 | 87 | The Corgi Engine includes everything you need to add parallax effects to your game. There are basically two ways to do it. 88 | 89 | * **3D Parallax** : the easiest way, built-in in Unity, is to have a 2.5D scene. Meaning you have a 3D scene and lateral movement from left to right. The Demos/Corgi3D/3DLevel demo scene is a good showcase of that. You don’t need anything in particular for it to work, just position some elements further from the camera than your main plane (the plane where the character moves) and they’ll move slower from left to right when your character moves (and the camera follows). Position them between the camera and your main plane, and they’ll appear to move faster when the camera moves. 90 | 91 | * **2D Parallax** : to achieve the same effect in 2D though, you’ll need the help of a few of the Corgi Engine’s scripts. First of all, you’ll need a Camera, with a CameraController script on top of it. You can assemble one yourself, or copy one from the Minimal demo scene. On that camera you need to add a ParallaxCamera component, and leave its MoveParallax checkbox checked. Then, on any gameobject in your scene that you want to move on sync with the camera movement, you can just add a ParallaxElement component. 92 | 93 | There are a few options to setup there : vertical and horizontal speed (the higher the value, the faster it’ll move), and whether or not this should move in the opposite direction as the camera. In most cases **you’ll want to leave that checked**. Then you can either press play and check the result, or simply, while in editor mode, move the camera around and see how these elements react. This is useful for artists and level designers, you can check where a background element will be when the camera reaches a certain position. All that’s left to do is adjust speed values to give an impression of depth if you have more than one plane. For example, if you have 3 background elements : a tree, a mountain and the moon, respective values of 0.5, 0.3 and 0.1 should give a good impression of depth. 94 | 95 | One last thing to consider is the LevelBackground script. Useful for 2D levels, it allows you to glue a sprite to the camera, and it’ll just follow it everywhere. Mostly used for skies. 96 | 97 | ------- 98 | 99 | 100 | -------------------------------------------------------------------------------- /3.General/media/15011432639033.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Caizc/corgi-engine-docs/21cae88dd5f5430837a23e21afa0b741ec556ce8/3.General/media/15011432639033.jpg -------------------------------------------------------------------------------- /3.General/media/15011436782426.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Caizc/corgi-engine-docs/21cae88dd5f5430837a23e21afa0b741ec556ce8/3.General/media/15011436782426.jpg -------------------------------------------------------------------------------- /3.General/media/15011514343185.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Caizc/corgi-engine-docs/21cae88dd5f5430837a23e21afa0b741ec556ce8/3.General/media/15011514343185.jpg -------------------------------------------------------------------------------- /3.General/media/15012114241306.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Caizc/corgi-engine-docs/21cae88dd5f5430837a23e21afa0b741ec556ce8/3.General/media/15012114241306.jpg -------------------------------------------------------------------------------- /3.General/media/15012273290066.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Caizc/corgi-engine-docs/21cae88dd5f5430837a23e21afa0b741ec556ce8/3.General/media/15012273290066.jpg -------------------------------------------------------------------------------- /3.General/media/15012325544967.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Caizc/corgi-engine-docs/21cae88dd5f5430837a23e21afa0b741ec556ce8/3.General/media/15012325544967.jpg -------------------------------------------------------------------------------- /3.General/media/15014710179423.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Caizc/corgi-engine-docs/21cae88dd5f5430837a23e21afa0b741ec556ce8/3.General/media/15014710179423.jpg -------------------------------------------------------------------------------- /3.General/media/15014817559889.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Caizc/corgi-engine-docs/21cae88dd5f5430837a23e21afa0b741ec556ce8/3.General/media/15014817559889.jpg -------------------------------------------------------------------------------- /3.General/media/15014825032837.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Caizc/corgi-engine-docs/21cae88dd5f5430837a23e21afa0b741ec556ce8/3.General/media/15014825032837.jpg -------------------------------------------------------------------------------- /3.General/media/15014835521919.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Caizc/corgi-engine-docs/21cae88dd5f5430837a23e21afa0b741ec556ce8/3.General/media/15014835521919.jpg -------------------------------------------------------------------------------- /3.General/media/15014985543651.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Caizc/corgi-engine-docs/21cae88dd5f5430837a23e21afa0b741ec556ce8/3.General/media/15014985543651.jpg -------------------------------------------------------------------------------- /3.General/media/15015540341371.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Caizc/corgi-engine-docs/21cae88dd5f5430837a23e21afa0b741ec556ce8/3.General/media/15015540341371.jpg -------------------------------------------------------------------------------- /3.General/media/15015582494754.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Caizc/corgi-engine-docs/21cae88dd5f5430837a23e21afa0b741ec556ce8/3.General/media/15015582494754.jpg -------------------------------------------------------------------------------- /3.General/media/15015706225957.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Caizc/corgi-engine-docs/21cae88dd5f5430837a23e21afa0b741ec556ce8/3.General/media/15015706225957.jpg -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # corgi-engine-docs 2 | 3 | Corgi Engine Documentation in Simplified Chinese, the engine is a 2D + 2.5D Platformer Solution for Unity. 4 | 5 | Corgi Engine 的**简体中文文档**,Corgi Engine 是一款适用于 Unity 的 2D + 2.5D 平台游戏解决方案,可以在 [Unity Asset Store](https://www.assetstore.unity3d.com/en/#!/content/26617) 中找到。 6 | 7 | 本中文文档根据 Corgi Engine 的[官方文档页面](http://corgi-engine-docs.moremountains.com/)翻译而成,**原始文档发布日期**为 `2017.8.1`,**对应引擎版本**为 `v4.0`。 8 | 9 | 为避免官方文档更新后,本项目的译文找不到出处,**在译文的最后都附上了相应的英文原文**,以供对照阅读。 10 | 11 | 本项目**非官方发起**,仅为方便他人学习交流,本人水平有限,如发现翻译不当之处可以在本项目 [Issues](https://github.com/Caizc/corgi-engine-docs/issues) 中提出,欢迎批评指正,谢谢。 12 | 13 | * [Corgi Engine](http://corgi-engine.moremountains.com/) 14 | * [Corgi Engine Documentation](http://corgi-engine-docs.moremountains.com/) 15 | * [Corgi Engine Documentation in Simplified Chinese](https://github.com/Caizc/corgi-engine-docs) 16 | 17 | ------- 18 | 19 | --------------------------------------------------------------------------------