Skip to content

Instantly share code, notes, and snippets.

View DevEarley's full-sized avatar
🎯
Focusing

Alex Earley DevEarley

🎯
Focusing
View GitHub Profile
@DevEarley
DevEarley / RNGController.cs
Created December 2, 2023 17:47
C# RNG implementation for Unity3D
public class RNGController : MonoBehaviour
{
private int index = 0;
private int lastLargestIndex = 0;
private int max_index = 1000;
private List <int> values = new List<int>();
public int Next(int RNG_ID)
{
var offsetIndex = RNG_ID + index;
@DevEarley
DevEarley / ScreenResolutionUtility.cs
Last active March 25, 2024 10:52
Static Screen Resolution Utility for Unity 3D with Common Resolutions
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public enum CommonScreenResolutions
{
gameConsole_16bit_pocket_10x9, //160 × 144 160∶144 10:9 1∶1
gameConsole_16bit_low_4x3, //256 × 224 256∶224 4∶3 7∶6
gameConsole_16bit_super_4x3, //400 × 300 4∶3 4∶3 1∶1
gameConsole_32bit_low_4x3, //256 × 224 256∶224 4∶3 7∶6
@DevEarley
DevEarley / InputController.cs
Created April 28, 2023 19:01
Unity Input Controller & Service
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public enum InputControllerState
{
NO_INPUT_DEVICE_CONNECTED,
NO_CONTROLLER_CONNECTED,
NO_KEYBOARD_CONNECTED,
BOTH_KEYBOARD_AND_CONTROLLER_CONNECTED
@DevEarley
DevEarley / unity3d-basic-classes.md
Last active July 3, 2023 15:45
Unity3D basic classes

Behaviours

  • Attached to a GO. Many GOs may have this script.
  • A MonoBehaviour.
  • Can be used multiple times in a scene.
  • Can implement interfaces.
  • Great for enemy behaviour, trigger & door logic, reacting to OnTrigger events.

Controllers

  • Attached to a GO like a Behaviour
  • Single instance of this may exist in a scene at once.
@DevEarley
DevEarley / A-service-locator-in-unity.md
Last active October 10, 2022 20:13
Service Locator pattern in Unity3D

Service Locator pattern in Unity3D

Using the Service Locator pattern in Unity allows you connect various services together to a single source. When a script needs access to something on the Service Locator, it just needs to access the Service Locators's Instance. This instance will have any service the invoker may need.

To setup, the service must be referenced in the script and the script must find these services on Awake. You can look them up by the GameObject they are attached to or attach them to the Service Locator's GO. In this example, I use GetComponentInChildren<T>(). Alternatively you can search for the GameObject by name and then get the component, PlayerController = GameObject.Find("PlayerController").GetComponent<PlayerController>();

  • Contains references to all Controllers and all Services.
  • Attached to a GO.
  • Must reference all controllers and services automatically.
@DevEarley
DevEarley / A-Delegate-pattern-in-Uniy3D.md
Last active October 10, 2022 20:46
Delegate pattern in Uniy3D

Delegate pattern in Uniy3D

  • A delegate is something that acts on another thing's behalf.

  • So if Thing A needed something, Thing B to Thing Z could deliver that to Thing A. This makes Things B to Z all delegates to Thing A. Thing A invokes a delegate function. Thing A doesn't care who runs the errand. Thing A doesn't care how it happens. As long as it happens.

Delegate Invoker

@DevEarley
DevEarley / fe-testing.md
Last active April 1, 2022 15:24
Notes on front end testing

Notes on Frontend Testing

Use Data Attributes Rather Than CSS Selectors.

... choose selectors less prone to change. My favorite type of selector is the data attribute. A developer is less likely to change data attributes while refactoring, making them perfect for locating elements in tests. I recommend naming them in a meaningful way to clearly convey their purpose to any developers working on the source code.

* Frontend Testing Pitfalls

Don't Use AAA, Use BDD!

AAA refers to Arrange, Act, Assert. This is a tried and true pattern for unit testing things like APIS. But does that work for something like integration testing with the DOM? Consider another approach, behavioral-driven development (BDD).

@DevEarley
DevEarley / psm.cmd
Created March 31, 2022 19:56
PSM - Commit and Push all Submodules
echo off
git submodule foreach "git add . || :"
git submodule foreach "git commit -m \"%*\" || :"
git submodule foreach "git push || :"
git add .
git commit -m "%*"
git push
@DevEarley
DevEarley / VertexColor.shader
Last active March 19, 2022 14:15
Shader that works well with Unity3d. Tested with Collada file that had vertex colors.
Shader "Custom/VertexColorEmissive"
{
Properties
{
_MainTex("Color (RGB) Alpha (A)", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic("Metallic", Range(0,1)) = 0.0
_Emissive ("Emissive", Range(0,1)) = 1.0
_Cutoff("Alpha cutoff", Range(0,1)) = 0.2
}
@DevEarley
DevEarley / convert-flv-to-mp4.cmd
Last active December 8, 2020 17:32
FFMPEG FLV to MP4 converter
ffmpeg -i "./%*.flv" -c:v libx264 -crf 19 -strict experimental "./%*.mp4"