Skip to content

Commit

Permalink
Update ProjectDocument.md
Browse files Browse the repository at this point in the history
  • Loading branch information
coreymason authored Jun 11, 2019
1 parent 010b6e9 commit f124510
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion ProjectDocument.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f124510

Please sign in to comment.