Skip to content

Instantly share code, notes, and snippets.

@ricardojmendez
Created November 21, 2011 22:17
Show Gist options
  • Save ricardojmendez/1384140 to your computer and use it in GitHub Desktop.
Save ricardojmendez/1384140 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
public enum EdgeType { Clear, Road, Bounce, Stop, Blocker, Killer, Burning };
public interface IAura
{
float Level { get; }
}
public class Aura : IAura
{
public float Level { get; set; }
public Aura(float level)
{
Level = level;
}
}
public class EnumeratorTest : MonoBehaviour {
EdgeType[] _edges = new EdgeType[7];
int[] numbers;
List<string> words;
List<Aura> auras = new List<Aura>();
// Use this for initialization
void Start ()
{
numbers = new int[5] {1, 2, 3, 4, 5};
words = new List<string> { "a", "bb", "ccc", "dddd", "eeeee" };
Debug.Log("Listing numbers");
foreach(var x in numbers)
{
Debug.Log("Listed "+x);
}
_edges[0] = EdgeType.Clear;
_edges[1] = EdgeType.Road;
_edges[2] = EdgeType.Bounce;
_edges[3] = EdgeType.Blocker;
_edges[4] = EdgeType.Killer;
_edges[5] = EdgeType.Burning;
_edges[6] = EdgeType.Burning;
auras.Add(new Aura(1));
auras.Add(new Aura(2));
auras.Add(new Aura(3));
auras.Add(new Aura(5));
auras.Add(new Aura(8));
}
// Update is called once per frame
void Update () {
}
void OnGUI()
{
if (GUILayout.Button("Any under 5"))
{
var found = numbers.Any( x => x < 5);
Debug.Log("Found any under 5 == "+found);
}
if (GUILayout.Button("Select the firt one over 3"))
{
var first = numbers.FirstOrDefault( x => x >= 4);
Debug.Log("First one found == "+first);
}
if (GUILayout.Button("All words longer than 2 characters"))
{
var longer = words.Where( x => x.Length > 2);
Debug.Log("Longer == ");
foreach (var s in longer)
{
Debug.Log(s);
}
}
if (GUILayout.Button("Any burning edge"))
{
var hasEdge = _edges.Any(x => x == EdgeType.Burning);
Debug.Log("Has Edge == "+hasEdge);
}
/* Uncomment me after the first test
if (GUILayout.Button("All killer edges"))
{
var killerEdges = _edges.Where( x => x == EdgeType.Killer);
Debug.Log("Killer Edge total == "+ killerEdges.Count());
}
*/
if (GUILayout.Button("Sum"))
{
var sum = auras.Sum( x => x.Level);
Debug.Log("Sum == "+sum);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment