Skip to content

Instantly share code, notes, and snippets.

View unitycoder's full-sized avatar
✅
‏‏‎

mika unitycoder

✅
‏‏‎
View GitHub Profile
@unitycoder
unitycoder / streamreader-notes.txt
Last active August 10, 2022 05:41
c# file stream binary stream seek position tips
binarystream vs bufferedstream
https://jacksondunstan.com/articles/3568
- Avoid setting the Position property. Always prefer the Seek method
- Avoid reading properties in loops (like Position or Length)
- Prefer using SeekOrigin.Begin
https://www.codeproject.com/Tips/1073643/%2FTips%2F1073643%2FImprove-Stream-Reading-Performance-in-Csharp
filestream supports seek
https://bytes.com/topic/net/answers/549896-rewinding-textreader-file-stream
@unitycoder
unitycoder / WarpedPerlinNoise.cs
Created January 10, 2019 12:18
Warped Perlin Noise Texture
// inspiration from https://www.youtube.com/watch?v=C9RyEiEzMiU
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NoiseTest : MonoBehaviour
{
int size = 128;
Texture2D tex;
@unitycoder
unitycoder / Line.cs
Created January 13, 2019 14:58
Compute Shader for Drawing Lines
// https://forum.unity.com/threads/compute-shader-for-line-drawing.599989/
using UnityEngine;
public class Line : MonoBehaviour
{
public ComputeShader CS;
void Start()
{
RenderTexture RT = new RenderTexture(1024, 1024, 0);
@unitycoder
unitycoder / MiniProfiler.cs
Created January 14, 2019 11:03
SRP batcher Profiler
// https://forum.unity.com/threads/srp-batcher-in-2018-2.527397/#post-4099828
// SRP batcher, changing material is way faster than before ( because material data are now persistent in GPU ).
// You just have to use same shader, but you can have any number of materials.
// In the previous case ( 1000 meshes with 1000 different material), the CPU speedup factor is about 5 times
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Profiling;
@unitycoder
unitycoder / StructLayout.txt
Last active November 23, 2021 08:22
C# Struct StructLayout LayoutKind.Sequential c++
// https://www.codeproject.com/Articles/25896/Reading-Unmanaged-Data-Into-Structures
// https://forum.unity.com/threads/convert-byte-array-with-offset-to-a-small-color32-array.452089/#post-2927740
Color32[] colorArray = new Color32[10];
IntPtr test = Marshal.UnsafeAddrOfPinnedArrayElement(Colors,4);
for (int i=0;i<10;++i)
{
colorArray[i] = (Color32)Marshal.PtrToStructure(test,typeof(Color32));
test+=SizeOf(Color32);
@unitycoder
unitycoder / GifImport.cs
Created January 16, 2019 11:54
Gif Header Parse Test
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using UnityEngine;
// http://www.onicos.com/staff/iz/formats/gif.html
public class GifImport : MonoBehaviour
@unitycoder
unitycoder / StringBuilderExt.cs
Created January 28, 2019 09:02
Garbage free extensions for the StringBuilder class
// https://forum.unity.com/threads/how-to-write-directly-into-an-existing-string.617224/#post-4153573
/// <summary>
/// Garbage free extensions for the StringBuilder class
/// </summary>
static public class StringBuilderExt
{
#if !NET_LEGACY
/// <summary>TemporaryList used for StringBuilders concatenations in order to reverse the chunks</summary>
static private ThreadLocal<List<StringBuilder>> m_TempList;
@unitycoder
unitycoder / keymap.txt
Created January 28, 2019 18:11
Common Key Mappings in 3D Applications
https://developer.blender.org/T54963