Skip to content

unitycoder/GameWork-Foundation

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

93 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation


version license top language code quality

A set of code useful for developing Unity based games. It is independent of any architecture, so you can use it together with your favorite framework.

These are the foundations on which Game:Work Core is built.

Features πŸŽ‡

  • Architecture agnostic, use it in any code.
  • Many attributes to make your classes more usable in the editor (without having to write a custom Editor).
  • Multiple utilities to improve your developments: checkers, debug draw, profiling and a console with custom commands.
  • A lot of .Net and Unity types extensions.
  • The most used design patterns, in generic versions so that they are easy to adapt to your needs.
  • Commented code with test units.

Requisites πŸ”§

  • Unity 2021.3 or higher.
  • Test Framework 1.1.31 or higher.

Installation βš™οΈ

Editing your 'manifest.json'

  • Open the manifest.json file of your Unity project.
  • In the section "dependencies" add:
{
  ...
  "dependencies":
  {
    ...
    "FronkonGames.GameWork.Foundation": "git+https://github.com/FronkonGames/GameWork-Foundation.git"
  }
  ...
}

Git

Just clone the repository into your Assets folder:

git clone https://github.com/FronkonGames/GameWork-Foundation.git 

Use πŸš€

The functionality is divided into folders, this is its structure:

|
|\_Runtime......................... Utilities for the game.
|   |\_Attributes.................. Attributes for fields and class properties.
|   |\_Development................. Developer utilities.
|   |   |\_Check................... Assert extension.
|   |   |\_Console................. Development console.
|   |   |\_Draw.................... Utilities for drawing gameplay information.
|   |    \_Profiling............... To find bottlenecks.
|   |\_Extensions.................. Utility extensions.
|   |   |\_System.................. C# extensions.
|   |    \_Unity................... Unity extensions.
|   |\_Math........................ Mathematical utilities.
|   |\_Patterns.................... Design patterns.
|   |   |\_Behavioral.............. Behavioural patterns.
|   |   |\_Creational.............. Creation patterns.
|   |    \_Structural.............. Structure patterns.
|    \_Unity....................... Utilities for Unity.
|       |\_MonoBehaviours.......... MonoBehaviours utilities.
|        \_Utils................... Misc.
|
 \_Editor.......................... Editor utilities.
    |\_Drawers..................... Custom attribute viewers.
     \_Inspector................... Editor appearance utilities.

Check the comments for each file for more information.

Attributes

[Title("Attributes Demo")]
[Label("Nice name")]
public string badName;
[Password]
public string password;
[Indent(0)]
public string noIndent;

[Indent(1)]
public string indented;
[NotNull]
public GameObject cantBeNull;
[File]
public string filePath;

[Folder]
public string folderPath;
[Scene]
public int sceneIndex;
[NotEditable]
public string notEditable;

[OnlyEditableInEditor]
public string editableInEdit;

[OnlyEditableInPlay]
public string editableInPlay;
public bool toggle;

[EnableIf(nameof(toggle))]
public string enableIf;

[DisableIf(nameof(toggle))]
public string disableIf;
public bool toggle;

[ShowIf(nameof(toggle))]
public string showIf;
public bool toggle;

[HideIf(nameof(toggle))]
public string hideIf;
[NotEditable]
public int counter;

[Button(nameof(Increase))]
public string buttonInc;

[Button(nameof(Reset))]
public string buttonReset;

public void Increase() => counter++;
public void Reset()    => counter = 0;

Check

Checks the values of the variables that a function receives. If the condition is not met, an exception is thrown. Only active when 'UNITY_ASSERTIONS' is defined (default only in the Editor).

public void GetImpact(GameObject gameObject, float damage, Vector3 impact)
{
    Check.IsNotNull(gameObject);
    Check.IsWithin(damage, 0.0f, 100.0f);
    Check.Greater(impact, Vector3.zero);
    
    ...
}

Take a look at the Check class folder.

Draw

Visualize in the Editor Scene window useful information of your game, in a simple way and without affecting the final performance of the game.

// Displays an array of points.
points.Draw();

// Displays the player's direction.
player.transform.Draw();

// Displays the name of the GameObject.
player.DrawName();

// Displays RaycastHits.
int hits = Physics.RaycastNonAlloc(playerRay, playerHits, 100.0f);
if (hits > 0)
  playerHits.Draw(playerRay);

Development Console

A developer console for executing commands.

Simply add a GameObject with the DevelopmentConsole component and assign the commands you want to use to it.

Commands are ScriptableObjects that you can create from DevelopmentCommand. See the commands included in this folder.

/// <summary>
/// Quit application.
/// </summary>
[CreateAssetMenu(fileName = "Quit", menuName = "Game:Work/Development/Command/Quit")]
public class QuitCommand : DevelopmentCommand
{
    public QuitCommand()
    {
      Id = "quit";
      Usage = "quit";
      Description = "Quit application.";
    }

    public override bool Execute(string[] args)
    {
        Application.Quit();
    
        return true;
    }
}

Profiling

It measures in a simple way the time it takes for a block of code to execute, or the memory it consumes.

using (Profiling.Time("Some slow code"))
{
    ...
}

Output the message: "Task 'Some slow code' took 27.66ms (0 frames)"

using (Profiling.Memory("Some hungry code"))
{
    ...
}

Output the message: "Task 'Some hungry code' consume 4.00 kb".

Patterns

The most used design patterns:

All using generics.

License πŸ“œ

Code released under MIT License.

'Prototype Textures' by Kenney.

About

Generic code and tools to build the basis of a framework to develop Unity based games.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%