Insanely huge initial commit

This commit is contained in:
2026-02-21 16:40:15 -08:00
parent 208d626100
commit f74c547a13
33825 changed files with 5213498 additions and 0 deletions

View File

@@ -0,0 +1,92 @@
using UnityEngine;
using System.Collections;
using UnityEngine.AI;
namespace Com.LuisPedroFonseca.ProCamera2D.TopDownShooter
{
public class EnemyAttack : MonoBehaviour
{
public float RotationSpeed = 2f;
public Pool BulletPool;
public Transform WeaponTip;
public float FireRate = .3f;
public float FireAngleRandomness = 10f;
bool _hasTarget;
Transform _target;
NavMeshAgent _navMeshAgent;
Transform _transform;
void Awake()
{
_transform = transform;
_navMeshAgent = this.GetComponentInChildren<NavMeshAgent>();
}
public void Attack(Transform target)
{
_navMeshAgent.updateRotation = false;
_target = target;
_hasTarget = true;
StartCoroutine(LookAtTarget());
StartCoroutine(FollowTarget());
StartCoroutine(Fire());
}
public void StopAttack()
{
_navMeshAgent.updateRotation = true;
_hasTarget = false;
}
IEnumerator LookAtTarget()
{
while (_hasTarget)
{
var lookAtPos = new Vector3(_target.position.x, _transform.position.y, _target.position.z);
var diff = lookAtPos - _transform.position;
var newRotation = Quaternion.LookRotation(diff, Vector3.up);
_transform.rotation = Quaternion.Slerp(_transform.rotation, newRotation, RotationSpeed * Time.deltaTime);
yield return null;
}
}
IEnumerator FollowTarget()
{
while (_hasTarget)
{
var rnd = Random.insideUnitCircle;
_navMeshAgent.destination = _target.position - (_target.position - _transform.position).normalized * 5f + new Vector3(rnd.x, 0, rnd.y);
yield return null;
}
}
IEnumerator Fire()
{
while (_hasTarget)
{
var bullet = BulletPool.nextThing;
bullet.transform.position = WeaponTip.position;
bullet.transform.rotation = _transform.rotation * Quaternion.Euler(new Vector3(0, -90 + Random.Range(-FireAngleRandomness, FireAngleRandomness), 0));
yield return new WaitForSeconds(FireRate);
}
}
public static Vector2 RandomOnUnitCircle2(float radius)
{
Vector2 randomPointOnCircle = Random.insideUnitCircle;
randomPointOnCircle.Normalize();
randomPointOnCircle *= radius;
return randomPointOnCircle;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: e39f48ce520924bc68288749482d359f
timeCreated: 1443805796
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,128 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace Com.LuisPedroFonseca.ProCamera2D.TopDownShooter
{
[RequireComponent(typeof(EnemySight))]
[RequireComponent(typeof(EnemyAttack))]
[RequireComponent(typeof(EnemyWander))]
public class EnemyFSM : MonoBehaviour
{
public int Health = 100;
public Color AttackColor = Color.red;
public DoorKey Key;
EnemySight _sight;
EnemyAttack _attack;
EnemyWander _wander;
Renderer[] _renderers;
Color _originalColor;
Color _currentColor;
void Awake()
{
_sight = GetComponent<EnemySight>();
_attack = GetComponent<EnemyAttack>();
_wander = GetComponent<EnemyWander>();
_renderers = GetComponentsInChildren<Renderer>();
_originalColor = _renderers[0].material.color;
_currentColor = _originalColor;
_sight.OnPlayerInSight += OnPlayerInSight;
_sight.OnPlayerOutOfSight += OnPlayerOutOfSight;
if(Key != null)
Key.gameObject.SetActive(false);
}
void Start()
{
_wander.StartWandering();
}
void OnDestroy()
{
_sight.OnPlayerInSight -= OnPlayerInSight;
_sight.OnPlayerOutOfSight -= OnPlayerOutOfSight;
}
void Hit(int damage)
{
if (Health <= 0)
return;
Health -= damage;
StartCoroutine(HitAnim());
if (Health <= 0)
{
Die();
}
}
IEnumerator HitAnim()
{
Colorize(Color.white);
yield return new WaitForSeconds(.05f);
Colorize(_currentColor);
}
void OnPlayerInSight (Transform obj)
{
_wander.StopWandering();
_attack.Attack(obj);
ProCamera2D.Instance.AddCameraTarget(this.transform);
_currentColor = AttackColor;
Colorize(_currentColor);
}
void OnPlayerOutOfSight ()
{
_wander.StartWandering();
_attack.StopAttack();
ProCamera2D.Instance.RemoveCameraTarget(this.transform, 2);
_currentColor = _originalColor;
Colorize(_currentColor);
}
void Colorize(Color color)
{
for (int i = 0; i < _renderers.Length; i++)
{
_renderers[i].material.color = color;
}
}
void DropLoot()
{
if (Key != null)
{
Key.gameObject.SetActive(true);
Key.transform.position = transform.position + new Vector3(0, 3, 0);
}
}
void Die()
{
ProCamera2DShake.Instance.Shake("SmallExplosion");
OnPlayerOutOfSight();
DropLoot();
Destroy(gameObject, .2f);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: e946a0f41f0fe4390a946ec4bb71c996
timeCreated: 1443796697
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,119 @@
using UnityEngine;
using System.Collections.Generic;
using UnityEngine.AI;
namespace Com.LuisPedroFonseca.ProCamera2D.TopDownShooter
{
public class EnemyPatrol : MonoBehaviour
{
public Transform PathContainer;
public float WaypointOffset = .1f;
public bool Loop = true;
public bool IsPaused;
NavMeshAgent _navMeshAgent;
List<Transform> _path;
int _currentWaypoint;
bool _hasReachedDestination;
float _stopTime;
void Awake ()
{
_navMeshAgent = this.GetComponentInChildren<NavMeshAgent>();
_path = new List<Transform>();
if(PathContainer != null)
{
foreach (Transform child in PathContainer)
{
_path.Add(child);
}
}
else
{
Debug.LogWarning("No path set.");
}
}
void Update()
{
if(IsPaused)
return;
if (_navMeshAgent.remainingDistance <= WaypointOffset && !_hasReachedDestination)
{
_hasReachedDestination = true;
PatrolWaypoint patrolWaypoint = _path[_currentWaypoint].GetComponent<PatrolWaypoint>();
if (patrolWaypoint != null)
{
_stopTime = Random.Range(patrolWaypoint.StopDuration - patrolWaypoint.StopDurationVariation, patrolWaypoint.StopDuration + patrolWaypoint.StopDurationVariation);
if (Random.value >= patrolWaypoint.StopProbability)
{
GoToNextWaypoint();
}
}
else
{
GoToNextWaypoint();
}
}
if (_hasReachedDestination)
{
_stopTime -= Time.deltaTime;
if (_stopTime <= 0)
GoToNextWaypoint();
}
}
public void StartPatrol()
{
GoToWaypoint(0);
}
public void PausePatrol()
{
IsPaused = true;
_navMeshAgent.isStopped = true;
}
public void ResumePatrol()
{
GoToWaypoint(_currentWaypoint);
}
void GoToNextWaypoint()
{
if (_currentWaypoint < _path.Count - 1)
{
_currentWaypoint++;
}
else
{
if (Loop)
{
_currentWaypoint = 0;
}
else
{
Debug.Log("Path completed");
}
}
GoToWaypoint(_currentWaypoint);
}
void GoToWaypoint(int waypoint)
{
IsPaused = false;
_hasReachedDestination = false;
_currentWaypoint = waypoint;
Vector3 destination = new Vector3(_path[_currentWaypoint].position.x, _navMeshAgent.transform.position.y, _path[_currentWaypoint].position.z);
_navMeshAgent.SetDestination(destination);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 4b87f48aa5b4c49ada8a12a40848bf25
timeCreated: 1443796907
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,61 @@
using UnityEngine;
using System;
using System.Collections;
namespace Com.LuisPedroFonseca.ProCamera2D.TopDownShooter
{
public class EnemySight : MonoBehaviour
{
public Action<Transform> OnPlayerInSight;
public Action OnPlayerOutOfSight;
public float RefreshRate = 1f;
public float fieldOfViewAngle = 110f;
public float ViewDistance = 30f;
public bool playerInSight;
public Transform player;
public LayerMask LayerMask;
RaycastHit _hit;
void Awake()
{
RefreshRate += UnityEngine.Random.Range(-RefreshRate * .2f, RefreshRate * .2f);
}
IEnumerator Start()
{
while (true)
{
Vector3 direction = player.position - transform.position;
float angle = Vector3.Angle(direction, transform.forward);
if (angle < fieldOfViewAngle * 0.5f &&
Physics.Raycast(transform.position + transform.up, direction.normalized, out _hit, ViewDistance, LayerMask) &&
_hit.collider.transform.GetInstanceID() == player.GetInstanceID())
{
if (!playerInSight)
{
playerInSight = true;
if (OnPlayerInSight != null)
OnPlayerInSight(_hit.collider.transform);
}
}
else
{
if (playerInSight)
{
playerInSight = false;
if (OnPlayerOutOfSight != null)
OnPlayerOutOfSight();
}
}
yield return new WaitForSeconds(RefreshRate);
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: ed3d1f64777f94a48b2b5df7d48b1307
timeCreated: 1443802521
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,83 @@
using UnityEngine;
using System.Collections;
using UnityEngine.AI;
namespace Com.LuisPedroFonseca.ProCamera2D.TopDownShooter
{
public class EnemyWander : MonoBehaviour
{
public float WanderDuration = 10; // 0 to loop
public float WaypointOffset = .1f;
public float WanderRadius = 10f;
NavMeshAgent _navMeshAgent;
bool _hasReachedDestination;
Vector3 _startingPos;
float _startingTime;
void Awake ()
{
_navMeshAgent = this.GetComponentInChildren<NavMeshAgent>();
_startingPos = _navMeshAgent.transform.position;
}
public void StartWandering()
{
_startingTime = Time.time;
GoToWaypoint();
StartCoroutine(CheckAgentPosition());
}
public void StopWandering()
{
StopAllCoroutines();
}
IEnumerator CheckAgentPosition()
{
while(true)
{
if (_navMeshAgent.remainingDistance <= WaypointOffset && !_hasReachedDestination)
{
_hasReachedDestination = true;
if(Time.time - _startingTime >= WanderDuration && WanderDuration > 0)
{
// Dispatch complete event
Debug.Log("Stopped wandering");
}
else
{
GoToWaypoint();
}
}
yield return null;
}
}
void GoToWaypoint()
{
var path = new NavMeshPath();
Vector3 newLocation = Vector3.zero;
while (path.status == NavMeshPathStatus.PathPartial || path.status == NavMeshPathStatus.PathInvalid)
{
Vector3 ran = Random.insideUnitSphere * WanderRadius;
ran.y = _startingPos.y;
newLocation = _startingPos + ran;
_navMeshAgent.CalculatePath(newLocation, path);
}
_navMeshAgent.SetDestination(newLocation);
_hasReachedDestination = false;
}
#if UNITY_EDITOR
void OnDrawGizmosSelected()
{
Gizmos.matrix = Matrix4x4.TRS(Application.isPlaying ? _startingPos : transform.position, Quaternion.identity, new Vector3(1f, 0f, 1f));
Gizmos.DrawWireSphere(Vector3.zero, WanderRadius);
}
#endif
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 0593f0cb075b14c009fbe3ce5eaabebf
timeCreated: 1445624233
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
using UnityEngine;
using System.Collections;
public class PatrolWaypoint : MonoBehaviour
{
public float StopProbability = .5f;
public float StopDuration = 3f;
public float StopDurationVariation = 2f;
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 581369a436eca4fd092a2ab8b8cbf967
timeCreated: 1443797076
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: