Added NaughtyAttributes
This commit is contained in:
parent
0d33a6b3c6
commit
fbae06233e
@ -1,12 +1,16 @@
|
||||
#nullable enable
|
||||
using System.Collections;
|
||||
using NaughtyAttributes;
|
||||
using UnityEngine;
|
||||
|
||||
public class Arena : MonoBehaviour {
|
||||
//TODO probably add initial direction too
|
||||
[SerializeField] Vector3[] spawners = null!;
|
||||
[SerializeField] ArenaStats stats = null!;
|
||||
[SerializeField] GameObject monsterPrefab = null!;
|
||||
[SerializeField] [Required]
|
||||
Vector3[] spawners = null!;
|
||||
[SerializeField] [Required]
|
||||
ArenaStats stats = null!;
|
||||
[SerializeField] [Required]
|
||||
GameObject monsterPrefab = null!;
|
||||
|
||||
SafeZone safeZone = null!;
|
||||
|
||||
|
||||
@ -1,10 +1,13 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using NaughtyAttributes;
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(Rigidbody2D))]
|
||||
public class Entity : MonoBehaviour
|
||||
{
|
||||
[field: SerializeField] [field: Required]
|
||||
protected EntityStats stats { get; private set; }
|
||||
[field: SerializeField]protected float Health { get; private set; }
|
||||
[SerializeField]private float movementSpeed;
|
||||
[SerializeField]private float rotSpeed;
|
||||
@ -18,6 +21,7 @@ public class Entity : MonoBehaviour
|
||||
private Collider atkCollider;
|
||||
private Vector3 direction;
|
||||
Rigidbody2D rb;
|
||||
bool beingPushed;
|
||||
|
||||
void Awake() => rb = GetComponent<Rigidbody2D>();
|
||||
|
||||
@ -78,4 +82,9 @@ public class Entity : MonoBehaviour
|
||||
float angle = Vector2.SignedAngle(direction, (target.position - transform.position));
|
||||
return angle >= -fov && angle <= fov;
|
||||
}
|
||||
|
||||
protected void AddImpulse(Vector3 impulse) {
|
||||
beingPushed = true;
|
||||
rb.AddForce(impulse, ForceMode2D.Impulse);
|
||||
}
|
||||
}
|
||||
|
||||
6
Assets/Scripts/EntityStats.cs
Normal file
6
Assets/Scripts/EntityStats.cs
Normal file
@ -0,0 +1,6 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class EntityStats {
|
||||
[field: SerializeField] [field: Min(0f)]
|
||||
public float MinVelocityWhenPushed { get; private set; } = 5f;
|
||||
}
|
||||
3
Assets/Scripts/EntityStats.cs.meta
Normal file
3
Assets/Scripts/EntityStats.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f3b49b8d7dbc43dfbd074996aa811570
|
||||
timeCreated: 1648908811
|
||||
@ -1,10 +1,13 @@
|
||||
#nullable enable
|
||||
using NaughtyAttributes;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
[RequireComponent(typeof(PlayerInput), typeof(Rigidbody2D))]
|
||||
public class PlayerMovement : MonoBehaviour {
|
||||
[SerializeField] PlayerStats stats = null!;
|
||||
[SerializeField] [field: Required]
|
||||
PlayerStats stats = null!;
|
||||
[field: Required]
|
||||
Rigidbody2D rb = null!;
|
||||
|
||||
Vector2 moveDirection;
|
||||
@ -48,7 +51,7 @@ public class PlayerMovement : MonoBehaviour {
|
||||
return;
|
||||
|
||||
if (safeZone.IsInSafeZone) {
|
||||
if (moveDirection.magnitude >= safeZone.stats.MinJumpJoystickValue)
|
||||
if (moveDirection.magnitude >= safeZone.Stats.MinJumpJoystickValue)
|
||||
SwitchState(new ExitSafeZoneMovementState(safeZone, moveDirection));
|
||||
} else //TODO if (AngleBetween(moveDirection, toSafeZone) < 90)
|
||||
SwitchState(new EnterSafeZoneMovementState(safeZone));
|
||||
@ -139,7 +142,7 @@ public class PlayerMovement : MonoBehaviour {
|
||||
|
||||
class EnterSafeZoneMovementState : JumpingMovementState {
|
||||
readonly SafeZone safeZone;
|
||||
public EnterSafeZoneMovementState(SafeZone safeZone) : base(safeZone.stats.JumpDuration, safeZone.transform.position) {
|
||||
public EnterSafeZoneMovementState(SafeZone safeZone) : base(safeZone.Stats.JumpDuration, safeZone.transform.position) {
|
||||
this.safeZone = safeZone;
|
||||
}
|
||||
|
||||
@ -152,12 +155,12 @@ public class PlayerMovement : MonoBehaviour {
|
||||
|
||||
protected override BaseState Transition() => new ImmobileMovementState();
|
||||
|
||||
protected override float ModifyLerpTime(float t) => safeZone.stats.JumpSpeedCurve.Evaluate(t);
|
||||
protected override float ModifyLerpTime(float t) => safeZone.Stats.JumpSpeedCurve.Evaluate(t);
|
||||
}
|
||||
|
||||
class ExitSafeZoneMovementState : JumpingMovementState {
|
||||
readonly SafeZone safeZone;
|
||||
public ExitSafeZoneMovementState(SafeZone safeZone, Vector2 direction) : base(safeZone.stats.JumpDuration, safeZone.GetOutsidePosition(direction)) {
|
||||
public ExitSafeZoneMovementState(SafeZone safeZone, Vector2 direction) : base(safeZone.Stats.JumpDuration, safeZone.GetOutsidePosition(direction)) {
|
||||
this.safeZone = safeZone;
|
||||
}
|
||||
|
||||
@ -168,7 +171,7 @@ public class PlayerMovement : MonoBehaviour {
|
||||
playerMovement.SetRigidbodyEnabled(true);
|
||||
}
|
||||
|
||||
protected override float ModifyLerpTime(float t) => safeZone.stats.JumpSpeedCurve.Evaluate(t);
|
||||
protected override float ModifyLerpTime(float t) => safeZone.Stats.JumpSpeedCurve.Evaluate(t);
|
||||
}
|
||||
|
||||
class ImmobileMovementState : BaseState {
|
||||
@ -184,7 +187,7 @@ public class PlayerMovement : MonoBehaviour {
|
||||
return;
|
||||
|
||||
Vector3 dropPosition = playerMovement.safeZone.GetOutsidePosition(playerMovement.moveDirection);
|
||||
bool canJump = playerMovement.moveDirection.magnitude >= playerMovement.safeZone.stats.MinJumpJoystickValue;
|
||||
bool canJump = playerMovement.moveDirection.magnitude >= playerMovement.safeZone.Stats.MinJumpJoystickValue;
|
||||
Gizmos.color = canJump ? Color.green : Color.red;
|
||||
Gizmos.DrawLine(playerMovement.transform.position, dropPosition);
|
||||
if (canJump)
|
||||
|
||||
@ -1,7 +1,10 @@
|
||||
using NaughtyAttributes;
|
||||
using UnityEngine;
|
||||
|
||||
public class SafeZone : MonoBehaviour {
|
||||
public SafeZoneStats stats;
|
||||
[field: SerializeField] [field: Required]
|
||||
public SafeZoneStats Stats { get; private set; }
|
||||
|
||||
[SerializeField] CircleCollider2D moatCollider;
|
||||
public bool IsInSafeZone { get; private set; } = true;
|
||||
|
||||
@ -14,6 +17,6 @@ public class SafeZone : MonoBehaviour {
|
||||
}
|
||||
|
||||
public Vector3 GetOutsidePosition(Vector2 direction) {
|
||||
return transform.position + (moatCollider.radius + stats.JumpOffset) * (Vector3)direction;
|
||||
return transform.position + (moatCollider.radius + Stats.JumpOffset) * (Vector3)direction;
|
||||
}
|
||||
}
|
||||
@ -1,9 +1,10 @@
|
||||
//TODO Replace with Damageable?
|
||||
|
||||
using NaughtyAttributes;
|
||||
using UnityEngine;
|
||||
|
||||
public class VampireEntity : Entity {
|
||||
[SerializeField] HealthBar healthBar;
|
||||
[SerializeField] [Required]
|
||||
HealthBar healthBar;
|
||||
[Min(10f)]
|
||||
float initialHealth;
|
||||
|
||||
protected override void Start() {
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"com.dbrizov.naughtyattributes": "https://github.com/dbrizov/NaughtyAttributes.git#upm",
|
||||
"com.unity.2d.animation": "5.1.1",
|
||||
"com.unity.2d.pixel-perfect": "4.0.1",
|
||||
"com.unity.2d.psdimporter": "4.2.0",
|
||||
|
||||
@ -1,5 +1,12 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"com.dbrizov.naughtyattributes": {
|
||||
"version": "https://github.com/dbrizov/NaughtyAttributes.git#upm",
|
||||
"depth": 0,
|
||||
"source": "git",
|
||||
"dependencies": {},
|
||||
"hash": "8a8fa5a9659a6d63f196391c71e06c4286c8acd7"
|
||||
},
|
||||
"com.unity.2d.animation": {
|
||||
"version": "5.1.1",
|
||||
"depth": 0,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user