Skip to content
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

F priority workaround #123

Draft
wants to merge 2 commits into
base: mod
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
23 changes: 23 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,28 @@ 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))
{
float originalZ = base.transform.localPosition.z;

// This should work for all possible layers (technically would work for layers between 0-999)
base.transform.localPosition -= new Vector3(0, 0, thisLayerNumber * .0001f);

// 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}.\n" +
$"Z-position has been adjusted from {originalZ} to {base.transform.localPosition.z} to try to fix it.\n" +
$"NOTE: 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
Loading