Skip to content

Instantly share code, notes, and snippets.

View zsoi's full-sized avatar

Oliver zsoi

View GitHub Profile
@zsoi
zsoi / SettingsAdapter.cs
Created October 19, 2020 15:49
Unity's addressables project config API is private. This hack provides a public API for some parts of the ProjectConfigData and can be easily extended.
namespace UnityEditor.AddressableAssets.Settings
{
/// <summary>
/// Adapter to provide a public API into <seealso cref="ProjectConfigData"/> internals.
/// </summary>
public static class ProjectConfigDataAdapter
{
public static bool generateBuildLayout
{
get => ProjectConfigData.generateBuildLayout;
@zsoi
zsoi / CustomComponent.cs
Created February 22, 2018 10:53
Unity3D custom editor framing bounds
using UnityEngine;
class CustomComponent : MonoBehaviour
{
// Configure custom world-space bounds as you like in the editor
public Bounds CustomFocusBounds;
}
@zsoi
zsoi / CustomLodBias.cs
Last active July 20, 2017 09:22
Unity3D Behaviours for changing LodBias and ShadowCasting for individual cameras. Add scripts to chosen cameras and modify the LodBias / ShadowCasting method as you require. Serves well to have e.g. reflection cameras draw with less quality.
namespace Game.Camera
{
using UnityEngine;
/// <summary>
/// Applies a custom LOD bias factor to rendering when attached to a camera
/// </summary>
[RequireComponent(typeof(Camera))]
class CustomLodBias : MonoBehaviour
{
@zsoi
zsoi / ByValueArray.cs
Created March 2, 2017 15:22
Hack to avoid creating garbage by allocating very small arrays in C# - emulating an array with a struct
// Hack to avoid creating lots of garbage by creating long[] arr = new long[2];
// There may be ways to implement this in a better way
// But all of them coming to my mind involve unsafe code
// Quickly breaks down when trying to emulate larger arrays
// -> then using switch() to select the right values
// -> Some compilers will optimize the switch() as a binary search, but still - Unsafe implementation can be O(1)!
struct ulong2
{
ulong l0;
ulong l1;
@zsoi
zsoi / SafeDouble.cs
Created January 6, 2017 17:14
Utility classes to store floats or doubles in human-readable, yet exact representations. Inspired by http://the-witness.net/news/2011/12/engine-tech-concurrent-world-editing/
namespace ZS.Tools
{
using System;
using System.Globalization;
using System.Text;
/// <summary>
/// The safe double class is mainly a interface between doubles and
/// their string representation. Traditional string representations of
/// doubles suffer from lossy precision. i.e. converting doubles to strings
@zsoi
zsoi / post-commit
Created November 4, 2016 13:13
SVN post-commit hook for TC branch-agnostic build trigger
#!/bin/sh
# SVN post-commit hook that triggers a team city build with the modified branch
# and with the provided changeset
REPOS="$1"
REV="$2"
TXN_NAME="$3"
tcApi="https://teamcity/httpAuth/app/rest/buildQueue"
@zsoi
zsoi / SpeechActionMassEditor.cs
Last active December 18, 2016 03:12
Mass speech editor for Adventure Creator
// Copyright (c) 2015 Z-Software GmbH
// http://www.z-software.net/
// Author: Oliver Iking
//
//
// 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
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
@zsoi
zsoi / CameraFixedAspectViewport.cs
Created November 3, 2015 15:52
Unity3D component which enforces a certain aspect ratio to the viewport of a camera, so that the camera always renders with this aspect rather than the actual screen aspect
using UnityEngine;
using System.Collections;
namespace ZS.Tools
{
/// <summary>
/// Adjusts the camera viewport so the actually drawn portion is always of a specific aspect ratio,
/// uninfluenced by the actual screen size. The viewport maximize its covered space.
/// </summary>
[RequireComponent(typeof(Camera)), ExecuteInEditMode]
@zsoi
zsoi / TerrainDataCloner.cs
Last active January 4, 2024 17:57
Helper to deep-copy a TerrainData object in Unity3D
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace ZS.Tools
{
/// <summary>
/// Provides means to deep-copy a TerrainData object because Unitys' built-in "Instantiate" method
@zsoi
zsoi / UnityPromisePlatformLayer.cs
Last active October 25, 2015 17:47
Threadsafe Unity3D platform layer ("event loop") for RSG.Promise
using namespace RSG;
namespace PromisePlatformLayerUnity
{
public class UnityPromisePlatformLayer : MonoBehaviour
{
static IPromiseTimer gTimer = new ThreadsafePromiseTimer();
// Public access to the promise timer
public static IPromiseTimer Timer { get { return gTimer; } }