BITFALL/Assets/Artists/Scripts/Props/Prop_Shield.cs

67 lines
1.6 KiB
C#
Raw Normal View History

2023-10-30 01:25:53 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
using BITKit;
using BITKit.Entities;
using UnityEngine;
using Random = UnityEngine.Random;
namespace BITFALL.Props
{
public class Prop_Shield : MonoBehaviour,IDamagable
{
[SerializeField] private SpringEulerAngle spring=new();
[SerializeField] private Optional<int> maxSpring;
2023-11-15 23:54:54 +08:00
[SerializeField] private Optional<LocationAdditive> locationAdditive;
2023-11-30 00:23:23 +08:00
[SerializeField] private Optional<Transform> optionalReset;
2024-04-06 16:33:57 +08:00
public string Tag => tag;
public IHealth Health => _health;
2023-10-30 01:25:53 +08:00
public IUnityEntity UnityEntity => null;
public Rigidbody Rigidbody => null;
private Vector3 initialEulerAngles;
[Inject]
private IHealth _health;
2023-10-30 01:25:53 +08:00
private void Start()
{
initialEulerAngles = transform.localEulerAngles;
2023-10-31 18:07:15 +08:00
spring.value = initialEulerAngles;
2023-11-30 00:23:23 +08:00
if (optionalReset.Allow)
{
optionalReset.Value.rotation = Quaternion.LookRotation(
Vector3.ProjectOnPlane(
optionalReset.Value.forward,
Vector3.up)
);
}
2023-10-30 01:25:53 +08:00
}
private void FixedUpdate()
{
spring.Update(Time.fixedDeltaTime,initialEulerAngles);
transform.localEulerAngles = spring.value;
2023-11-15 23:54:54 +08:00
if (locationAdditive.Allow)
{
2024-02-21 01:40:53 +08:00
locationAdditive.Value.AddRotation(Quaternion.Euler(spring.value-initialEulerAngles) );
2023-11-15 23:54:54 +08:00
}
2023-10-30 01:25:53 +08:00
}
public void GiveDamage(DamageMessage message)
{
var damage = message.Damage;
if (maxSpring.Allow)
{
damage = Mathf.Min(damage, maxSpring.Value);
}
spring.value =initialEulerAngles + new Vector3(
Random.Range(-damage, damage),
Random.Range(-damage, damage),
Random.Range(-damage, damage)
);
}
}
}