Skip to content

Instantly share code, notes, and snippets.

View soraphis's full-sized avatar

Soraphis soraphis

View GitHub Profile
@soraphis
soraphis / CamerFadeScript.cs
Last active March 13, 2018 15:13
Implementation of an CameraFadeScript for Unity 5 with Code only, no gameobjects or ui elements needed. (There has to be a main camera in the scene :P)
using System.Collections;
using UnityEngine;
// does need UnityStandardAssets > ImageEffects
// does not work if you use the ImageEffect "ScreenOverlay" on your camera for visual effects
// Usage:
// From a MonoBehaviour-Class: StartCoroutine(CameraFade.FadeOut(0.8f));
// From inside a coroutine (if you want to wait for finished fading): yield return CameraFade.FadeOut(0.5f);
// From inside a coroutine (if you dont want to wait): CameraFade.FadeOut(0.5f);
@soraphis
soraphis / CInput.cs
Last active January 5, 2019 13:04
Unity3D more Complex Input. Differentiate between UI clicks and world clicks, check if mouse is dragging
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 / 01_ProfilerResults.png
Last active April 9, 2019 16:40
Testing garbage allocation of strings and string concatenation in unity
01_ProfilerResults.png
@soraphis
soraphis / singleton.cs
Last active October 8, 2019 07:34
generic version of thread safe singletons based on: https://csharpindepth.com/Articles/Singleton
// ---------------------------------------------------------------------------------------------
// SOME UTILY CLASSES
// ---------------------------------------------------------------------------------------------
public abstract class ThreadSafeSingleton<T> where T : ThreadSafeSingleton<T>, new()
{
static ThreadSafeSingleton(){}
protected ThreadSafeSingleton() { }
public static T Instance { get; } = new T();
}
/*
this is an example
*/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
@soraphis
soraphis / ClickWordInTextTest.cs
Created August 8, 2016 14:24
Test Unity script to handle clicks on specific words in UI-Text components
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace DefaultNamespace {
public class ClickWordInTextTest : MonoBehaviour, IPointerClickHandler{
public Text TheTextComponent; // filled in the inspector or somewhere else
@soraphis
soraphis / PositionHandleEditor.cs
Created April 1, 2016 16:33
Unity3D Handles by Propertydrawer
#if UNITY_EDITOR
namespace Editor {
using UnityEditor;
[CustomEditor(typeof(MonoBehaviour), true, isFallback = true)]
public class PositionHandleEditor : UnityEditor.Editor {
void OnSceneGUI() {
var t = target as MonoBehaviour;
if(t == null) return;
@soraphis
soraphis / trait_impl_proposal.md
Created February 18, 2023 11:48
C# trait interface implementation proposal

Disclaimer: ChatGPT helped me to write this markdown file

Proposal for a C# Language Feature: Trait Implementations

Summary

This proposal introduces a new language feature for C# called Trait Implementations. This feature allows developers to provide implementations for interfaces on types that they don't have access to. Trait Implementations can also be used to extend existing interfaces with default implementations.

@soraphis
soraphis / RevertibleChangeProxy.cs
Last active March 8, 2023 11:12
a realproxy implementation of IRevertibleChangeTracking
/*
Copyright © 2021 github.com/soraphis
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
@soraphis
soraphis / UnityAppStatusBarExtender.cs
Last active April 23, 2023 21:02
Pendant for the https://github.com/marijnz/unity-toolbar-extender just for the bottom status bar. Add
/*
* This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the