namespacing and multiplayer lobby
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using EnemyAI;
|
||||
|
||||
/*
|
||||
# Enemy System
|
||||
## States
|
||||
@ -32,7 +32,7 @@ using EnemyAI;
|
||||
*/
|
||||
class AIStateMachine : MonoBehaviour{
|
||||
[SerializeField]
|
||||
private EnemyState state;
|
||||
private EnemyAI.EnemyState state;
|
||||
|
||||
|
||||
|
||||
|
@ -2,130 +2,133 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class SkinlessMonsterAnimator : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Animator animator;
|
||||
|
||||
[SerializeField] [Tooltip("This is the object with the skin dissolve material")]
|
||||
private GameObject modelObject;
|
||||
|
||||
[SerializeField] private List<GameObject> objectsThatFallOnDeath = new();
|
||||
|
||||
[SerializeField] private float deathSpeed = 5f;
|
||||
|
||||
[SerializeField] private float fastDeathduration = 1f;
|
||||
|
||||
[SerializeField] private float deathDuration = 5f;
|
||||
|
||||
private float curDeathSpeed = 5f;
|
||||
|
||||
private Material dissolveMaterial;
|
||||
private bool isAlive = true;
|
||||
|
||||
private float speed;
|
||||
public bool IsRunning { get; private set; }
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
namespace Enemy {
|
||||
public class SkinlessMonsterAnimator : MonoBehaviour
|
||||
{
|
||||
dissolveMaterial = modelObject.GetComponent<SkinnedMeshRenderer>().materials[0];
|
||||
curDeathSpeed = deathSpeed;
|
||||
}
|
||||
[SerializeField] private Animator animator;
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
if (isAlive)
|
||||
[SerializeField]
|
||||
[Tooltip("This is the object with the skin dissolve material")]
|
||||
private GameObject modelObject;
|
||||
|
||||
[SerializeField] private List<GameObject> objectsThatFallOnDeath = new();
|
||||
|
||||
[SerializeField] private float deathSpeed = 5f;
|
||||
|
||||
[SerializeField] private float fastDeathduration = 1f;
|
||||
|
||||
[SerializeField] private float deathDuration = 5f;
|
||||
|
||||
private float curDeathSpeed = 5f;
|
||||
|
||||
private Material dissolveMaterial;
|
||||
private bool isAlive = true;
|
||||
|
||||
private float speed;
|
||||
public bool IsRunning { get; private set; }
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
animator.SetFloat("Speed", speed);
|
||||
}
|
||||
else
|
||||
{
|
||||
var quantity = dissolveMaterial.GetFloat("_DissolveQuantity");
|
||||
quantity = Mathf.Lerp(quantity, -2, Time.deltaTime * curDeathSpeed);
|
||||
dissolveMaterial.SetFloat("_DissolveQuantity", quantity);
|
||||
}
|
||||
}
|
||||
|
||||
public void StartMoving()
|
||||
{
|
||||
if (isAlive)
|
||||
{
|
||||
IsRunning = true;
|
||||
speed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
public void StopMoving()
|
||||
{
|
||||
if (isAlive)
|
||||
{
|
||||
speed = 0;
|
||||
IsRunning = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void Attack()
|
||||
{
|
||||
if (isAlive) animator.SetTrigger("Attack");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 0,1,2,3
|
||||
/// </summary>
|
||||
/// <param name="attackType"></param>
|
||||
public void SetAttackType(int attackType)
|
||||
{
|
||||
animator.SetInteger("AttackIndex", attackType);
|
||||
}
|
||||
|
||||
public void InLight()
|
||||
{
|
||||
if (isAlive)
|
||||
animator.SetBool("InLight", true);
|
||||
}
|
||||
|
||||
public void NotInLight()
|
||||
{
|
||||
if (isAlive)
|
||||
animator.SetBool("InLight", false);
|
||||
}
|
||||
|
||||
public void AttackScream()
|
||||
{
|
||||
if (isAlive)
|
||||
animator.SetTrigger("AttackScream");
|
||||
}
|
||||
|
||||
public void Kill(bool fast = false)
|
||||
{
|
||||
//animator.speed = 0;
|
||||
InLight();
|
||||
|
||||
|
||||
isAlive = false;
|
||||
foreach (var obj in objectsThatFallOnDeath)
|
||||
{
|
||||
obj.AddComponent<Rigidbody>();
|
||||
if (obj.GetComponent<Collider>() != null) obj.GetComponent<Collider>().enabled = false;
|
||||
dissolveMaterial = modelObject.GetComponent<SkinnedMeshRenderer>().materials[0];
|
||||
curDeathSpeed = deathSpeed;
|
||||
}
|
||||
|
||||
var dur = deathDuration;
|
||||
if (fast)
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
dur = fastDeathduration;
|
||||
curDeathSpeed = deathSpeed * (deathDuration / fastDeathduration);
|
||||
if (isAlive)
|
||||
{
|
||||
animator.SetFloat("Speed", speed);
|
||||
}
|
||||
else
|
||||
{
|
||||
var quantity = dissolveMaterial.GetFloat("_DissolveQuantity");
|
||||
quantity = Mathf.Lerp(quantity, -2, Time.deltaTime * curDeathSpeed);
|
||||
dissolveMaterial.SetFloat("_DissolveQuantity", quantity);
|
||||
}
|
||||
}
|
||||
|
||||
StartCoroutine(destroyAfterSeconds(dur));
|
||||
}
|
||||
public void StartMoving()
|
||||
{
|
||||
if (isAlive)
|
||||
{
|
||||
IsRunning = true;
|
||||
speed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
public void StopMoving()
|
||||
{
|
||||
if (isAlive)
|
||||
{
|
||||
speed = 0;
|
||||
IsRunning = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void Attack()
|
||||
{
|
||||
if (isAlive) animator.SetTrigger("Attack");
|
||||
}
|
||||
|
||||
|
||||
private IEnumerator destroyAfterSeconds(float duration)
|
||||
{
|
||||
yield return new WaitForSeconds(duration);
|
||||
Destroy(gameObject);
|
||||
/// <summary>
|
||||
/// 0,1,2,3
|
||||
/// </summary>
|
||||
/// <param name="attackType"></param>
|
||||
public void SetAttackType(int attackType)
|
||||
{
|
||||
animator.SetInteger("AttackIndex", attackType);
|
||||
}
|
||||
|
||||
public void InLight()
|
||||
{
|
||||
if (isAlive)
|
||||
animator.SetBool("InLight", true);
|
||||
}
|
||||
|
||||
public void NotInLight()
|
||||
{
|
||||
if (isAlive)
|
||||
animator.SetBool("InLight", false);
|
||||
}
|
||||
|
||||
public void AttackScream()
|
||||
{
|
||||
if (isAlive)
|
||||
animator.SetTrigger("AttackScream");
|
||||
}
|
||||
|
||||
public void Kill(bool fast = false)
|
||||
{
|
||||
//animator.speed = 0;
|
||||
InLight();
|
||||
|
||||
|
||||
isAlive = false;
|
||||
foreach (var obj in objectsThatFallOnDeath)
|
||||
{
|
||||
obj.AddComponent<Rigidbody>();
|
||||
if (obj.GetComponent<Collider>() != null) obj.GetComponent<Collider>().enabled = false;
|
||||
}
|
||||
|
||||
var dur = deathDuration;
|
||||
if (fast)
|
||||
{
|
||||
dur = fastDeathduration;
|
||||
curDeathSpeed = deathSpeed * (deathDuration / fastDeathduration);
|
||||
}
|
||||
|
||||
StartCoroutine(destroyAfterSeconds(dur));
|
||||
}
|
||||
|
||||
|
||||
private IEnumerator destroyAfterSeconds(float duration)
|
||||
{
|
||||
yield return new WaitForSeconds(duration);
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ public class SkinlessMonsterComponent : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private NavMeshAgent agent;
|
||||
|
||||
[SerializeField] private SkinlessMonsterAnimator animator;
|
||||
[SerializeField] private Enemy.SkinlessMonsterAnimator animator;
|
||||
|
||||
[SerializeField] private float atTargetDistance = 2;
|
||||
|
||||
@ -32,12 +32,12 @@ public class SkinlessMonsterComponent : MonoBehaviour
|
||||
|
||||
private bool isAlive = true;
|
||||
|
||||
private InGameManager manager;
|
||||
private Game.InGameManager manager;
|
||||
|
||||
|
||||
private Vector3 oppositeVector;
|
||||
|
||||
private PlayerComponent player;
|
||||
private Player.PlayerComponent player;
|
||||
private TargetInformation target;
|
||||
|
||||
private GameObject targetObject;
|
||||
@ -46,12 +46,12 @@ public class SkinlessMonsterComponent : MonoBehaviour
|
||||
private void Awake()
|
||||
{
|
||||
//Find active player rn.
|
||||
var players = FindObjectsOfType<PlayerComponent>();
|
||||
var players = FindObjectsOfType<Player.PlayerComponent>();
|
||||
foreach (var p in players)
|
||||
if (p.isActiveAndEnabled)
|
||||
player = p;
|
||||
|
||||
manager = FindObjectOfType<InGameManager>();
|
||||
manager = FindObjectOfType<Game.InGameManager>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
@ -61,7 +61,7 @@ public class SkinlessMonsterComponent : MonoBehaviour
|
||||
targetObject = new GameObject();
|
||||
targetObject.name = "Enemy Target";
|
||||
|
||||
if (player == null) player = FindObjectOfType<PlayerComponent>();
|
||||
if (player == null) player = FindObjectOfType<Player.PlayerComponent>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
@ -236,10 +236,10 @@ public class SkinlessMonsterComponent : MonoBehaviour
|
||||
{
|
||||
var hitObject = hit.transform.gameObject;
|
||||
|
||||
if (hitObject.GetComponent<PlayerComponent>() != null)
|
||||
if (hitObject.GetComponent<Player.PlayerComponent>() != null)
|
||||
//hit player
|
||||
return angleToPosition <= visibilityConeLimit || !withAngle;
|
||||
if (hitObject.GetComponentInParent<PlayerComponent>() != null)
|
||||
if (hitObject.GetComponentInParent<Player.PlayerComponent>() != null)
|
||||
//also hit player
|
||||
return angleToPosition <= visibilityConeLimit || !withAngle;
|
||||
}
|
||||
|
@ -1,22 +1,25 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class DummyComponent : MonoBehaviour
|
||||
namespace Enemy
|
||||
{
|
||||
private Animator anim;
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
public class DummyComponent : MonoBehaviour
|
||||
{
|
||||
anim = GetComponentInParent<Animator>();
|
||||
}
|
||||
private Animator anim;
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
}
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
anim = GetComponentInParent<Animator>();
|
||||
}
|
||||
|
||||
private void OnCollisionEnter(Collision collision)
|
||||
{
|
||||
if (collision.gameObject.GetComponent<BulletComponent>() != null) anim.Play("DummyFall");
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
}
|
||||
|
||||
private void OnCollisionEnter(Collision collision)
|
||||
{
|
||||
if (collision.gameObject.GetComponent<BulletComponent>() != null) anim.Play("DummyFall");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,22 +1,24 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class MonsterComponent : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float attackDamage = 1f;
|
||||
|
||||
[SerializeField] private bool shakeCameraOnHit = true;
|
||||
|
||||
public float AttackDamage => attackDamage;
|
||||
|
||||
public bool ShakeCameraOnHit => shakeCameraOnHit;
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
namespace Enemy {
|
||||
public class MonsterComponent : MonoBehaviour
|
||||
{
|
||||
}
|
||||
[SerializeField] private float attackDamage = 1f;
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
[SerializeField] private bool shakeCameraOnHit = true;
|
||||
|
||||
public float AttackDamage => attackDamage;
|
||||
|
||||
public bool ShakeCameraOnHit => shakeCameraOnHit;
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,62 +1,65 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.VFX;
|
||||
|
||||
[ExecuteAlways]
|
||||
public class SwarmAnimator : MonoBehaviour
|
||||
namespace Enemy
|
||||
{
|
||||
[SerializeField] private VisualEffect vfx;
|
||||
|
||||
[SerializeField] private Rigidbody rb;
|
||||
//[SerializeField]
|
||||
//private string parameterName = "DeltaVector";
|
||||
|
||||
[SerializeField] private Vector3 avoidancePosDefault;
|
||||
|
||||
[SerializeField] private float explodeDuration = 1.0f;
|
||||
|
||||
private Vector3 currentPosition;
|
||||
private float dur;
|
||||
private bool isExploding;
|
||||
private Vector3 previousPosition;
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
[ExecuteAlways]
|
||||
public class SwarmAnimator : MonoBehaviour
|
||||
{
|
||||
}
|
||||
[SerializeField] private VisualEffect vfx;
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
previousPosition = currentPosition;
|
||||
currentPosition = transform.position;
|
||||
var velocity = currentPosition - previousPosition;
|
||||
vfx.SetVector3("DeltaVector", velocity);
|
||||
[SerializeField] private Rigidbody rb;
|
||||
//[SerializeField]
|
||||
//private string parameterName = "DeltaVector";
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.Space)) Explode();
|
||||
if (isExploding)
|
||||
[SerializeField] private Vector3 avoidancePosDefault;
|
||||
|
||||
[SerializeField] private float explodeDuration = 1.0f;
|
||||
|
||||
private Vector3 currentPosition;
|
||||
private float dur;
|
||||
private bool isExploding;
|
||||
private Vector3 previousPosition;
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
if (dur > explodeDuration) StopExplode();
|
||||
dur += Time.deltaTime;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
previousPosition = currentPosition;
|
||||
currentPosition = transform.position;
|
||||
var velocity = currentPosition - previousPosition;
|
||||
vfx.SetVector3("DeltaVector", velocity);
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.Space)) Explode();
|
||||
if (isExploding)
|
||||
{
|
||||
if (dur > explodeDuration) StopExplode();
|
||||
dur += Time.deltaTime;
|
||||
}
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
}
|
||||
|
||||
private void Explode()
|
||||
{
|
||||
vfx.SetVector3("Avoid", transform.position);
|
||||
isExploding = true;
|
||||
dur = 0;
|
||||
|
||||
//Wait a sec then stop.
|
||||
}
|
||||
|
||||
private void StopExplode()
|
||||
{
|
||||
vfx.SetVector3("Avoid", avoidancePosDefault);
|
||||
isExploding = false;
|
||||
vfx.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
}
|
||||
|
||||
private void Explode()
|
||||
{
|
||||
vfx.SetVector3("Avoid", transform.position);
|
||||
isExploding = true;
|
||||
dur = 0;
|
||||
|
||||
//Wait a sec then stop.
|
||||
}
|
||||
|
||||
private void StopExplode()
|
||||
{
|
||||
vfx.SetVector3("Avoid", avoidancePosDefault);
|
||||
isExploding = false;
|
||||
vfx.Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user