Skip to content

Instantly share code, notes, and snippets.

@onewinter
onewinter / BaseGameEvent.cs
Created June 3, 2023 23:17
An updated version of https://gist.github.com/onewinter/ce46fd5091ffd3e3ec8bf429e6d49ce7 using standard Events subscriptions instead of Lists
using System;
using UnityEngine;
public class BaseGameEvent : ScriptableObject
{
#if UNITY_EDITOR
[TextArea] public string developerDescription = "";
#endif
public event Action Raised;
@onewinter
onewinter / Hex.cs
Last active May 31, 2023 09:17 — forked from inca/Hex.cs
[Unity] Simple Hex Grid System
// https://gist.github.com/inca/0b3d194b755e2efd9d7d8e3665e6cfbb
// math from https://www.redblobgames.com/grids/hexagons/
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public static class HexVectorExtensions {
public static Vector2 WorldToPlanar(this Vector3 world) {
@onewinter
onewinter / GameEffect.cs
Last active March 22, 2023 20:17
A Unity 2021+ Pooling Framework using TypeObjects and ScriptableObjects; GameEffect & GameEffectSetup show how to use it to easily start/stop Particle Systems effects; Pickup & PickupSetup show how to use it to create pickups like Gems or Coins.
using UnityEngine;
public class GameEffect : PooledObjectBase
{
public Transform EffectTarget;
public float EffectDuration;
[SerializeField] private float timer;
public override void BeforeEnable()
@onewinter
onewinter / BaseGameEvent.cs
Last active October 7, 2022 20:09
A lightweight Scriptable Object event system for Unity.
using System;
using System.Collections.Generic;
using UnityEngine;
public abstract class BaseGameEvent : ScriptableObject
{
#if UNITY_EDITOR
[TextArea] public string developerDescription = "";
#endif
[SerializeField] private AnimationCurve curveHeight;
[SerializeField] private float curveMaxHeight;
public Vector3 Move(Projectile projectile)
{
// move towards the target in an arc, taking a constant amount of time
var linearT = projectile.CurrentTime / Duration;
// we have to move XZ and Y separately so they dont fight each other
var movePosition = Vector3.Lerp(projectile.StartPosition.PositionXZ(), projectile.TargetPosition.PositionXZ(), linearT);
// in case the start and end Y values are different (which they should be since the turret is higher)
# function adapted from https://stackoverflow.com/posts/42995301/revisions
Function Execute-Command ($commandTitle, $commandPath, $commandArguments)
{
Try {
$pinfo = New-Object System.Diagnostics.ProcessStartInfo
$pinfo.FileName = $commandPath
$pinfo.RedirectStandardOutput = $true
$pinfo.UseShellExecute = $false
$pinfo.Arguments = $commandArguments
$p = New-Object System.Diagnostics.Process