/// <summary> /// Show the scene view editor for editing waypoints. /// </summary> virtual protected void ShowEditWaypoints(EnemyMovement_WaypointMover movement) { GUIStyle centeredLabelStyle = GUI.skin.GetStyle("Label"); centeredLabelStyle.alignment = TextAnchor.UpperCenter; for (int i = 0; i < movement.wayPoints.Count; i++) { if (Event.current.shift && movement.wayPoints.Count > 2) { if (DrawRemoveHandle(movement.wayPoints[i])) { movement.wayPoints.RemoveAt(i); EditorUtility.SetDirty(movement); return; } } else { Vector2 newPosition = DrawMoveHandle(movement.wayPoints[i]); if (newPosition != movement.wayPoints[i]) { movement.wayPoints[i] = newPosition; EditorUtility.SetDirty(movement); } } if (i > 0) { if (DrawAddHandle(movement.wayPoints[i], movement.wayPoints[i - 1])) { movement.wayPoints.Insert(i, (movement.wayPoints[i] + movement.wayPoints[i - 1]) / 2.0f); EditorUtility.SetDirty(movement); } } else if (movement.loop) { if (DrawAddHandle(movement.wayPoints[i], movement.wayPoints[movement.wayPoints.Count - 1])) { movement.wayPoints.Add((movement.wayPoints[i] + movement.wayPoints[movement.wayPoints.Count - 1]) / 2.0f); EditorUtility.SetDirty(movement); } } } }
/// <summary> /// Show the scene view editor for editing waypoints. /// </summary> virtual protected void ShowWaypoints(EnemyMovement_WaypointMover movement) { GUIStyle centeredLabelStyle = GUI.skin.GetStyle("Label"); centeredLabelStyle.alignment = TextAnchor.UpperCenter; Handles.color = handleColor; for (int i = 0; i < movement.wayPoints.Count; i++) { if (i == 0 && movement.loop) { Handles.DrawLine(movement.wayPoints[movement.wayPoints.Count - 1], movement.wayPoints[i]); Vector2 v = movement.wayPoints[i] - movement.wayPoints[movement.wayPoints.Count - 1]; v = Vector3.Cross(v, Vector3.forward); v.Normalize(); Vector2 a1 = (Vector2)(Quaternion.Euler(0, 0, -60) * (0.5f * v)) + movement.wayPoints[i]; Vector2 a2 = (Vector2)(Quaternion.Euler(0, 0, 60) * (-0.5f * v)) + movement.wayPoints[i]; Handles.DrawLine(a1, movement.wayPoints[i]); Handles.DrawLine(a2, movement.wayPoints[i]); } if (i != 0) { Handles.DrawLine(movement.wayPoints[i - 1], movement.wayPoints[i]); //Handles.DrawLine( movement.wayPoints[i], a2); Vector2 v = movement.wayPoints[i] - movement.wayPoints[i - 1]; v = Vector3.Cross(v, Vector3.forward); v.Normalize(); Vector2 a1 = (Vector2)(Quaternion.Euler(0, 0, -60) * (0.5f * v)) + movement.wayPoints[i]; Vector2 a2 = (Vector2)(Quaternion.Euler(0, 0, 60) * (-0.5f * v)) + movement.wayPoints[i]; Handles.DrawLine(a1, movement.wayPoints[i]); Handles.DrawLine(a2, movement.wayPoints[i]); } } }