maint: updated aline
This commit is contained in:
@@ -1,19 +1,16 @@
|
||||
// TODO: Check HDRP custom pass support, and log a warning if it is disabled
|
||||
#pragma warning disable 649 // Field `Drawing.GizmoContext.activeTransform' is never assigned to, and will always have its default value `null'. Not used outside of the unity editor.
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
#endif
|
||||
using System.Collections.Generic;
|
||||
using Unity.Jobs;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine.Rendering;
|
||||
using Unity.Profiling;
|
||||
#if MODULE_RENDER_PIPELINES_UNIVERSAL
|
||||
using UnityEngine.Rendering.Universal;
|
||||
using UnityEngine.Profiling;
|
||||
#endif
|
||||
#if MODULE_RENDER_PIPELINES_HIGH_DEFINITION
|
||||
using UnityEngine.Rendering.HighDefinition;
|
||||
@@ -140,6 +137,7 @@ namespace Drawing {
|
||||
public DrawingData gizmos;
|
||||
static List<GizmoDrawerGroup> gizmoDrawers = new List<GizmoDrawerGroup>();
|
||||
static Dictionary<System.Type, int> gizmoDrawerIndices = new Dictionary<System.Type, int>();
|
||||
static bool ignoreAllDrawing;
|
||||
static DrawingManager _instance;
|
||||
bool framePassed;
|
||||
int lastFrameCount = int.MinValue;
|
||||
@@ -238,6 +236,14 @@ namespace Drawing {
|
||||
};
|
||||
_instance = go.AddComponent<DrawingManager>();
|
||||
if (Application.isPlaying) DontDestroyOnLoad(go);
|
||||
|
||||
if (Application.isBatchMode) {
|
||||
// In batch mode, we never want to draw anything.
|
||||
// See https://forum.arongranberg.com/t/drawingmanager-holds-on-to-memory-in-batch-mode/17765
|
||||
ignoreAllDrawing = true;
|
||||
gizmoDrawers.Clear();
|
||||
gizmoDrawerIndices.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Detects which render pipeline is being used and configures them for rendering</summary>
|
||||
@@ -594,6 +600,10 @@ namespace Drawing {
|
||||
#if UNITY_EDITOR
|
||||
void DrawGizmos (bool usingRenderPipeline) {
|
||||
GizmoContext.SetDirty();
|
||||
|
||||
// Reduce overhead if there's nothing to render
|
||||
if (gizmoDrawers.Count == 0) return;
|
||||
|
||||
MarkerGizmosAllowed.Begin();
|
||||
|
||||
// Figure out which component types should be rendered
|
||||
@@ -721,6 +731,8 @@ namespace Drawing {
|
||||
/// The DrawGizmos method on the object will be called every frame until it is destroyed (assuming there are cameras with gizmos enabled).
|
||||
/// </summary>
|
||||
public static void Register (IDrawGizmos item) {
|
||||
if (ignoreAllDrawing) return;
|
||||
|
||||
var tp = item.GetType();
|
||||
|
||||
int index;
|
||||
@@ -782,9 +794,41 @@ namespace Drawing {
|
||||
|
||||
/// <summary>
|
||||
/// Get an empty builder for queuing drawing commands.
|
||||
/// TODO: Example usage.
|
||||
///
|
||||
/// <code>
|
||||
/// // Just a nice looking curve (which uses a lot of complex math)
|
||||
/// // See https://en.wikipedia.org/wiki/Butterfly_curve_(transcendental)
|
||||
/// static float2 ButterflyCurve (float t) {
|
||||
/// t *= 12 * math.PI;
|
||||
/// var k = math.exp(math.cos(t)) - 2*math.cos(4*t) - math.pow(math.sin(t/12f), 5);
|
||||
/// return new float2(k * math.sin(t), k * math.cos(t));
|
||||
/// }
|
||||
///
|
||||
/// // Make the butterfly "flap its wings" two times per second
|
||||
/// var scale = Time.time % 0.5f < 0.25f ? new float2(1, 1) : new float2(0.7f, 1);
|
||||
///
|
||||
/// // Hash all inputs that you use for drawing something complex
|
||||
/// var hasher = new DrawingData.Hasher();
|
||||
/// // The only thing making the drawing change, in this case, is the scale
|
||||
/// hasher.Add(scale);
|
||||
///
|
||||
/// // Try to draw a previously cached mesh with this hash
|
||||
/// if (!DrawingManager.TryDrawHasher(hasher)) {
|
||||
/// // If there's no cached mesh, then draw it from scratch
|
||||
/// using (var builder = DrawingManager.GetBuilder(hasher)) {
|
||||
/// // Draw a complex curve using 10000 lines
|
||||
/// var prev = ButterflyCurve(0);
|
||||
/// for (float t = 0; t < 1; t += 0.0001f) {
|
||||
/// var next = ButterflyCurve(t);
|
||||
/// builder.xy.Line(prev*scale, next*scale, Color.white);
|
||||
/// prev = next;
|
||||
/// }
|
||||
/// }
|
||||
/// }
|
||||
/// </code>
|
||||
///
|
||||
/// See: <see cref="Drawing.CommandBuilder"/>
|
||||
/// See: caching (view in online documentation for working links)
|
||||
/// </summary>
|
||||
/// <param name="hasher">Hash of whatever inputs you used to generate the drawing data.</param>
|
||||
/// <param name="redrawScope">Scope for this command builder. See #GetRedrawScope.</param>
|
||||
@@ -792,7 +836,50 @@ namespace Drawing {
|
||||
public static CommandBuilder GetBuilder(DrawingData.Hasher hasher, RedrawScope redrawScope = default, bool renderInGame = false) => instance.gizmos.GetBuilder(hasher, redrawScope, renderInGame);
|
||||
|
||||
/// <summary>
|
||||
/// A scope which can be used to draw things over multiple frames.
|
||||
/// Tries to draw a builder that was rendered during the last frame using the same hash.
|
||||
///
|
||||
/// Returns: True if the builder was found and scheduled for rendering. If false, you should draw everything again and submit a new command builder.
|
||||
///
|
||||
/// <code>
|
||||
/// // Just a nice looking curve (which uses a lot of complex math)
|
||||
/// // See https://en.wikipedia.org/wiki/Butterfly_curve_(transcendental)
|
||||
/// static float2 ButterflyCurve (float t) {
|
||||
/// t *= 12 * math.PI;
|
||||
/// var k = math.exp(math.cos(t)) - 2*math.cos(4*t) - math.pow(math.sin(t/12f), 5);
|
||||
/// return new float2(k * math.sin(t), k * math.cos(t));
|
||||
/// }
|
||||
///
|
||||
/// // Make the butterfly "flap its wings" two times per second
|
||||
/// var scale = Time.time % 0.5f < 0.25f ? new float2(1, 1) : new float2(0.7f, 1);
|
||||
///
|
||||
/// // Hash all inputs that you use for drawing something complex
|
||||
/// var hasher = new DrawingData.Hasher();
|
||||
/// // The only thing making the drawing change, in this case, is the scale
|
||||
/// hasher.Add(scale);
|
||||
///
|
||||
/// // Try to draw a previously cached mesh with this hash
|
||||
/// if (!DrawingManager.TryDrawHasher(hasher)) {
|
||||
/// // If there's no cached mesh, then draw it from scratch
|
||||
/// using (var builder = DrawingManager.GetBuilder(hasher)) {
|
||||
/// // Draw a complex curve using 10000 lines
|
||||
/// var prev = ButterflyCurve(0);
|
||||
/// for (float t = 0; t < 1; t += 0.0001f) {
|
||||
/// var next = ButterflyCurve(t);
|
||||
/// builder.xy.Line(prev*scale, next*scale, Color.white);
|
||||
/// prev = next;
|
||||
/// }
|
||||
/// }
|
||||
/// }
|
||||
/// </code>
|
||||
///
|
||||
/// See: caching (view in online documentation for working links)
|
||||
/// </summary>
|
||||
/// <param name="hasher">Hash of whatever inputs you used to generate the drawing data.</param>
|
||||
/// <param name="redrawScope">Optional redraw scope for this command builder. See #GetRedrawScope.</param>
|
||||
public static bool TryDrawHasher(DrawingData.Hasher hasher, RedrawScope redrawScope = default) => instance.gizmos.Draw(hasher, redrawScope);
|
||||
|
||||
/// <summary>
|
||||
/// A scope which will persist rendered items over multiple frames until it is disposed.
|
||||
///
|
||||
/// You can use <see cref="GetBuilder(RedrawScope,bool)"/> to get a builder with a given redraw scope.
|
||||
/// Everything drawn using the redraw scope will be drawn every frame until the redraw scope is disposed.
|
||||
@@ -811,6 +898,8 @@ namespace Drawing {
|
||||
/// redrawScope.Dispose();
|
||||
/// }
|
||||
/// </code>
|
||||
///
|
||||
/// See: caching (view in online documentation for working links)
|
||||
/// </summary>
|
||||
/// <param name="associatedGameObject">If not null, the scope will only be drawn if gizmos for the associated GameObject are drawn.
|
||||
/// This is useful in the unity editor when e.g. opening a prefab in isolation mode, to disable redraw scopes for objects outside the prefab. Has no effect in standalone builds.</param>
|
||||
|
||||
Reference in New Issue
Block a user