Skip to content

Instantly share code, notes, and snippets.

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

mika unitycoder

✅
‏‏‎
View GitHub Profile
@unitycoder
unitycoder / compare-angle-range.cs
Created September 26, 2018 10:55
Compare if an angle is between two angles (or, Compare if angle is within threshold distance to given angle)
anglediff = (facingAngle - angleOfTarget + 180 + 360) % 360 - 180
if (abs(anglediff>30) // within 60 degrees from facing angle
// https://stackoverflow.com/a/12234633/5452781
@unitycoder
unitycoder / VisitInDisorder.cs
Last active October 1, 2018 06:27
Algorithms Random Number
// c# version of https://lemire.me/blog/2017/09/18/visiting-all-values-in-an-array-exactly-once-in-random-order/
using System;
using System.Collections;
using System.Collections.Generic;
public class VisitInDisorder
{
int maxRange;
@unitycoder
unitycoder / fix.cs
Created October 1, 2018 02:43
Send Receive Images in TCP Python to Unity
// fix
int increment = 0;
while (recieved < fileSize)
{
byte[] data = new byte[camClient.ReceiveBufferSize];
increment = dataStream.Read(data, 0, data.Length);
recieved += increment;
ms.Write(data.Take(increment).ToArray(), 0, increment);
}
@unitycoder
unitycoder / NativeHashMapList.cs
Created October 3, 2018 06:26
Unity ECS Stuff & Snippets
// https://forum.unity.com/threads/hybrid-native-container-nativehashmaplist-tkey-tvalue.564118/
//#define DEBUG_HML
using Unity.Collections;
using System;
namespace E7.Native
{
/// <summary>
@unitycoder
unitycoder / ScaleCanvasToScreen.cs
Created October 4, 2018 01:34
Stretch canvas to fit device screen
// https://forum.unity.com/threads/stretch-canvas-to-fit-device.564016/#post-3745738
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ScaleCanvasToScreen : MonoBehaviour
{
void Start()
{
@unitycoder
unitycoder / wpf_string_array_to_datagrid.cs
Created October 13, 2018 10:50
WPF Add String Array to DataGrid as ItemsSource
// get all files into array
var files = Directory.GetFiles(sourceFolder, "*", SearchOption.AllDirectories);
// add results to gridarray, first need to convert into objects
var results = new List<ResultItem>();
for (int i = 0, length = files.Length; i < length; i++)
{
var o = new ResultItem();
o.path = files[i];
results.Add(o);
@unitycoder
unitycoder / wpf-notes.txt
Last active November 4, 2025 17:01
WPF Notes c# Visual Studio
----------
----------
----------
----------
----------
----------
----------
----------
----------
----------
@unitycoder
unitycoder / sizeof.txt
Last active December 7, 2022 15:50
size of float, byte, int, double - max min value - range - bytes - bits - bit - nibble - sizeof - CheatSheet
type | bytes | bits | range | binary |
-------------------------------------------------------------------------
halfbyte| 0.5 | 4 | 0 to 15 | 0000 to 1111 |
bool | 1 | 8 | 0 to 1 ||
byte | 1 | 8 | -128 to 127 ||
ubyte | 1 | 8 | 0 to 255 ||
uint8_t | 1 | 8 | 0 to 255 ||
int16 | 2 | 16 | -32,768 to +32,767 ||
uint16 | 2 | 16 | 0 to +65,535 ||
int | 4 | 32 | -2,147,483,648 to 2,147,483,647 ||
@unitycoder
unitycoder / PaintBrush.cs
Created October 23, 2018 09:06
Paint On Lightmaps
// https://pastebin.com/rMx1PVXi
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PaintBrush : MonoBehaviour
{
public int resolution = 512;
Texture2D whiteMap;