Skip to content

Instantly share code, notes, and snippets.

@twobob
twobob / GridTracking.cs
Created April 11, 2015 15:11
Reads vector3's from a scriptable object to do the tracking
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class GridValue
{
// should we ever need it
public enum EntityType
{
None,
@twobob
twobob / UpdateGridOnTrigger.cs
Last active February 20, 2016 15:43
3x3 UpdateGridOnTrigger example
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class UpdateGridOnTrigger : MonoBehaviour {
MonoBehaviour script;
readonly static float TerrainSize = 256f; // set this
void Start(){
@twobob
twobob / MoveWhenFar.cs
Created May 8, 2015 23:46
3x3 UpdateGridOnTrigger Supporting MoveWhenFar sorting logic
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;
// could easily be refactored into a static class...
public class MoveWhenFar : MonoBehaviour {
readonly static float TerrainSize = 256f; // D R Y... refactor centrally...
const float2 r = float2(
23.1406926327792690, // e^pi (Gelfond's constant)
2.6651441426902251); // 2^sqrt(2) (Gelfond–Schneider constant)
return frac( cos( fmod( 12345678., 1e-7 + 256. * dot(p,r) ) ) );
// Random, enjoy
@twobob
twobob / GenerateTextObjectAndPositionDuringRuntime.cs
Created December 11, 2015 17:03
GenerateTextObjectAndPositionDuringRuntime Allows for positioning labels over the world objects, use with LOD to decide draw distances.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class GenerateTextObjectAndPositionDuringRuntime : MonoBehaviour
{
public Canvas CanvasToPopulate;
public GameObject TextPrefab;
private GameObject instantiatedPrefab;
@twobob
twobob / WorldToCanvasPosition.cs
Created December 11, 2015 17:05
WorldToCanvasPosition supporting logic for GenerateTextObjectAndPositionDuringRuntime.cs
using UnityEngine;
using System.Collections;
public static class WorldToCanvasPosition {
// Use this for initialization
public static Vector2 ConvertWorldToCanvasPosition(RectTransform canvas, Camera camera, Vector3 position)
{
Vector2 temp = camera.WorldToViewportPoint(position);
temp.x *= canvas.sizeDelta.x;
@twobob
twobob / TopMostFont.shader
Created December 11, 2015 17:12
Top Most Font shader. Useful to ignore Z Buffer reads...
Shader "UI/TopMostFont" {
Properties {
_MainTex ("Font Texture", 2D) = "white" {}
_Color ("Text Color", Color) = (1,1,1,1)
_StencilComp ("Stencil Comparison", Float) = 8
_Stencil ("Stencil ID", Float) = 0
_StencilOp ("Stencil Operation", Float) = 0
_StencilWriteMask ("Stencil Write Mask", Float) = 255
_StencilReadMask ("Stencil Read Mask", Float) = 255
@twobob
twobob / GenerateTextObjectAndPositionDuringRuntime_FOR_PREFABS.cs
Created December 11, 2015 18:43
This allow us the position text elements over world objects, With screen overlay, on prefabbed things. Tags are required on the elements to find at runtime.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class GenerateTextObjectAndPositionDuringRuntime_FOR_PREFABS : MonoBehaviour
{
public string CanvasToPopulatesTag;
public string TextPrefabTag;
@twobob
twobob / OverlayReferenceHolders.cs
Created December 11, 2015 18:45
OverlayReferenceHolders supporting static class for GenerateTextObjectAndPositionDuringRuntime_FOR_PREFABS
using System;
using System.Collections;
using UnityEngine.UI;
using UnityEngine;
public static class OverlayReferenceHolders
{
public static GameObject OverlayCanvas;
public static GameObject TextPrefab;
@twobob
twobob / ListBundles.cs
Last active December 28, 2015 02:50
Simple helper Editor method to list out all known asset bundles and their bundle-names.
using UnityEngine;
using UnityEditor;
using System.Collections;
public class ListBundles : MonoBehaviour
{
[MenuItem("Assets/AssetBundles/List AssetBundles %#l")]
static void List()
{