namespacing and multiplayer lobby

This commit is contained in:
2023-06-01 14:25:46 -04:00
parent 1d4a6319e9
commit 3e1b55b036
37 changed files with 2962 additions and 785 deletions

View File

@ -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;

View File

@ -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);
}
}
}
}

View File

@ -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;
}