Insanely huge initial commit

This commit is contained in:
2026-02-21 17:04:05 -08:00
parent 9cdd36191a
commit 613d75914a
22525 changed files with 4035207 additions and 0 deletions

View File

@@ -0,0 +1,72 @@
using UnityEngine;
using System.Collections;
namespace Com.LuisPedroFonseca.ProCamera2D.TopDownShooter
{
public class Bullet : MonoBehaviour
{
public float BulletDuration = 1f;
public float BulletSpeed = 50f;
public float SkinWidth = .1f;
public LayerMask CollisionMask;
public float BulletDamage = 10f;
Transform _transform;
RaycastHit _raycastHit;
Vector2 _collisionPoint;
float _startTime;
bool _exploding;
Vector3 _lastPos;
void Awake()
{
_transform = this.transform;
}
void OnEnable()
{
_exploding = false;
_startTime = Time.time;
}
void Update()
{
if (_exploding)
return;
_lastPos = _transform.position;
_transform.Translate(Vector3.right * BulletSpeed * Time.deltaTime);
if(Physics.Raycast(_lastPos, _transform.position - _lastPos, out _raycastHit, (_lastPos - _transform.position).magnitude + SkinWidth, CollisionMask))
{
_collisionPoint = _raycastHit.point;
_transform.up = _raycastHit.normal;
Collide();
}
if (Time.time - _startTime > BulletDuration)
Disable();
}
void Collide()
{
_exploding = true;
_transform.position = _collisionPoint;
_raycastHit.collider.SendMessageUpwards("Hit", BulletDamage, SendMessageOptions.DontRequireReceiver);
Disable();
}
void Disable()
{
gameObject.SetActive(false);
}
}
}

View File

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

View File

@@ -0,0 +1,97 @@
using UnityEngine;
using System.Collections;
using Com.LuisPedroFonseca.ProCamera2D;
namespace Com.LuisPedroFonseca.ProCamera2D.TopDownShooter
{
public enum DoorDirection
{
Left,
Right,
Up,
Down
}
public class Door : MonoBehaviour
{
public bool IsOpen { get { return _isOpen; } }
bool _isOpen;
public DoorDirection DoorDirection = DoorDirection.Left;
public float MovementRange = 5f;
public float AnimDuration = 1f;
public float OpenDelay = 0f;
public float CloseDelay = 0f;
Vector3 _origPos;
Coroutine _moveCoroutine;
void Awake()
{
_origPos = this.transform.position;
}
public void OpenDoor(float openDelay = -1f)
{
if (openDelay == -1f)
openDelay = OpenDelay;
_isOpen = true;
switch (DoorDirection)
{
case DoorDirection.Up:
Move(_origPos + new Vector3(0, 0, MovementRange), AnimDuration, openDelay);
break;
case DoorDirection.Down:
Move(_origPos - new Vector3(0, 0, MovementRange), AnimDuration, openDelay);
break;
case DoorDirection.Left:
Move(_origPos - new Vector3(MovementRange, 0, 0), AnimDuration, openDelay);
break;
case DoorDirection.Right:
Move(_origPos + new Vector3(MovementRange, 0, 0), AnimDuration, openDelay);
break;
}
}
public void CloseDoor()
{
_isOpen = false;
Move(_origPos, AnimDuration, CloseDelay);
}
void Move(Vector3 newPos, float duration, float delay)
{
if (_moveCoroutine != null)
StopCoroutine(_moveCoroutine);
_moveCoroutine = StartCoroutine(MoveRoutine(newPos, duration, delay));
}
IEnumerator MoveRoutine(Vector3 newPos, float duration, float delay)
{
yield return new WaitForSeconds(delay);
var origPos = transform.position;
var t = 0f;
while (t <= 1.0f)
{
t += Time.deltaTime / duration;
transform.position = new Vector3(
Utils.EaseFromTo(origPos.x, newPos.x, t, EaseType.EaseOut),
Utils.EaseFromTo(origPos.y, newPos.y, t, EaseType.EaseOut),
Utils.EaseFromTo(origPos.z, newPos.z, t, EaseType.EaseOut));
yield return null;
}
}
}
}

View File

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

View File

@@ -0,0 +1,25 @@
using UnityEngine;
using System.Collections;
namespace Com.LuisPedroFonseca.ProCamera2D.TopDownShooter
{
public class DoorKey : MonoBehaviour
{
public Door Door;
public string PickupTag = "Player";
public ProCamera2DCinematics Cinematics;
void OnTriggerEnter(Collider other)
{
if (other.transform.CompareTag(PickupTag) && !Door.IsOpen)
{
Door.OpenDoor();
if (Cinematics != null)
Cinematics.Play();
Destroy(this.gameObject);
}
}
}
}

View File

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

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 17465936b658b49f8832c21b35125e6e
folderAsset: yes
timeCreated: 1443796572
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

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:

View File

@@ -0,0 +1,28 @@
using UnityEngine;
using System.Collections;
namespace Com.LuisPedroFonseca.ProCamera2D.TopDownShooter
{
public class GameOver : MonoBehaviour
{
public Canvas GameOverScreen;
void Awake()
{
GameOverScreen.gameObject.SetActive(false);
}
public void ShowScreen()
{
GameOverScreen.gameObject.SetActive(true);
Time.timeScale = 0;
}
public void PlayAgain()
{
Time.timeScale = 1;
UnityEngine.SceneManagement.SceneManager.LoadScene(UnityEngine.SceneManagement.SceneManager.GetActiveScene().name);
}
}
}

View File

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

View File

@@ -0,0 +1,15 @@
using UnityEngine;
using System.Collections;
namespace Com.LuisPedroFonseca.ProCamera2D.TopDownShooter
{
public class Goal : MonoBehaviour
{
public GameOver GameOverScreen;
void OnTriggerEnter(Collider other)
{
GameOverScreen.ShowScreen();
}
}
}

View File

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

View File

@@ -0,0 +1,23 @@
using UnityEngine;
using System.Collections;
namespace Com.LuisPedroFonseca.ProCamera2D.TopDownShooter
{
public class ObjectMove : MonoBehaviour
{
public float Amplitude = 1;
public float Frequency = 1;
Transform _transform;
void Awake()
{
_transform = transform;
}
void LateUpdate()
{
_transform.position += Amplitude * (Mathf.Sin(2 * Mathf.PI * Frequency * Time.time) - Mathf.Sin(2 * Mathf.PI * Frequency * (Time.time - Time.deltaTime))) * Vector3.up;
}
}
}

View File

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

View File

@@ -0,0 +1,22 @@
using UnityEngine;
using System.Collections;
namespace Com.LuisPedroFonseca.ProCamera2D.TopDownShooter
{
public class ObjectRotate : MonoBehaviour
{
public Vector3 Rotation = Vector3.one;
Transform _transform;
void Awake()
{
_transform = transform;
}
void LateUpdate()
{
_transform.Rotate(Rotation);
}
}
}

View File

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

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: e979f7a541ee4458c9917c2b88a21e11
folderAsset: yes
timeCreated: 1443612812
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,49 @@
using UnityEngine;
using System.Collections;
namespace Com.LuisPedroFonseca.ProCamera2D.TopDownShooter
{
public class PlayerFire : MonoBehaviour
{
public Pool BulletPool;
public Transform WeaponTip;
public float FireRate = .3f;
public float FireShakeForce = .2f;
public float FireShakeDuration = .05f;
Transform _transform;
void Awake()
{
_transform = transform;
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0))
{
StartCoroutine(Fire());
}
}
IEnumerator Fire()
{
while (Input.GetKey(KeyCode.Space) || Input.GetMouseButton(0))
{
var bullet = BulletPool.nextThing;
bullet.transform.position = WeaponTip.position;
bullet.transform.rotation = _transform.rotation;
var angle = _transform.rotation.eulerAngles.y - 90;
var radians = angle * Mathf.Deg2Rad;
var vForce = new Vector2((float)Mathf.Sin(radians), (float)Mathf.Cos(radians)) * FireShakeForce;
ProCamera2DShake.Instance.ApplyShakesTimed(new Vector2[]{ vForce }, new Vector3[]{Vector3.zero}, new float[]{ FireShakeDuration });
yield return new WaitForSeconds(FireRate);
}
}
}
}

View File

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

View File

@@ -0,0 +1,48 @@
using UnityEngine;
using System.Collections;
namespace Com.LuisPedroFonseca.ProCamera2D.TopDownShooter
{
public class PlayerHealth : MonoBehaviour
{
public int Health = 100;
Renderer[] _renderers;
Color _originalColor;
void Awake()
{
_renderers = GetComponentsInChildren<Renderer>();
_originalColor = _renderers[0].material.color;
}
void Hit(int damage)
{
Health -= damage;
StartCoroutine(HitAnim());
if (Health <= 0)
{
// Do something here
}
}
IEnumerator HitAnim()
{
ProCamera2DShake.Instance.Shake("PlayerHit");
for (int i = 0; i < _renderers.Length; i++)
{
_renderers[i].material.color = Color.white;
}
yield return new WaitForSeconds(.05f);
for (int i = 0; i < _renderers.Length; i++)
{
_renderers[i].material.color = _originalColor;
}
}
}
}

View File

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

View File

