Skip to content

Replace gizmos FindObjectsOfType with static list #6168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using System;
using UnityEngine.Serialization;
using UnityEditor.Experimental;
using Unity.Collections;
using System.Collections.Generic;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;
Expand Down Expand Up @@ -39,6 +35,7 @@ public class ProbeVolume : MonoBehaviour
[SerializeField] internal Matrix4x4 cachedTransform;
[SerializeField] internal int cachedHashCode;

#if UNITY_EDITOR
/// <summary>
/// Returns the extents of the volume.
/// </summary>
Expand All @@ -48,7 +45,6 @@ public Vector3 GetExtents()
return size;
}

#if UNITY_EDITOR
internal void UpdateGlobalVolume(Scene scene)
{
if (gameObject.scene != scene) return;
Expand Down Expand Up @@ -126,8 +122,6 @@ public override int GetHashCode()
return hash;
}

#endif

internal float GetMinSubdivMultiplier()
{
float maxSubdiv = ProbeReferenceVolume.instance.GetMaxSubdivision() - 1;
Expand All @@ -145,6 +139,8 @@ internal float GetMaxSubdivMultiplier()
// other non-hidden component related to APV.
#region APVGizmo

static List<ProbeVolume> sProbeVolumeInstances = new();

MeshGizmo brickGizmos;
MeshGizmo cellGizmo;

Expand All @@ -156,23 +152,19 @@ void DisposeGizmos()
cellGizmo = null;
}

void OnDestroy()
void OnEnable()
{
DisposeGizmos();
sProbeVolumeInstances.Add(this);
}

void OnDisable()
{
sProbeVolumeInstances.Remove(this);
DisposeGizmos();
}
#if UNITY_EDITOR

// Only the first PV of the available ones will draw gizmos.
bool IsResponsibleToDrawGizmo()
{
var pvList = GameObject.FindObjectsOfType<ProbeVolume>();
return this == pvList[0];
}
bool IsResponsibleToDrawGizmo() => sProbeVolumeInstances.Count > 0 && sProbeVolumeInstances[0] == this;

internal bool ShouldCullCell(Vector3 cellPosition, Vector3 originWS = default(Vector3))
{
Expand Down Expand Up @@ -219,7 +211,6 @@ void OnDrawGizmos()
cellSizeInMeters = profile.cellSizeInMeters;
}


if (debugDisplay.drawBricks)
{
var subdivColors = ProbeReferenceVolume.instance.subdivisionDebugColors;
Expand Down Expand Up @@ -327,8 +318,8 @@ IEnumerable<Vector4> GetVisibleCellCentersAndState()
cellGizmo.RenderWireframe(Gizmos.matrix, gizmoName: "Brick Gizmo Rendering");
}
}

#endif
#endregion

#endif // UNITY_EDITOR
}
} // UnityEngine.Experimental.Rendering.HDPipeline