Skip to content

Commit 1f11c35

Browse files
committed
Update arrow view
1 parent 0f30488 commit 1f11c35

File tree

2 files changed

+49
-18
lines changed

2 files changed

+49
-18
lines changed

Editor/NoteArrowEditor.cs

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,27 @@ namespace DCFApixels.Notes.Editors
99
[InitializeOnLoad]
1010
public class NoteArrowEditor : Editor
1111
{
12-
private const float arrowHeight = 0.0085f;
12+
private struct Segment
13+
{
14+
public float halfHeight;
15+
public float lerpT;
16+
public Segment(float halfHeight, float lerpT)
17+
{
18+
this.halfHeight = halfHeight;
19+
this.lerpT = lerpT;
20+
}
21+
}
22+
private static float _heightMultiplier = 0.0215f;
23+
private static Segment[] _segments = new Segment[] {
24+
new Segment(0.00f / 2f, 0.00f * 0.99f),
25+
new Segment(0.66f / 2f, 0.01f * 0.97f),
26+
new Segment(1.00f / 2f, 0.04f * 0.94f),
27+
new Segment(0.55f / 2f, 0.20f * 0.90f),
28+
new Segment(0.15f / 2f, 0.55f * 0.90f),
29+
new Segment(0.00f / 2f, 1.00f * 0.85f),
30+
//new Segment(0.00f / 2f, 1.00f),
31+
};
32+
1333
[DrawGizmo(GizmoType.Active | GizmoType.NonSelected)]
1434
static void DrawGizmo(NoteArrow obj, GizmoType type)
1535
{
@@ -20,7 +40,7 @@ static void DrawGizmo(NoteArrow obj, GizmoType type)
2040
_arrows.Add(obj);
2141
}
2242
private static HashSet<NoteArrow> _arrows = new HashSet<NoteArrow>();
23-
private static HashSet<NoteArrow> _removedArrows = new HashSet<NoteArrow>();
43+
private static List<NoteArrow> _removedArrows = new List<NoteArrow>();
2444
static NoteArrowEditor()
2545
{
2646
SceneView.duringSceneGui += SceneView_duringSceneGui;
@@ -38,6 +58,8 @@ private static void SceneView_duringSceneGui(SceneView scene)
3858
_removedArrows.Add(item);
3959
}
4060
_arrows.SymmetricExceptWith(_removedArrows);
61+
62+
4163
foreach (var obj in _arrows)
4264
{
4365
if (obj.Target == null)
@@ -68,24 +90,36 @@ private static void SceneView_duringSceneGui(SceneView scene)
6890
toCameraDirection = camera.transform.position - startPoint;
6991
}
7092

71-
float height = arrowHeight * toCameraDirection.magnitude;
72-
7393
float startOffset = 0.02f * toCameraDirection.magnitude;
74-
float endOffset = 0.2f;
7594

7695
Vector3 direction = endPoint - startPoint;
77-
Quaternion q = Quaternion.LookRotation(toCameraDirection, direction);
78-
79-
endPoint -= direction.normalized * endOffset;
80-
startPoint = startPoint + q * (Vector3.up * startOffset);
96+
Quaternion rotation = Quaternion.LookRotation(toCameraDirection, direction);
97+
startPoint = startPoint + rotation * (Vector3.up * startOffset);
98+
direction = endPoint - startPoint;
8199

82-
Vector3 startPoint1 = startPoint + q * (Vector3.left * height / 2f);
83-
Vector3 startPoint2 = startPoint + q * (Vector3.right * height / 2f);
100+
//TODO çàìåíèòü îòðèñîâêó èêîíîê ñ Gizmos.DrawIcon íà GUI.DrawTexture, äëÿ áîëüøåé ãèáêîñòè
101+
//Handles.BeginGUI();
102+
//GUI.DrawTexture(new Rect(0, 0, 100, 100), tex, ScaleMode.StretchToFill, true, 10.0F);
103+
//Handles.EndGUI();
84104

85105
Handles.DrawLine(startPoint, endPoint);
86-
Handles.DrawLine(startPoint1, endPoint);
87-
Handles.DrawLine(startPoint2, endPoint);
88-
106+
Vector3 startPoint1 = Vector3.zero;
107+
Vector3 startPoint2 = Vector3.zero;
108+
for (int i = 0; i < _segments.Length; i++)
109+
{
110+
Segment segment = _segments[i];
111+
Vector3 lerpPoint = startPoint + direction.normalized * direction.magnitude * segment.lerpT;
112+
float height = segment.halfHeight * toCameraDirection.magnitude / 2f * _heightMultiplier;
113+
Vector3 endPoint1 = lerpPoint + rotation * (Vector3.left * height);
114+
Vector3 endPoint2 = lerpPoint + rotation * (Vector3.right * height);
115+
if (i > 0)
116+
{
117+
Handles.DrawLine(startPoint1, endPoint1);
118+
Handles.DrawLine(startPoint2, endPoint2);
119+
}
120+
startPoint1 = endPoint1;
121+
startPoint2 = endPoint2;
122+
}
89123
Handles.color = defaultColor;
90124
}
91125
}
@@ -106,9 +140,6 @@ public override void OnInspectorGUI()
106140
Rect rect = new Rect(0, 0, EditorGUIUtility.currentViewWidth, EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing * 2 + 9);
107141
EditorGUI.DrawRect(rect, color);
108142

109-
float labelWidth = EditorGUIUtility.labelWidth;
110-
EditorGUIUtility.labelWidth = 0;
111-
112143
EditorGUI.BeginChangeCheck();
113144
EditorGUILayout.PropertyField(targetProp);
114145
if (EditorGUI.EndChangeCheck())

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"displayName": "Notes",
99
"description": "",
1010
"unity": "2020.3",
11-
"version": "0.9.22",
11+
"version": "0.9.23",
1212
"repository": {
1313
"type": "git",
1414
"url": "https://github.com/DCFApixels/Notes-Unity.git"

0 commit comments

Comments
 (0)