Skip to content

Instantly share code, notes, and snippets.

View AngryAnt's full-sized avatar

Emil "AngryAnt" Johansen AngryAnt

View GitHub Profile
const int
kPreLevelScenes = 2, // Number of scenes before the first level (splash, menu, etc.)
kPostLevelScenes = 0; // Number of scenes after last level (score, credits, whatever)
const string kLevelScorePrefix = "Score for level ";
// ...
void OnLevelBeat ()
{
if (Application.loadedLevel < Application.levelCount - kPostLevelScenes - 1)
@AngryAnt
AngryAnt / BehaveExtensions.cs
Last active August 29, 2015 14:14
Tree.ReflectClassForwards (GameObject) and Tree.SetForwards (int id, IActionClass actionClass). This is now built-in per Behave 2.6.
using UnityEngine;
using Behave.Runtime;
using Library = BLYourLibraryName;
using Tree = Behave.Runtime.Tree;
public interface IActionClass
{
bool OnForward (Tree sender);
BehaveResult Init (Tree sender);
using UnityEngine;
using System.Collections;
[RequireComponent (typeof (Renderer))]
public class RenderGUIToTexture : MonoBehaviour
{
public RenderTexture texture;
public Texture2D background;
@AngryAnt
AngryAnt / GameManager.cs
Created May 2, 2011 08:59
GameManager.cs
using UnityEngine;
using System.Collections;
public enum GameStatus
{
Setup,
Initializing,
ReInitializing,
AwaitingMasterServer,
@AngryAnt
AngryAnt / Player.cs
Created May 2, 2011 09:45
Player.cs
using UnityEngine;
using System.Collections;
[RequireComponent (typeof (NetworkView))]
[RequireComponent (typeof (Rigidbody))]
[RequireComponent (typeof (AnimationController))]
public class Player : MonoBehaviour, System.IComparable
{
public Transform graphicsPrefab;
public float GetCost (Agent agent)
{
return (To.Position - From.Position).Magnitude *
Weight *
(customWeightHandler == null ? 1.0f : customWeightHandler (agent, this));
}
@AngryAnt
AngryAnt / MyAgent.cs
Created May 30, 2011 09:57
Tree tick frequency.
using UnityEngine;
using System.Collections;
using Behave.Runtime;
using Tree = Behave.Runtime.Tree;
public class MyAgent : IAgent
{
private Tree myTree;
@AngryAnt
AngryAnt / ExplicitProperty.txt
Created May 30, 2011 14:02
Explicit property type
// This:
public Rigidbody target;
void FixedUpdate ()
{
target.AddForce (transform.forward * 1.0f);
}
@AngryAnt
AngryAnt / MyStateMachine.cs
Created May 31, 2011 08:45
A simple state machine using a dictionary of delegates indexed by an enum.
using UnityEngine;
using System.Collections.Generic;
public class MyStateMachine : MonoBehaviour
{
public delegate void StateHandlerDelegate ();
public enum MyStateType
@AngryAnt
AngryAnt / DelayedInitialization.cs
Created June 6, 2011 13:21
An example of how to do delayed initialization - spreading heavy initialization workloads across multiple frames.
private static int newID = 0;
private int id;
private bool initialized = false;
IEnumerator Start ()
{
id = newID++;
for (int i = 0; i < id; i++)
{