static public void GraphField(float[] peaks) { EditorGUILayout.Space(); Rect rect = GUILayoutUtility.GetRect(120, 1000, 64, 64); GUI.BeginGroup(rect); #if UNITY_2017_2_OR_NEWER if (Event.current.type == EventType.Repaint) #else if (Event.current.type == EventType.repaint) #endif { GL.Clear(true, false, Color.grey); if (mat == null) { var shader = Shader.Find("Hidden/LDG/UI"); mat = new Material(shader); } mat.SetPass(0); // background DrawGL.Rect(rect, true, new Color(0.33f, 0.33f, 0.33f)); //if (masterLevel) { if (EditorApplication.isPlaying) { // draw spectrum #if UNITY_5_6_OR_NEWER GL.Begin(GL.LINE_STRIP); #else GL.Begin(GL.LINES); #endif for (int i = 0; i < rect.width; i++) { float iLevel = Spline.Tween((float)i / (rect.width - 1), peaks, false, InterpolationMode.Curve); GL.Color(new Color(0.0f, 0.75f, 0.0f)); GL.Vertex3(i, Mathf.Clamp01(1.0f - iLevel) * rect.height, 0); } GL.End(); } } // background outline DrawGL.Rect(rect, false, new Color(0.45f, 0.45f, 0.45f)); } GUI.EndGroup(); }
void OnDrawGL(object obj) { if (CameraMgr.instance == null) { return; } CameraHandle handle = CameraMgr.instance.CurHandle; if (handle == null) { return; } DrawGL draw = (DrawGL)obj; handle.OnDrawGL(draw); }
public void Draw(Transform transform, float layoutSize, float elementSize, float travel, bool isLine, bool anchored, float anchoredDiameter, Material material) { if (vertexElements == null || vertexElements.Length == 0) { return; } UpdateVertexBuffer(vertexElements.Length); if (material) { // Apply the line material material.SetPass(0); } for (int i = 0; i < vertexElements.Length; i++) { if (vertexElements[i].level) { vertices[i] = vertexElements[i].vertex + vertexElements[i].normal * vertexElements[i].level.fallingLevel * travel; normals[i] = vertexElements[i].normal; mainColors[i] = vertexElements[i].mainColor; restingColors[i] = vertexElements[i].restingColor; } } GL.PushMatrix(); GL.MultMatrix(transform.localToWorldMatrix); if (isLine) { DrawGL.Line(vertices, mainColors, elementSize, 10, false, InterpolationMode.Curve); } if (!isLine) { DrawGL.Ring(vertices, mainColors, restingColors, layoutSize, elementSize, 10, anchored, anchoredDiameter, InterpolationMode.Curve); } GL.PopMatrix(); }
public void OnDrawGL(DrawGL draw) { Gizmos.color = Color.white; Vector3 pos = m_info.refPos + Quaternion.Euler(0, m_info.horizontalAngle, 0) * m_info.offset; if (m_info.NeedShowRefPos) { draw.DrawSphere(Color.white, m_info.refPos, 0.5f); draw.DrawSphere(Color.yellow, pos, 0.5f); } if (m_info.uselock)//方向上的锁定 { draw.DrawLine(Color.yellow, pos, Quaternion.Euler(m_info.lockEuler) * Vector3.forward, 5); } //Quaternion rotate = Quaternion.Euler(m_info.verticalAngle, m_info.horizontalAngle, 0); //Vector3 forward = rotate * Vector3.forward; //draw.DrawSphere(Color.red, StillPos, 0.5f); //draw.DrawLine(Color.red, StillPos, forward, 5); }
public void OnEnable() { m_observer = DrawGL.Add(OnDrawGL); }
void Update() { if (Time.time - currentGestureStartTime > timeForCurrentGesture) { //Debug.Log("LOST"); string[] arr = bestResultTextGO.GetComponent <Text>().text.Split(':'); bestResultTextGO.GetComponent <Text>().text = arr[0] + string.Format(": {0:0}", Mathf.Max(Time.time - startTime, System.Convert.ToInt32(arr[1]))); onLost.Invoke(); return; } timerTextGO.GetComponent <Text>().text = timerTextGO.GetComponent <Text>().text.Split(':')[0] + string.Format(": {0:0}", timeForCurrentGesture - (Time.time - currentGestureStartTime)); if (!isSavingPoints) { if (Input.GetMouseButton(0)) { savedPoints.Clear(); bounds = null; } } else { if (!Input.GetMouseButton(0)) { GestureTask gestureTask = currentGesture.GetComponent <GestureTask>(); List <bool> touchedPoints = new List <bool>(); for (int i = 0; i < gestureTask.gestureVertices.Count; i++) { touchedPoints.Add(false); } for (int i = 0; i < savedPoints.Count; i++) { savedPoints[i] = new Vector2((savedPoints[i].x - bounds.Value.xMin) * gestureTask.bounds.width / bounds.Value.width + gestureTask.bounds.xMin, (savedPoints[i].y - bounds.Value.yMin) * gestureTask.bounds.height / bounds.Value.height + gestureTask.bounds.yMin); for (int j = 0; j < gestureTask.gestureVertices.Count; j++) { if ((savedPoints[i] - gestureTask.gestureVertices[j]).magnitude < threshold) { touchedPoints[j] = true; } } } bool isAllPointsTouched = true; for (int i = 0; i < touchedPoints.Count; i++) { if (!touchedPoints[i]) { isAllPointsTouched = false; break; } } if (isAllPointsTouched) { //Debug.Log("TIME TO CHECK LINES"); bool isCloseToLine = false; bool isAllPointsCloseToLine = true; for (int i = 0; i < savedPoints.Count; i++) { isCloseToLine = false; for (int j = 1; j < gestureTask.gestureVertices.Count; j++) { Vector2 line = gestureTask.gestureVertices[j] - gestureTask.gestureVertices[j - 1]; if ((Vector2.Dot(savedPoints[i] - gestureTask.gestureVertices[j - 1], line) * line / Mathf.Pow(line.magnitude, 2) + gestureTask.gestureVertices[j - 1] - savedPoints[i]).magnitude < threshold) { isCloseToLine = true; break; } } if (!isCloseToLine) { isAllPointsCloseToLine = false; break; } } if (isAllPointsCloseToLine) { //Debug.Log("VICTORY"); SetNextGesture(); } } } else { Vector2 point = Camera.main.ScreenToViewportPoint(Input.mousePosition); savedPoints.Add(point); bounds = DrawGL.UpdateBounds(bounds, point); } } isSavingPoints = Input.GetMouseButton(0); }
public static void Draw(RangeCfg cfg, DrawGL draw, Vector3 pos, Vector3 dir, Color clr, float factor = 0f) { if (!cfg.showRange) { return; } //碰撞类型的话画调线 if (cfg.type == enRangeType.collider) { if (cfg.heightLimit <= 0) { return; } draw.DrawLine(clr * 0.7f, pos + Vector3.up * cfg.heightLimit, pos - Vector3.up * cfg.heightLimit); return; } //下面是其他类型 //计算偏移后的点 float offsetAngle; Vector3 offsetPos; if (factor == 0) { offsetAngle = cfg.beginOffsetAngle; offsetPos = cfg.begingOffsetPos; } else if (factor == 1f) { offsetAngle = cfg.endOffsetAngle; offsetPos = cfg.endOffsetPos; } else { offsetAngle = Mathf.Lerp(cfg.beginOffsetAngle, cfg.endOffsetAngle, factor); offsetPos = Vector3.Lerp(cfg.begingOffsetPos, cfg.endOffsetPos, factor); } //计算偏移后的点 dir.y = 0;//y方向无效 if (offsetAngle != 0) { dir = Quaternion.Euler(0, offsetAngle, 0) * dir; } if (dir == Vector3.zero)//没有方向??? { return; } dir.y = 0; if (offsetPos != Vector3.zero) { pos += Quaternion.LookRotation(dir) * offsetPos; } float d2 = cfg.distance * 2; if (cfg.type == enRangeType.circle) { Vector3 scale = new Vector3(d2, cfg.heightLimit <= 0 ? 3 : cfg.heightLimit * 2, d2); draw.DrawCylinder(clr * 0.7f, pos, scale, Quaternion.LookRotation(dir)); } else if (cfg.type == enRangeType.sector) { Vector3 scale = new Vector3(d2, cfg.heightLimit <= 0 ? 3 : cfg.heightLimit * 2, d2); draw.DrawSectorCylinder(clr * 0.7f, cfg.angleLimit, pos, scale, Quaternion.LookRotation(dir)); } else if (cfg.type == enRangeType.rect) { pos += dir.normalized * cfg.distance / 2; Vector3 scale = new Vector3(cfg.rectLimit * 2, cfg.heightLimit <= 0 ? 3 : cfg.heightLimit * 2, cfg.distance); draw.DrawBox(clr * 0.7f, pos, scale, Quaternion.LookRotation(dir)); } }
void Start() { bounds = DrawGL.GetBounds(gestureVertices); }
static public float SpectrumField(SpectrumFilter spectrumFilter, float linearizedFrequency, float levelBeat) { float peakInverse; EditorGUILayout.Space(); Rect rect = GUILayoutUtility.GetRect(120, 1000, 64, 64); bool insideRect = rect.Contains(Event.current.mousePosition); if (rect.Contains(Event.current.mousePosition)) { mousePosition = Event.current.mousePosition - rect.min; GUI.changed = true; } #if UNITY_2017_2_OR_NEWER if (Event.current.type == EventType.MouseDown && insideRect) #else if (Event.current.type == EventType.mouseDown && insideRect) #endif { markerPos = Event.current.mousePosition - rect.min; linearizedFrequency = markerPos.x / rect.width; mouseDown = true; GUI.changed = true; } #if UNITY_2017_2_OR_NEWER else if (Event.current.type == EventType.MouseUp) #else else if (Event.current.type == EventType.mouseUp) #endif { mouseDown = false; } #if UNITY_2017_2_OR_NEWER if ((Event.current.type == EventType.MouseDrag && mouseDown)) #else if ((Event.current.type == EventType.mouseDrag && mouseDown)) #endif { markerPos = Event.current.mousePosition - rect.min; linearizedFrequency = markerPos.x / rect.width; GUI.changed = true; } linearizedFrequency = Mathf.Clamp01(linearizedFrequency); GUI.BeginGroup(rect); #if UNITY_2017_2_OR_NEWER if (Event.current.type == EventType.Repaint) #else if (Event.current.type == EventType.repaint) #endif { GL.Clear(true, false, Color.grey); if (mat == null) { var shader = Shader.Find("Hidden/LDG/UI"); mat = new Material(shader); } mat.SetPass(0); // background DrawGL.Rect(rect, true, new Color(0.33f, 0.33f, 0.33f)); if (spectrumFilter) { peakInverse = 1.0f - Mathf.Clamp01(levelBeat); // peak line DrawGL.Line(new Vector2(0, peakInverse * rect.height), new Vector2(rect.width, peakInverse * rect.height), new Color(0.15f, 0.15f, 0.15f)); // mouse x pos if (insideRect) { DrawGL.Line(new Vector2(mousePosition.x, 0), new Vector2(mousePosition.x, rect.height), new Color(0.15f, 0.15f, 0.15f)); } if (EditorApplication.isPlaying && Time.frameCount > 5) { //DrawGL.Curve(spectrumFilter.spectrumSource.normalizedPeaks, 1, rect.width, rect.height, new Color(0.2f, 0.2f, 0.2f)); DrawGL.Graph(spectrumFilter.fallingLevels, 1, rect.width, rect.height, new Color(0.0f, 0.5f, 1.0f), spectrumFilter.interpolationMode); // draw spectrum #if UNITY_5_6_OR_NEWER GL.Begin(GL.LINE_STRIP); for (int i = 0; i < rect.width; i++) { float iLevel = spectrumFilter.GetLevel((float)i / rect.width); GL.Color(new Color(0.0f, 0.75f, 0.0f)); GL.Vertex3(i, Mathf.Clamp01(1.0f - iLevel) * rect.height, 0); } #else GL.Begin(GL.LINES); Vector2 xy = Vector2.zero; Vector2 xyPrev = xy; for (int i = 0; i < rect.width; i++) { xy.Set(i, Mathf.Clamp01(1.0f - spectrumFilter.GetLevel((float)i / rect.width)) * rect.height); if (i > 0) { GL.Color(new Color(0.0f, 0.75f, 0.0f)); GL.Vertex3(xyPrev.x, xyPrev.y, 0); GL.Vertex3(xy.x, xy.y, 0); } xyPrev = xy; } #endif GL.End(); } } DrawGL.Line(new Vector2(linearizedFrequency * rect.width, 0), new Vector2(linearizedFrequency * rect.width, rect.height), new Color(0.95f, 0.2f, 0.2f)); // background outline DrawGL.Rect(rect, false, new Color(0.45f, 0.45f, 0.45f)); } GUI.EndGroup(); statsStyle.normal.textColor = new Color(0.8f, 0.8f, 0.8f); statsStyle.alignment = TextAnchor.UpperRight; float freq = Frequency.UnlinearizeFrequency(1.0f - Mathf.Clamp01(mousePosition.x / rect.width)); //GUI.Label(rect, "Freq: " + freq.ToString("n2") + ", Peak: " + levelBeat.ToString("n2") + " ", statsStyle); if (insideRect) { GUI.Label(rect, "Freq: " + freq.ToString("n2") + " ", statsStyle); } return(linearizedFrequency); }