Skip to content

Instantly share code, notes, and snippets.

View Occuros's full-sized avatar

Roger Küng Occuros

View GitHub Profile
@juancampa
juancampa / egui_centerer.rs
Created March 16, 2023 13:50
Centering arbitrary UIs in egui
// Helper function to center arbitrary widgets. It works by measuring the width of the widgets after rendering, and
// then using that offset on the next frame.
fn centerer(ui: &mut Ui, add_contents: impl FnOnce(&mut Ui)) {
ui.horizontal(|ui| {
let id = ui.id().with("_centerer");
let last_width: Option<f32> = ui.memory_mut(|mem| mem.data.get_temp(id));
if let Some(last_width) = last_width {
ui.add_space((ui.available_width() - last_width) / 2.0);
}
let res = ui
@FreyaHolmer
FreyaHolmer / FlyCamera.cs
Last active May 22, 2024 14:26
A camera controller for easily flying around a scene in Unity smoothly. WASD for lateral movement, Space & Ctrl for vertical movement, Shift to move faster. Add this script to an existing camera, or an empty game object, hit play, and you're ready to go~
using UnityEngine;
[RequireComponent( typeof(Camera) )]
public class FlyCamera : MonoBehaviour {
public float acceleration = 50; // how fast you accelerate
public float accSprintMultiplier = 4; // how much faster you go when "sprinting"
public float lookSensitivity = 1; // mouse look sensitivity
public float dampingCoefficient = 5; // how quickly you break to a halt after you stop your input
public bool focusOnEnable = true; // whether or not to focus and lock cursor immediately on enable
@maxweisel
maxweisel / FloatQueue.cs
Created October 29, 2019 23:44
Oculus Platform Microphone Test
#region Copyright & License
/*************************************************************************
*
* The MIT License (MIT)
*
* Copyright (c) 2014 Roman Atachiants (kelindar@gmail.com)
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
@StagPoint
StagPoint / QuaternionCompression.cs
Last active May 3, 2024 22:23
C# - Use "smallest three" compression for transmitting Quaternion rotations in Unity's UNET networking, from 16 bytes to 7 bytes.
// Copyright (c) 2016 StagPoint Software
namespace StagPoint.Networking
{
using System;
using UnityEngine;
using UnityEngine.Networking;
/// <summary>
/// Provides some commonly-used functions for transferring compressed data over the network using