Files

158 lines
5.1 KiB
C#
Raw Permalink Normal View History

using Demonics;
2021-08-20 11:16:49 +02:00
using UnityEngine;
2022-10-07 00:59:20 +03:00
public class PlayerAnimator : DemonicsAnimator
2021-08-20 11:16:49 +02:00
{
2022-09-14 23:06:52 +03:00
[SerializeField] private Player _player = default;
2023-10-01 13:19:40 +03:00
[SerializeField] private Material _normal = default;
[SerializeField] private Material _invincible = default;
2023-10-01 17:21:54 +03:00
[SerializeField] private Material _armor = default;
[SerializeField] private Material _fire = default;
2023-10-01 17:21:54 +03:00
[SerializeField] private Material _parry = default;
2023-11-14 16:34:15 +02:00
[SerializeField] private Material _ar = default;
[SerializeField] private Material _arArmor = default;
[SerializeField] private Material _arInvincible = default;
2022-10-21 21:20:37 +03:00
private Shadow _shadow;
2021-08-20 11:16:49 +02:00
2021-12-11 19:25:29 +01:00
2022-10-21 21:20:37 +03:00
void Awake()
{
_shadow = GetComponent<Shadow>();
}
void Start()
2022-10-07 14:54:38 +03:00
{
_animation = _player.playerStats._animation;
}
2023-10-01 13:19:40 +03:00
public void NormalMaterial() => _spriteRenderer.material = _normal;
2023-11-14 16:34:15 +02:00
public void InvincibleMaterial() => _spriteRenderer.material = _invincible;
2023-10-01 17:21:54 +03:00
public void ArmorMaterial() => _spriteRenderer.material = _armor;
public void FireMaterial() => _spriteRenderer.material = _fire;
2023-10-01 17:21:54 +03:00
public void ParryMaterial() => _spriteRenderer.material = _parry;
2023-11-14 16:34:15 +02:00
public void ARMaterial() => _spriteRenderer.material = _ar;
public void ARArmorMaterial() => _spriteRenderer.material = _arArmor;
public void ARInvincibleMaterial() => _spriteRenderer.material = _arInvincible;
2023-01-12 19:12:56 +02:00
public bool GetProjectile(string name, int frame)
{
2023-01-23 18:31:58 +02:00
return GetEvent(name, frame, out _).projectile;
2023-01-12 19:12:56 +02:00
}
2023-01-09 18:16:00 +02:00
public bool GetParrying(string name, int frame)
{
2023-01-23 18:31:58 +02:00
return GetEvent(name, frame, out _).parry;
2023-01-09 18:16:00 +02:00
}
2023-01-16 13:26:54 +02:00
public bool GetThrowArcanaEnd(string name, int frame)
{
2023-01-23 18:31:58 +02:00
return GetEvent(name, frame, out _).throwArcanaEnd;
2023-01-16 13:26:54 +02:00
}
2023-01-19 19:06:45 +02:00
public bool GetInvincible(string name, int frame)
{
2023-01-23 18:31:58 +02:00
return GetEvent(name, frame, out _).invisibile;
2023-01-19 19:06:45 +02:00
}
2023-01-23 18:31:58 +02:00
public bool GetFootstep(string name, int frame, out int cel)
2023-01-20 17:59:16 +02:00
{
2023-01-23 18:31:58 +02:00
return GetEvent(name, frame, out cel).footstep;
2023-01-20 17:59:16 +02:00
}
2023-07-02 23:17:37 +03:00
public DemonVector2 GetJump(string name, int frame)
2023-01-16 13:26:54 +02:00
{
2023-07-02 23:17:37 +03:00
DemonVector2 jumpDirection = DemonVector2.Zero;
2023-01-23 18:31:58 +02:00
if (GetEvent(name, frame, out _).jump)
2023-01-16 13:26:54 +02:00
{
2023-07-02 23:17:37 +03:00
jumpDirection = new DemonVector2((DemonFloat)GetEvent(name, frame, out _).jumpDirection.x * transform.root.localScale.x, (DemonFloat)GetEvent(name, frame, out _).jumpDirection.y);
2023-01-16 13:26:54 +02:00
}
return jumpDirection;
}
2023-07-02 23:17:37 +03:00
public DemonVector2 GetGrabPoint(string name, int frame)
2023-01-10 18:39:07 +02:00
{
2023-01-23 18:31:58 +02:00
Vector2 grabPoint = GetEvent(name, frame, out _).grabPoint;
2023-07-02 23:17:37 +03:00
return new DemonVector2((DemonFloat)grabPoint.x, (DemonFloat)grabPoint.y);
2023-01-10 18:39:07 +02:00
}
2022-10-06 17:42:26 +03:00
2022-12-28 14:10:45 +02:00
public override void SetAnimation(string name, int frame)
{
if (name == "Wallsplat")
2024-01-08 23:13:48 +02:00
transform.SetLocalPositionAndRotation(new Vector2(10 * -transform.localScale.x, 0), Quaternion.Euler(0, 0, -90));
2022-12-28 14:10:45 +02:00
else
2024-01-08 23:13:48 +02:00
transform.SetLocalPositionAndRotation(Vector2.zero, Quaternion.identity);
2022-12-28 14:10:45 +02:00
base.SetAnimation(name, frame);
}
2022-10-07 00:59:20 +03:00
protected override void CheckAnimationBoxes()
2022-09-27 10:01:43 +03:00
{
2022-10-07 00:59:20 +03:00
base.CheckAnimationBoxes();
2022-09-27 10:01:43 +03:00
}
2022-10-21 21:20:37 +03:00
public void SetInvinsible(bool state)
{
_spriteRenderer.enabled = !state;
_shadow.SetInvinsible(state);
}
2023-01-09 18:16:00 +02:00
public bool InRecovery(string name, int frame)
2022-10-19 01:26:22 +03:00
{
2023-01-09 18:16:00 +02:00
_group = _animation.GetGroupId(name);
_cel = GetCellByFrame(frame);
2023-01-10 18:39:07 +02:00
for (int i = 0; i < _animation.animationCelsGroup[_group].animationCel.Count; i++)
if (i < _cel)
if (_animation.animationCelsGroup[_group].animationCel[i].hitboxes.Count > 0
|| _animation.GetCel(_group, i).animationEvent.projectile
|| _animation.GetCel(_group, i).animationEvent.parry)
2023-01-10 18:39:07 +02:00
return true;
return false;
2022-10-19 01:26:22 +03:00
}
public FramedataTypesEnum GetFramedata(string name, int frame)
2022-10-19 01:26:22 +03:00
{
_group = _animation.GetGroupId(name);
_cel = GetCellByFrame(frame);
if (_animation.animationCelsGroup[_group].animationCel[_cel].hitboxes?.Count > 0 || GetProjectile(name, frame))
return FramedataTypesEnum.Active;
else if (GetParrying(name, frame))
return FramedataTypesEnum.Parry;
else
2023-04-01 22:50:26 +03:00
{
if (InRecovery(name, frame))
return FramedataTypesEnum.Recovery;
else
return FramedataTypesEnum.StartUp;
}
2022-10-17 19:11:28 +02:00
}
2022-09-14 23:06:52 +03:00
public Sprite GetCurrentSprite()
{
return _spriteRenderer.sprite;
}
2022-05-23 17:48:43 +02:00
2022-10-19 01:26:22 +03:00
public void SpriteSuperArmorEffect()
{
_spriteRenderer.color = Color.red;
}
public void SpriteNormalEffect()
{
_spriteRenderer.color = Color.white;
}
2022-09-14 23:06:52 +03:00
public int SetSpriteLibraryAsset(int skinNumber)
{
2022-10-15 14:34:31 +02:00
_animation = _player.playerStats._animation;
if (skinNumber > _animation.spriteAtlas.Length - 1)
2022-09-14 23:06:52 +03:00
{
2022-09-27 10:01:43 +03:00
_skin = 0;
2022-09-14 23:06:52 +03:00
}
else if (skinNumber < 0)
{
skinNumber = _animation.spriteAtlas.Length - 1;
2022-09-14 23:06:52 +03:00
}
2022-09-27 10:01:43 +03:00
_skin = skinNumber;
2022-09-14 23:06:52 +03:00
return skinNumber;
}
public void SetSpriteOrder(int index)
{
_spriteRenderer.sortingOrder = index;
}
2021-08-20 11:16:49 +02:00
}