Fixes and improvements, no more FindObjectsOfType
This commit is contained in:
1 parent
a740fec7c8
commit
fb002cbf0c
328 files changed
+4318
-299
No files matched your search
@@ -18,7 +18,7 @@ namespace Skopje.ThirdPerson
|
||||
{
|
||||
public const string PluginGuid = "com.skopje.thirdperson";
|
||||
public const string PluginName = "Skopje Third Person";
|
||||
public const string PluginVersion = "1.2.0";
|
||||
public const string PluginVersion = "1.3.0";
|
||||
|
||||
internal static ManualLogSource LogSource;
|
||||
|
||||
@@ -76,8 +76,6 @@ namespace Skopje.ThirdPerson
|
||||
Patch(AccessTools.Method(typeof(RenderPipelineManager), "BeginCameraRendering"), nameof(ThirdPersonPatches.AfterBeginCamera));
|
||||
Patch(AccessTools.Method(typeof(RenderPipelineManager), "EndCameraRendering"), nameof(ThirdPersonPatches.AfterEndCamera));
|
||||
Patch(AccessTools.Method(typeof(SkopjeCharacterController), "UpdateRotation"), nameof(ThirdPersonPatches.AfterBodyRotation), nameof(ThirdPersonPatches.BeforeBodyRotation));
|
||||
PatchInteract(AccessTools.Method(typeof(InteractController), "Update"));
|
||||
PatchInteract(AccessTools.Method(typeof(InteractController), "LateUpdate"));
|
||||
|
||||
LogSource.LogInfo($"{PluginName} {PluginVersion} loaded. Config: {Config.ConfigFilePath}");
|
||||
}
|
||||
@@ -96,21 +94,6 @@ namespace Skopje.ThirdPerson
|
||||
return true;
|
||||
}
|
||||
|
||||
static void PatchInteract(MethodInfo method)
|
||||
{
|
||||
if (method == null)
|
||||
{
|
||||
LogSource.LogWarning("Third person hook was not found: InteractController");
|
||||
return;
|
||||
}
|
||||
|
||||
_harmony.Patch(
|
||||
method,
|
||||
prefix: new HarmonyMethod(typeof(ThirdPersonPatches), nameof(ThirdPersonPatches.BeforeInteract)),
|
||||
postfix: new HarmonyMethod(typeof(ThirdPersonPatches), nameof(ThirdPersonPatches.AfterInteract)),
|
||||
finalizer: new HarmonyMethod(typeof(ThirdPersonPatches), nameof(ThirdPersonPatches.RestoreInteract)));
|
||||
}
|
||||
|
||||
static void Patch(MethodInfo method, string postfix, string prefix = null)
|
||||
{
|
||||
if (method == null)
|
||||
@@ -159,20 +142,5 @@ namespace Skopje.ThirdPerson
|
||||
ThirdPersonRig.HoldBodyFacing(__instance, ref currentRotation, deltaTime);
|
||||
}
|
||||
|
||||
public static void BeforeInteract()
|
||||
{
|
||||
ThirdPersonRig.HideBodiesFromInteract();
|
||||
}
|
||||
|
||||
public static void AfterInteract()
|
||||
{
|
||||
ThirdPersonRig.RestoreInteractLayers();
|
||||
}
|
||||
|
||||
public static Exception RestoreInteract(Exception __exception)
|
||||
{
|
||||
ThirdPersonRig.RestoreInteractLayers();
|
||||
return __exception;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,6 @@ namespace Skopje.ThirdPerson
|
||||
static readonly List<Renderer> ArmRenderers = new List<Renderer>();
|
||||
static readonly List<Renderer> ShadowOnly = new List<Renderer>();
|
||||
static readonly List<Collider> InteractColliders = new List<Collider>();
|
||||
static readonly List<int> InteractLayers = new List<int>();
|
||||
static readonly RaycastHit[] Hits = new RaycastHit[24];
|
||||
|
||||
static SkopjePlayer _player;
|
||||
@@ -64,8 +63,6 @@ namespace Skopje.ThirdPerson
|
||||
static Camera _viewCamera;
|
||||
static Vector3 _movePlanar;
|
||||
static float _turnSharpness;
|
||||
static int _interactMask = -1;
|
||||
static bool _layersShifted;
|
||||
static float _nextColliderScan;
|
||||
|
||||
public static void OnClientStarted()
|
||||
@@ -111,11 +108,10 @@ namespace Skopje.ThirdPerson
|
||||
|
||||
try
|
||||
{
|
||||
CacheInteractMask();
|
||||
if (Time.unscaledTime >= _nextColliderScan)
|
||||
{
|
||||
_nextColliderScan = Time.unscaledTime + 0.5f;
|
||||
CacheInteractColliders();
|
||||
SilenceBodyColliders();
|
||||
}
|
||||
|
||||
Present(_player, null);
|
||||
@@ -492,102 +488,37 @@ namespace Skopje.ThirdPerson
|
||||
cam.cullingMask |= _bodyLayers;
|
||||
}
|
||||
|
||||
public static void HideBodiesFromInteract()
|
||||
static void SilenceBodyColliders()
|
||||
{
|
||||
RestoreInteractLayers();
|
||||
if (_interactMask == 0 || InteractColliders.Count == 0)
|
||||
if (_player == null || _player.ThirdPerson == null)
|
||||
return;
|
||||
|
||||
int free = 2;
|
||||
if ((_interactMask & (1 << free)) != 0)
|
||||
{
|
||||
free = -1;
|
||||
for (int layer = 8; layer < 32; layer++)
|
||||
{
|
||||
if ((_interactMask & (1 << layer)) == 0)
|
||||
{
|
||||
free = layer;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (free < 0)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < InteractColliders.Count; i++)
|
||||
{
|
||||
Collider collider = InteractColliders[i];
|
||||
if (collider == null)
|
||||
{
|
||||
InteractLayers.Add(0);
|
||||
continue;
|
||||
}
|
||||
|
||||
int layer = collider.gameObject.layer;
|
||||
InteractLayers.Add(layer);
|
||||
if ((_interactMask & (1 << layer)) != 0)
|
||||
collider.gameObject.layer = free;
|
||||
}
|
||||
|
||||
_layersShifted = true;
|
||||
}
|
||||
|
||||
public static void RestoreInteractLayers()
|
||||
{
|
||||
if (!_layersShifted)
|
||||
return;
|
||||
|
||||
for (int i = InteractColliders.Count - 1; i >= 0; i--)
|
||||
{
|
||||
Collider collider = InteractColliders[i];
|
||||
if (collider != null && i < InteractLayers.Count)
|
||||
collider.gameObject.layer = InteractLayers[i];
|
||||
}
|
||||
|
||||
InteractLayers.Clear();
|
||||
_layersShifted = false;
|
||||
}
|
||||
|
||||
static void CacheInteractMask()
|
||||
{
|
||||
InteractController interact = _player.InteractController;
|
||||
if (interact == null)
|
||||
{
|
||||
_interactMask = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
_interactMask = interact.BlockingLayers.value | interact.InteractLayers.value;
|
||||
}
|
||||
|
||||
static void CacheInteractColliders()
|
||||
{
|
||||
if (_layersShifted)
|
||||
return;
|
||||
|
||||
InteractColliders.Clear();
|
||||
SkopjePlayer[] players = UnityEngine.Object.FindObjectsOfType<SkopjePlayer>();
|
||||
for (int i = 0; i < players.Length; i++)
|
||||
AddPlayerColliders(players[i]);
|
||||
}
|
||||
|
||||
static void AddPlayerColliders(SkopjePlayer player)
|
||||
{
|
||||
if (player == null || player.ThirdPerson == null)
|
||||
return;
|
||||
|
||||
Collider owner = player.OwnerCollider;
|
||||
Collider[] found = player.ThirdPerson.GetComponentsInChildren<Collider>(true);
|
||||
Collider owner = _player.OwnerCollider;
|
||||
Collider[] found = _player.ThirdPerson.GetComponentsInChildren<Collider>(true);
|
||||
for (int i = 0; i < found.Length; i++)
|
||||
{
|
||||
Collider collider = found[i];
|
||||
if (collider == null || collider.isTrigger || collider == owner || InteractColliders.Contains(collider))
|
||||
if (collider == null || collider.isTrigger || collider == owner || !collider.enabled)
|
||||
continue;
|
||||
if (InteractColliders.Contains(collider))
|
||||
continue;
|
||||
|
||||
collider.enabled = false;
|
||||
InteractColliders.Add(collider);
|
||||
}
|
||||
}
|
||||
|
||||
static void RestoreBodyColliders()
|
||||
{
|
||||
for (int i = 0; i < InteractColliders.Count; i++)
|
||||
{
|
||||
if (InteractColliders[i] != null)
|
||||
InteractColliders[i].enabled = true;
|
||||
}
|
||||
|
||||
InteractColliders.Clear();
|
||||
}
|
||||
|
||||
static void RestoreArms()
|
||||
{
|
||||
for (int i = 0; i < ArmRenderers.Count; i++)
|
||||
@@ -617,8 +548,7 @@ namespace Skopje.ThirdPerson
|
||||
if (_scaledThird && _thirdRoot != null)
|
||||
_thirdRoot.transform.localScale = _thirdScale;
|
||||
|
||||
RestoreInteractLayers();
|
||||
InteractColliders.Clear();
|
||||
RestoreBodyColliders();
|
||||
RestoreArms();
|
||||
BodyRenderers.Clear();
|
||||
ArmRenderers.Clear();
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -13,7 +13,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("Skopje.ThirdPerson")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+9f4f8bf5235790c04718d7ca24b0f3f76e93b270")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+a740fec7c87ba4b24aefb7faf991fc5b69c71bd4")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("Skopje.ThirdPerson")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("Skopje.ThirdPerson")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
@@ -1 +1 @@
|
||||
bc8b2b18196c3acb4bcc9f717e44bd539bfb6c46a1061eb8c275c7da7f6dfc9f
|
||||
c2aed9ec173430136e51ebe3f7189291e0c0c925543d2de9dee8a01a4853eae8
|
||||
Binary file not shown.
Binary file not shown.
Reference in new issue
Block a user