Skip to content
This repository was archived by the owner on Mar 24, 2022. It is now read-only.

Commit 4baa2c6

Browse files
committed
Coding style enforcement
1 parent b7b2d8c commit 4baa2c6

File tree

11 files changed

+107
-78
lines changed

11 files changed

+107
-78
lines changed

Diff for: Assets/Common/Cameras/Scripts/GroundCam.cs

+70-55
Original file line numberDiff line numberDiff line change
@@ -2,144 +2,159 @@
22
using UnityEngine;
33

44
namespace Assets.Common.Cameras.Scripts {
5+
56
[AddComponentMenu("Scripts/Cameras/GroundCam")]
67
public class GroundCam : MonoBehaviour {
7-
private Transform _mChildCameraTransform;
8-
private Vector2 _mInput;
9-
private bool _mIsMoving;
10-
private Vector3 _mMoveDir = Vector3.zero;
118
public float MBoostSpeed = 10f;
129
public float MMoveSpeed = 1f;
1310

1411
[SerializeField]
1512
public MouseLook MouseLook;
1613

17-
// Use this for initialization
18-
private void Start() {
19-
_mChildCameraTransform = transform.GetChild(0);
20-
MouseLook.Init(transform, _mChildCameraTransform);
21-
}
14+
private Transform childCameraTransform;
15+
private Vector2 input;
16+
private Vector3 moveDir = Vector3.zero;
2217

2318
private void FixedUpdate() {
2419
float speed;
2520
GetInput(out speed);
2621

2722
// always move along the camera forward as it is the direction that it being aimed at
28-
Vector3 desiredMove = transform.forward * _mInput.y + transform.right * _mInput.x;
23+
Vector3 desiredMove = (transform.forward * input.y) + (transform.right * input.x);
2924

3025
// get a normal for the surface that is being touched to move along it
31-
_mMoveDir.x = desiredMove.x * speed;
32-
_mMoveDir.z = desiredMove.z * speed;
26+
moveDir.x = desiredMove.x * speed;
27+
moveDir.z = desiredMove.z * speed;
3328

3429
Vector3 pos = transform.position;
35-
pos.x += _mMoveDir.x;
36-
pos.z += _mMoveDir.z;
30+
pos.x += moveDir.x;
31+
pos.z += moveDir.z;
3732
transform.position = pos;
3833
MouseLook.UpdateCursorLock();
3934
RotateView();
4035
}
4136

42-
private void RotateView() {
43-
MouseLook.LookRotation(transform, _mChildCameraTransform);
44-
}
45-
4637
private void GetInput(out float speed) {
4738
// Read input
4839
float horizontal = Input.GetAxis("Horizontal");
4940
float vertical = Input.GetAxis("Vertical");
5041

5142
speed = Input.GetKey(KeyCode.LeftShift) ? MBoostSpeed : MMoveSpeed;
52-
_mInput = new Vector2(horizontal, vertical);
43+
input = new Vector2(horizontal, vertical);
44+
45+
if (input.sqrMagnitude > 1) {
46+
input.Normalize();
47+
}
48+
}
5349

54-
if (_mInput.sqrMagnitude > 1) _mInput.Normalize();
50+
private void RotateView() {
51+
MouseLook.LookRotation(transform, childCameraTransform);
52+
}
53+
54+
// Use this for initialization
55+
private void Start() {
56+
childCameraTransform = transform.GetChild(0);
57+
MouseLook.Init(transform, childCameraTransform);
5558
}
5659
}
5760

5861
[Serializable]
5962
public class MouseLook {
60-
private bool _mCursorIsLocked = true;
6163
public bool ClampVerticalRotation = true;
6264
public bool LockCursor = true;
63-
private Quaternion m_CameraTargetRot;
64-
65-
private Quaternion m_CharacterTargetRot;
6665
public float MaximumX = 90F;
6766
public float MinimumX = -90F;
6867
public bool Smooth;
6968
public float SmoothTime = 5f;
7069
public float XSensitivity = 2f;
7170
public float YSensitivity = 2f;
71+
private Quaternion cameraTargetRot;
72+
73+
private Quaternion characterTargetRot;
74+
private bool cursorIsLocked = true;
7275

7376
public void Init(Transform character, Transform camera) {
74-
m_CharacterTargetRot = character.localRotation;
75-
m_CameraTargetRot = camera.localRotation;
77+
characterTargetRot = character.localRotation;
78+
cameraTargetRot = camera.localRotation;
7679
}
7780

78-
7981
public void LookRotation(Transform character, Transform camera, float yRotOptional = 0f) {
8082
float yRot = Input.GetAxis("Mouse X") * XSensitivity;
8183
float xRot = Input.GetAxis("Mouse Y") * YSensitivity;
8284

83-
if (yRotOptional != 0f) m_CharacterTargetRot *= Quaternion.Euler(0f, yRotOptional, 0f);
84-
else m_CharacterTargetRot *= Quaternion.Euler(0f, yRot, 0f);
85+
if (yRotOptional != 0f) {
86+
characterTargetRot *= Quaternion.Euler(0f, yRotOptional, 0f);
87+
} else {
88+
characterTargetRot *= Quaternion.Euler(0f, yRot, 0f);
89+
}
8590

86-
m_CameraTargetRot *= Quaternion.Euler(-xRot, 0f, 0f);
91+
cameraTargetRot *= Quaternion.Euler(-xRot, 0f, 0f);
8792

88-
if (ClampVerticalRotation)
89-
m_CameraTargetRot = ClampRotationAroundXAxis(m_CameraTargetRot);
93+
if (ClampVerticalRotation) {
94+
cameraTargetRot = ClampRotationAroundXAxis(cameraTargetRot);
95+
}
9096

9197
if (Smooth) {
92-
character.localRotation = Quaternion.Slerp(character.localRotation, m_CharacterTargetRot,
98+
character.localRotation = Quaternion.Slerp(
99+
character.localRotation,
100+
characterTargetRot,
93101
SmoothTime * Time.deltaTime);
94-
camera.localRotation = Quaternion.Slerp(camera.localRotation, m_CameraTargetRot,
102+
camera.localRotation = Quaternion.Slerp(
103+
camera.localRotation,
104+
cameraTargetRot,
95105
SmoothTime * Time.deltaTime);
96106
} else {
97-
character.localRotation = m_CharacterTargetRot;
98-
camera.localRotation = m_CameraTargetRot;
107+
character.localRotation = characterTargetRot;
108+
camera.localRotation = cameraTargetRot;
99109
}
100110

101111
UpdateCursorLock();
102112
}
103113

104114
public void SetCursorLock(bool value) {
105115
LockCursor = value;
106-
if (!LockCursor) {
107-
Cursor.lockState = CursorLockMode.None;
108-
Cursor.visible = true;
116+
if (LockCursor) {
117+
return;
109118
}
110-
}
111119

112-
public void UpdateCursorLock() {
113-
if (LockCursor) InternalLockUpdate();
120+
Cursor.lockState = CursorLockMode.None;
121+
Cursor.visible = true;
114122
}
115123

116-
private void InternalLockUpdate() {
117-
if (Input.GetKeyUp(KeyCode.Escape)) _mCursorIsLocked = false;
118-
else if (Input.GetMouseButtonUp(0)) _mCursorIsLocked = true;
119-
120-
if (_mCursorIsLocked) {
121-
Cursor.lockState = CursorLockMode.Locked;
122-
Cursor.visible = false;
123-
} else if (!_mCursorIsLocked) {
124-
Cursor.lockState = CursorLockMode.None;
125-
Cursor.visible = true;
124+
public void UpdateCursorLock() {
125+
if (LockCursor) {
126+
InternalLockUpdate();
126127
}
127128
}
128129

129-
130130
private Quaternion ClampRotationAroundXAxis(Quaternion q) {
131131
q.x /= q.w;
132132
q.y /= q.w;
133133
q.z /= q.w;
134134
q.w = 1.0f;
135135

136136
float angleX = 2.0f * Mathf.Rad2Deg * Mathf.Atan(q.x);
137-
138137
angleX = Mathf.Clamp(angleX, MinimumX, MaximumX);
139-
140138
q.x = Mathf.Tan(0.5f * Mathf.Deg2Rad * angleX);
141139

142140
return q;
143141
}
142+
143+
private void InternalLockUpdate() {
144+
if (Input.GetKeyUp(KeyCode.Escape)) {
145+
cursorIsLocked = false;
146+
} else if (Input.GetMouseButtonUp(0)) {
147+
cursorIsLocked = true;
148+
}
149+
150+
if (cursorIsLocked) {
151+
Cursor.lockState = CursorLockMode.Locked;
152+
Cursor.visible = false;
153+
} else if (!cursorIsLocked) {
154+
Cursor.lockState = CursorLockMode.None;
155+
Cursor.visible = true;
156+
}
157+
}
144158
}
159+
145160
}

Diff for: Assets/Common/Scripts/BindTextToAnotherTextElement.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
SOFTWARE.
2323
*/
2424

25-
using UnityEditor;
2625
using UnityEngine;
2726
using UnityEngine.UI;
2827

@@ -34,9 +33,10 @@ namespace Assets.Common.Scripts {
3433
public class BindTextToAnotherTextElement : MonoBehaviour {
3534

3635
public Text TargetText;
37-
[MenuItem("MyMenu/Do Something")]
38-
void Update() {
39-
this.GetComponent<Text>().text = TargetText.text;
36+
37+
public void Update() {
38+
GetComponent<Text>().text = TargetText.text;
4039
}
4140
}
42-
}
41+
42+
}

Diff for: Assets/Common/Scripts/ExtentionMethods.cs

+17-11
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,20 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2828

2929
namespace Assets.Common.Scripts {
3030

31-
[AddComponentMenu("Scripts/Common/ExtentionMethods")]
31+
[AddComponentMenu("Scripts/Common/Extention Methods")]
3232
public static class ExtentionMethods {
33-
public static int RoundToTenth(this int i) {
34-
return ((int)Math.Round(i / 10.0)) * 10;
35-
}
3633

3734
public static IEnumerable<IList<T>> Chunks<T>(this IEnumerable<T> xs, int size) {
3835
List<T> curr = new List<T>(size);
3936

4037
foreach (T x in xs) {
4138
curr.Add(x);
42-
if (curr.Count == size) {
43-
yield return curr;
44-
curr = new List<T>(size);
39+
if (curr.Count != size) {
40+
continue;
4541
}
42+
43+
yield return curr;
44+
curr = new List<T>(size);
4645
}
4746
}
4847

@@ -54,11 +53,18 @@ public static IEnumerable<T[]> ChunksAsArray<T>(this IEnumerable<T> xs, int size
5453
foreach (T x in xs) {
5554
curr[i % size] = x;
5655

57-
if (++i % size == 0) {
58-
yield return curr;
59-
curr = new T[size];
56+
if (++i % size != 0) {
57+
continue;
6058
}
59+
60+
yield return curr;
61+
curr = new T[size];
6162
}
6263
}
64+
65+
public static int RoundToTenth(this int i) {
66+
return (int)Math.Round(i / 10.0) * 10;
67+
}
6368
}
64-
}
69+
70+
}

Diff for: Assets/Common/StandardAssets/Cameras/Scripts/HandHeldCam.cs

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
#if UNITY_EDITOR
21
using UnityEngine;
3-
#endif
42

53
namespace Assets.Common.StandardAssets.Cameras.Scripts {
64
[AddComponentMenu("Scripts/Cameras/HandHeldCam")]

Diff for: Assets/Common/StandardAssets/CrossPlatformInput/Scripts/MobileControlRig.cs

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
#if UNITY_EDITOR
12
using UnityEditor;
3+
#endif
24

35
using UnityEngine;
46
using UnityEngine.EventSystems;

Diff for: Assets/Common/StandardAssets/Editor/CrossPlatformInput/CrossPlatformInputInitialize.cs

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System.Collections.Generic;
2+
#if UNITY_EDITOR
23
using UnityEditor;
4+
#endif
35

46
namespace Assets.Common.StandardAssets.Editor.CrossPlatformInput
57
{

Diff for: Assets/Common/StandardAssets/Utility/AutoMobileShaderSwitch.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
2-
using System.Collections.Generic;
2+
#if UNITY_EDITOR
33
using UnityEditor;
4+
#endif
45
using UnityEngine;
56

67
namespace Assets.Common.StandardAssets.Utility

Diff for: Assets/Common/StandardAssets/Utility/PlatformSpecificContent.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
using UnityEditor;
2-
using UnityEngine;
31
#if UNITY_EDITOR
4-
2+
using UnityEditor;
53
#endif
4+
using UnityEngine;
65

76
namespace Assets.Common.StandardAssets.Utility
87
{

Diff for: Assets/Common/StandardAssets/Utility/TimedObjectActivator.cs

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using System.Collections;
3+
#if UNITY_EDITOR
34
using UnityEditor;
5+
#endif
46
using UnityEngine;
57
using UnityEngine.SceneManagement;
68

Diff for: Assets/Common/StandardAssets/Utility/WaypointCircuit.cs

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using System.Collections;
3+
#if UNITY_EDITOR
34
using UnityEditor;
5+
#endif
46
using UnityEngine;
57

68
namespace Assets.Common.StandardAssets.Utility

Diff for: unity-ui-examples.sln.DotSettings

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@
77
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/BRACES_FOR_FOREACH/@EntryValue">Required</s:String>
88
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/BRACES_FOR_IFELSE/@EntryValue">Required</s:String>
99
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/BRACES_FOR_WHILE/@EntryValue">Required</s:String>
10-
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/BRACES_REDUNDANT/@EntryValue">False</s:Boolean></wpf:ResourceDictionary>
10+
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/BRACES_REDUNDANT/@EntryValue">False</s:Boolean>
11+
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/BLANK_LINES_AROUND_FIELD/@EntryValue">0</s:Int64>
12+
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/BLANK_LINES_INSIDE_REGION/@EntryValue">0</s:Int64></wpf:ResourceDictionary>

0 commit comments

Comments
 (0)