Skip to content

Instantly share code, notes, and snippets.

@mchamplain
mchamplain / FSMState.cs
Created October 12, 2023 01:32 — forked from FNGgames/FSMState.cs
Generic Finite State Machine
public abstract class FSMState<T_Data, T_Id>
{
public abstract T_Id id { get; protected set; }
public virtual void OnEnter(T_Data data) { }
public virtual void OnUpdate(T_Data data) { }
public virtual void OnExit(T_Data data) { }
public delegate void TransitionEventHandler(T_Id id);
public event TransitionEventHandler TransitionEvent;
@mchamplain
mchamplain / SceneHelpers.cs
Created October 12, 2023 01:32 — forked from FNGgames/SceneHelpers.cs
Scene Loader
using System;
using System.Collections.Generic;
using System.IO;
using UnityEngine.SceneManagement;
public static class SceneHelpers
{
public static string[] GetValidSceneNames()
{
@mchamplain
mchamplain / IApplicationService.cs
Created October 12, 2023 01:30 — forked from FNGgames/IApplicationService.cs
Entitias Scene Initialization Example
public interface IApplicationService : IService
{
HashSet<string> GetValidScenes();
void Load(string sceneName, Action<string, float> onProgress, Action<string> onComplete);
void Unload(string sceneName, Action<string, float> onProgress, Action<string> onComplete);
void Quit();
}
@mchamplain
mchamplain / SystemsVerificationTool.cs
Created October 5, 2023 02:59
Helper to find Entitas systems that we didn't add to the systems (Entitas v1.x)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Entitas;
using UnityEngine;
namespace Common.Utilities
{
public static class SystemsVerificationTool
@mchamplain
mchamplain / IPEndPointTypeDrawer.cs
Created July 22, 2022 18:33
Entitas custom TypeDrawer for IPEndPoint value
using System;
using System.Net;
using JCMG.EntitasRedux.Editor;
using UnityEditor;
namespace Scripts.VisualDebugging
{
public class IPEndPointTypeDrawer: ITypeDrawer
{
public bool HandlesType(Type type) {
@mchamplain
mchamplain / toggle-windows-vms.sh
Created May 17, 2020 13:27
Start & Stop VMs on Unraid Servers with only 1 GPU
#!/bin/bash
# Set the name of your VMs here
VM_TO_SHUTDOWN="Windows 7"
VM_TO_START="Windows 10"
# How long to wait for the VM to shutdown (avoid having an infinite loop)
waitTimeout=30
@mchamplain
mchamplain / Day.php
Created May 14, 2020 01:37 — forked from Ocramius/Day.php
Example abstraction that only allows a resolution of "day" for time inside a specific business domain
<?php
declare(strict_types=1);
namespace Core\Domain\Time;
use DateTimeImmutable;
use DateTimeZone;
use Generator;
use Iterator;
@mchamplain
mchamplain / .bashrc
Last active November 21, 2019 14:21
git-bash alias on Windows10
alias composer='winpty docker run -it --rm --net=host -v "/$HOME":"/$HOME" -e COMPOSER_HOME="$HOME/.composer" -u $UID -w "/$(pwd)" composer'
alias node='winpty docker run -it --rm --net=host -v "/$HOME":"/$HOME" -u $UID -w "/$(pwd)" node:12-stretch node'
alias npm='winpty docker run -it --rm --net=host -v "/$HOME":"/$HOME" -u $UID -w "/$(pwd)" node:12-stretch npm'
@mchamplain
mchamplain / MyNetworkManager.cs
Created March 7, 2019 20:03
Sample code for a possible replacement of the various InstantiateXXX methods in the NetworkManager class generated by ForgeNetworkingRemastered
public class MyNetworkManager:NetworkManager
{
public T InstantiateNetworkObject<T>(GameObject[] networkObjects, int index, Vector3? position = null, Quaternion? rotation = null, bool sendTransform = true) where T:NetworkBehavior
{
var go = Instantiate(networkObjects[index]);
var netBehavior = go.GetComponent<T>();
NetworkObject obj = null;
if (!sendTransform && position == null && rotation == null)
obj = netBehavior.CreateNetworkObject(Networker, index);
@mchamplain
mchamplain / GameController.cs
Created May 26, 2017 03:46 — forked from FNGgames/GameController.cs
store ids for every entity in a component then look up the entities by their ID using a PrimaryEntityIndex
void Start()
{
// ...
_contexts.game.OnEntityCreated += AddId;
_contexts.input.OnEntityCreated += AddId;
// ...
}
private void AddId(IContext context, IEntity entity)
{