-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move large conditional blocks to partial classes
- Loading branch information
Showing
7 changed files
with
451 additions
and
439 deletions.
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
Source/CustomAvatar-Editor/Scripts/AvatarDescriptor.Editor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
using System.IO; | ||
using System.Reflection; | ||
using UnityEngine; | ||
|
||
namespace CustomAvatar | ||
{ | ||
public partial class AvatarDescriptor | ||
{ | ||
private Mesh _saberMesh; | ||
|
||
protected void OnDrawGizmos() | ||
{ | ||
if (!isActiveAndEnabled) return; | ||
if (!_saberMesh) _saberMesh = LoadMesh(Assembly.GetExecutingAssembly().GetManifestResourceStream("CustomAvatar.Resources.saber.dat")); | ||
|
||
DrawSaber(transform.Find("LeftHand"), _saberMesh, new Color(0.78f, 0.08f, 0.08f)); | ||
DrawSaber(transform.Find("RightHand"), _saberMesh, new Color(0, 0.46f, 0.82f)); | ||
} | ||
|
||
private Mesh LoadMesh(Stream stream) | ||
{ | ||
var mesh = new Mesh(); | ||
|
||
using (var reader = new BinaryReader(stream)) | ||
{ | ||
int length = reader.ReadInt32(); | ||
var vertices = new Vector3[length]; | ||
|
||
for (int i = 0; i < length; i++) | ||
{ | ||
vertices[i] = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); | ||
} | ||
|
||
length = reader.ReadInt32(); | ||
var normals = new Vector3[length]; | ||
|
||
for (int i = 0; i < length; i++) | ||
{ | ||
normals[i] = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); | ||
} | ||
|
||
length = reader.ReadInt32(); | ||
int[] triangles = new int[length]; | ||
|
||
for (int i = 0; i < length; i++) | ||
{ | ||
triangles[i] = reader.ReadInt32(); | ||
} | ||
|
||
mesh.SetVertices(vertices); | ||
mesh.SetNormals(normals); | ||
mesh.SetTriangles(triangles, 0); | ||
} | ||
|
||
return mesh; | ||
} | ||
|
||
internal void SaveMesh(Mesh mesh) | ||
{ | ||
using (var writer = new BinaryWriter(File.OpenWrite("mesh.dat"))) | ||
{ | ||
writer.Write(mesh.vertices.Length); | ||
|
||
foreach (Vector3 vertex in mesh.vertices) | ||
{ | ||
writer.Write(vertex.x); | ||
writer.Write(vertex.y); | ||
writer.Write(vertex.z); | ||
} | ||
|
||
writer.Write(mesh.normals.Length); | ||
|
||
foreach (Vector3 normal in mesh.normals) | ||
{ | ||
writer.Write(normal.x); | ||
writer.Write(normal.y); | ||
writer.Write(normal.z); | ||
} | ||
|
||
writer.Write(mesh.triangles.Length); | ||
|
||
foreach (int triangle in mesh.triangles) | ||
{ | ||
writer.Write(triangle); | ||
} | ||
} | ||
} | ||
|
||
private void DrawSaber(Transform transform, Mesh mesh, Color color) | ||
{ | ||
if (!transform) return; | ||
|
||
Color prev = Gizmos.color; | ||
Gizmos.color = color; | ||
Gizmos.DrawMesh(mesh, transform.position, transform.rotation, Vector3.one); | ||
Gizmos.color = prev; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using UnityEngine; | ||
using UnityEngine.Events; | ||
using UnityEngine.Serialization; | ||
|
||
namespace CustomAvatar | ||
{ | ||
public partial class EventManager | ||
{ | ||
[SerializeField] | ||
[FormerlySerializedAs("OnSlice")] | ||
private UnityEvent _leftGoodCut; | ||
|
||
[SerializeField] | ||
[FormerlySerializedAs("OnSlice")] | ||
private UnityEvent _rightGoodCut; | ||
|
||
[SerializeField] | ||
private UnityEvent _leftBadCut; | ||
|
||
[SerializeField] | ||
private UnityEvent _rightBadCut; | ||
|
||
[SerializeField] | ||
private UnityEvent _leftNoteMissed; | ||
|
||
[SerializeField] | ||
private UnityEvent _rightNoteMissed; | ||
|
||
[SerializeField] | ||
[FormerlySerializedAs("SaberStartColliding")] | ||
private UnityEvent _leftSaberStartedColliding; | ||
|
||
[SerializeField] | ||
[FormerlySerializedAs("SaberStartColliding")] | ||
private UnityEvent _rightSaberStartedColliding; | ||
|
||
[SerializeField] | ||
[FormerlySerializedAs("SaberStopColliding")] | ||
private UnityEvent _leftSaberStoppedColliding; | ||
|
||
[SerializeField] | ||
[FormerlySerializedAs("SaberStopColliding")] | ||
private UnityEvent _rightSaberStoppedColliding; | ||
|
||
[SerializeField] | ||
[FormerlySerializedAs("OnComboChanged")] | ||
private IntUnityEvent _comboIncreased; | ||
|
||
[SerializeField] | ||
[FormerlySerializedAs("OnComboBreak")] | ||
private UnityEvent _comboBroken; | ||
|
||
[SerializeField] | ||
[FormerlySerializedAs("MultiplierUp")] | ||
private IntUnityEvent _multiplierIncreased; | ||
|
||
[SerializeField] | ||
private IntUnityEvent _multiplierDecreased; | ||
|
||
[SerializeField] | ||
[FormerlySerializedAs("OnLevelStart")] | ||
private UnityEvent _levelStarted; | ||
|
||
[SerializeField] | ||
[FormerlySerializedAs("OnLevelFinish")] | ||
private UnityEvent _levelFinished; | ||
|
||
[SerializeField] | ||
[FormerlySerializedAs("OnLevelFail")] | ||
private UnityEvent _levelFailed; | ||
|
||
[SerializeField] | ||
[FormerlySerializedAs("OnMenuEnter")] | ||
private UnityEvent _menuEntered; | ||
|
||
[SerializeField] | ||
private UnityEvent _multiplayerLobbyEntered; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace CustomAvatar | ||
{ | ||
public partial class VRIKManager | ||
{ | ||
private GUIStyle _redLabelStyle; | ||
private GUIStyle _greenLabelStyle; | ||
private GUIStyle _blueLabelStyle; | ||
|
||
protected void OnDrawGizmosSelected() | ||
{ | ||
if (_redLabelStyle == null) | ||
{ | ||
_redLabelStyle = new GUIStyle(EditorStyles.label); | ||
_redLabelStyle.normal.textColor = Color.red; | ||
} | ||
|
||
if (_greenLabelStyle == null) | ||
{ | ||
_greenLabelStyle = new GUIStyle(EditorStyles.label); | ||
_greenLabelStyle.normal.textColor = Color.green; | ||
} | ||
|
||
if (_blueLabelStyle == null) | ||
{ | ||
_blueLabelStyle = new GUIStyle(EditorStyles.label); | ||
_blueLabelStyle.normal.textColor = Color.blue; | ||
} | ||
|
||
DrawHandAxes(references_leftHand, solver_leftArm_wristToPalmAxis, solver_leftArm_palmToThumbAxis, true); | ||
DrawHandAxes(references_rightHand, solver_rightArm_wristToPalmAxis, solver_rightArm_palmToThumbAxis, false); | ||
} | ||
|
||
private void DrawHandAxes(Transform reference, Vector3 wristToPalmAxis, Vector3 palmToThumbAxis, bool invertNormal) | ||
{ | ||
if (!reference) | ||
{ | ||
return; | ||
} | ||
|
||
Vector3 wristToPalmVector = default; | ||
Vector3 palmToThumbVector = default; | ||
|
||
if (wristToPalmAxis.sqrMagnitude > 0) | ||
{ | ||
wristToPalmVector = reference.rotation * wristToPalmAxis.normalized; | ||
|
||
Handles.color = Color.green; | ||
Handles.ArrowHandleCap(0, reference.position, Quaternion.LookRotation(wristToPalmVector), 0.1f, EventType.Repaint); | ||
Handles.Label(reference.position + wristToPalmVector * 0.12f, "Wrist to Palm Axis", _greenLabelStyle); | ||
} | ||
|
||
if (palmToThumbAxis.sqrMagnitude > 0) | ||
{ | ||
palmToThumbVector = reference.rotation * palmToThumbAxis.normalized; | ||
|
||
Handles.color = Color.red; | ||
Handles.ArrowHandleCap(0, reference.position, Quaternion.LookRotation(palmToThumbVector), 0.1f, EventType.Repaint); | ||
Handles.Label(reference.position + palmToThumbVector * 0.12f, "Palm to Thumb Axis", _redLabelStyle); | ||
} | ||
|
||
if (wristToPalmAxis.sqrMagnitude > 0 && palmToThumbAxis.sqrMagnitude > 0) | ||
{ | ||
Vector3 planeNormal = new Plane(reference.position, reference.position + wristToPalmVector, reference.position + palmToThumbVector).normal; | ||
|
||
if (invertNormal) | ||
{ | ||
planeNormal = -planeNormal; | ||
} | ||
|
||
Handles.color = Color.blue; | ||
Handles.ArrowHandleCap(0, reference.position, Quaternion.LookRotation(planeNormal), 0.1f, EventType.Repaint); | ||
Handles.Label(reference.position + planeNormal * 0.12f, "Palm Inside Axis", _blueLabelStyle); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.