Skip to content

Instantly share code, notes, and snippets.

@viruseg
viruseg / .Interaction in unity with Gradient via jobs + burst.cs
Last active June 24, 2024 10:28
Interaction in unity with Gradient via jobs + burst
Interaction in unity with Gradient via jobs + burst
var gradient = new Gradient();
//Access Gradient.colorKeys and Gradient.alphaKey via NativeArray without a Garbage Collector:
//Single threaded mode:
var gradientPtr = gradient.DirectAccess();
using var colorKeys = gradientPtr->GetColorKeys(Allocator.Temp);
using var alphaKeys = gradientPtr->GetAlphaKeys(Allocator.Temp);
@viruseg
viruseg / .Encrypting & Decrypting (file, string, byte array) in C#, NET 8.0 and Unity.cs
Last active April 3, 2024 19:22
Encrypting & Decrypting (file, string, byte array) in C#, NET 8.0 and Unity
//The code is based on the code from here: https://stackoverflow.com/a/10177020/1221983
//And adapted for NET 8 and Unity.
//Reduced memory consumption.
//Added possibility to encrypt byte arrays, not only strings.
//You can also attach custom data that will not be encrypted.
var password = "nso%dhfkl$siohf";
var str = "This is test string!№;%^#@^&";
@viruseg
viruseg / .Manually Convert World to Screen Position in Unity with Burst.cs
Last active June 2, 2024 09:00
Manually Convert World to Screen Position in Unity with Burst. The code is intended for the Burst compiler, which does the same thing as Camera.WorldToScreenPoint.
//camera-like projection matrix
var cameraData = new CameraDataForBurst(camera);
//or
//projection matrix for the rendering target of a given size
var cameraData = new CameraDataForBurst(camera, 320, 240);
var worldPoint = new float3(10, 10, 0);
var screenPointWithZ = cameraData.WorldToScreenPointWithZ(worldPoint);
var screenPoint = cameraData.WorldToScreenPoint(worldPoint);
@viruseg
viruseg / .Unity Package Extractor
Last active May 18, 2024 10:24
Unity Package Extractor. Extract your .unitypackage with .net C#
Use the command line to extract the package.
program.exe packagePath outputPath extractMetaFiles
program.exe "d:\dir\package.unitypackage" "d:\outputDir" "true"