public static DrawLine ( Vector2 start, Vector2 end, Color color, float width ) : void | ||
start | Vector2 | |
end | Vector2 | |
color | Color | |
width | float | |
Результат | void |
private void FixedUpdate() { if (!room.IsActive) { return; } curAngle = GetLookRotAngle(this.transform.position, targetMovePos); this.transform.localRotation = Quaternion.Euler(Vector3.forward * (curAngle)); if (room.IsAlert) { if (targetMovePos == (Vector2)PlayerManager.player.position && PlayerIsWithinRange(noticeRange)) { TryFire(); GLDraw.DrawLine(this.transform.position, targetMovePos, GameManager.roomGenerationFields.dangerColor); } else { rb.MovePosition(Vector3.MoveTowards(this.transform.position, targetMovePos, moveSpeed * Time.deltaTime * GameManager.timeScale)); GLDraw.DrawLine(this.transform.position, targetMovePos, GameManager.roomGenerationFields.warningColor); } } else { rb.MovePosition(Vector3.MoveTowards(this.transform.position, targetMovePos, moveSpeed * Time.deltaTime * GameManager.timeScale)); GLDraw.DrawLine(this.transform.position, targetMovePos, GameManager.roomGenerationFields.moveColor); if (PlayerIsWithinRange(noticeRange) && PlayerIsWithinFOV()) { GLDraw.DrawLine(this.transform.position, PlayerManager.player.position, GameManager.roomGenerationFields.warningColor); if (HasDirectLineOFSight(this.transform.position, PlayerManager.player.position, 0)) { AlertRoom(true); } } } }
public static void DrawTitleRect(Rect rect, string title, string content, Color color, Color bg, float width) { GLDraw.DrawFillBox(rect, color, bg, width); int top = 20; var lRect = new Rect(rect.x, rect.y + 2, rect.width, top); GLDraw.DrawLine( new Vector2(rect.x, lRect.yMax), new Vector2(rect.x + rect.width, lRect.yMax), color, 1); GUI.Label(lRect, title); var bRect = new Rect(rect.x, rect.y + top + 2, rect.width, rect.height - top); GUI.Label(bRect, content); }
private void AlertRoom(bool _status) { if (room.IsAlert && _status) { return; } room.IsAlert = _status; if (_status) { Physics2D.IgnoreLayerCollision(LayerMask.NameToLayer("Enemy"), LayerMask.NameToLayer("Enemy"), false); for (int i = 0; i < room.enemyTransforms.Count; i++) { GLDraw.DrawLine(this.transform.position, room.enemyTransforms[i].position, GameManager.roomGenerationFields.infoColor, 0.15f); } } else { //Physics2D.IgnoreLayerCollision(LayerMask.NameToLayer("Enemy"), LayerMask.NameToLayer("Enemy"), true); } }
private void OnGUI() { Repaint(); //GetPlayingInfo (); Color color = Color.black; float lS = 230; DrawOp(); if (data == null) { return; } _scroll = GUI.BeginScrollView(new Rect(0, 0, position.width - lS, position.height), _scroll, view); var currentView = new Rect(_scroll.x, _scroll.y, position.width - lS, position.height); BeginWindows(); var offsetX = 50; var offsetY = 10; var sizeX = 200; var sizeY = 60; var sizeYBase = 100; Vector2 cOffset = new Vector2(offsetX + sizeX + offsetX, offsetY); Vector2 eOffset = new Vector2(cOffset.x + sizeX + offsetX, offsetY); float maxY = 0; int indexC = 100; List <TargetPoint> cEndPoint = new List <TargetPoint> (); foreach (var i in data.Containers) { int indexE = indexC * 100;; var oldOffset = eOffset; var listEndPoint = new List <Vector2> (); foreach (var e in i.effectGroup) { var eRect = new Rect(eOffset, new Vector2(sizeX, sizeY)); if (Event.current.type == UnityEngine.EventType.ContextClick) { if (eRect.Contains(Event.current.mousePosition)) { GenericMenu m = new GenericMenu(); m.AddItem(new GUIContent("Delete"), false, DeleteEffectGroupDe, new DeleteEffectGroup { egroup = e, Container = i }); m.AddSeparator(""); m.AddItem(new GUIContent("Edit Effects"), false, ShowEffectGroup, e); m.ShowAsContext(); Event.current.Use(); } } if (DrawWindow(indexE, eRect, EffectWindow, e.key)) { ShowObject(e); } listEndPoint.Add(new Vector2(eOffset.x, eOffset.y + 5)); eOffset = new Vector2(eOffset.x, eOffset.y + offsetY + sizeY); indexE++; } var center = oldOffset.y + ((eOffset.y - oldOffset.y) / 2); if (maxY < center) { maxY = center; } var cRect = new Rect(new Vector2(cOffset.x, maxY), new Vector2(sizeX, sizeY)); if (DrawWindow(indexC, cRect, EventWindow, i.type.ToString())) { ShowObject(i); } if (IsRuning(i.type)) { cEndPoint.Add(new TargetPoint(Color.yellow, new Vector2(cOffset.x, maxY + 5), 2)); GLDraw.DrawBox(cRect, Color.yellow, 2); } else { cEndPoint.Add(new TargetPoint(color, new Vector2(cOffset.x, maxY + 5), 1)); } if (Event.current.type == UnityEngine.EventType.ContextClick) { if (cRect.Contains(Event.current.mousePosition)) { GenericMenu m = new GenericMenu(); m.AddItem(new GUIContent("Delete"), false, DeleteEvent, i); m.AddSeparator(""); m.AddItem(new GUIContent("Add Effect Group"), false, AddEffectGroup, i); if (!string.IsNullOrEmpty(i.layoutPath)) { m.AddItem(new GUIContent("Open Layout Editor"), false, OpenLayout, i); } m.ShowAsContext(); Event.current.Use(); } } var start = new Vector2(cOffset.x + sizeX, maxY + sizeY / 2); foreach (var p in listEndPoint) { if (currentView.Contains(start) && currentView.Contains(p)) { GLDraw.DrawConnectingCurve(start, p, color, 1); } } maxY += offsetY + sizeY; indexC++; } var rectBase = new Rect(new Vector2(offsetX, offsetY + maxY / 2), new Vector2(sizeX, sizeYBase)); if (Event.current.type == UnityEngine.EventType.ContextClick) { if (rectBase.Contains(Event.current.mousePosition)) { GenericMenu m = new GenericMenu(); m.AddItem(new GUIContent("Add Event"), false, AddEvent, data); m.AddSeparator(""); m.AddItem(new GUIContent("Save"), false, Save, data); m.AddItem(new GUIContent("Save As"), false, SaveAs, data); m.ShowAsContext(); Event.current.Use(); } } if (DrawWindow(0, rectBase, MagicWindow, data.name)) { ShowObject(data); } // content var startBase = new Vector2(offsetX + sizeX, offsetY + maxY / 2 + sizeYBase / 2); foreach (var p in cEndPoint) { if (currentView.Contains(startBase) && currentView.Contains(p.point)) { GLDraw.DrawConnectingCurve(startBase, p.point, p.color, p.withd); } } EndWindows(); GUI.EndScrollView(); view = new Rect(0, 0, eOffset.x + sizeX + offsetX, Mathf.Max(maxY, eOffset.y)); var view2P = new Rect(position.width - lS, 0, lS, position.height); GUILayout.BeginArea(view2P); GUILayout.BeginVertical(GUILayout.Width(lS - 10)); GUILayout.Label("Property"); scrollProperty = GUILayout.BeginScrollView(scrollProperty); GUILayout.BeginVertical(); if (currentObj != null) { PropertyDrawer.DrawObject(currentObj); } GUILayout.EndVertical(); GUILayout.EndScrollView(); GUILayout.EndVertical(); GUILayout.EndArea(); GLDraw.DrawLine(new Vector2(position.width - lS, 0), new Vector2(position.width - lS, position.height), color, 1); }
void OnGUI() { Repaint(); if (groupData == null) { return; } var leftWidth = 200; var height = 50; var color = Color.black; var topHeight = 25; var rectLeft = new Rect(0, topHeight, position.width - leftWidth, position.height - topHeight); //var rectRight = new Rect (rectLeft.width , 0, leftWidth , position.height); GUILayout.BeginArea(new Rect(0, 0, rectLeft.width, topHeight)); GUILayout.BeginHorizontal(GUILayout.Height(topHeight), GUILayout.Width(rectLeft.width)); index = EditorGUILayout.Popup(index, _effectNames); if (GUILayout.Button("Create", GUILayout.Width(70))) { if (index >= 0) { var t = _effects [index]; var effect = EffectBase.CreateInstance(t); groupData.Add(effect); } } GUILayout.EndHorizontal(); GUILayout.EndArea(); var re = new Rect(rectLeft); re.width = re.width + 20; _scroll = GUI.BeginScrollView(re, _scroll, new Rect(0, 0, rectLeft.width, groupData.Count * 50)); float h = 0; foreach (var i in groupData) { var attrs = i.GetType().GetCustomAttributes(typeof(EditorEffectAttribute), false) as EditorEffectAttribute[]; var name = i.GetType().Name; if (attrs.Length > 0) { name = attrs [0].Name; } var rect = new Rect(0, h, rectLeft.width, height); GUI.Label(new Rect(10, h + 5, 200, 16), name); GUI.Label(new Rect(10, h + 20, 200, 16), i.ToString()); GLDraw.DrawBox(rect, color, 1); if (current == i) { GLDraw.DrawBox(new Rect(rect.x + 2, rect.y + 2, rect.width - 4, rect.height - 4), Color.green, 2); } else { if (Event.current.type == UnityEngine.EventType.MouseDown) { if (rect.Contains(Event.current.mousePosition)) { current = i; Event.current.Use(); } } } if (Event.current.type == UnityEngine.EventType.ContextClick) { if (rect.Contains(Event.current.mousePosition)) { GenericMenu m = new GenericMenu(); m.AddItem(new GUIContent("Delete"), false, DeleteThis, i); m.ShowAsContext(); //Event.current.Use (); } } h += height; } GUI.EndScrollView(); GUILayout.BeginArea(new Rect(position.width - leftWidth + 16, 0, leftWidth - 20, position.height)); GUILayout.BeginVertical(); GUILayout.Label("Property", GUILayout.Height(20)); scrollProperty = GUILayout.BeginScrollView(scrollProperty); GUILayout.BeginVertical(); if (current != null) { PropertyDrawer.DrawObject(current, "EFFECT"); } GUILayout.EndVertical(); GUILayout.EndScrollView(); GUILayout.EndVertical(); GUILayout.EndArea(); GLDraw.DrawLine(new Vector2(rectLeft.width, 0), new Vector2(rectLeft.width, position.height), color, 1); }
void OnGUI() { GetPlayingInfo(); int offset = 2; Repaint(); var group = new Rect(5, position.height - 30, 250, 25); GUI.Box(new Rect(3, position.height - 55, 226, 50), "Operator"); GUILayout.BeginArea(group); GUILayout.BeginHorizontal(GUILayout.Width(250)); if (GUILayout.Button("Run", GUILayout.Width(50))) { //release PlayLayout(); } if (GUILayout.Button("Open", GUILayout.Width(50))) { Open(); } if (GUILayout.Button("Save", GUILayout.Width(50))) { Save(); } if (GUILayout.Button("Save As", GUILayout.Width(50))) { SaveAs(); } GUILayout.EndHorizontal(); GUILayout.EndArea(); if (line == null) { return; } int topHeight = 30; int leftWidth = 240; Color color = Color.black; var rectTop = new Rect(0, 0, position.width - leftWidth, topHeight); currentzTime = Mathf.Min(currentzTime, line.Time); if (currentObj == line) { if (Event.current.type == EventType.mouseDrag) { if (rectTop.Contains(Event.current.mousePosition)) { currentzTime = line.Time * (Event.current.mousePosition.x / rectTop.width); if (EditorApplication.isPaused) { if (currentzTime < s && lastStep != 0) { PlayLayout(); } s = Time.deltaTime; var now = (lastStep - 1) * s; if (now <= currentzTime) { if ((DateTime.Now - lastTime).TotalSeconds >= s) { lastTime = DateTime.Now; lastStep++; EditorApplication.Step(); //currentzTime = now; } } } Event.current.Use(); } } } if (Event.current.type == EventType.ContextClick) { if (rectTop.Contains(Event.current.mousePosition)) { GenericMenu m = new GenericMenu(); //m.AddItem (new GUIContent ("查看属性"), false, ShowProperty, line); m.AddSeparator(""); foreach (var i in _layouts) { m.AddItem(new GUIContent(i.Value), false, CreateLayout, i.Key); } m.ShowAsContext(); Event.current.Use(); } } if (currentObj != line) { if (Event.current.type == EventType.mouseDown) { if (rectTop.Contains(Event.current.mousePosition)) { ShowProperty(line); Event.current.Use(); } } } int layoutHeight = 35; var viewLayout = new Rect(0, topHeight, rectTop.width + 18, position.height - topHeight); var vewSize = new Rect(0, 0, rectTop.width, line.Layouts.Count * (layoutHeight + 1)); _scroll = GUI.BeginScrollView(viewLayout, _scroll, vewSize); for (var i = 0; i < line.Layouts.Count; i++) { var l = line.Layouts[i]; var points = line.FindPointByGuid(l.GUID); var rect = new Rect(0, i * (layoutHeight + 1), rectTop.width, layoutHeight); //var name = string.Empty; var attrs = l.GetType().GetCustomAttributes(typeof(EditorLayoutAttribute), false) as EditorLayoutAttribute[]; if (attrs.Length > 0) { name = attrs[0].Name; } GLDraw.DrawBox(rect, currentObj == l? Color.green:color, 1); foreach (var point in points) { var time = point.Time; int withd = 1; float xt = rect.width * (time / line.Time); var rectTick = new Rect(xt - 5, rect.yMin, 10, rect.height); //GLDraw.DrawBox(rectTick, Color.yellow, 2); if (Event.current.type == EventType.ContextClick) { if (rectTick.Contains(Event.current.mousePosition)) { GenericMenu m = new GenericMenu(); m.AddItem(new GUIContent("DeletePoint"), false, DeletePoint, point); m.ShowAsContext(); Event.current.Use(); } } if (currentPoint == point) { withd = 2; } else { if (Event.current.type == EventType.mouseDown) { if (rectTick.Contains(Event.current.mousePosition)) { currentPoint = point; } } } GLDraw.DrawLine(new Vector2(xt, rect.y), new Vector2(xt, rect.y + rect.height), color, 1); GLDraw.DrawTick(new Vector2(xt, rect.y), color, withd, rect.height); GUI.Label(new Rect(xt, rect.y + 2, 200, 16), string.Format("{0:0.00}s", time)); } if (Event.current.type == EventType.mouseDrag) { if (rect.Contains(Event.current.mousePosition)) { if (currentPoint != null && currentPoint.GUID == l.GUID) { var rT = line.Time * Event.current.mousePosition.x / rect.width; currentPoint.Time = rT; Event.current.Use(); } } } if (Event.current.type == EventType.ContextClick) { if (rect.Contains(Event.current.mousePosition)) { GenericMenu m = new GenericMenu(); m.AddItem(new GUIContent("AddPoint"), false, AddPoint, l); m.AddSeparator("-"); m.AddItem(new GUIContent("DeleteLayout"), false, DeleteLayout, l); //m.AddSeparator (""); m.ShowAsContext(); Event.current.Use(); } } if (currentObj != l) { if (Event.current.type == EventType.mouseDown) { if (rect.Contains(Event.current.mousePosition)) { if (currentObj != l) { ShowProperty(l);// currentObj ; } Event.current.Use(); } } } GUI.Label(new Rect(2, rect.y + 16, 300, 20), l.ToString()); } GUI.EndScrollView(); GUILayout.BeginArea(new Rect(position.width - leftWidth, 0, leftWidth, position.height)); scrollProperty = GUILayout.BeginScrollView(scrollProperty); GUILayout.BeginVertical(GUILayout.Width(leftWidth - 25), GUILayout.Height(position.height - 2)); if (currentObj != null) { PropertyDrawer.DrawObject(currentObj); } GUILayout.EndVertical(); GUILayout.EndScrollView(); GUILayout.EndArea(); //selected if (currentObj == line) { GLDraw.DrawBox( new Rect(rectTop.x + offset, rectTop.y + offset, rectTop.width - offset * 2, rectTop.height - offset * 2), Color.green, 2); } //show Lines GUI.Label(new Rect(0, 0, 200, 20), string.Format("Time: {1:0.0}s of {0:0.0}s ", line.Time, currentzTime)); var count = (int)((rectTop.width / 100) * 10); float x = 0; for (var i = 0; i <= count; i++) { //pre100FixeTick float h = 0; if (i % 10 == 0) { h = rectTop.height; } else if (i % 5 == 0) { h = rectTop.height * 0.5f; } else { h = rectTop.height * 0.2f; } GLDraw.DrawLine(new Vector2(x, topHeight), new Vector2(x, topHeight - h), color, 1); if (h == rectTop.height) { GUI.Label(new Rect(x, 16, 20, 20), string.Format("{0:0.0}", line.Time * ((float)i / (float)count))); } x += (100 / pre100FixeTick); } { var w = rectTop.width * (currentzTime / line.Time); GLDraw.DrawLine(new Vector2(rectTop.width, 0), new Vector2(rectTop.width, position.height), color, 1); GLDraw.DrawLine(new Vector2(0, topHeight), new Vector2(rectTop.width, topHeight), color, 1); GLDraw.DrawLine(new Vector2(w, 0), new Vector2(w, position.height), Color.green, 1); } if (currentRunTime != null) { var w = rectTop.width * (currentRunTime.Value / line.Time); GUI.Label(new Rect(w, topHeight, 50, 20), string.Format("{0:0.0}s", (float)currentRunTime.Value)); GLDraw.DrawLine(new Vector2(w, 0), new Vector2(w, position.height), Color.yellow, 2); } }