Skip to content

Instantly share code, notes, and snippets.

@PopupAsylum
PopupAsylum / PreviewCulling.cs
Created September 23, 2016 08:45
When attached to a Camera, shows that cameras frustum culling in the scene view
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
using System.Collections;
[ExecuteInEditMode]
public class PreviewCulling : MonoBehaviour {
#if UNITY_EDITOR
@PopupAsylum
PopupAsylum / ConveyorBelt.cs
Created September 23, 2016 10:07
A behaviour that makes a rigidbody act like a conveyor, moving rigidbodies that collide with it without moving itself
using UnityEngine;
using System.Collections;
public class ConveyorBelt : MonoBehaviour {
public float speed = 2.0f;
void FixedUpdate()
{
Rigidbody rigidbody = GetComponent<Rigidbody>();
float3 GetAxis(float3 input) {
input = normalize(input) ;
float3 signs = sign(input) ;
float3 abss = abs(input) ;
float maxs = max(abss.x, max(abss.y, abbs.z));
return floor(abss/maxs) * signs;
}
@PopupAsylum
PopupAsylum / IsBetween0And1.cginc
Created September 23, 2016 14:07
Returns 1 if 0<=x<1, 0 otherwise
//returns 1 if 0<=x<1, 0 otherwise
float IsBetween0And1(float x) {
return 1 - saturate(floor(abs((x-0.5)*2)));
}
@PopupAsylum
PopupAsylum / SymbolicProjectMenu.cs
Created September 23, 2016 14:23
Adds a menu option to create a copy of the current Unity project using symbolic links, Windows only, usually needs admin
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Runtime.InteropServices;
internal static class SymbolicLink {
#if UNITY_EDITOR_WIN
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool CreateSymbolicLink(string lpSymlinkFileName, string lpTargetFileName, SymLinkFlag dwFlags);
@PopupAsylum
PopupAsylum / MeshBatcher.cs
Last active October 6, 2016 08:22
Combines multiple meshes based on materials and lightmap index
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class MeshBatcher : MonoBehaviour {
class MeshStrip
{
public List<int> strip = new List<int>();
float3 Refract(float3 position, float4 surface, float refractionIndex){
//ray origin is the camera position
float3 viewerPosition = _WorldSpaceCameraPos.xyz;
//ray end is the vertex's undistorted position
float3 vertexPosition = position;
//get the vector from the camera to the vertex
float3 worldRay = vertexPosition - viewerPosition;
@PopupAsylum
PopupAsylum / RefractedBounds.cs
Created October 29, 2016 22:11
Behaviour that modifies a renderers position during the render process to prevent it being culled
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
[RequireComponent(typeof(MeshRenderer))]
public class RefractedBounds : MonoBehaviour {
MeshRenderer renderer;
void OnEnable() {
@PopupAsylum
PopupAsylum / PointerCursor.cs
Created December 20, 2016 15:00
PointerCursor.jslib goes in Assets/Plugins/WebGL, PointerCursor.cs goes in your scripts folder, call SetPointer(true) to set the cursor as a pointer
using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;
public class PointerCursor : MonoBehaviour {
[DllImport("__Internal")]
public static extern void SetPointer(bool arg);
}
@PopupAsylum
PopupAsylum / PointerCursor.cs
Last active December 20, 2016 15:00
PointerCursor.jslib goes in Assets/Plugins/WebGL, PointerCursor.cs goes in your scripts folder, call PointerCursor.SetPointer(true) to set the cursor as a pointer
using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;
public class PointerCursor : MonoBehaviour {
[DllImport("__Internal")]
public static extern void SetPointer(bool arg);
}