Skip to content

Instantly share code, notes, and snippets.

@FNGgames
FNGgames / TimerSystem.cs
Last active October 20, 2021 10:05
Entitas Timer System
using Entitas;
using UnityEngine;
public class TimerSystem : IExecuteSystem, ICleanupSystem
{
readonly IGroup<GameEntity> _timers;
readonly IGroup<GameEntity> _timerCompletes;
readonly GameContext _context;
public TimerSystem(Contexts contexts)
void Start()
{
// ...
_contexts.game.OnEntityCreated += AddId;
_contexts.input.OnEntityCreated += AddId;
// ...
}
private void AddId(IContext context, IEntity entity)
{
@FNGgames
FNGgames / SimplePool,cs
Created June 25, 2017 17:23
Simple Game Object Pooler
// Modified from Quill18's version
using UnityEngine;
using System.Collections.Generic;
public static class SimplePool
{
// You can avoid resizing of the Stack's internal array by
// setting this to a number equal to or greater to what you
// expect most of your pool sizes to be.
@FNGgames
FNGgames / Graph.cs
Last active July 24, 2017 16:26
Pathfinding stuff
public abstract class Graph
{
public GraphNode[] Nodes;
public abstract void GenerateGraph();
public abstract float HeuristicCostEstimate(GraphNode current, GraphNode target);
public bool Dirty;
}
// interface for graph nodes
public abstract class GraphNode : IHeapItem<GraphNode>
using System;
using System.Collections.Generic;
public class Task
{
public readonly string taskName;
public readonly float taskDuration;
public readonly float repeatDuration;
public readonly int minWorkers = 1;
public readonly int maxWorkers = 1;
@FNGgames
FNGgames / AssignGameViewSystem.cs
Last active October 24, 2018 10:27
View layer abstraction for Entitas (with Unity implementation).
using System.Collections.Generic;
using Entitas;
public class AssignGameViewSystem : ReactiveSystem<GameEntity>
{
private readonly Contexts _contexts;
public AssignGameViewSystem(Contexts contexts) : base(contexts.game)
{
_contexts = contexts;
@FNGgames
FNGgames / ContextHelpers.cs
Created February 1, 2018 10:17
Context helpers
public static class ContextHelpers
{
private static readonly Dictionary<string, IContext> _contextsLookup = new Dictionary<string, IContext>();
public static IContext GetContextByName(this Contexts contexts, string name)
{
if (_contextsLookup.Count == 0) SetContextsDictionary(contexts);
return _contextsLookup[name];
}
@FNGgames
FNGgames / FSMState.cs
Created September 22, 2018 13:09
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;
@FNGgames
FNGgames / SceneHelpers.cs
Last active October 12, 2023 01:32
Scene Loader
using System;
using System.Collections.Generic;
using System.IO;
using UnityEngine.SceneManagement;
public static class SceneHelpers
{
public static string[] GetValidSceneNames()
{
@FNGgames
FNGgames / BaseCollisionSystem.cs
Last active March 7, 2019 11:19
Entitias Collisions
using Entitas;
using System.Collections.Generic;
public abstract class CollisionSystem : ReactiveSystem<InputEntity>
{
protected Contexts _contexts;
public CollisionSystem(Contexts contexts) : base(contexts.input)
{
_contexts = contexts;