@@ -0,0 +1,73 @@
using UnityEngine;
namespace Com.LuisPedroFonseca.ProCamera2D.TopDownShooter
{
[RequireComponent(typeof(CharacterController))]
public class PlayerInput : MonoBehaviour
{
public float RunSpeed = 12;
public float Acceleration = 30;
float _currentSpeedH;
float _currentSpeedV;
Vector3 _amountToMove;
int _totalJumps;
CharacterController _characterController;
bool _movementAllowed = true;
void Start()
{
_characterController = GetComponent<CharacterController>();
var cinematics = FindObjectsOfType<ProCamera2DCinematics>();
for (int i = 0; i < cinematics.Length; i++)
{
cinematics[i].OnCinematicStarted.AddListener(() =>
{
_movementAllowed = false;
_currentSpeedH = 0;
_currentSpeedV = 0;
});
cinematics[i].OnCinematicFinished.AddListener(() =>
{
_movementAllowed = true;
});
}
}
void Update()
{
if (!_movementAllowed)
return;
var targetSpeedH = Input.GetAxis("Horizontal") * RunSpeed;
_currentSpeedH = IncrementTowards(_currentSpeedH, targetSpeedH, Acceleration);
var targetSpeedV = Input.GetAxis("Vertical") * RunSpeed;
_currentSpeedV = IncrementTowards(_currentSpeedV, targetSpeedV, Acceleration);
_amountToMove.x = _currentSpeedH;
_amountToMove.z = _currentSpeedV;
_characterController.Move(_amountToMove * Time.deltaTime);
}
// Increase n towards target by speed
private float IncrementTowards(float n, float target, float a)
{
if (n == target)
{
return n;
}
else
{
float dir = Mathf.Sign(target - n);
n += a * Time.deltaTime * dir;
return (dir == Mathf.Sign(target - n)) ? n : target;
}
}
}
}

View File

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

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 491f574a4541746cea1d1eaf350e56f3
folderAsset: yes
timeCreated: 1443708245
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,42 @@
/*
* Credit to:
* http://blog.boredmormongames.com/2014/08/object-pooling.html
*/
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace Com.LuisPedroFonseca.ProCamera2D.TopDownShooter
{
public class Pool : MonoBehaviour
{
public GameObject thing;
private List<GameObject> things = new List<GameObject>();
public GameObject nextThing
{
get
{
if (things.Count < 1)
{
GameObject newClone = (GameObject)Instantiate(thing);
newClone.transform.parent = transform;
newClone.SetActive(false);
things.Add(newClone);
PoolMember poolMember = newClone.AddComponent<PoolMember>();
poolMember.pool = this;
}
GameObject clone = things[0];
things.RemoveAt(0);
clone.SetActive(true);
return clone;
}
set
{
value.SetActive(false);
things.Add(value);
}
}
}
}

View File

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

View File

@@ -0,0 +1,20 @@
/*
* Credit to:
* http://blog.boredmormongames.com/2014/08/object-pooling.html
*/
using UnityEngine;
using System.Collections;
namespace Com.LuisPedroFonseca.ProCamera2D.TopDownShooter
{
public class PoolMember : MonoBehaviour
{
public Pool pool;
void OnDisable()
{
pool.nextThing = gameObject;
}
}
}

View File

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

View File

@@ -0,0 +1,26 @@
using UnityEngine;
using System.Collections;
namespace Com.LuisPedroFonseca.ProCamera2D.TopDownShooter
{
public class RotateTowardsMouse : MonoBehaviour
{
public float Ease = .15f;
Transform _transform;
void Awake()
{
_transform = transform;
}
void Update()
{
var mouse = Input.mousePosition;
var screenPoint = Camera.main.WorldToScreenPoint(_transform.localPosition);
var offset = new Vector2(mouse.x - screenPoint.x, mouse.y - screenPoint.y);
var angle = Mathf.Atan2(offset.y, offset.x) * Mathf.Rad2Deg;
_transform.rotation = Quaternion.Slerp(_transform.rotation, Quaternion.Euler(0, -angle, 0), Ease);
}
}
}

View File

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

View File

@@ -0,0 +1,32 @@
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
namespace Com.LuisPedroFonseca.ProCamera2D.TopDownShooter
{
public class SwitchCameraProjection : MonoBehaviour
{
public string _cameraMode;
void Awake()
{
Switch();
}
void OnGUI()
{
if (GUI.Button(new Rect(Screen.width - 210, 10, 200, 30), "Switch to " + _cameraMode + " mode"))
{
PlayerPrefs.SetInt("orthoCamera", Camera.main.orthographic ? 0 : 1);
Switch();
}
}
void Switch()
{
Camera.main.orthographic = PlayerPrefs.GetInt("orthoCamera", 0) == 1;
_cameraMode = Camera.main.orthographic ? "perspective" : "orthographic";
}
}
}

View File

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