Skip to content

Instantly share code, notes, and snippets.

@soraphis
soraphis / ExampleUsage.cs
Last active Feb 23, 2021
a realproxy implementation of IRevertibleChangeTracking
View ExampleUsage.cs
/*
* Copyright © 2021 github.com/soraphis
* This work is free. You can redistribute it and/or modify it under the
* terms of the Do What The Fuck You Want To Public License, Version 2,
* as published by Sam Hocevar. See the COPYING file or http://www.wtfpl.net/
* for more details.
*/
using System;
using System.Diagnostics;
@soraphis
soraphis / singleton.cs
Last active Oct 8, 2019
generic version of thread safe singletons based on: https://csharpindepth.com/Articles/Singleton
View singleton.cs
// ---------------------------------------------------------------------------------------------
// SOME UTILY CLASSES
// ---------------------------------------------------------------------------------------------
public abstract class ThreadSafeSingleton<T> where T : ThreadSafeSingleton<T>, new()
{
static ThreadSafeSingleton(){}
protected ThreadSafeSingleton() { }
public static T Instance { get; } = new T();
}
@soraphis
soraphis / 01_ProfilerResults.png
Last active Apr 9, 2019
Testing garbage allocation of strings and string concatenation in unity
@soraphis
soraphis / CInput.cs
Last active Jan 5, 2019
Unity3D more Complex Input. Differentiate between UI clicks and world clicks, check if mouse is dragging
View CInput.cs
using System.Linq;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Experimental.LowLevel;
using UnityEngine.Experimental.PlayerLoop;
using UInput = UnityEngine.Input;
public static class CInput {
[RuntimeInitializeOnLoadMethod]
@soraphis
soraphis / _output
Last active Jan 7, 2018
python file that calculates base ressources needed to craft components.
View _output
Minecraft Mod: "Solar Flux"
Modpack: Project Ozone Lite
Calculating Cost Efficiency
3 x Chaotic Solar Panel -> 1572864.0 RF/t 100.00%
4 x Draconic Solar Panel -> 524288.0 RF/t 33.33%
8 x Solar Panel 8 -> 262144.0 RF/t 16.67%
View DummyComponent.cs
/*
this is an example
*/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
@soraphis
soraphis / SomeCameraTest.cs
Last active Oct 8, 2016
a script for orthogonal cameras, which starts moving the camera when the player is about to leave the visible region. can be seen here: https://gfycat.com/NecessaryFelineHare
View SomeCameraTest.cs
using UnityEngine;
public class SomeCameraTest : MonoBehaviour {
private Bounds outer_bounds;
private Bounds inner_bounds;
private bool bounds_reached = false;
[SerializeField] private Transform target;
[SerializeField] private Camera cam;
[SerializeField] private float camSpeed = 8f; // set to player speed
@soraphis
soraphis / RectExtensions.cs
Last active Oct 30, 2017
Unity3D c# extension class for Rect objects. useful for developing editor addons
View RectExtensions.cs
using UnityEngine;
namespace Assets.Soraphis.Lib {
public static class RectExtensions {
/// <summary>
/// Splits a Rect in vertical ordered, even, pieces and returns the piece at the given index
/// </summary>
public static Rect SplitRectV(this Rect rect, int many, int start, int length = 1) {
var height = rect.height/many;
@soraphis
soraphis / PhysicsDisposable.cs
Last active Aug 16, 2016
Reduces code clutter when using sphere casts or raycasts when the actual object should be ignored
View PhysicsDisposable.cs
/// <summary>
/// This class uses the decorator pattern and the Idisposable interface to allow a cleaner usage of raycast/spherecasts
/// or other physic quarrys, which should not hit the gameobject
/// </summary>
class PhysicsDisposable : IDisposable {
private static Stack<PhysicsDisposable> Pool = new Stack<PhysicsDisposable>(4);
private List<Collider> colliders = new List<Collider>(2);
private List<int> originalLayer;