Skip to content

Commit

Permalink
Merge pull request #2 from GameResearchAtMcGill/combat
Browse files Browse the repository at this point in the history
Adding combat simulation to main branch
  • Loading branch information
Shirkit committed Apr 29, 2014
2 parents 7662ecb + 6add640 commit 2dee4bf
Show file tree
Hide file tree
Showing 95 changed files with 5,158 additions and 2,806 deletions.
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,19 @@
*.csproj
*.unityproj
*.sln

# Added manually

*.xml
*.svg
*.pidb

ProjectSettings/GraphicsSettings.asset

SvgToPdf.py

*.userprefs

Output.pdf

Assets/Levels/Human Study.meta
Binary file removed Assembly-CSharp-Editor.pidb
Binary file not shown.
Binary file removed Assembly-CSharp.pidb
Binary file not shown.
184 changes: 116 additions & 68 deletions Assets/Editor/MapperEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,94 +9,142 @@
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Threading;
using Common;

[CustomEditor(typeof(Mapper))]
public class MapperEditor : Editor
{

public static bool editGrid = false, didUpdate = false;

public override void OnInspectorGUI ()
{
Mapper mapper = (Mapper)target;

DrawDefaultInspector ();

MapperEditorDrawer drawer = mapper.gameObject.GetComponent<MapperEditorDrawer> ();
if (drawer == null) {
drawer = mapper.gameObject.AddComponent<MapperEditorDrawer> ();
drawer.hideFlags = HideFlags.HideInInspector;
}
namespace EditorArea {
[CustomEditor(typeof(Mapper))]
public class MapperEditor : Editor {

editGrid = EditorGUILayout.Toggle ("Edit grid", editGrid);
drawer.editGrid = editGrid;
if (editGrid) {
public static Cell[][] grid;
//
public static bool editGrid = false, didUpdate = false;
//
private Mapper mapper;
private MapperEditorDrawer drawer;

public void OnSceneGUI () {
// Update drawer
if (drawer != null)
drawer.editGrid = editGrid;

// Stop if needed
if (!editGrid) {
didUpdate = false;
return;
}

// Create grid
if (grid == null || grid.Length != MapperWindowEditor.gridSize) {
grid = new Cell[MapperWindowEditor.gridSize][];
for (int i = 0; i < MapperWindowEditor.gridSize; i++)
grid [i] = new Cell[MapperWindowEditor.gridSize];
}

// Prepare holders
if (mapper == null) {
mapper = (Mapper)target;
}
if (drawer == null) {
drawer = mapper.gameObject.GetComponent<MapperEditorDrawer> ();
}

drawer.editingGrid = grid;

// Update Scene
if (!didUpdate) {
mapper.ComputeTileSize (mapper.collider.bounds.min, mapper.collider.bounds.max, MapperWindowEditor.gridSize, MapperWindowEditor.gridSize);
drawer.tileSize.Set (SpaceState.TileSize.x, SpaceState.TileSize.y);
drawer.zero.Set (SpaceState.FloorMin.x, SpaceState.FloorMin.z);
mapper.ComputeTileSize (SpaceState.Editor, mapper.collider.bounds.min, mapper.collider.bounds.max, MapperWindowEditor.gridSize, MapperWindowEditor.gridSize);
drawer.tileSize.Set (SpaceState.Editor.tileSize.x, SpaceState.Editor.tileSize.y);
drawer.zero.Set (SpaceState.Editor.floorMin.x, SpaceState.Editor.floorMin.z);
didUpdate = true;
}
} else {
didUpdate = false;
}

SceneView.RepaintAll ();
}

public static Cell[][] grid;

public void OnSceneGUI ()
{
if (!editGrid)
return;

//Mapper mapper = (Mapper)target;
if (grid == null || grid.Length != MapperWindowEditor.gridSize) {
grid = new Cell[MapperWindowEditor.gridSize][];
for (int i = 0; i < MapperWindowEditor.gridSize; i++)
grid [i] = new Cell[MapperWindowEditor.gridSize];
}
// Disabled part to do raycasting to identify the cell which the user clicked
Event current = Event.current;
switch (current.type) {
case EventType.KeyDown:
switch (current.keyCode) {
case KeyCode.Alpha1:
case KeyCode.Alpha2:
case KeyCode.Alpha3:
case KeyCode.Alpha4:
case KeyCode.Alpha0:

// Raycast
Event current = Event.current;
if (current != null && EventType.KeyDown == current.type) {
Ray ray = HandleUtility.GUIPointToWorldRay (current.mousePosition);
RaycastHit hit;
Debug.Log("RockAndRoll");
if (Physics.Raycast (ray, out hit, Mathf.Infinity, 1 << LayerMask.NameToLayer ("Floor"))) {
if (hit.transform.CompareTag ("Floor")) {
Vector2 pos = new Vector2 ((hit.point.x - hit.collider.bounds.min.x) / SpaceState.TileSize.x, (hit.point.z - hit.collider.bounds.min.x) / SpaceState.TileSize.y);
Vector2 pos = new Vector2 ((hit.point.x - hit.collider.bounds.min.x) / SpaceState.Editor.tileSize.x, (hit.point.z - hit.collider.bounds.min.x) / SpaceState.Editor.tileSize.y);
Cell c = grid [(int)pos.x] [(int)pos.y];
if (c == null) {
c = new Cell ();
grid [(int)pos.x] [(int)pos.y] = c;
}
if (current.keyCode == KeyCode.Alpha1)
{

switch (current.keyCode) {
case KeyCode.Alpha0:
grid [(int)pos.x] [(int)pos.y] = null;
break;

case KeyCode.Alpha1:
c.safe = true;
}
else if (current.keyCode == KeyCode.Alpha2)
break;

case KeyCode.Alpha2:
c.blocked = true;
else if (current.keyCode == KeyCode.Alpha3)
break;

case KeyCode.Alpha3:
c.noisy = true;
else if (current.keyCode == KeyCode.Alpha4)
break;

case KeyCode.Alpha4:
c.waypoint = true;
else if (current.keyCode == KeyCode.Alpha0)
grid [(int)pos.x] [(int)pos.y] = null;
break;

case KeyCode.U:
c.cluster = 0;
break;


case KeyCode.Alpha6:
c.cluster |= 1;
break;

case KeyCode.Alpha7:
c.cluster |= 2;
break;

case KeyCode.Alpha8:
c.cluster |= 4;
break;

case KeyCode.Alpha9:
c.cluster |= 8;
break;



case KeyCode.Keypad4:
c.cluster |= 8;
break;

case KeyCode.Keypad5:
c.cluster |= 16;
break;

case KeyCode.Keypad6:
c.cluster |= 32;
break;

case KeyCode.Keypad7:
c.cluster |= 64;
break;

case KeyCode.Keypad8:
c.cluster |= 128;
break;

case KeyCode.Keypad9:
c.cluster |= 256;
break;
}

SceneView.RepaintAll ();
}
}
break;
}
break;
}
}
}
} // OnSceneGui
} // Class
} // NS
Loading

0 comments on commit 2dee4bf

Please sign in to comment.