Skip to content

Commit 542ec05

Browse files
Improved debug box and various fixes
- Removed static box prefab and added script to dynamically create it based on the specified screen dimensions - Fixed NullReferenceException thrown when exiting
1 parent 492fd02 commit 542ec05

29 files changed

+204
-8
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
/[Bb]uild/
55
/[Bb]uilds/
66
/Assets/AssetStoreTools*
7+
/Assets/ThirdParty*
8+
/Assets/SmirkingCat/Scenes*
79

810
# Autogenerated VS/MD solution and project files
911
ExportedObj/

Assets/SmirkingCat.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.
-38.9 KB
Binary file not shown.

Assets/SmirkingCat/Prefabs/JohnnyLeeBox.prefab.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
2.82 KB
Binary file not shown.
4.28 KB
Binary file not shown.
6.65 KB
Binary file not shown.

Assets/SmirkingCat/Prefabs/Wall.prefab.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
/*
2+
*
3+
* JohnnyLeeBox.cs (c) Ryan Sullivan 2017
4+
* url: http://smirkingcat.software/picturewindow
5+
*
6+
* Creates a box in the style of the infamous "Head Tracking for Desktop VR Displays using the WiiRemote" video:
7+
* https://www.youtube.com/watch?v=Jd3-eiid-Uw
8+
*
9+
*/
10+
11+
using System;
12+
using System.Collections.Generic;
13+
using UnityEngine;
14+
15+
public class JohnnyLeeBox : MonoBehaviour
16+
{
17+
18+
19+
[Tooltip("The prefab to use for the walls of the box")]
20+
public GameObject _wallPrefab;
21+
22+
[Tooltip("The depth of the box")]
23+
public float _depth = 2;
24+
25+
[Tooltip("The thickness of the walls of the box")]
26+
public float _wallThickness = 0.1f;
27+
28+
[Tooltip("The prefab to use for the targets")]
29+
public GameObject _targetPrefab;
30+
31+
[Tooltip("The number of targets to generate")]
32+
public float _numberOfTargets = 10;
33+
34+
35+
public enum Wall { Top, Bottom, Left, Right, Back };
36+
37+
private Dictionary <Wall, GameObject> _walls = new Dictionary<Wall, GameObject>();
38+
39+
private float Height
40+
{
41+
get { return ((PictureWindow.Instance != null) ? PictureWindow.Instance.Height : 0 ); }
42+
}
43+
44+
private float Width
45+
{
46+
get { return ((PictureWindow.Instance != null) ? PictureWindow.Instance.Width : 0 ); }
47+
}
48+
49+
50+
private void Update()
51+
{
52+
53+
if ( _walls.Count == 0 && (Height != 0 && Width != 0) )
54+
{
55+
56+
MakeBox();
57+
58+
MakeTargets();
59+
60+
}
61+
62+
}
63+
64+
65+
private void MakeBox()
66+
{
67+
68+
GameObject box = new GameObject("Box");
69+
box.transform.SetParent(transform);
70+
box.transform.localPosition = Vector3.zero;
71+
box.transform.localRotation = Quaternion.identity;
72+
73+
foreach( Wall wall in Enum.GetValues(typeof(Wall)) )
74+
{
75+
76+
_walls.Add( wall, Instantiate( _wallPrefab, box.transform ));
77+
_walls[wall].transform.localRotation = Quaternion.identity;
78+
79+
switch (wall)
80+
{
81+
82+
case Wall.Top:
83+
_walls[wall].name = "Top";
84+
_walls[wall].transform.localPosition = new Vector3( 0, ((Height + _wallThickness) / 2), 1 );
85+
_walls[wall].transform.localScale = new Vector3( Width, _wallThickness, _depth );
86+
break;
87+
case Wall.Bottom:
88+
_walls[wall].name = "Bottom";
89+
_walls[wall].transform.localPosition = new Vector3( 0, -((Height + _wallThickness) / 2), 1 );
90+
_walls[wall].transform.localScale = new Vector3( Width, _wallThickness, _depth );
91+
break;
92+
case Wall.Left:
93+
_walls[wall].name = "Left";
94+
_walls[wall].transform.localPosition = new Vector3( -((Width + _wallThickness) / 2), 0, 1 );
95+
_walls[wall].transform.localScale = new Vector3( _wallThickness, Height, _depth );
96+
break;
97+
case Wall.Right:
98+
_walls[wall].name = "Right";
99+
_walls[wall].transform.localPosition = new Vector3( ((Width + _wallThickness) / 2), 0, 1 );
100+
_walls[wall].transform.localScale = new Vector3( _wallThickness, Height, _depth );
101+
break;
102+
case Wall.Back:
103+
_walls[wall].name = "Back";
104+
_walls[wall].transform.localPosition = new Vector3( 0, 0, _depth + (_wallThickness / 2) );
105+
_walls[wall].transform.localScale = new Vector3( Width, Height, _wallThickness );
106+
break;
107+
108+
}
109+
110+
}
111+
112+
}
113+
114+
115+
private void MakeTargets()
116+
{
117+
118+
GameObject targets = new GameObject("Targets");
119+
targets.transform.SetParent(transform);
120+
targets.transform.localPosition = Vector3.zero;
121+
targets.transform.localRotation = Quaternion.identity;
122+
123+
for (int i = 0; i < _numberOfTargets; i++)
124+
{
125+
126+
// X and Y are within the bounds of the box such that they don't clip the walls
127+
float x = UnityEngine.Random.Range(-(Width/2-_targetPrefab.transform.lossyScale.x/2), (Width/2-_targetPrefab.transform.lossyScale.x/2));
128+
float y = UnityEngine.Random.Range(-(Height/2-_targetPrefab.transform.lossyScale.y/2), (Height/2-_targetPrefab.transform.lossyScale.y/2));
129+
// Z is most of the depth of the box and slightly sticking out forward of it
130+
float z = UnityEngine.Random.Range(-(_depth/5), (_depth/1.2f));
131+
132+
GameObject target = Instantiate(_targetPrefab, targets.transform);
133+
target.transform.localPosition = new Vector3(x, y, z);
134+
target.transform.localRotation = Quaternion.identity;
135+
136+
}
137+
138+
}
139+
140+
141+
private void OnDestroy()
142+
{
143+
144+
_walls.Clear();
145+
146+
}
147+
148+
149+
}

