-
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
438 additions
and
413 deletions.
There are no files selected for viewing
115 changes: 115 additions & 0 deletions
115
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,115 @@ | ||
// Beat Saber Custom Avatars - Custom player models for body presence in Beat Saber. | ||
// Copyright © 2018-2024 Nicolas Gnyra and Beat Saber Custom Avatars Contributors | ||
// | ||
// This library is free software: you can redistribute it and/or | ||
// modify it under the terms of the GNU Lesser General Public | ||
// License as published by the Free Software Foundation, either | ||
// version 3 of the License, or (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
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,41 @@ | ||
// Beat Saber Custom Avatars - Custom player models for body presence in Beat Saber. | ||
// Copyright © 2018-2024 Nicolas Gnyra and Beat Saber Custom Avatars Contributors | ||
// | ||
// This library is free software: you can redistribute it and/or | ||
// modify it under the terms of the GNU Lesser General Public | ||
// License as published by the Free Software Foundation, either | ||
// version 3 of the License, or (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
using UnityEngine; | ||
using UnityEngine.Serialization; | ||
|
||
namespace CustomAvatar | ||
{ | ||
public partial class EventManager | ||
{ | ||
[SerializeField] | ||
[FormerlySerializedAs("OnComboChanged")] | ||
private IntUnityEvent _comboIncreased; | ||
|
||
[SerializeField] | ||
[FormerlySerializedAs("MultiplierUp")] | ||
private IntUnityEvent _multiplierIncreased; | ||
|
||
[SerializeField] | ||
private IntUnityEvent _multiplierDecreased; | ||
|
||
public IntUnityEvent comboIncreased { get; private set; } | ||
|
||
public IntUnityEvent multiplierIncreased { get; private set; } | ||
|
||
public IntUnityEvent multiplierDecreased { get; private set; } | ||
} | ||
} |
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,95 @@ | ||
// Beat Saber Custom Avatars - Custom player models for body presence in Beat Saber. | ||
// Copyright © 2018-2024 Nicolas Gnyra and Beat Saber Custom Avatars Contributors | ||
// | ||
// This library is free software: you can redistribute it and/or | ||
// modify it under the terms of the GNU Lesser General Public | ||
// License as published by the Free Software Foundation, either | ||
// version 3 of the License, or (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
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.