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 / 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 / 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 ();
@AngryAnt
AngryAnt / ContainerGravity.cs
Created July 2, 2012 11:14
Example of simple component for keeping objects inside defined bounds by physically repelling them back when they exit.
using UnityEngine;
using System.Collections;
[RequireComponent (typeof (BoxCollider))]
public class ContainerGravity : MonoBehaviour
{
public float strength = 10.0f;
@AngryAnt
AngryAnt / CameraControl.cs
Created July 6, 2012 12:00
Example of a clamped camera look rotation.
target.RotateAround (target.position, target.right, addedRotation);
bool lookingUp = Vector3.Angle (target.forward, Vector3.up) < Vector3.Angle (target.forward, Vector3.up * -1.0f);
float angle = Vector3.Angle (target.forward, Vector3.Cross (target.right, Vector3.up));
if (angle > forwardAngleClamp)
{
target.RotateAround (target.position, target.right, lookingUp ? angle - forwardAngleClamp : forwardAngleClamp - angle);
}
@AngryAnt
AngryAnt / AnimationStateInspector.cs
Created July 7, 2012 10:29
Animation state inspector
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
public class AnimationStateInspector : EditorWindow
{
Dictionary<int, List<AnimationState>> layers = null;