Skip to content

Instantly share code, notes, and snippets.

View AngryAnt's full-sized avatar

Emil "AngryAnt" Johansen AngryAnt

View GitHub Profile
@AngryAnt
AngryAnt / GravityWell.cs
Created August 18, 2011 09:01
An example of how to easily do an inexpensive alternative gravity setup (untested).
// GravityObject.cs
using UnityEngine;
using System.Collections;
[RequireComponent (typeof (Rigidbody))]
public class GravityObject : MonoBehaviour
{
public float gravityModifier = 1.0f;
@AngryAnt
AngryAnt / TotalBounds.cs
Created August 18, 2011 12:49
Getting the total rendering bounds of a hierarchy of renderers.
private Bounds bounds;
void Start ()
{
bounds = new Bounds (transform.position, Vector3.one);
Renderer[] renderers = GetComponentsInChildren<Renderer> ();
foreach (Renderer renderer in renderers)
{
bounds.Encapsulate (renderer.bounds);
@AngryAnt
AngryAnt / CustomGUILayout.cs
Created September 7, 2011 11:19
Quick example of a custom GUILayout control (untested).
using UnityEngine;
public class CustomGUILayout
{
public static bool MyFocusControl (Texture2D texture, params GUILayoutOption[] options)
{
int id = GUIUtility.GetControlID ();
Color color = GUI.color;
GUI.color = GUIUtility.hotControl == id ? Color.green : Color.red;
@AngryAnt
AngryAnt / FocusedEventHandling.cs
Created September 8, 2011 10:14
Untested example of dealing with handled events and focused controls.
const string controlName = "My text field";
string myString = "Text";
void OnGUI ()
{
EventType handledEventType = Event.current.type;
GUI.SetNextControlName (controlName);
myString = GUILayout.TextField (myString);
@AngryAnt
AngryAnt / MyProxy.cs
Created October 12, 2011 10:32
Example of how to make editor classes in assemblies accessible in Unity (untested pseudo code).
/////////////////////////////////////////////////////////////////
// MyProxy.cs - the C# source file in your assets
/////////////////////////////////////////////////////////////////
using UnityEngine;
using UnityEditor;
using MyAssemblyNamespace;
@AngryAnt
AngryAnt / TileBuilder.cs
Created November 4, 2011 11:13
Example of tile level construction in C# - overly simplified, quite useless and completely untested
public Tile tilePrefabs[];
public int width = 1, height = 1;
public Vector2 tileSize = new Vector2 (1.0f, 1.0f);
Tile tiles[];
void Start ()
{
tiles = new Tile[width * height];
@AngryAnt
AngryAnt / SurveillanceCameraController.cs
Created December 18, 2011 14:09
An example of a four-split camera setup where one camera can be brought to front. UNTESTED.
using UnityEngine;
using System.Collections;
enum CameraIdentity
{
None,
One,
Two,
Three,
@AngryAnt
AngryAnt / CustomAnimationEditor.cs
Created February 22, 2012 11:53
An old example of how to easily preview animations on objects in-scene.
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
[CustomEditor (typeof (Animation))]
public class CustomAnimationEditor : Editor
{
AnimationClip m_SampleClip;
float m_SampleTime = 0.0f;
@AngryAnt
AngryAnt / PanicPatrol.cs
Created April 19, 2012 05:43
Parameterized subtree execution
public BehaveResult StartPanicAction
{
get
{
panic = true;
return BehaveResult.Success;
}
}
public BehaveResult PatrolAction
@AngryAnt
AngryAnt / InvokeDelayed.cs
Created June 6, 2012 09:46
Stab at easing the delayed invoke of whatever (untested).
void InvokeDelayed (Action action, float seconds)
{
StartCoroutine (DoInvokeDelayed (action, seconds));
}
IEnumerator DoInvokeDelayed (Action action, float seconds)
{
yield return new WaitForSeconds (seconds);
action ();