Skip to content

Commit

Permalink
Log when two layers use the same priority
Browse files Browse the repository at this point in the history
  • Loading branch information
drojf committed Mar 13, 2024
1 parent ced9302 commit f01c034
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Assets.Scripts.Core.Scene/Layer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Assets.Scripts.Core.AssetManagement;
using MOD.Scripts.Core;
using MOD.Scripts.Core.Scene;
using System.Collections;
using System.IO;
Expand Down Expand Up @@ -651,6 +652,22 @@ public void SetPriority(int newpriority)
Vector3 localPosition2 = base.transform.localPosition;
targetPosition = new Vector3(x, localPosition2.y, (float)Priority * -0.1f);
base.transform.localPosition = targetPosition;

try
{
if (GameSystem.Instance.SceneController.PriorityInUseByOtherLayer(this, out int layerUsingPriority, out int thisLayerNumber))
{
// In-engine "Priority" is 1 higher than the priority you specify in the game script.
MODLogger.Log(
$"WARNING: Attempted to use [Layer {thisLayerNumber}] with priority {Priority - 1}, " +
$"but [Layer {layerUsingPriority}] is already using priority {Priority - 1}. " +
$"This layer may not be drawn correctly/graphical artifacts may occur.", true);
}
}
catch (System.Exception e)
{
MODLogger.Log($"Error while checking Layer Priority: {e}", true);
}
}

public void FadeInLayer(float time)
Expand Down
38 changes: 38 additions & 0 deletions Assets.Scripts.Core.Scene/SceneController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,44 @@ public void RemoveLayerReference(Layer l)
}
}

public bool PriorityInUseByOtherLayer(Layer layerToCheck, out int layerUsingPriority, out int layerToCheckNumber)
{
layerToCheckNumber = -1;
layerUsingPriority = -1;

for (int id = 0; id < layers.Length; id++)
{
if (layers[id] == null)
{
continue;
}

if (LayerPool.IsInPool(layers[id].gameObject))
{
continue;
}

if (!layers[id].IsInUse)
{
continue;
}

// Don't check layer against itself
if (layers[id].gameObject == layerToCheck.gameObject)
{
layerToCheckNumber = id;
continue;
}

if (layers[id].Priority == layerToCheck.Priority)
{
layerUsingPriority = id;
}
}

return layerUsingPriority != -1;
}

public int GetActiveLayerMask()
{
if (activeScene == 0)
Expand Down

0 comments on commit f01c034

Please sign in to comment.