Skip to content

Instantly share code, notes, and snippets.

@jkredz
jkredz / ShowAssetIds.cs
Created March 3, 2019 01:04
Shows GUID, InstanceID, File ID for an asset in Unity
//Get instance, guid, and file ID of file during play mode
//Possibly useful for getting the type or instance of a specific file in the project folder and possibly loading
//This script prints these details for a selected asset in project window
using System.Text;
using UnityEngine;
using UnityEditor;
class ShowAssetIds
{
@jkredz
jkredz / SaveTransform.cs
Created March 3, 2019 00:54
Save and rewrite transforms outside of play mode
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
[CustomEditor(typeof(Transform))]
public class keepTransformEditor : UnityEditor.Editor
{
//...
public override void OnInspectorGUI()
@jkredz
jkredz / fastcopy.cs
Created February 4, 2019 00:45
Copy from native array to managed ECS utility snippet
public static unsafe void CopyToFast<T>(this NativeArray<T> nativeArray, T[] array) where T : struct {
int byteLength = nativeArray.Length * UnsafeUtility.SizeOf(typeof(T));
void* managedBuffer = UnsafeUtility.AddressOf(ref array[0]);
void* nativeBuffer = nativeArray.GetUnsafePtr();
UnsafeUtility.MemCpy(managedBuffer, nativeBuffer, byteLength);
}
// Usage
NativeArray<Vector3> nativeVertices = new NativeArray<Vector3>(vertexCount, Allocator.Persistent);
Vector3[] managedVertices = new Vector3[vertexCount];
@jkredz
jkredz / gist:4a28caddb533796a4410
Created April 10, 2015 21:41
Breaking Gesture Sensor Code
/****************************************************************
GestureTest.ino
APDS-9960 RGB and Gesture Sensor
Shawn Hymel @ SparkFun Electronics
May 30, 2014
https://github.com/sparkfun/APDS-9960_RGB_and_Gesture_Sensor
Tests the gesture sensing abilities of the APDS-9960. Configures
APDS-9960 over I2C and waits for gesture events. Calculates the
direction of the swipe (up, down, left, right) and displays it