Skip to content
This repository was archived by the owner on Nov 5, 2024. It is now read-only.

Code & Style Conventions

Lithrun edited this page Jun 20, 2021 · 6 revisions

Code & Style Conventions

Last updated: 20th of June 2021

Code Improvements & Quality of Life Improvements

Boy Scout Rule: "Always leave the code you're editing a little better than you found it". Software will never be possible, but if you see the opportunity and it won't take a significant amount of time, improve it. Initiative: Don't wait until someone else does it, take the initiative! AoTTG2 is a large project, so if you see something that can be done better, do it or create an issue for it.

ScriptableObjects

Try to use ScriptableObjects when you are dealing with configuration data. Using ScriptableObjects allows us to easily modify & extend logic that uses these.

[Obsolete] class/method/property

When you enter these, you are dealing with logic which has been outdated. When you are working on your issue, and you encounter one of these, see if it is possible to refactor the logic (if related to your issue) within a reasonable time. If it is, do it. If it does take more time, check if there's an issue already for it, if not, create it.

Localization

New text that is introduced MUST be localized. For localization we use Unity's Localization Package. To add a new localization key, either extend an existing table within Assets/Localization or create a new category.

Runtime

For runtime localization you can use the convenient static class named Localization.

Compile time

Compile time localization can conveniently be done by adding a "Localize String Event" component to the UI.

Comments

Type of Comments

Only comment what is useful to comment on

  • Decisions (We did this weird logic due to Issue #666, to assure to Isk cannot spawn)
  • Complex methods (Generally methods should be simple, but for complicated algorithms or long methods this is fine)

Where to use /// summary comments

  • public/abstract classes (Define the scope & responsibilities of the class)
  • public/protected/internal/virtual methods (Describe what the method is supposed to do)
  • public/protected/internal properties/fields (Describe the purpose of the property / field)
  • interfaces
  • events

Photon Networking

PhotonView.RPC

Do not use a hardcoded string for PhotonView.RPC, instead make use of nameof(methodRpc). Using nameof allows us to easily see which methods are used and makes renaming RPCs easier.

Invalid photonView.RPC("MethodRpc"

Valid photonView.RPC(nameof(MethodRpc)

Clone this wiki locally