# Design Decisions

### **EasyCode Opinionated Design Choices**

* **EasyCode** uses **Zenject dependency injection** internally so I can scale EasyCode without breaking projects in future releases, and to be friendly/compatible with teams working on big projects that already use dependency injection. Also, I am using **Project Context prefab** in Resources folder. If you have a **Project Context** as well it may conflict with **EasyCode** Project Context.\
  **Zenject** supports **IL2CPP** but <mark style="color:red;">be aware there may be issues if using</mark> <mark style="color:red;"></mark><mark style="color:red;">**IL2CPP**</mark>\
  [**read more here**](https://github.com/modesttree/Zenject#aot-support) about **IL2CPP** compatibility
* The **3D demo** scene uses **NetCodeForGameObjects**. I was originally going to use **Mirror Networking,** but they made a lot of breaking changes and at the time (**Oct 2022**) tutorials I **followed/bought** weren't updated, so I decided to adopt NetCode since it's part of Unity's Ecosystem and was finally production ready.
* Designed with some ***static variables to keep track of session (EasySession.cs),*** instead of *Singleton design pattern,* for persistent session data across scenes (I had problems properly Implementing Singleton, previous instances would be destroyed and replaced with new instances thus destroying session data. This happened back in late 2020/early 2021 when I was still a fairly new programmer. I have learned a lot since then and re-written/re-designed EasyCode about 3 1/2 times and still went with a few static variables over singleton design pattern).
* <mark style="color:orange;">Uses Reflection for Dynamic events</mark>. It is the slower option, but I don't know how to use **Mono.Cecil** or **C#** **Dynamic Methods** with **IL Emit/Opcodes (maybe one day).**&#x20;
* At the time of this writing **namespace&#x20;***<mark style="color:orange;">**VivoxAccessToken**</mark>  located at* **`Assets/EasyCodeForVivox/Plugins/VivoxAccessToken.dll`** \
  is basically a direct copy of how to implement ***Vivox Access Token*** [from the Vivox documentation](https://docs.vivox.com/v5/general/unity/15_1_180000/en-us/Default.htm#access-token-guide/generate-token-secure-server/example-c-sharp.htm%3FTocPath%3DVivox%2520Unity%2520SDK%2520documentation%7CAccess%2520Token%2520Developer%2520Guide%7CGenerate%2520a%2520token%2520on%2520a%2520secure%2520server%7C_____2). I didn't change method names so it would be easier to reference the docs.&#x20;

{% hint style="warning" %} <mark style="color:orange;">**VivoxAccessToken**</mark> may be changed in the future since later Unity Versions since they provide a **NewtonSoft Json package** in the **Unity Package Manager** which can be used to serialize instead of the **JavaScriptWebSerializer.** This would mean one less **Plugin/dll** to maintain separately, and source code would be included in **EasyCode . Once Unity releases 2022 LTS I may make the switch to support 2020 and above with a dependency on Unity's version of NewtonSoft.Json**
{% endhint %}

* Designed **`EasyManager.cs`** to be ***inherited*** from. <mark style="color:orange;">You can</mark> *<mark style="color:orange;">**reference it**</mark>* <mark style="color:orange;"></mark><mark style="color:orange;">using</mark> <mark style="color:orange;"></mark><mark style="color:orange;">**`GetComponent<EasyManager>();`**</mark> to gain access to its public methods or use Dependency Injection in your classes
* ***Balance of Ease of Use and Performance*** (My laptop is pretty performant (*Processor Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz, 2208 Mhz, **6 Core(s), 12 Logical Processor(s), 16 GB RAM, although I am running Docker on WSL so it does steal some performance***) so results may vary. **Only when using Dynamic events should you worry about performance.** Even so events are fire and forget and you should never see a performance hit)

Designed with scaling in mind but if you think your game is going to have over 10, 000 players or need an enterprise solution I would look at **`Assets/EasyCodeForVivox/Scripts/VivoxBackend`** and **`EasyManager.cs`** And implement your own solution based on the code in this asset and ***Vivox documentation***. Especially if you don't like my naming conventions or design :grin:. I am open to feedback and pull requests to make EasyCode a goto solution for Enterprise level games/apps
