From f124510b69a6225281674be92cc9716f9aa91172 Mon Sep 17 00:00:00 2001 From: Corey Mason Date: Tue, 11 Jun 2019 12:07:05 -0700 Subject: [PATCH] Update ProjectDocument.md --- ProjectDocument.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ProjectDocument.md b/ProjectDocument.md index fedaafb..d75037b 100644 --- a/ProjectDocument.md +++ b/ProjectDocument.md @@ -50,7 +50,7 @@ Dependency Injection & Facades: With dependency injection, I can decouple dependencies from code and strictly define how those dependencies should be found or created in Unity as needed. For example, the Player prefab contains Player.cs (high level player management) and a Zenject Game Object Context, which essentially acts like a local context - making this a facade. The child PlayerController can then inject InputManager, Player, needed factories, and so on without these polluting the root dependency graph. An additional benefit is that our Player factory will auto link all these dependencies as well. Why is this useful? Consider adding co-op or an AI controlled player for instance, the only change I would have to make is factory making another player (no logic change at all is required) or injecting a different input manager (using an interface, a so-called “AI input manager” could pass in raw input just like a real person) respectively. For brevity, some of the technical specifics are excluded here but those two examples should convey the power of injecting dependencies instead of simpying manually accessing a traditional global singleton. Of course, there are numerous other benefits like dependency validation and making unit testing possible (I can inject a dummy class when testing instead of having to worry about components not existing). Also note that injections operate on a series of rules and bindings so I control how those dependency instances are or aren’t reused (this is how I can emulate a scoped singleton, cache, or never reuse depending on the specific case). Lastly, if we had multiple scenes, I can inject across scenes without issue; this would likely get complicated with traditional singletons and require some unwanted DontDestroyOnLoad logic. [Example Dependency Injection](https://github.com/coreymason/ECS-189L-Game/blob/f31c7a9d0fa1c024be97b927c282390a062ea148/UnityProject/Assets/Scripts/Actors/PlayerController.cs#L29) Enemy Artificial Intelligence: -For AI, I forwent complex state machines and instead simplified the system into two key states -- a peaceful state and a hostile state. I then add one script of each type onto an enemy prefab in addition to a vision component that handles triggering the transition into hostile state upon sighting a player. As for how AI actually moves, I integrated the A Star Pathfinding Project (another library widely used in industry like Zenject), and then modify the a prefab’s base AIPath settings as well as target destination from code. In doing so, I can achieve some pretty straight forward AI code as seen in [Wander](https://github.com/coreymason/ECS-189L-Game/blob/f31c7a9d0fa1c024be97b927c282390a062ea148/UnityProject/Assets/Scripts/Actors/AI/Wander.cs) and [RunAttack](https://github.com/coreymason/ECS-189L-Game/blob/f31c7a9d0fa1c024be97b927c282390a062ea148/UnityProject/Assets/Scripts/Actors/AI/RunAttack.cs). +For AI, I forwent complex state machines and instead simplified the system into two key states -- a peaceful state and a hostile state. I then add one script of each type onto an enemy prefab in addition to a [vision script](https://github.com/coreymason/ECS-189L-Game/blob/010b6e9314790445f38408239d648085a5d9c39b/UnityProject/Assets/Scripts/Actors/AI/AIVision.cs) that handles triggering the transition into hostile state upon sighting a player. As for how AI actually moves, I integrated the A Star Pathfinding Project (another library widely used in industry like Zenject), and then modify the a prefab’s base AIPath settings as well as target destination from code. In doing so, I can achieve some pretty straight forward AI code as seen in [Wander](https://github.com/coreymason/ECS-189L-Game/blob/f31c7a9d0fa1c024be97b927c282390a062ea148/UnityProject/Assets/Scripts/Actors/AI/Wander.cs) and [RunAttack](https://github.com/coreymason/ECS-189L-Game/blob/f31c7a9d0fa1c024be97b927c282390a062ea148/UnityProject/Assets/Scripts/Actors/AI/RunAttack.cs). Example in-game scene view (note the pathing in progress and field of view detection area) ![alt text](https://lh5.googleusercontent.com/jtC5Og5iJxkJd7Y47cM0ALIGKHYrdzujDO-t5tzb8YhS67ZS8FGLiPc_DcPUzVSbTkngJpmEoScdu6ueRFTy58rT8to0ca8Vvgb9P8GR)