forked from Summerfirefly/ASW
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathKerwisRedRound.cs
81 lines (79 loc) · 3.07 KB
/
KerwisRedRound.cs
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
78
79
80
81
using System;
using UnityEngine;
using UnityEngine.Rendering;
using Sonar;
namespace AntiSubmarineWeapon
{
public class KerwisRedRound : MonoBehaviour
{
public float nexttime = 0;
public static SonarSystem sonarSystem;
public static Material lineMaterial;
public static Vector2[,] vertexArray;
static void CreateLineMaterial()
{
if (!lineMaterial)
{
lineMaterial = new Material("Shader \"Lines/Colored Blended\" {" +
"SubShader { Pass { " +
" Blend SrcAlpha OneMinusSrcAlpha " +
" ZWrite Off Cull Off Fog { Mode Off } " +
" BindChannels {" +
" Bind \"vertex\", vertex Bind \"color\", color }" +
"} } }");
lineMaterial.hideFlags = HideFlags.HideAndDontSave;
lineMaterial.shader.hideFlags = HideFlags.HideAndDontSave;
// Turn on alpha blending
lineMaterial.SetInt("_SrcBlend", (int)BlendMode.SrcAlpha);
lineMaterial.SetInt("_DstBlend", (int)BlendMode.OneMinusSrcAlpha);
// Turn backface culling off
lineMaterial.SetInt("_Cull", (int)CullMode.Off);
// Turn off depth writes
lineMaterial.SetInt("_ZWrite", 0);
}
}
public static void start()
{
sonarSystem = new SonarSystem();
sonarSystem.Rposition(new Vector2(Screen.width / 2, Screen.height / 2), new Vector2(Screen.width, Screen.height));
sonarSystem.Round();
CreateLineMaterial();
}
//void Update()
//{
// if (Time.time > nexttime)
// {
// vertexArray = sonarSystem.DrawOuterCircle();
// nexttime = (float)(nexttime + 0.1);
// }
//}
void OnPostRender()
{
//Draw();
}
internal static void Draw()
{
if (!lineMaterial || vertexArray == null || sonarSystem == null)
start();
GL.PushMatrix();
GL.LoadPixelMatrix();
lineMaterial.SetPass(0);
GL.Color(new Color(1f,0.4f,0f));
GL.Begin(GL.LINES);
var length = vertexArray.GetLength(0);
var length2 = vertexArray.GetLength(1);
for (int index = 0; index < length; index++)
{
for (int index2 = 0; index2 < length2 - 1; index2++)
{
GL.Vertex3(vertexArray[index, index2].x, vertexArray[index, index2].y, 0);
GL.Vertex3(vertexArray[index, index2 + 1].x, vertexArray[index, index2 + 1].y, 0);
}
GL.Vertex3(vertexArray[index, 0].x, vertexArray[index, 0].y, 0);
GL.Vertex3(vertexArray[index, length2 - 1].x, vertexArray[index, length2 - 1].y, 0);
}
GL.End();
GL.PopMatrix();
}
}
}