-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c5162f5
commit 48c2880
Showing
20 changed files
with
1,076 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System.Collections; | ||
using BepInEx.Unity.IL2CPP.Utils; | ||
using Jungle.Player.Managers; | ||
using UnityEngine; | ||
|
||
namespace Jungle.Effects.DefaultEffects; | ||
|
||
public abstract class CoroutineEffect : IPlayerEffect | ||
{ | ||
public float Timer { get; set; } = 1; | ||
public PlayerManager Owner { get; set; } = null!; | ||
public Coroutine EffectRoutine { get; set; } = null!; | ||
|
||
public virtual void Awake() | ||
{ | ||
EffectRoutine = Owner.StartCoroutine(CoEffect()); | ||
} | ||
|
||
public abstract IEnumerator CoEffect(); | ||
|
||
public virtual void Cancel() | ||
{ | ||
Owner.StopCoroutine(EffectRoutine); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace Jungle.Effects; | ||
|
||
public interface IEffect | ||
{ | ||
public float Timer { get; set; } | ||
|
||
public virtual void Awake() { } | ||
public virtual void Update() { } | ||
public virtual void LateUpdate() { } | ||
public virtual void FixedUpdate() { } | ||
public virtual void OnDestroy() { } | ||
public virtual void Cancel() { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Jungle.Player.Managers; | ||
|
||
namespace Jungle.Effects; | ||
|
||
public interface IPlayerEffect : IEffect | ||
{ | ||
public PlayerManager Owner { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Il2CppInterop.Runtime.Attributes; | ||
using Reactor.Networking.Rpc; | ||
using Reactor.Utilities.Attributes; | ||
using UnityEngine; | ||
|
||
namespace Jungle.Effects.Managers; | ||
|
||
[RegisterInIl2Cpp] | ||
public class GlobalEffectManager : MonoBehaviour, IEffectManager | ||
{ | ||
public GlobalEffectManager(IntPtr ptr) : base(ptr) | ||
{ | ||
} | ||
|
||
public static GlobalEffectManager Instance { get; set; } | ||
|
||
public static List<PlayerEffectManager> PlayerEffectManagers { get; } = new(); | ||
|
||
private IEffect _primaryEffect; | ||
|
||
[HideFromIl2Cpp] | ||
public IEffect PrimaryEffect | ||
{ | ||
get => _primaryEffect; | ||
set | ||
{ | ||
foreach (PlayerEffectManager playerEffectManager in PlayerEffectManagers) playerEffectManager.PrimaryEffect = null; | ||
|
||
IEffect current = PrimaryEffect; | ||
if (current is not null) | ||
{ | ||
current.Cancel(); | ||
RemoveEffect(current); | ||
} | ||
|
||
_primaryEffect = value; | ||
} | ||
} | ||
|
||
[HideFromIl2Cpp] | ||
public List<IEffect> Effects { get; } = new(); | ||
|
||
[HideFromIl2Cpp] | ||
public void RpcAddEffect(IEffect effect, bool primary = false) | ||
{ | ||
Rpc<RpcAddEffect>.Instance.Send(new RpcAddEffect.EffectInfo(this, effect, primary), true); | ||
} | ||
|
||
[HideFromIl2Cpp] | ||
public void AddEffect(IEffect effect, bool primary) | ||
{ | ||
if (primary) PrimaryEffect = effect; | ||
|
||
if (effect != null) | ||
{ | ||
effect.Awake(); | ||
Effects.Add(effect); | ||
} | ||
} | ||
|
||
[HideFromIl2Cpp] | ||
public void RemoveEffect(IEffect effect) | ||
{ | ||
if (_primaryEffect == effect) _primaryEffect = null; | ||
else effect.OnDestroy(); | ||
effect.Timer = -1; | ||
Effects.Remove(effect); | ||
} | ||
|
||
[HideFromIl2Cpp] | ||
public void ClearEffects() | ||
{ | ||
foreach (IEffect effect in Effects) | ||
{ | ||
RemoveEffect(effect); | ||
} | ||
} | ||
|
||
private void Awake() | ||
{ | ||
Instance = this; | ||
} | ||
|
||
private void FixedUpdate() | ||
{ | ||
foreach (IEffect effect in Effects) effect.FixedUpdate(); | ||
} | ||
|
||
private void Update() | ||
{ | ||
foreach (IEffect effect in Effects) effect.Update(); | ||
} | ||
|
||
private void LateUpdate() | ||
{ | ||
List<IEffect> effects = new(); | ||
foreach (IEffect effect in Effects) | ||
{ | ||
effect.LateUpdate(); | ||
if (effect.Timer < 0) effects.Add(effect); | ||
} | ||
|
||
foreach (IEffect effect in effects) | ||
{ | ||
if (_primaryEffect == effect) _primaryEffect = null; | ||
RemoveEffect(effect); | ||
} | ||
} | ||
|
||
private void OnDestroy() | ||
{ | ||
foreach (IEffect effect in Effects) effect.Cancel(); | ||
Instance = null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Jungle.Effects.Managers; | ||
|
||
public interface IEffectManager | ||
{ | ||
List<IEffect> Effects { get; } | ||
|
||
void AddEffect(IEffect effect, bool primary); | ||
void RemoveEffect(IEffect effect); | ||
void ClearEffects(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Il2CppInterop.Runtime.Attributes; | ||
using Jungle.Player.Attributes; | ||
using Jungle.Player.Extensions; | ||
using Jungle.Player.Managers; | ||
using Reactor.Networking.Rpc; | ||
using Reactor.Utilities.Attributes; | ||
using UnityEngine; | ||
|
||
namespace Jungle.Effects.Managers; | ||
|
||
[RegisterInIl2Cpp, PlayerComponent] | ||
public class PlayerEffectManager : MonoBehaviour, IEffectManager | ||
{ | ||
public PlayerEffectManager(IntPtr ptr) : base(ptr) | ||
{ | ||
} | ||
|
||
[HideFromIl2Cpp] | ||
public PlayerManager Manager { get; private set; } = null!; | ||
|
||
private IEffect _primaryEffect; | ||
|
||
[HideFromIl2Cpp] | ||
public IEffect PrimaryEffect | ||
{ | ||
get => GlobalEffectManager.Instance != null ? GlobalEffectManager.Instance.PrimaryEffect ?? _primaryEffect : _primaryEffect; | ||
set | ||
{ | ||
IEffect current = PrimaryEffect; | ||
if (current is not null) | ||
{ | ||
current.Cancel(); | ||
RemoveEffect(current); | ||
} | ||
|
||
_primaryEffect = value; | ||
} | ||
} | ||
|
||
[HideFromIl2Cpp] | ||
public List<IEffect> Effects { get; } = new(); | ||
|
||
[HideFromIl2Cpp] | ||
public void RpcAddEffect(IEffect effect, bool primary = false) | ||
{ | ||
Rpc<RpcAddEffect>.Instance.Send(new RpcAddEffect.EffectInfo(this, effect, primary), true); | ||
} | ||
|
||
[HideFromIl2Cpp] | ||
public void AddEffect(IEffect effect, bool primary) | ||
{ | ||
if (primary && PrimaryEffect != null && PrimaryEffect == GlobalEffectManager.Instance!.PrimaryEffect && effect != null) | ||
{ | ||
effect.Timer = -1; | ||
return; | ||
} | ||
|
||
if (primary) PrimaryEffect = effect; | ||
|
||
if (effect == null) return; | ||
if (effect is IPlayerEffect playerEffect) | ||
{ | ||
playerEffect.Owner = Manager; | ||
} | ||
|
||
effect.Awake(); | ||
Effects.Add(effect); | ||
} | ||
|
||
[HideFromIl2Cpp] | ||
public void RemoveEffect(IEffect effect) | ||
{ | ||
if (_primaryEffect == effect) _primaryEffect = null; | ||
else effect.OnDestroy(); | ||
effect.Timer = -1; | ||
Effects.Remove(effect); | ||
} | ||
|
||
[HideFromIl2Cpp] | ||
public void ClearEffects() | ||
{ | ||
foreach (IEffect effect in new List<IEffect>(Effects)) | ||
{ | ||
RemoveEffect(effect); | ||
} | ||
} | ||
|
||
private void Start() | ||
{ | ||
Manager = this.GetPlayerManager(); | ||
GlobalEffectManager.PlayerEffectManagers.Add(this); | ||
} | ||
|
||
private void FixedUpdate() | ||
{ | ||
foreach (IEffect effect in Effects) effect.FixedUpdate(); | ||
} | ||
|
||
private void Update() | ||
{ | ||
foreach (IEffect effect in Effects) effect.Update(); | ||
} | ||
|
||
private void LateUpdate() | ||
{ | ||
List<IEffect> effects = new(); | ||
foreach (IEffect effect in Effects) | ||
{ | ||
effect.LateUpdate(); | ||
if (effect.Timer < 0) effects.Add(effect); | ||
} | ||
|
||
foreach (IEffect effect in effects) | ||
{ | ||
if (_primaryEffect == effect) _primaryEffect = null; | ||
RemoveEffect(effect); | ||
} | ||
} | ||
|
||
private void OnDestroy() | ||
{ | ||
foreach (IEffect effect in Effects) effect.Cancel(); | ||
GlobalEffectManager.PlayerEffectManagers.Remove(this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using HarmonyLib; | ||
using Jungle.Effects.Managers; | ||
using UnityEngine; | ||
|
||
namespace Jungle.Effects.Patches; | ||
|
||
[HarmonyPatch(typeof(HudManager), nameof(HudManager.Start))] | ||
public static class HudManager_Start_Patch | ||
{ | ||
public static void Postfix() | ||
{ | ||
Camera.main!.gameObject.AddComponent<CameraZoomController>(); | ||
if (!GlobalEffectManager.Instance) GlobalEffectManager.Instance = new GameObject("GlobalEffects").AddComponent<GlobalEffectManager>(); | ||
} | ||
} |
Oops, something went wrong.