Skip to content

Instantly share code, notes, and snippets.

Avatar

daniel danielbierwirth

View GitHub Profile
@danielbierwirth
danielbierwirth / PostProcessorFileCopy.cs
Last active Mar 23, 2020
#unity3d post-process class (c#) that copies a directory including content and subdirectories from source to target location as unity build post-process. place this script inside Editor folder somewhere within Assets directory
View PostProcessorFileCopy.cs
/// <summary>
/// PostProcessorFileCopy class contains functions to copy source folder and subfolders/files (recursive)
/// to build directory as post process after build. Place this class inside Editor folder.
/// </summary>
public class PostProcessorFileCopy {
[PostProcessBuild]
public static void OnPostprocessBuild(BuildTarget target, string pathToBuildfile) {
@danielbierwirth
danielbierwirth / GetComponents.cs
Last active Feb 23, 2019
Quickly access Child Components
View GetComponents.cs
using System.Collections.Generic;
namespace UnityEngine
{
public static class UnityEngineEx
{
public static T GetComponentInDirectChildren<T>(this Component parent) where T : Component
{
@danielbierwirth
danielbierwirth / addmeshcollider.cs
Last active Jul 18, 2017
unity function that gets all meshes of parent gameObject including it's child gameObjects and adds corresponding meshcollider to parent gameObject
View addmeshcollider.cs
/// <summary>
/// Add mesh collider to game object
/// Gets all child components, looks for meshes and assings
/// them to gameobject meshcollider
/// </summary>
/// <param name="containerModel">The gameobject</param>
private void AddMeshCollider (GameObject containerModel)
{
// Add mesh collider
MeshFilter meshFilter = containerModel.GetComponent<MeshFilter>();
@danielbierwirth
danielbierwirth / TCPTestClient.cs
Last active Sep 19, 2020
TCP Client-Server Connection Example | Unity | C# | Bidirectional communication sample: Client can connect to server; Client can send and receive messages: Server accepts clients; Server reads client messages; Server sends messages to client
View TCPTestClient.cs
using System;
using System.Collections;
using System.Collections.Generic;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using UnityEngine;
public class TCPTestClient : MonoBehaviour {
#region private members
@danielbierwirth
danielbierwirth / OffscreenRendering.cs
Last active May 21, 2020
Offscreen rendering script (unity | c#) | render camera view to texture | save texture as png
View OffscreenRendering.cs
using System.Collections; using System.Collections.Generic;
using System.IO; using UnityEngine;
/// <summary>
/// Attach this script to an empty gameObject. Create a secondary camera
/// gameObject for offscreen rendering (not your main camera) and connect it
/// with this script. Offscreen camera should have a texture object attached to it.
/// OffscreenCamera texture object is used for rendering (please see camera properties).
/// </summary>
public class OffscreenRendering : MonoBehaviour {
@danielbierwirth
danielbierwirth / pickingmatrixcalculation.cs
Last active Dec 11, 2015
OpenTK pick matrix calculation. Transforms viewmatrix according to pick location and picking region. Modified matrix can be used for object pick determination.
View pickingmatrixcalculation.cs
/// <summary>
/// OpenTK/OpenGl pick matrix calculation. Takes pick location,pick region to
// modify the current viewport matrix.
/// </summary>
/// <param name="x">The x pick location.</param>
/// <param name="y">The y pick location.</param>
/// <param name="deltax">The pick region x bounds.</param>
/// <param name="deltay">The pick region y bounds.</param>
/// <param name="viewport">The viewport matrix.</param>
public void PickMatrix(double x, double y, double deltax, double deltay, int[] viewport)
You can’t perform that action at this time.