-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMarkerRenderer.cs
More file actions
77 lines (64 loc) · 2.66 KB
/
MarkerRenderer.cs
File metadata and controls
77 lines (64 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System.Collections.Generic;
using UnityEngine;
namespace com.github.lhervier.ksp {
public class MarkerRenderer {
private Material lineMaterial;
public MarkerRenderer() {
Shader shader = Shader.Find("Hidden/Internal-Colored");
if( shader == null ) {
Logger.LogError("Shader 'Hidden/Internal-Colored' not found");
return;
}
lineMaterial = new Material(shader) {
hideFlags = HideFlags.HideAndDontSave
};
lineMaterial.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
lineMaterial.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
lineMaterial.SetInt("_Cull", (int)UnityEngine.Rendering.CullMode.Off);
lineMaterial.SetInt("_ZWrite", 0);
}
public void DrawMarkers(
List<VisualMarker> markers,
VisualMarker editingMarker = null
) {
if (lineMaterial == null || markers == null) return;
lineMaterial.SetPass(0);
GL.PushMatrix();
GL.LoadPixelMatrix();
foreach (var marker in markers) {
if (!marker.visible) continue;
DrawMarker(marker);
}
// Dessiner le marqueur d'aperçu s'il existe
if (editingMarker != null ) {
DrawMarker(editingMarker);
}
GL.PopMatrix();
}
private void DrawMarker(VisualMarker marker) {
Vector2 screenPos = new Vector2(
Screen.width * marker.positionX / 100f,
Screen.height * marker.positionY / 100f
);
if (marker.type == MarkerType.CrossLines) {
var crossLinesMarker = new CrossLinesMarker(screenPos, marker.color.ToColor());
crossLinesMarker.Draw();
} else if (marker.type == MarkerType.Circle) {
float radius = Screen.width * marker.radius / 100f;
var circleMarker = new CircleMarker(
screenPos,
radius,
marker.color.ToColor(),
marker.divisions
);
circleMarker.Draw();
}
}
public void Dispose() {
if (lineMaterial != null) {
Object.DestroyImmediate(lineMaterial);
lineMaterial = null;
}
}
}
}