-
Notifications
You must be signed in to change notification settings - Fork 3
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
Showing
10 changed files
with
224 additions
and
15 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,46 @@ | ||
using MiraAPI.Animations; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace MiraAPI.Modifiers; | ||
|
||
/// <summary> | ||
/// The manager for handling modifiers. | ||
/// </summary> | ||
public static class AnimationPresetManager | ||
{ | ||
private static uint _nextId; | ||
|
||
/// <summary> | ||
/// Gets registered Animation Presets. | ||
/// </summary> | ||
public static List<CustomAnimationPreset> Presets { get; internal set; } = new List<CustomAnimationPreset>(); | ||
|
||
private static uint GetNextId() | ||
{ | ||
_nextId++; | ||
return _nextId; | ||
} | ||
|
||
/// <summary> | ||
/// Get Animation Preset by ID. | ||
/// </summary> | ||
/// <param name="id">The id of the preset you want to find.</param> | ||
/// <returns>The animation preset.</returns> | ||
public static CustomAnimationPreset? GetPresetById(uint id) | ||
{ | ||
return Presets.Find(p => p.Id == id); | ||
} | ||
|
||
internal static void RegisterPreset(Type modifierType) | ||
{ | ||
if (!typeof(CustomAnimationPreset).IsAssignableFrom(modifierType)) | ||
{ | ||
return; | ||
} | ||
|
||
CustomAnimationPreset preset = (CustomAnimationPreset)Activator.CreateInstance(modifierType); | ||
preset.Id = GetNextId(); | ||
Presets.Add(preset); | ||
} | ||
} |
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,24 @@ | ||
using UnityEngine; | ||
|
||
namespace MiraAPI.Animations; | ||
|
||
/// <summary> | ||
/// Configure an animation's settings using presets. | ||
/// </summary> | ||
/// <param name="clip">The animation clip the preset will use.</param> | ||
public abstract class CustomAnimationPreset(AnimationClip clip) | ||
{ | ||
internal uint Id; | ||
|
||
internal void PlayAnimation(PlayerControl source) | ||
{ | ||
|
||
} | ||
|
||
/// <summary> | ||
/// Check whether the local player should be able to see this animation. | ||
/// </summary> | ||
/// <param name="source">The player who the animation is being triggered upon.</param> | ||
/// <returns>Whether the local player can see the animation or not.</returns> | ||
public abstract bool AnimationVisible(PlayerControl source); | ||
} |
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,38 @@ | ||
using MiraAPI.Animations.Presets; | ||
using MiraAPI.Modifiers; | ||
using MiraAPI.Networking; | ||
using MiraAPI.Utilities; | ||
using Reactor.Networking.Attributes; | ||
using Reactor.Utilities.Attributes; | ||
using System; | ||
using UnityEngine; | ||
|
||
namespace MiraAPI.Animations; | ||
|
||
[RegisterInIl2Cpp] | ||
public class CustomAnimator(IntPtr cppPtr) : MonoBehaviour(cppPtr) | ||
Check warning on line 13 in MiraAPI/Animations/CustomAnimator.cs GitHub Actions / build
Check warning on line 13 in MiraAPI/Animations/CustomAnimator.cs GitHub Actions / build
|
||
{ | ||
private PlayerControl _player; | ||
|
||
private void Start() | ||
{ | ||
_player = gameObject.GetComponent<PlayerControl>(); | ||
|
||
_player.GetCustomAnimator()?.TriggerCustomAnimation(new LocalAnimationPreset(new AnimationClip())); | ||
} | ||
|
||
public void TriggerCustomAnimation(CustomAnimationPreset preset) => RpcTriggerCustomAnimation(_player, preset.Id); | ||
|
||
|
||
[MethodRpc((uint)MiraRpc.TriggerAnimation)] | ||
internal static void RpcTriggerCustomAnimation(PlayerControl source, uint presetId) | ||
{ | ||
CustomAnimationPreset preset = AnimationPresetManager.GetPresetById(presetId); | ||
if (preset is null) return; | ||
|
||
if (preset.AnimationVisible(source)) | ||
{ | ||
preset.PlayAnimation(source); | ||
} | ||
} | ||
} |
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,11 @@ | ||
using UnityEngine; | ||
|
||
namespace MiraAPI.Animations.Presets; | ||
public class LocalAnimationPreset(AnimationClip clip) : CustomAnimationPreset(clip) | ||
Check warning on line 4 in MiraAPI/Animations/Presets/LocalAnimationPreset.cs GitHub Actions / build
|
||
{ | ||
/// <inheritdoc/> | ||
public override bool AnimationVisible(PlayerControl source) | ||
{ | ||
return source.AmOwner; | ||
} | ||
} |
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,6 @@ | ||
using System; | ||
|
||
namespace MiraAPI.Animations; | ||
|
||
[AttributeUsage(AttributeTargets.Class)] | ||
public class RegisterAnimationPresetAttribute : Attribute; |
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
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
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
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
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