Large diffs are not rendered by default.

@@ -4,11 +4,12 @@
using System.Linq;
using UnityEngine;

[ExecuteInEditMode]
public class Cube : MonoBehaviour
{
public int DeathCount;


public static string LevelString = "";
public string DefaultLevelString = "";
public Transform CenterTransform;
public AnimationCurve RotationCurve;
public float SpinSpeed;
@@ -37,7 +38,10 @@ public enum RotationAxis { X, Y, Z }

void Awake()
{
Graph = Graph.LoadGraphFromCsv( "" );
var stringLevelName = DefaultLevelString;
if ( LevelString.Length != 0 ) stringLevelName = LevelString;

Graph = Graph.LoadLevel( stringLevelName );
HasStarted = false;
}

@@ -69,9 +73,10 @@ void Start()
var childQuad = QuadArray[ i ];

childQuad.Node = Graph.GetNodeByName( childQuad.NodeName );
QuadArray[ i ].Configure();
}


goat.Configure( this );

}

@@ -1,12 +1,16 @@
using UnityEngine;
using System;
using System.Collections;
using System.Linq;
using System;
using System.Collections.Generic;


public class Graph
{
public Node[,] Nodes;

private static Dictionary<string, Func<Graph>> levelSelectionDictionary = new Dictionary<string, Func<Graph>>()
{
{ "Level 1", LevelOne }
};

public Graph( int rows, int columns )
{
Nodes = new Node[ rows, columns ];
@@ -15,14 +19,37 @@ public Graph( int rows, int columns )

#region Static methods

public static Graph LoadGraphFromCsv( string csvPath )
public static Graph LoadLevel( string levelName )
{
Graph graph = new Graph( 4, 8 );

var func = levelSelectionDictionary[ levelName ];

return func == null ? null : func();
}

private static Graph LevelOne()
{
Graph graph = new Graph( 4, 8 );

// Fore now just use this function to hardcode a path.
graph.CreateTestPath();

// TODO Load Graph from the CSV file.
graph.Nodes[ 0, 6 ].Type = NodeTypeEnum.Start;
graph.Nodes[ 0, 5 ].Type = NodeTypeEnum.End;

graph.Nodes[ 0, 6 ].MoveableDirections.Add( Node.Direction.up );
graph.Nodes[ 1, 6 ].MoveableDirections.Add( Node.Direction.up );
graph.Nodes[ 1, 6 ].MoveableDirections.Add( Node.Direction.down );
graph.Nodes[ 2, 6 ].MoveableDirections.Add( Node.Direction.up );
graph.Nodes[ 2, 6 ].MoveableDirections.Add( Node.Direction.left );
graph.Nodes[ 2, 5 ].MoveableDirections.Add( Node.Direction.left );
graph.Nodes[ 2, 5 ].MoveableDirections.Add( Node.Direction.right );
graph.Nodes[ 2, 4 ].MoveableDirections.Add( Node.Direction.right );
graph.Nodes[ 2, 4 ].MoveableDirections.Add( Node.Direction.up );
graph.Nodes[ 1, 4 ].MoveableDirections.Add( Node.Direction.down );
graph.Nodes[ 1, 4 ].MoveableDirections.Add( Node.Direction.up );
graph.Nodes[ 0, 5 ].MoveableDirections.Add( Node.Direction.right );

graph.Nodes[ 2, 6 ].AddNeighbor( graph.Nodes[ 2, 5 ] );
graph.Nodes[ 2, 5 ].AddNeighbor( graph.Nodes[ 2, 4 ] );

return graph;
}
@@ -9,7 +9,7 @@ public class Quad : MonoBehaviour

private Cube Cube;

public void Start()
public void Configure()
{
Cube = FindObjectOfType<Cube>();

@@ -44,7 +44,7 @@ void Awake()
hasBSCoroutineFinished = true;
}

void Start()
public void Configure( Cube realCube )
{
Transform t = transform.FindChild( "DeathSound" );
if ( t != null )
@@ -62,7 +62,7 @@ void Start()
StartSound = t.audio;
}
// Determine start node
cube = FindObjectOfType<Cube>();
cube = realCube;

var startNode = cube.Graph.Nodes.Cast<Node>()
.Single( node => node.Type == NodeTypeEnum.Start );
@@ -97,10 +97,10 @@ void Start()
Vector3 directionVector = Vector3.zero;
switch ( currentDirection )
{
case Node.Direction.up: currentDirectionVector = quad.transform.up; break;
case Node.Direction.down: currentDirectionVector = -quad.transform.up; break;
case Node.Direction.right: currentDirectionVector = quad.transform.right; break;
case Node.Direction.left: currentDirectionVector = -quad.transform.right; break;
case Node.Direction.up: directionVector = quad.transform.up; break;
case Node.Direction.down: directionVector = -quad.transform.up; break;
case Node.Direction.right: directionVector = quad.transform.right; break;
case Node.Direction.left: directionVector = -quad.transform.right; break;
}

StartRotation = transform.rotation = Quaternion.LookRotation( directionVector, hit.normal );
@@ -119,8 +119,11 @@ void OnDisable()

IEnumerator UpdateCoroutine()
{
yield return null;
yield return null;

if ( cube == null )
yield return null;
cube = FindObjectOfType<Cube>();

while ( true )
{
@@ -253,15 +256,11 @@ void NormalMovingBehaviour( RaycastHit rayHitInfo )
.Where( h => h.collider != prevCenterHit )
.ToArray();

Debug.Log( "Sphere Hits: " + sphereHits.Length );
Debug.Log( "Hits: " + hits.Length );

if ( sphereHits.Length == 1 && hits.Length == 3 && prevCenterHit == null )
{
var sphereHit = sphereHits.First();

var quad = rayHitInfo.collider.GetComponent<Quad>();
Debug.Log( "Got HERE" );

var dotpPairs = quad.Node.MoveableDirections
.Select( d =>