Skip to content

Commit d1d07ce

Browse files
committed
Update code style to remove var, use explicit private scope, and fix spelling errors
1 parent 7c61c83 commit d1d07ce

File tree

7 files changed

+86
-76
lines changed

7 files changed

+86
-76
lines changed

Assets/HoloToolkit-Examples/GazeRuler/Scripts/IPolygonClosable.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace HoloToolkit.Examples.GazeRuler
1010
/// </summary>
1111
public interface IPolygonClosable
1212
{
13-
//finish special ploygon
14-
void ClosePloygon(GameObject LinePrefab, GameObject TextPrefab);
13+
//finish special polygon
14+
void ClosePolygon(GameObject LinePrefab, GameObject TextPrefab);
1515
}
1616
}

Assets/HoloToolkit-Examples/GazeRuler/Scripts/LineManager.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ public class LineManager : Singleton<LineManager>, IGeometry
2424
public void AddPoint(GameObject LinePrefab, GameObject PointPrefab, GameObject TextPrefab)
2525
{
2626

27-
var hitPoint = GazeManager.Instance.HitPosition;
27+
Vector3 hitPoint = GazeManager.Instance.HitPosition;
2828

29-
var point = (GameObject)Instantiate(PointPrefab, hitPoint, Quaternion.identity);
29+
GameObject point = (GameObject)Instantiate(PointPrefab, hitPoint, Quaternion.identity);
3030
if (lastPoint != null && lastPoint.IsStart)
3131
{
32-
var centerPos = (lastPoint.Position + hitPoint) * 0.5f;
32+
Vector3 centerPos = (lastPoint.Position + hitPoint) * 0.5f;
3333

34-
var directionFromCamera = centerPos - Camera.main.transform.position;
34+
Vector3 directionFromCamera = centerPos - Camera.main.transform.position;
3535

36-
var distanceA = Vector3.Distance(lastPoint.Position, Camera.main.transform.position);
37-
var distanceB = Vector3.Distance(hitPoint, Camera.main.transform.position);
36+
float distanceA = Vector3.Distance(lastPoint.Position, Camera.main.transform.position);
37+
float distanceB = Vector3.Distance(hitPoint, Camera.main.transform.position);
3838

3939
Debug.Log("A: " + distanceA + ",B: " + distanceB);
4040
Vector3 direction;
@@ -47,20 +47,20 @@ public void AddPoint(GameObject LinePrefab, GameObject PointPrefab, GameObject T
4747
direction = lastPoint.Position - hitPoint;
4848
}
4949

50-
var distance = Vector3.Distance(lastPoint.Position, hitPoint);
51-
var line = (GameObject)Instantiate(LinePrefab, centerPos, Quaternion.LookRotation(direction));
50+
float distance = Vector3.Distance(lastPoint.Position, hitPoint);
51+
GameObject line = (GameObject)Instantiate(LinePrefab, centerPos, Quaternion.LookRotation(direction));
5252
line.transform.localScale = new Vector3(distance, defaultLineScale, defaultLineScale);
5353
line.transform.Rotate(Vector3.down, 90f);
5454

55-
var normalV = Vector3.Cross(direction, directionFromCamera);
56-
var normalF = Vector3.Cross(direction, normalV) * -1;
57-
var tip = (GameObject)Instantiate(TextPrefab, centerPos, Quaternion.LookRotation(normalF));
55+
Vector3 normalV = Vector3.Cross(direction, directionFromCamera);
56+
Vector3 normalF = Vector3.Cross(direction, normalV) * -1;
57+
GameObject tip = (GameObject)Instantiate(TextPrefab, centerPos, Quaternion.LookRotation(normalF));
5858

5959
//unit is meter
6060
tip.transform.Translate(Vector3.up * 0.05f);
6161
tip.GetComponent<TextMesh>().text = distance + "m";
6262

63-
var root = new GameObject();
63+
GameObject root = new GameObject();
6464
lastPoint.Root.transform.parent = root.transform;
6565
line.transform.parent = root.transform;
6666
point.transform.parent = root.transform;
@@ -99,7 +99,7 @@ public void Delete()
9999
{
100100
if (Lines != null && Lines.Count > 0)
101101
{
102-
var lastLine = Lines.Pop();
102+
Line lastLine = Lines.Pop();
103103
Destroy(lastLine.Root);
104104
}
105105

@@ -112,7 +112,7 @@ public void Clear()
112112
{
113113
while (Lines.Count > 0)
114114
{
115-
var lastLine = Lines.Pop();
115+
Line lastLine = Lines.Pop();
116116
Destroy(lastLine.Root);
117117
}
118118
}

Assets/HoloToolkit-Examples/GazeRuler/Scripts/MeasureManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class MeasureManager : Singleton<MeasureManager>, IHoldHandler, IInputCli
2424
public GameObject ModeTipObject;
2525
public GameObject TextPrefab;
2626

27-
void Start()
27+
private void Start()
2828
{
2929
InputManager.Instance.PushFallbackInputHandler(gameObject);
3030

@@ -62,7 +62,7 @@ public void ClearAll()
6262
public void OnPolygonClose()
6363
{
6464
IPolygonClosable client = PolygonManager.Instance;
65-
client.ClosePloygon(LinePrefab, TextPrefab);
65+
client.ClosePolygon(LinePrefab, TextPrefab);
6666
}
6767

6868
// change measure mode

Assets/HoloToolkit-Examples/GazeRuler/Scripts/ModeTip.cs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,33 @@ namespace HoloToolkit.Examples.GazeRuler
1212
public class ModeTip : Singleton<ModeTip>
1313
{
1414
private const string LineMode = "Line Mode";
15-
private const string PloygonMode = "Geometry Mode";
15+
private const string PolygonMode = "Geometry Mode";
1616
private TextMesh text;
1717
private int fadeTime = 100;
18+
private Material material;
1819

19-
void Start()
20+
private void Start()
2021
{
2122
text = GetComponent<TextMesh>();
23+
material = GetComponent<Renderer>().material;
2224
switch (MeasureManager.Instance.Mode)
2325
{
2426
case GeometryMode.Line:
2527
text.text = LineMode;
2628
break;
2729
default:
28-
text.text = PloygonMode;
30+
text.text = PolygonMode;
2931
break;
3032
}
3133
}
3234

35+
protected override void OnDestroy()
36+
{
37+
DestroyImmediate(material);
38+
}
39+
3340
// Update is called once per frame
34-
void Update()
41+
private void Update()
3542
{
3643
if (gameObject.activeInHierarchy)
3744
{
@@ -41,30 +48,33 @@ void Update()
4148
{
4249
case GeometryMode.Line:
4350
if (!text.text.Contains(LineMode))
51+
{
4452
text.text = LineMode;
53+
}
4554
break;
4655
default:
47-
if (!text.text.Contains(PloygonMode))
48-
text.text = PloygonMode;
56+
if (!text.text.Contains(PolygonMode))
57+
{
58+
text.text = PolygonMode;
59+
}
4960
break;
5061
}
5162

52-
var render = GetComponent<MeshRenderer>().material;
5363
fadeTime = 100;
5464
// fade tip text
5565
if (fadeTime == 0)
5666
{
57-
var color = render.color;
67+
var color = material.color;
5868
fadeTime = 100;
5969
color.a = 1f;
60-
render.color = color;
70+
material.color = color;
6171
gameObject.SetActive(false);
6272
}
6373
else
6474
{
65-
var color = render.color;
75+
var color = material.color;
6676
color.a -= 0.01f;
67-
render.color = color;
77+
material.color = color;
6878
fadeTime--;
6979
}
7080
}

Assets/HoloToolkit-Examples/GazeRuler/Scripts/PolygonManager.cs

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

44
using UnityEngine;
@@ -14,8 +14,8 @@ namespace HoloToolkit.Examples.GazeRuler
1414
public class PolygonManager : Singleton<PolygonManager>, IGeometry, IPolygonClosable
1515
{
1616
// save all geometries
17-
public Stack<Ploygon> Ploygons = new Stack<Ploygon>();
18-
public Ploygon CurrentPloygon;
17+
public Stack<Polygon> Polygons = new Stack<Polygon>();
18+
public Polygon CurrentPolygon;
1919

2020
/// <summary>
2121
/// handle new point users place
@@ -32,32 +32,32 @@ public void AddPoint(GameObject LinePrefab, GameObject PointPrefab, GameObject T
3232
Position = hitPoint,
3333
Root = point
3434
};
35-
if (CurrentPloygon.IsFinished)
35+
if (CurrentPolygon.IsFinished)
3636
{
37-
CurrentPloygon = new Ploygon()
37+
CurrentPolygon = new Polygon()
3838
{
3939
IsFinished = false,
4040
Root = new GameObject(),
4141
Points = new List<Vector3>()
4242
};
4343

44-
CurrentPloygon.Points.Add(newPoint.Position);
45-
newPoint.Root.transform.parent = CurrentPloygon.Root.transform;
44+
CurrentPolygon.Points.Add(newPoint.Position);
45+
newPoint.Root.transform.parent = CurrentPolygon.Root.transform;
4646
}
4747
else
4848
{
49-
CurrentPloygon.Points.Add(newPoint.Position);
50-
newPoint.Root.transform.parent = CurrentPloygon.Root.transform;
51-
if (CurrentPloygon.Points.Count > 1)
49+
CurrentPolygon.Points.Add(newPoint.Position);
50+
newPoint.Root.transform.parent = CurrentPolygon.Root.transform;
51+
if (CurrentPolygon.Points.Count > 1)
5252
{
53-
var index = CurrentPloygon.Points.Count - 1;
54-
var centerPos = (CurrentPloygon.Points[index] + CurrentPloygon.Points[index - 1]) * 0.5f;
55-
var direction = CurrentPloygon.Points[index] - CurrentPloygon.Points[index - 1];
56-
var distance = Vector3.Distance(CurrentPloygon.Points[index], CurrentPloygon.Points[index - 1]);
53+
var index = CurrentPolygon.Points.Count - 1;
54+
var centerPos = (CurrentPolygon.Points[index] + CurrentPolygon.Points[index - 1]) * 0.5f;
55+
var direction = CurrentPolygon.Points[index] - CurrentPolygon.Points[index - 1];
56+
var distance = Vector3.Distance(CurrentPolygon.Points[index], CurrentPolygon.Points[index - 1]);
5757
var line = (GameObject)Instantiate(LinePrefab, centerPos, Quaternion.LookRotation(direction));
5858
line.transform.localScale = new Vector3(distance, 0.005f, 0.005f);
5959
line.transform.Rotate(Vector3.down, 90f);
60-
line.transform.parent = CurrentPloygon.Root.transform;
60+
line.transform.parent = CurrentPolygon.Root.transform;
6161
}
6262

6363
}
@@ -69,35 +69,35 @@ public void AddPoint(GameObject LinePrefab, GameObject PointPrefab, GameObject T
6969
/// </summary>
7070
/// <param name="LinePrefab"></param>
7171
/// <param name="TextPrefab"></param>
72-
public void ClosePloygon(GameObject LinePrefab, GameObject TextPrefab)
72+
public void ClosePolygon(GameObject LinePrefab, GameObject TextPrefab)
7373
{
74-
if (CurrentPloygon != null)
74+
if (CurrentPolygon != null)
7575
{
76-
CurrentPloygon.IsFinished = true;
77-
var area = CalculatePloygonArea(CurrentPloygon);
78-
var index = CurrentPloygon.Points.Count - 1;
79-
var centerPos = (CurrentPloygon.Points[index] + CurrentPloygon.Points[0]) * 0.5f;
80-
var direction = CurrentPloygon.Points[index] - CurrentPloygon.Points[0];
81-
var distance = Vector3.Distance(CurrentPloygon.Points[index], CurrentPloygon.Points[0]);
76+
CurrentPolygon.IsFinished = true;
77+
var area = CalculatePolygonArea(CurrentPolygon);
78+
var index = CurrentPolygon.Points.Count - 1;
79+
var centerPos = (CurrentPolygon.Points[index] + CurrentPolygon.Points[0]) * 0.5f;
80+
var direction = CurrentPolygon.Points[index] - CurrentPolygon.Points[0];
81+
var distance = Vector3.Distance(CurrentPolygon.Points[index], CurrentPolygon.Points[0]);
8282
var line = (GameObject)Instantiate(LinePrefab, centerPos, Quaternion.LookRotation(direction));
8383
line.transform.localScale = new Vector3(distance, 0.005f, 0.005f);
8484
line.transform.Rotate(Vector3.down, 90f);
85-
line.transform.parent = CurrentPloygon.Root.transform;
85+
line.transform.parent = CurrentPolygon.Root.transform;
8686

8787
var vect = new Vector3(0, 0, 0);
88-
foreach (var point in CurrentPloygon.Points)
88+
foreach (var point in CurrentPolygon.Points)
8989
{
9090
vect += point;
9191
}
9292
var centerPoint = vect / (index + 1);
93-
var direction1 = CurrentPloygon.Points[1] - CurrentPloygon.Points[0];
93+
var direction1 = CurrentPolygon.Points[1] - CurrentPolygon.Points[0];
9494
var directionF = Vector3.Cross(direction, direction1);
9595
var tip = (GameObject)Instantiate(TextPrefab, centerPoint, Quaternion.LookRotation(directionF));//anchor.x + anchor.y + anchor.z < 0 ? -1 * anchor : anchor));
9696

9797
// unit is ㎡
9898
tip.GetComponent<TextMesh>().text = area + "㎡";
99-
tip.transform.parent = CurrentPloygon.Root.transform;
100-
Ploygons.Push(CurrentPloygon);
99+
tip.transform.parent = CurrentPolygon.Root.transform;
100+
Polygons.Push(CurrentPolygon);
101101
}
102102
}
103103

@@ -106,11 +106,11 @@ public void ClosePloygon(GameObject LinePrefab, GameObject TextPrefab)
106106
/// </summary>
107107
public void Clear()
108108
{
109-
if (Ploygons != null && Ploygons.Count > 0)
109+
if (Polygons != null && Polygons.Count > 0)
110110
{
111-
while (Ploygons.Count > 0)
111+
while (Polygons.Count > 0)
112112
{
113-
var lastLine = Ploygons.Pop();
113+
var lastLine = Polygons.Pop();
114114
Destroy(lastLine.Root);
115115
}
116116
}
@@ -119,9 +119,9 @@ public void Clear()
119119
// delete latest geometry
120120
public void Delete()
121121
{
122-
if (Ploygons != null && Ploygons.Count > 0)
122+
if (Polygons != null && Polygons.Count > 0)
123123
{
124-
var lastLine = Ploygons.Pop();
124+
var lastLine = Polygons.Pop();
125125
Destroy(lastLine.Root);
126126
}
127127
}
@@ -133,7 +133,7 @@ public void Delete()
133133
/// <param name="p2"></param>
134134
/// <param name="p3"></param>
135135
/// <returns></returns>
136-
float CalculateTriangleArea(Vector3 p1, Vector3 p2, Vector3 p3)
136+
private float CalculateTriangleArea(Vector3 p1, Vector3 p2, Vector3 p3)
137137
{
138138
var a = Vector3.Distance(p1, p2);
139139
var b = Vector3.Distance(p1, p3);
@@ -146,22 +146,22 @@ float CalculateTriangleArea(Vector3 p1, Vector3 p2, Vector3 p3)
146146
/// <summary>
147147
/// Calculate an area of geometry
148148
/// </summary>
149-
/// <param name="ploygon"></param>
149+
/// <param name="polygon"></param>
150150
/// <returns></returns>
151-
float CalculatePloygonArea(Ploygon ploygon)
151+
private float CalculatePolygonArea(Polygon polygon)
152152
{
153153
var s = 0.0f;
154154
var i = 1;
155-
var n = ploygon.Points.Count;
155+
var n = polygon.Points.Count;
156156
for (; i < n - 1; i++)
157-
s += CalculateTriangleArea(ploygon.Points[0], ploygon.Points[i], ploygon.Points[i + 1]);
157+
s += CalculateTriangleArea(polygon.Points[0], polygon.Points[i], polygon.Points[i + 1]);
158158
return 0.5f * Mathf.Abs(s);
159159
}
160160

161161
// Use this for initialization
162-
void Start()
162+
private void Start()
163163
{
164-
CurrentPloygon = new Ploygon()
164+
CurrentPolygon = new Polygon()
165165
{
166166
IsFinished = false,
167167
Root = new GameObject(),
@@ -175,10 +175,10 @@ void Start()
175175
/// </summary>
176176
public void Reset()
177177
{
178-
if (CurrentPloygon != null && !CurrentPloygon.IsFinished)
178+
if (CurrentPolygon != null && !CurrentPolygon.IsFinished)
179179
{
180-
Destroy(CurrentPloygon.Root);
181-
CurrentPloygon = new Ploygon()
180+
Destroy(CurrentPolygon.Root);
181+
CurrentPolygon = new Polygon()
182182
{
183183
IsFinished = false,
184184
Root = new GameObject(),
@@ -189,7 +189,7 @@ public void Reset()
189189
}
190190

191191

192-
public class Ploygon
192+
public class Polygon
193193
{
194194
public float Area { get; set; }
195195

Assets/HoloToolkit-Examples/GazeRuler/Scripts/Test/LineTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class LineTest : MonoBehaviour
1818
public GameObject text;
1919

2020
// Update is called once per frame
21-
void Update()
21+
private void Update()
2222
{
2323
var distance = Vector3.Distance(start.transform.position, end.transform.position);
2424
var midPoint = (start.transform.position + end.transform.position) * 0.5f;

0 commit comments

Comments
 (0)