Assets/SmirkingCat/Scripts/JohnnyLeeBox.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/SmirkingCat/Scripts/PictureWindow.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ public Vector3 TopRight
7676
get { return _corners[Corner.TopRight]; }
7777
}
7878

79+
public float Width
80+
{
81+
get { return (BottomRight - BottomLeft).magnitude; }
82+
}
83+
84+
public float Height
85+
{
86+
get { return (TopLeft - BottomLeft).magnitude; }
87+
}
7988

8089
// The normal of the window
8190
private Vector3 _windowNormal;
@@ -134,11 +143,11 @@ private void Update()
134143
if (_useTargetBox && _targetBox == null)
135144
{
136145

137-
_targetBox = Instantiate(_targetBoxPrefab,
138-
CenterOfVectors(new Vector3[]{ BottomLeft, BottomRight, TopLeft, TopRight }),
139-
Quaternion.LookRotation(_windowNormal));
146+
_targetBox = Instantiate(_targetBoxPrefab);
140147
_targetBox.transform.SetParent(transform);
141148
_targetBox.SetActive(false);
149+
_targetBox.transform.position = CenterOfVectors(new Vector3[] { BottomLeft, BottomRight, TopLeft, TopRight });
150+
_targetBox.transform.rotation = Quaternion.LookRotation(_windowNormal);
142151

143152
}
144153

@@ -175,6 +184,9 @@ public void ResetWindow()
175184

176185
_windowController.DestroyCamera();
177186

187+
_useTargetBox = false;
188+
Destroy(_targetBox);
189+
178190
ShowInstruction(INSTRUCTION.BottomLeft);
179191

180192
}

Assets/SmirkingCat/Scripts/PictureWindowControl.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,13 @@ private void Update()
104104
private void OnDestroy()
105105
{
106106

107-
_controller.Gripped -= Controller_Gripped;
108-
_controller.Ungripped -= Controller_Ungripped;
109-
_controller.PadClicked -= Controller_PadClicked;
110-
_controller.TriggerClicked -= Controller_TriggerClicked;
107+
if (_controller != null)
108+
{
109+
_controller.Gripped -= Controller_Gripped;
110+
_controller.Ungripped -= Controller_Ungripped;
111+
_controller.PadClicked -= Controller_PadClicked;
112+
_controller.TriggerClicked -= Controller_TriggerClicked;
113+
}
111114

112115
}
113116

ProjectSettings/AudioManager.asset

4.04 KB
Binary file not shown.
4.01 KB
Binary file not shown.

ProjectSettings/DynamicsManager.asset

4.18 KB
Binary file not shown.
4.01 KB
Binary file not shown.

ProjectSettings/EditorSettings.asset

4.07 KB
Binary file not shown.
4.29 KB
Binary file not shown.

ProjectSettings/InputManager.asset

5.39 KB
Binary file not shown.

ProjectSettings/NavMeshAreas.asset

4.28 KB
Binary file not shown.

ProjectSettings/NetworkManager.asset

4.02 KB
Binary file not shown.
4.28 KB
Binary file not shown.

ProjectSettings/ProjectSettings.asset

39.5 KB
Binary file not shown.

ProjectSettings/ProjectVersion.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
m_EditorVersion: 5.5.1f1

ProjectSettings/QualitySettings.asset

4.86 KB
Binary file not shown.

ProjectSettings/TagManager.asset

4.21 KB
Binary file not shown.

ProjectSettings/TimeManager.asset

4.02 KB
Binary file not shown.
4.11 KB
Binary file not shown.

0 commit comments

Comments
 (0)