Skip to content

Instantly share code, notes, and snippets.

View gustavopsantos's full-sized avatar
🦖

Gustavo Santos gustavopsantos

🦖
View GitHub Profile
@hybridherbst
hybridherbst / RuntimeInitializeOnLoad - Event Order.cs
Created March 8, 2021 15:04
[RuntimeInitializeOnLoad] Event Order
static Lifecycle() => Debug.Log(Prefix + "Static Constructor");
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] static void Subs() => Debug.Log(Prefix + "Subsystem Registration");
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterAssembliesLoaded)] static void AfterAsm() => Debug.Log(Prefix + "AfterAssembliesLoaded");
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSplashScreen)] static void BeforeSlash() => Debug.Log(Prefix + "Before Splash");
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] static void BeforeScene() => Debug.Log(Prefix + "BeforeScene");
private void Awake() => Debug.Log(Prefix + "Awake");
private void OnEnable() => Debug.Log(Prefix + "OnEnable");
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)] static void AfterScene() => Debug.Log(Prefix + "AfterSceneLoad");
[RuntimeInitializeOnLoadMethod] static void DefaultLog() => Debug.Log(Prefix + "RuntimeInit Default");
void Start() => Debug
@emilianavt
emilianavt / IKRunner.cs
Last active February 8, 2024 10:42
This component uses the UnityEngine.LowLevel API to run Final IK things before Unity constraints and particle systems are evaluated.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.LowLevel;
using RootMotion.FinalIK;
// Disable IK and TwistRelaxers and set them on this to have them run before constraints and particle systems are evaluated.
// Only one instance of IKRunner is possible, but it should be easy enough to extend.
// Remember to call Start() on the TwistRelaxers once if they are disabled from the beginning. The IK may also need manual initialization.
using UnityEngine;
using UnityEngine.LowLevel;
using UnityEngine.PlayerLoop;
public static class AddPlayerLoopCallback
{
// Add a callback to the PreUpdate phase
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
static void Setup()
{
using UnityEditor;
using UnityEngine.LowLevel;
using UnityEngine.UIElements;
public class ShowPlayerLoopWindow : EditorWindow
{
[MenuItem("Window/Player Loop")]
static void ShowWindow()
{
var wind = GetWindow<ShowPlayerLoopWindow>(false, "Player Loop");
@extrawurst
extrawurst / RunTestsBeforeBuild.cs
Created October 30, 2019 09:43
Unity TestRunnerApi to run UnitTests before each build
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEngine;
using UnityEditor.TestTools.TestRunner.Api;
public class ResultCollector : ICallbacks
{
public ITestResultAdaptor Result { get; private set; }
public void RunFinished(ITestResultAdaptor result)
@badcommandorfilename
badcommandorfilename / RuntimeCast.cs
Created June 29, 2018 00:57
C# Runtime type Cast and CastEnumerable
static IEnumerable CastEnumerable(IEnumerable<object> input, Type t)
{
foreach(var o in input)
{
yield return Cast(o, t);
}
}
static object Cast(object obj, Type t)
@LotteMakesStuff
LotteMakesStuff / PlayerLoop.cs
Last active March 25, 2024 02:38
Player Loop Visualizer: Built to explore the new PlayerLoopSystem api in Unity 2018.1b2. This tool shows you all the PlayerLoop systems that unity uses to update a frame, and demos how to add your own and even remove systems from the player loop. For more info see the patreon post https://www.patreon.com/posts/unity-2018-1-16336053
// Put this in an editor folder
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.Experimental.LowLevel;
using UnityEngine.Profiling;

How to Use?

GUIStyle mystyle = new GUIStyle("some string from the list below");


UnityEditor.ConsoleWindow.Constants

  • "CN Box"
  • "Button"
@ShawInnes
ShawInnes / MonoCecilReferenceCount.cs
Created July 11, 2014 06:38
Mono.Cecil Get Method Reference Count
private static int GetReferenceCount(Type type, string undesiredTypeName)
{
UriBuilder uri = new UriBuilder(type.Assembly.CodeBase);
string path = Uri.UnescapeDataString(uri.Path);
AssemblyDefinition assemblyDefinition = AssemblyDefinition.ReadAssembly(path);
TypeDefinition vm = assemblyDefinition.Modules.SelectMany(m => m.GetTypes().Where(p => p.FullName == type.FullName)).Single();
int referenceCount = vm.Methods.Where(p => p.HasBody)
.SelectMany(p => p.Body.Instructions.Where(i => i.OpCode.Code == Mono.Cecil.Cil.Code.Call &&
((Mono.Cecil.MethodReference)i.Operand).DeclaringType.FullName.Equals(undesiredTypeName))).Count();