Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
PUIExampleSineWaves.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using UnityEngine;
4using UnityEngine.UI;
5
7
8public class PUIExampleSineWaves : MonoBehaviour
9{
11
12 public Slider sliderPeriod;
13
14 public Slider sliderAmplitude;
15
16 public Slider sliderFrequency;
17
19
21
23
24 public float sampleSize = 0.01f;
25
27
29
31
32 private float lastSineProgress;
33
34 private void Start()
35 {
36 sliderPeriod.onValueChanged.AddListener(delegate
37 {
38 Draw();
39 });
40 sliderAmplitude.onValueChanged.AddListener(delegate
41 {
42 Draw();
43 });
44 sliderFrequency.onValueChanged.AddListener(delegate
45 {
46 Draw();
47 });
48 sinStrokeStyle = new StrokeStyle(Color.white, 0.025f, StrokeScaleMode.Relative);
51 }
52
53 private void Update()
54 {
55 Draw();
56 }
57
58 private void Draw()
59 {
61 float num = bgLinesStrokeStyle.thickness * (float)numBgLinesHorizontal;
62 float num2 = (1f - num) / (float)(numBgLinesHorizontal - 1);
63 float num3 = bgLinesStrokeStyle.thickness / 2f * (float)(numBgLinesHorizontal - 1);
64 for (int i = 0; i < numBgLinesHorizontal; i++)
65 {
66 float x = num3 + (float)i * num2;
67 primitiveCanvas.DrawLine(new Vector2(x, 0f), new Vector2(x, 1f), bgLinesStrokeStyle);
68 }
69 float num4 = bgLinesStrokeStyle.thickness * primitiveCanvas.aspectRatio;
71 int num5 = Mathf.CeilToInt(1f / (num4 + num2));
72 num3 = num4 / 2f * (float)(num5 - 1);
73 for (int j = 0; j < num5; j++)
74 {
75 float y = num3 + (float)j * num2;
76 primitiveCanvas.DrawLine(new Vector2(0f, y), new Vector2(1f, y), bgLinesStrokeStyle);
77 }
78 primitiveCanvas.DrawLine(new Vector2(0.5f, 0f), new Vector2(0.5f, 1f), centerLinesStrokeStyle);
79 primitiveCanvas.DrawLine(new Vector2(0f, 0.5f), new Vector2(1f, 0.5f), centerLinesStrokeStyle);
80 float num6 = 0.05f;
81 List<Vector2> list = new List<Vector2>();
82 for (float num7 = 0f - num6; num7 < 1f + num6; num7 += sampleSize)
83 {
84 float y2 = Mathf.Sin(MathF.PI * 2f / sliderPeriod.value * num7 * MathF.PI + lastSineProgress) * sliderAmplitude.value / 2f + 0.5f;
85 list.Add(new Vector2(num7, y2));
86 }
87 primitiveCanvas.DrawPath(list.ToArray(), sinStrokeStyle, closePath: false);
88 lastSineProgress += Time.deltaTime * sliderFrequency.value;
89 }
90}
void DrawPath(Vector2[] points)
void DrawLine(Vector2 point1, Vector2 point2)