init
This commit is contained in:
commit
341a877b4a
2338 changed files with 1346408 additions and 0 deletions
8
Assets/Scripts/Camera.meta
Normal file
8
Assets/Scripts/Camera.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ad1bf63a26b9b4141b022ab863d23f2a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
20
Assets/Scripts/Camera/CineMachineUpdater.cs
Normal file
20
Assets/Scripts/Camera/CineMachineUpdater.cs
Normal file
|
@ -0,0 +1,20 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CineMachineUpdater : MonoBehaviour
|
||||
{
|
||||
Cinemachine.CinemachineVirtualCamera _camera;
|
||||
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_camera = GetComponent<Cinemachine.CinemachineVirtualCamera>();
|
||||
_camera.Follow = GameMaster.Instance.player.transform.parent.GetComponentInChildren<WeightedLocation>().transform;
|
||||
}
|
||||
void setUP()
|
||||
{
|
||||
_camera.Follow = GameMaster.Instance.player.transform.parent.gameObject.GetComponent<WeightedLocation>().gameObject.transform;
|
||||
}
|
||||
|
||||
}
|
11
Assets/Scripts/Camera/CineMachineUpdater.cs.meta
Normal file
11
Assets/Scripts/Camera/CineMachineUpdater.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4f1c36c0c43fff943aedf210e8555d4f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 500
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
35
Assets/Scripts/Camera/RoomBasedCamera.cs
Normal file
35
Assets/Scripts/Camera/RoomBasedCamera.cs
Normal file
|
@ -0,0 +1,35 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class RoomBasedCamera : MonoBehaviour
|
||||
{
|
||||
public Vector3 cameraAngle=Vector3.zero;
|
||||
private float armLength=20;
|
||||
public Vector3 tweakVector = Vector3.zero;
|
||||
public LeanTweenType easeType = LeanTweenType.easeInOutCubic;
|
||||
public float easeTime = 0.5f;
|
||||
|
||||
private GameObject player;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
GameMaster.Instance.player.GetComponent<DungeonIntruder>().roomChange.AddListener(swapFocus);
|
||||
player=GameMaster.Instance.player;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
transform.eulerAngles = cameraAngle;
|
||||
if(GameMaster.Instance.Dungeon!=null && GameMaster.Instance.Dungeon.EntryRoom!=null)
|
||||
transform.position = GameMaster.Instance.Dungeon.EntryRoom.transform.position;
|
||||
transform.position += transform.forward * -armLength + tweakVector;
|
||||
}
|
||||
|
||||
void swapFocus()
|
||||
{
|
||||
transform.LeanMove(player.GetComponent<DungeonIntruder>().currentRoom.gameObject.transform.position+ transform.forward * -armLength+tweakVector, easeTime).setEase(easeType);
|
||||
}
|
||||
|
||||
|
||||
}
|
11
Assets/Scripts/Camera/RoomBasedCamera.cs.meta
Normal file
11
Assets/Scripts/Camera/RoomBasedCamera.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f735946c53bd8c24997d91bf7b6f1822
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 400
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
48
Assets/Scripts/DrawIfAttribute.cs
Normal file
48
Assets/Scripts/DrawIfAttribute.cs
Normal file
|
@ -0,0 +1,48 @@
|
|||
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// Draws the field/property ONLY if the compared property compared by the comparison type with the value of comparedValue returns true.
|
||||
/// Based on: https://forum.unity.com/threads/draw-a-field-only-if-a-condition-is-met.448855/
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = true)]
|
||||
public class DrawIfAttribute : PropertyAttribute
|
||||
{
|
||||
#region Fields
|
||||
|
||||
public string comparedPropertyName { get; private set; }
|
||||
public object comparedValue { get; private set; }
|
||||
public DisablingType disablingType { get; private set; }
|
||||
public Comparator comparisonMethod { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Types of comperisons.
|
||||
/// </summary>
|
||||
public enum DisablingType
|
||||
{
|
||||
ReadOnly = 2,
|
||||
DontDraw = 3
|
||||
}
|
||||
public enum Comparator
|
||||
{
|
||||
Equal=0,
|
||||
NotEqual=1
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Only draws the field only if a condition is met. Supports enum and bools.
|
||||
/// </summary>
|
||||
/// <param name="comparedPropertyName">The name of the property that is being compared (case sensitive).</param>
|
||||
/// <param name="comparedValue">The value the property is being compared to.</param>
|
||||
/// <param name="disablingType">The type of disabling that should happen if the condition is NOT met. Defaulted to DisablingType.DontDraw.</param>
|
||||
public DrawIfAttribute(string comparedPropertyName, object comparedValue, DisablingType disablingType = DisablingType.ReadOnly, Comparator comparisonMethod=Comparator.Equal)
|
||||
{
|
||||
this.comparedPropertyName = comparedPropertyName;
|
||||
this.comparedValue = comparedValue;
|
||||
this.disablingType = disablingType;
|
||||
this.comparisonMethod = comparisonMethod;
|
||||
}
|
||||
}
|
11
Assets/Scripts/DrawIfAttribute.cs.meta
Normal file
11
Assets/Scripts/DrawIfAttribute.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 59ab796cb1153714896e46467767082d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Dungeon.meta
Normal file
8
Assets/Scripts/Dungeon.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 93400f9e4ba1f12468d764085177e68a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
261
Assets/Scripts/Dungeon/DifficultyEstablisher.cs
Normal file
261
Assets/Scripts/Dungeon/DifficultyEstablisher.cs
Normal file
|
@ -0,0 +1,261 @@
|
|||
//#define _DIFFICULTYDEBUG
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
public class DifficultyEstablisher : MonoBehaviour
|
||||
{
|
||||
DungeonGen dung;
|
||||
|
||||
[Header("Difficulty Rates")]
|
||||
[Space(5)]
|
||||
public bool smartEdit = false;
|
||||
[Range(0, 100)]
|
||||
public float easyRate = 0;
|
||||
float easyRateOriginal;
|
||||
[Range(0, 100)]
|
||||
public float mediumRate = 0;
|
||||
float mediumRateOriginal;
|
||||
[Range(0, 100)]
|
||||
public float hardRate = 0;
|
||||
float hardRateOriginal;
|
||||
|
||||
[Header("Difficulty pity progress")]
|
||||
[Space(5)]
|
||||
public float easyPityProgress = 0;
|
||||
public float mediumPityProgress = 0;
|
||||
public float hardPityProgress = 0;
|
||||
|
||||
[Space(10)]
|
||||
[MinMaxCustomSlider]
|
||||
public ValueRange mediumRoomsMargin;
|
||||
|
||||
[Space(10)]
|
||||
[MinMaxCustomSlider]
|
||||
public ValueRange hardRoomsMargin;
|
||||
|
||||
//Room amount
|
||||
[SerializeField]
|
||||
List<GameObject> easyRooms;
|
||||
[SerializeField]
|
||||
List<GameObject> medRooms;
|
||||
[SerializeField]
|
||||
List<GameObject> hardRooms;
|
||||
|
||||
private void OnValidate()
|
||||
{
|
||||
if (smartEdit)
|
||||
{
|
||||
float totalRate = easyRate + mediumRate + hardRate;
|
||||
if (totalRate != 100)
|
||||
{
|
||||
easyRate = (easyRate * 100) / (totalRate);
|
||||
mediumRate = (mediumRate * 100) / (totalRate);
|
||||
hardRate = (hardRate * 100) / (totalRate);
|
||||
}
|
||||
}
|
||||
|
||||
#region MinMaxSlider to int
|
||||
mediumRoomsMargin.MaxValue = Mathf.Round(mediumRoomsMargin.MaxValue);
|
||||
mediumRoomsMargin.MinValue = Mathf.Round(mediumRoomsMargin.MinValue);
|
||||
|
||||
mediumRoomsMargin.MaxLimit = Mathf.Round(mediumRoomsMargin.MaxLimit);
|
||||
mediumRoomsMargin.MinLimit = Mathf.Round(mediumRoomsMargin.MinLimit);
|
||||
|
||||
hardRoomsMargin.MaxValue = Mathf.Round(hardRoomsMargin.MaxValue);
|
||||
hardRoomsMargin.MinValue = Mathf.Round(hardRoomsMargin.MinValue);
|
||||
|
||||
hardRoomsMargin.MaxLimit = Mathf.Round(hardRoomsMargin.MaxLimit);
|
||||
hardRoomsMargin.MinLimit = Mathf.Round(hardRoomsMargin.MinLimit);
|
||||
#endregion
|
||||
|
||||
mediumRoomsMargin.Name = "Medium room limits";
|
||||
hardRoomsMargin.Name = "Hard room limits";
|
||||
}
|
||||
|
||||
public static DifficultyEstablisher instance;
|
||||
private void Awake()
|
||||
{
|
||||
instance = this;
|
||||
dung = GetComponent<DungeonGen>();
|
||||
|
||||
easyRateOriginal = easyRate;
|
||||
mediumRateOriginal = mediumRate;
|
||||
hardRateOriginal = hardRate;
|
||||
|
||||
easyRooms = new List<GameObject>();
|
||||
medRooms = new List<GameObject>();
|
||||
hardRooms = new List<GameObject>();
|
||||
|
||||
}
|
||||
|
||||
[ContextMenu("Progress Med")]
|
||||
private void ProgressMediumRate()
|
||||
{
|
||||
mediumRate += mediumPityProgress * Utils.difficultyFormula(GameMaster.Instance.LevelNumber, GameMaster.Instance.Difficulty);
|
||||
easyRate = 100 - mediumRate - hardRate;
|
||||
|
||||
}
|
||||
|
||||
[ContextMenu("Progress Hard")]
|
||||
private void ProgressHardRate()
|
||||
{
|
||||
hardRate += hardPityProgress * Utils.difficultyFormula(GameMaster.Instance.LevelNumber, GameMaster.Instance.Difficulty);
|
||||
easyRate = 100 - mediumRate - hardRate;
|
||||
}
|
||||
|
||||
Difficulty getRandomDifficulty()
|
||||
{
|
||||
float rate = Random.value;
|
||||
if (rate <= easyRate / 100)
|
||||
{
|
||||
ProgressMediumRate();
|
||||
ProgressHardRate();
|
||||
return Difficulty.Easy;
|
||||
}
|
||||
else if (rate <= (mediumRate / 100 + easyRate / 100))
|
||||
{
|
||||
mediumRate = mediumRateOriginal;
|
||||
ProgressHardRate();
|
||||
|
||||
//if (medRooms >= mediumRoomsMargin.MaxValue)
|
||||
//{
|
||||
// mediumRate = 0;
|
||||
// float totalRate = easyRate + hardRooms >= hardRoomsMargin.MaxValue ? 0 : hardRooms;
|
||||
// easyRate = (easyRate * 100) / (totalRate);
|
||||
|
||||
// if (hardRooms < hardRoomsMargin.MaxValue)
|
||||
// hardRate = (hardRate * 100) / (totalRate);
|
||||
|
||||
//}
|
||||
return Difficulty.Medium;
|
||||
}
|
||||
else
|
||||
{
|
||||
hardRate = hardRateOriginal;
|
||||
ProgressMediumRate();
|
||||
|
||||
//if (hardRooms >= hardRoomsMargin.MaxValue)
|
||||
//{
|
||||
// hardRate = 0;
|
||||
// float totalRate = easyRate + medRooms >= mediumRoomsMargin.MaxValue ? 0 : medRooms;
|
||||
// easyRate = (easyRate * 100) / (totalRate);
|
||||
|
||||
// if(medRooms < mediumRoomsMargin.MaxValue)
|
||||
// mediumRate = (mediumRate * 100) / (totalRate);
|
||||
|
||||
//}
|
||||
return Difficulty.Hard;
|
||||
}
|
||||
}
|
||||
|
||||
void setDungeonDifficulty()
|
||||
{
|
||||
|
||||
foreach (GameObject r in dung.Dungeon)
|
||||
{
|
||||
Room localRoom = r.GetComponent<Room>();
|
||||
|
||||
if (localRoom.Difficulty == Difficulty.None)
|
||||
{
|
||||
localRoom.debugDiff.easyRate = easyRate;
|
||||
localRoom.debugDiff.mediumRate = mediumRate;
|
||||
localRoom.debugDiff.hardRate = hardRate;
|
||||
localRoom.debugDiff.hardEstablished = false;
|
||||
|
||||
localRoom.Difficulty = getRandomDifficulty();
|
||||
switch (localRoom.Difficulty)
|
||||
{
|
||||
case Difficulty.Easy:
|
||||
easyRooms.Add(r);
|
||||
break;
|
||||
case Difficulty.Medium:
|
||||
medRooms.Add(r);
|
||||
break;
|
||||
case Difficulty.Hard:
|
||||
hardRooms.Add(r);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if _DIFFICULTYDEBUG
|
||||
Utils.Print("Difficulty scalar: " + Utils.difficultyFormula(GameMaster.Instance.LevelNumber, GameMaster.Instance.Difficulty));
|
||||
|
||||
Utils.Print("Before:");
|
||||
Utils.Print("Easy rooms: " + easyRooms.Count);
|
||||
Utils.Print("Medium rooms: " + medRooms.Count);
|
||||
Utils.Print("Hard rooms: " + hardRooms.Count);
|
||||
#endif
|
||||
//Medium rooms margin fix
|
||||
if (medRooms.Count<mediumRoomsMargin.MinValue)
|
||||
{
|
||||
int difference = (int)mediumRoomsMargin.MinValue - medRooms.Count;
|
||||
for (int i=0; i<difference; ++i)
|
||||
{
|
||||
GameObject transferedObject = easyRooms[Random.Range(0, Mathf.Max(easyRooms.Count - 1, 0))];
|
||||
transferedObject.GetComponent<Room>().Difficulty = Difficulty.Medium;
|
||||
transferedObject.GetComponent<Room>().debugDiff.hardEstablished = true;
|
||||
medRooms.Add(transferedObject);
|
||||
easyRooms.Remove(transferedObject);
|
||||
}
|
||||
}
|
||||
else if(medRooms.Count > mediumRoomsMargin.MaxValue)
|
||||
{
|
||||
int difference = medRooms.Count - (int)mediumRoomsMargin.MaxValue;
|
||||
for (int i = 0; i < difference; ++i)
|
||||
{
|
||||
GameObject transferedObject = medRooms[Random.Range(0, Mathf.Max(medRooms.Count - 1, 0))];
|
||||
transferedObject.GetComponent<Room>().Difficulty = Difficulty.Easy;
|
||||
transferedObject.GetComponent<Room>().debugDiff.hardEstablished = true;
|
||||
easyRooms.Add(transferedObject);
|
||||
medRooms.Remove(transferedObject);
|
||||
}
|
||||
}
|
||||
|
||||
//Hard rooms margin fix
|
||||
if (hardRooms.Count < hardRoomsMargin.MinValue)
|
||||
{
|
||||
int difference = (int)hardRoomsMargin.MinValue - hardRooms.Count;
|
||||
for (int i = 0; i < difference; ++i)
|
||||
{
|
||||
GameObject transferedObject = easyRooms[Random.Range(0, Mathf.Max(easyRooms.Count - 1, 0))];
|
||||
transferedObject.GetComponent<Room>().Difficulty = Difficulty.Hard;
|
||||
transferedObject.GetComponent<Room>().debugDiff.hardEstablished = true;
|
||||
hardRooms.Add(transferedObject);
|
||||
easyRooms.Remove(transferedObject);
|
||||
}
|
||||
}
|
||||
else if (hardRooms.Count > hardRoomsMargin.MaxValue)
|
||||
{
|
||||
int difference = hardRooms.Count - (int)hardRoomsMargin.MaxValue;
|
||||
for (int i = 0; i < difference; ++i)
|
||||
{
|
||||
GameObject transferedObject = hardRooms[Random.Range(0, Mathf.Max(hardRooms.Count - 1, 0))];
|
||||
transferedObject.GetComponent<Room>().Difficulty = Difficulty.Easy;
|
||||
transferedObject.GetComponent<Room>().debugDiff.hardEstablished = true;
|
||||
easyRooms.Add(transferedObject);
|
||||
hardRooms.Remove(transferedObject);
|
||||
}
|
||||
}
|
||||
|
||||
#if _DIFFICULTYDEBUG
|
||||
Utils.Print("After:");
|
||||
Utils.Print("Easy rooms: " + easyRooms.Count);
|
||||
Utils.Print("Medium rooms: " + medRooms.Count);
|
||||
Utils.Print("Hard rooms: " + hardRooms.Count);
|
||||
#endif
|
||||
|
||||
easyRate = easyRateOriginal;
|
||||
mediumRate = mediumRateOriginal;
|
||||
hardRate = hardRateOriginal;
|
||||
}
|
||||
|
||||
public void SetDifficulty()
|
||||
{
|
||||
//Invoke(nameof(setDungeonDifficulty), 0.2f);
|
||||
setDungeonDifficulty();
|
||||
}
|
||||
}
|
11
Assets/Scripts/Dungeon/DifficultyEstablisher.cs.meta
Normal file
11
Assets/Scripts/Dungeon/DifficultyEstablisher.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8f36a910757941146befac5bdf901fe9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
204
Assets/Scripts/Dungeon/DungeonFiller.cs
Normal file
204
Assets/Scripts/Dungeon/DungeonFiller.cs
Normal file
|
@ -0,0 +1,204 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class DungeonFiller : MonoBehaviour
|
||||
{
|
||||
[System.Serializable]
|
||||
public struct RoomTypes
|
||||
{
|
||||
public List<GameObject> easy;
|
||||
public List<GameObject> medium;
|
||||
public List<GameObject> hard;
|
||||
}
|
||||
|
||||
public List<GameObject> dungeonContent;
|
||||
|
||||
public GameObject entryRoom;
|
||||
public GameObject exitRoom;
|
||||
public RoomTypes one_Entry;
|
||||
public RoomTypes two_Entries;
|
||||
public RoomTypes twoL_Entries;
|
||||
public RoomTypes threeEntries;
|
||||
public RoomTypes fourEntries;
|
||||
|
||||
//Atempt of singleton
|
||||
public static DungeonFiller instance;
|
||||
void Awake(){
|
||||
instance = this;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
dungeonContent = new List<GameObject>();
|
||||
|
||||
//Invoke(nameof(FillDungeon), 1f);
|
||||
}
|
||||
|
||||
public void Fill(){
|
||||
FillDungeon();
|
||||
}
|
||||
|
||||
private void FillDungeon()
|
||||
{
|
||||
foreach(GameObject go in GetComponent<DungeonGen>().Dungeon)
|
||||
{
|
||||
//Paint all rooms red
|
||||
//foreach(MeshRenderer mr in go.GetComponentsInChildren<MeshRenderer>())
|
||||
//{
|
||||
// mr.material.SetColor("RedChannel", Color.red);
|
||||
//}
|
||||
Room r = go.GetComponent<Room>();
|
||||
|
||||
//Determine target rotation depending on
|
||||
Quaternion rotation = Quaternion.identity;
|
||||
switch (r.RoomID)
|
||||
{
|
||||
default:
|
||||
case 1:
|
||||
rotation = Quaternion.Euler(0, 0, 0);
|
||||
break;
|
||||
case 2:
|
||||
rotation = Quaternion.Euler(0, 90, 0);
|
||||
break;
|
||||
case 3:
|
||||
rotation = Quaternion.Euler(0, 180, 0);
|
||||
break;
|
||||
case 4:
|
||||
rotation = Quaternion.Euler(0, 270, 0);
|
||||
break;
|
||||
|
||||
case 12:
|
||||
rotation = Quaternion.Euler(0, 0, 0);
|
||||
break;
|
||||
case 13:
|
||||
rotation = Quaternion.Euler(0, 0, 0);
|
||||
break;
|
||||
case 14:
|
||||
rotation = Quaternion.Euler(0, 270, 0);
|
||||
break;
|
||||
case 23:
|
||||
rotation = Quaternion.Euler(0, 90, 0);
|
||||
break;
|
||||
case 24:
|
||||
rotation = Quaternion.Euler(0, 90, 0);
|
||||
break;
|
||||
case 34:
|
||||
rotation = Quaternion.Euler(0, 180, 0);
|
||||
break;
|
||||
case 123:
|
||||
rotation = Quaternion.Euler(0, 0, 0);
|
||||
break;
|
||||
case 124:
|
||||
rotation = Quaternion.Euler(0, 270, 0);
|
||||
break;
|
||||
case 134:
|
||||
rotation = Quaternion.Euler(0, 180, 0);
|
||||
break;
|
||||
case 234:
|
||||
rotation = Quaternion.Euler(0, 90, 0);
|
||||
break;
|
||||
case 1234:
|
||||
rotation = Quaternion.Euler(0, Random.Range(0, 3)*90, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
int idLength = 0;
|
||||
float auxID = r.RoomID;
|
||||
while (auxID > 1)
|
||||
{
|
||||
idLength++;
|
||||
auxID /= 10;
|
||||
}
|
||||
|
||||
//Determine target prefabs depending on room entries
|
||||
RoomTypes targetRoomType = new RoomTypes();
|
||||
switch (idLength)
|
||||
{
|
||||
case 0:
|
||||
case 1:
|
||||
targetRoomType = one_Entry;
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
int num1 = Mathf.FloorToInt(r.RoomID / 10);
|
||||
int num2 = r.RoomID % 10;
|
||||
if (Utils.isOdd(num1) ^ Utils.isOdd(num2))
|
||||
targetRoomType = twoL_Entries;
|
||||
else
|
||||
targetRoomType = two_Entries;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
targetRoomType = threeEntries;
|
||||
break;
|
||||
case 4:
|
||||
targetRoomType = fourEntries;
|
||||
break;
|
||||
}
|
||||
|
||||
//Difficulty
|
||||
List<GameObject> targetPrefabs=null;
|
||||
switch (r.Difficulty)
|
||||
{
|
||||
case Difficulty.Easy:
|
||||
targetPrefabs = targetRoomType.easy;
|
||||
break;
|
||||
case Difficulty.Medium:
|
||||
targetPrefabs = targetRoomType.medium;
|
||||
break;
|
||||
case Difficulty.Hard:
|
||||
targetPrefabs = targetRoomType.hard;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
int z = 0;
|
||||
|
||||
if (targetPrefabs != null && targetPrefabs.Count!=0)
|
||||
{
|
||||
r.content = Instantiate(targetPrefabs[Random.Range(0, targetPrefabs.Count-1)], r.transform.position, rotation);
|
||||
dungeonContent.Add(r.content);
|
||||
}
|
||||
else
|
||||
{
|
||||
int a = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (entryRoom != null)
|
||||
{
|
||||
Room entrance = GameMaster.Instance.Dungeon.EntryRoom.GetComponent<Room>();
|
||||
entrance.content = Instantiate(entryRoom, entrance.transform.position, entrance.transform.rotation);
|
||||
dungeonContent.Add(entrance.content);
|
||||
}
|
||||
|
||||
if (exitRoom != null)
|
||||
{
|
||||
Room exit = GameMaster.Instance.Dungeon.ExitRoom.GetComponent<Room>();
|
||||
|
||||
Quaternion rotation = Quaternion.identity;
|
||||
|
||||
switch (exit.RoomID)
|
||||
{
|
||||
default:
|
||||
case 1:
|
||||
rotation = Quaternion.Euler(0, 0, 0);
|
||||
break;
|
||||
case 2:
|
||||
rotation = Quaternion.Euler(0, 90, 0);
|
||||
break;
|
||||
case 3:
|
||||
rotation = Quaternion.Euler(0, 180, 0);
|
||||
break;
|
||||
case 4:
|
||||
rotation = Quaternion.Euler(0, 270, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
exit.content = Instantiate(exitRoom, exit.transform.position, rotation);
|
||||
dungeonContent.Add(exit.content);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Dungeon/DungeonFiller.cs.meta
Normal file
11
Assets/Scripts/Dungeon/DungeonFiller.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 127a6cef63de33b4abaf3dc7c7d683b9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
1106
Assets/Scripts/Dungeon/DungeonGen.cs
Normal file
1106
Assets/Scripts/Dungeon/DungeonGen.cs
Normal file
File diff suppressed because it is too large
Load diff
11
Assets/Scripts/Dungeon/DungeonGen.cs.meta
Normal file
11
Assets/Scripts/Dungeon/DungeonGen.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 865d31958c6b3a946a0ec3623b95e5a3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 20
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
12
Assets/Scripts/Dungeon/LookAtCamOnStart.cs
Normal file
12
Assets/Scripts/Dungeon/LookAtCamOnStart.cs
Normal file
|
@ -0,0 +1,12 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class LookAtCamOnStart : MonoBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
transform.rotation = Quaternion.LookRotation(-Camera.main.transform.forward);
|
||||
}
|
||||
}
|
11
Assets/Scripts/Dungeon/LookAtCamOnStart.cs.meta
Normal file
11
Assets/Scripts/Dungeon/LookAtCamOnStart.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1451fb7b49debdc44b875474ea37ba77
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
246
Assets/Scripts/Dungeon/Room.cs
Normal file
246
Assets/Scripts/Dungeon/Room.cs
Normal file
|
@ -0,0 +1,246 @@
|
|||
//#define _DIFFICULTYDEBUG
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public enum Gate
|
||||
{
|
||||
open, closed, none
|
||||
}
|
||||
|
||||
public enum Difficulty
|
||||
{
|
||||
Easy, Medium, Hard, Special, None
|
||||
}
|
||||
|
||||
public class Room : MonoBehaviour
|
||||
{
|
||||
public Utils.DifficultyDebug debugDiff;
|
||||
|
||||
[SerializeField]
|
||||
private Difficulty difficulty=Difficulty.None;
|
||||
public Difficulty Difficulty
|
||||
{
|
||||
get
|
||||
{
|
||||
return difficulty;
|
||||
}
|
||||
set
|
||||
{
|
||||
difficulty = value;
|
||||
#if _DIFFICULTYDEBUG
|
||||
switch (difficulty)
|
||||
{
|
||||
case Difficulty.Easy:
|
||||
GetComponentInChildren<MeshRenderer>().material.SetColor("RedChannel", Color.green);
|
||||
break;
|
||||
case Difficulty.Medium:
|
||||
GetComponentInChildren<MeshRenderer>().material.SetColor("RedChannel", Color.yellow);
|
||||
break;
|
||||
case Difficulty.Hard:
|
||||
GetComponentInChildren<MeshRenderer>().material.SetColor("RedChannel", Color.red);
|
||||
break;
|
||||
case Difficulty.Special:
|
||||
GetComponentInChildren<MeshRenderer>().material.SetColor("RedChannel", Color.blue);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
private int roomID;
|
||||
public int RoomID
|
||||
{
|
||||
get
|
||||
{
|
||||
return roomID;
|
||||
}
|
||||
}
|
||||
|
||||
[Space(10)]
|
||||
public Gate top = Gate.none;
|
||||
public Gate right = Gate.none;
|
||||
public Gate bottom = Gate.none;
|
||||
public Gate left = Gate.none;
|
||||
|
||||
public bool TopWalkable
|
||||
{
|
||||
get
|
||||
{
|
||||
return (top == Gate.closed || top == Gate.open);
|
||||
}
|
||||
}
|
||||
public bool RightWalkable
|
||||
{
|
||||
get
|
||||
{
|
||||
return (right == Gate.closed || right == Gate.open);
|
||||
}
|
||||
}
|
||||
public bool BottomWalkable
|
||||
{
|
||||
get
|
||||
{
|
||||
return (bottom == Gate.closed || bottom == Gate.open);
|
||||
}
|
||||
}
|
||||
public bool LeftWalkable
|
||||
{
|
||||
get
|
||||
{
|
||||
return (left == Gate.closed || left == Gate.open);
|
||||
}
|
||||
}
|
||||
|
||||
public GameObject[] rooms;
|
||||
|
||||
public GameObject content=null;
|
||||
|
||||
public bool OpenEdges()
|
||||
{
|
||||
return top==Gate.open || right == Gate.open || bottom == Gate.open || left == Gate.open;
|
||||
}
|
||||
|
||||
private bool checkGates(bool t, bool r, bool b, bool l)
|
||||
{
|
||||
return
|
||||
(t ? top == Gate.open || top==Gate.closed : top == Gate.none) &&
|
||||
(r ? right == Gate.open || right == Gate.closed : right == Gate.none) &&
|
||||
(b ? bottom == Gate.open || bottom == Gate.closed : bottom == Gate.none) &&
|
||||
(l ? left == Gate.open || left == Gate.closed : left == Gate.none);
|
||||
}
|
||||
|
||||
[ContextMenu("Update room")]
|
||||
public GameObject updateRoom()
|
||||
{
|
||||
GameObject aux;
|
||||
//one open cases
|
||||
if(checkGates(true, false, false, false))
|
||||
aux=rooms[0];
|
||||
else if (checkGates(false, true, false, false))
|
||||
aux=rooms[1];
|
||||
else if (checkGates(false, false, true, false))
|
||||
aux=rooms[2];
|
||||
else if (checkGates(false, false, false, true))
|
||||
aux=rooms[3];
|
||||
|
||||
//two open cases
|
||||
else if (checkGates(true, true, false, false))
|
||||
aux=rooms[4];
|
||||
else if (checkGates(true, false, true, false))
|
||||
aux=rooms[5];
|
||||
else if (checkGates(true, false, false, true))
|
||||
aux=rooms[6];
|
||||
else if (checkGates(false, true, true, false))
|
||||
aux=rooms[7];
|
||||
else if (checkGates(false, true, false, true))
|
||||
aux=rooms[8];
|
||||
else if (checkGates(false, false, true, true))
|
||||
aux=rooms[9];
|
||||
|
||||
//three open cases
|
||||
else if (checkGates(true, true, true, false))
|
||||
aux=rooms[10];
|
||||
else if (checkGates(true, true, false, true))
|
||||
aux=rooms[11];
|
||||
else if (checkGates(true, false, true, true))
|
||||
aux=rooms[12];
|
||||
else if (checkGates(false, true, true, true))
|
||||
aux=rooms[13];
|
||||
|
||||
//four open cases
|
||||
else //(checkGates(true, true, true, true))
|
||||
aux=rooms[14];
|
||||
|
||||
if (aux.GetComponent<Room>().RoomID != RoomID)
|
||||
{
|
||||
aux = Instantiate(aux, transform);
|
||||
aux.transform.parent = null;
|
||||
StartCoroutine(Autodestroy(0.1f));//GameMaster.Instance.ReplaceGameObject(aux, gameObject);
|
||||
}
|
||||
return aux;
|
||||
}
|
||||
|
||||
IEnumerator Autodestroy(float time)
|
||||
{
|
||||
yield return new WaitForEndOfFrame();
|
||||
if (Application.isPlaying)
|
||||
Destroy(gameObject);
|
||||
else if (Application.isEditor)
|
||||
DestroyImmediate(gameObject);
|
||||
}
|
||||
|
||||
//deprecated
|
||||
public void siblingness()
|
||||
{
|
||||
Debug.Log("Awake " + gameObject.name);
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
Gate currentGate;
|
||||
switch (i)
|
||||
{
|
||||
default:
|
||||
case 0:
|
||||
currentGate = top;
|
||||
break;
|
||||
case 1:
|
||||
currentGate = right;
|
||||
break;
|
||||
case 2:
|
||||
currentGate = bottom;
|
||||
break;
|
||||
case 3:
|
||||
currentGate = left;
|
||||
break;
|
||||
}
|
||||
|
||||
if (currentGate != Gate.none)
|
||||
{
|
||||
Vector3 dir = Vector3.zero;
|
||||
switch (i)
|
||||
{
|
||||
default:
|
||||
case 0:
|
||||
dir = Vector3.up;
|
||||
break;
|
||||
case 1:
|
||||
dir = Vector3.right;
|
||||
break;
|
||||
case 2:
|
||||
dir = Vector3.down;
|
||||
break;
|
||||
case 3:
|
||||
dir = Vector3.left;
|
||||
break;
|
||||
}
|
||||
RaycastHit[] rch = Physics.RaycastAll(transform.position, dir, 10);
|
||||
|
||||
foreach (RaycastHit r in rch)
|
||||
{
|
||||
if (r.collider.gameObject != gameObject && r.collider.gameObject.GetComponent<Room>() != null)
|
||||
{
|
||||
Debug.Log(r.collider.gameObject.name + " awaken my master");
|
||||
switch (i)
|
||||
{
|
||||
default:
|
||||
case 0:
|
||||
top = r.collider.gameObject.GetComponent<Room>().BottomWalkable ? Gate.closed : Gate.none;
|
||||
break;
|
||||
case 1:
|
||||
right = r.collider.gameObject.GetComponent<Room>().LeftWalkable ? Gate.closed : Gate.none;
|
||||
break;
|
||||
case 2:
|
||||
bottom = r.collider.gameObject.GetComponent<Room>().TopWalkable ? Gate.closed : Gate.none;
|
||||
break;
|
||||
case 3:
|
||||
left = r.collider.gameObject.GetComponent<Room>().RightWalkable ? Gate.closed : Gate.none;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Dungeon/Room.cs.meta
Normal file
11
Assets/Scripts/Dungeon/Room.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 74890c04639ed1f4b8b20eeabe737f58
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
29
Assets/Scripts/Dungeon/RoomContent.cs
Normal file
29
Assets/Scripts/Dungeon/RoomContent.cs
Normal file
|
@ -0,0 +1,29 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class RoomContent : MonoBehaviour
|
||||
{
|
||||
public enum Difficulty
|
||||
{
|
||||
Easy, Medium, Hard
|
||||
}
|
||||
public enum RoomEntries
|
||||
{
|
||||
OneEntry, L_TwoEntries, TwoEntries, ThreeEntries, FourEntries
|
||||
}
|
||||
|
||||
public Difficulty difficulty = Difficulty.Easy;
|
||||
public RoomEntries entries = RoomEntries.OneEntry;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
11
Assets/Scripts/Dungeon/RoomContent.cs.meta
Normal file
11
Assets/Scripts/Dungeon/RoomContent.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 202b664a0a2346b4599cf8e4d21d487d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
14
Assets/Scripts/Dungeon/RoomFloor.cs
Normal file
14
Assets/Scripts/Dungeon/RoomFloor.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
enum type
|
||||
{
|
||||
Debug,
|
||||
}
|
||||
|
||||
public class RoomFloor : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
type _type;
|
||||
}
|
11
Assets/Scripts/Dungeon/RoomFloor.cs.meta
Normal file
11
Assets/Scripts/Dungeon/RoomFloor.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b2e2d66d4d680a8458a20911762924bc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
80
Assets/Scripts/Dungeon/Utils.cs
Normal file
80
Assets/Scripts/Dungeon/Utils.cs
Normal file
|
@ -0,0 +1,80 @@
|
|||
#define _DEBUG
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public enum Direction
|
||||
{
|
||||
_TOP, _RIGHT, _BOTTOM, _LEFT, _MAX
|
||||
}
|
||||
|
||||
public static class Utils
|
||||
{
|
||||
public static Vector3 dirToVec(Direction direction)
|
||||
{
|
||||
switch (direction)
|
||||
{
|
||||
case Direction._TOP:
|
||||
return new Vector3(0, 0, 1);
|
||||
case Direction._RIGHT:
|
||||
return new Vector3(1, 0, 0);
|
||||
case Direction._BOTTOM:
|
||||
return new Vector3(0, 0, -1);
|
||||
case Direction._LEFT:
|
||||
return new Vector3(-1, 0, 0);
|
||||
}
|
||||
return Vector3.one;
|
||||
}
|
||||
|
||||
public const float easyDifficultyK = 200;
|
||||
public const float mediumDifficultyK = 50;
|
||||
public const float hardDifficultyK = 5;
|
||||
|
||||
public static float difficultyFormula(int levelNumber, float difficultyConstant)
|
||||
{
|
||||
return levelNumber / Mathf.Sqrt(levelNumber * levelNumber + difficultyConstant);
|
||||
}
|
||||
public static void Print(string text){
|
||||
#if _DEBUG
|
||||
Debug.Log(text);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static bool isOdd(int num)
|
||||
{
|
||||
return num % 2 == 0;
|
||||
}
|
||||
|
||||
public static float step(float val, float edge)
|
||||
{
|
||||
return val >= edge ? 1 : 0;
|
||||
}
|
||||
public static float remap(float value, float from1, float to1, float from2, float to2)
|
||||
{
|
||||
return (value - from1) / (to1 - from1) * (to2 - from2) + from2;
|
||||
}
|
||||
|
||||
public static bool spawnDisk()
|
||||
{
|
||||
int maxHp = 15;
|
||||
int currentHealth=GameMaster.Instance.player.GetComponent<PlayerController>().health.currentHp;
|
||||
|
||||
float chance = Mathf.Min(.5f, 1-currentHealth / maxHp);
|
||||
|
||||
return chance>Random.value;
|
||||
}
|
||||
|
||||
public static int RAM_cleanseSmall = 5;
|
||||
public static int RAM_cleanseBig = 7;
|
||||
|
||||
[System.Serializable]
|
||||
public struct DifficultyDebug
|
||||
{
|
||||
public bool hardEstablished;
|
||||
public float easyRate;
|
||||
public float mediumRate;
|
||||
public float hardRate;
|
||||
}
|
||||
|
||||
}
|
11
Assets/Scripts/Dungeon/Utils.cs.meta
Normal file
11
Assets/Scripts/Dungeon/Utils.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 44bbb4d79b55ba6439311f0b3a381d9a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Enemies.meta
Normal file
8
Assets/Scripts/Enemies.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1794b1827c6a40b49b6814f3f768d4c2
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
246
Assets/Scripts/Enemies/BossBehaviour.cs
Normal file
246
Assets/Scripts/Enemies/BossBehaviour.cs
Normal file
|
@ -0,0 +1,246 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.UI;
|
||||
|
||||
[System.Serializable]
|
||||
public class BossState
|
||||
{
|
||||
[Range(0, 101)]
|
||||
public float healthActivation;
|
||||
public float activityTime;
|
||||
public float recoverTime;
|
||||
public ShootingPattern.ShootingStyle[] turretStyle=new ShootingPattern.ShootingStyle[7];
|
||||
public BulletMovement.BulletMovementType[] bulletStyle=new BulletMovement.BulletMovementType[7];
|
||||
|
||||
[HideInInspector]
|
||||
public bool used = false;
|
||||
|
||||
|
||||
public BossState()
|
||||
{
|
||||
turretStyle = new ShootingPattern.ShootingStyle[7];
|
||||
bulletStyle = new BulletMovement.BulletMovementType[7];
|
||||
}
|
||||
}
|
||||
|
||||
public class BossBehaviour : MonoBehaviour
|
||||
{
|
||||
[Header("Imperative references")]
|
||||
public SkinnedMeshRenderer myMesh;
|
||||
public TurretCoil_Behaviour[] turrets;
|
||||
public Image sheenImage;
|
||||
public UnityEvent harmEv;
|
||||
public UnityEvent dieEv;
|
||||
|
||||
[Header("General settings")]
|
||||
public float HP = 100;
|
||||
public int damageTaken = 2;
|
||||
public bool startPassive = false;
|
||||
public BossState[] states;
|
||||
|
||||
public Transform pantalla;
|
||||
|
||||
private BossState currentState;
|
||||
public BossState CurrentState
|
||||
{
|
||||
get
|
||||
{
|
||||
return currentState;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (flashInProcess)
|
||||
{
|
||||
myMesh.material.SetColor("EmissiveCol", Color.black);
|
||||
flashInProcess = false;
|
||||
}
|
||||
StopAllCoroutines();
|
||||
currentState = value;
|
||||
for(int i=0; i<turrets.Length; ++i)
|
||||
{
|
||||
turrets[i].Pattern = ShootingPattern.styleToPattern(currentState.turretStyle[i]);
|
||||
turrets[i].bulletMovementType = currentState.bulletStyle[i];
|
||||
|
||||
turrets[i].Deploy(currentState.turretStyle[i] != ShootingPattern.ShootingStyle.None);
|
||||
}
|
||||
|
||||
StartCoroutine(setTurretsState(false, currentState.activityTime));
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator setTurretsState(bool state, float time)
|
||||
{
|
||||
yield return new WaitForSeconds(time);
|
||||
if (HP > 0)
|
||||
{
|
||||
foreach (TurretCoil_Behaviour tc in turrets)
|
||||
{
|
||||
if (state)
|
||||
{
|
||||
tc.startShooting();
|
||||
}
|
||||
else
|
||||
{
|
||||
tc.stopShooting();
|
||||
}
|
||||
}
|
||||
StartCoroutine(setTurretsState(!state, !state ? currentState.recoverTime : currentState.activityTime));
|
||||
}
|
||||
}
|
||||
|
||||
bool musicStarted = false;
|
||||
private void Start()
|
||||
{
|
||||
AudioManager.instance.StopAll();
|
||||
currentState = new BossState();
|
||||
if (!startPassive)
|
||||
{
|
||||
Invoke(nameof(checkStateChange), 0.2f);
|
||||
|
||||
musicStarted = true;
|
||||
AudioManager.instance.Play("boss2");
|
||||
AudioManager.instance.PlayMuted("boss3");
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (TurretCoil_Behaviour tc in turrets)
|
||||
{
|
||||
tc.Deploy(false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Application.isEditor)
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Space))
|
||||
{
|
||||
Harm(33);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnCollisionEnterChild(Collision collision)
|
||||
{
|
||||
if (collision.gameObject.CompareTag("Disk"))
|
||||
Harm(damageTaken);
|
||||
}
|
||||
|
||||
bool modoDiablo = false;
|
||||
void Harm(int damage= 2)
|
||||
{
|
||||
if (HP > 0)
|
||||
{
|
||||
if (!musicStarted)
|
||||
{
|
||||
musicStarted = true;
|
||||
AudioManager.instance.Play("boss2");
|
||||
AudioManager.instance.PlayMuted("boss3");
|
||||
}
|
||||
HP -= damage;
|
||||
ScreenShakeCall.instance.ShakeCamera(2, .25f);
|
||||
if (HP > 0)
|
||||
checkStateChange();
|
||||
else
|
||||
Die();
|
||||
StartCoroutine(bodyFlash());
|
||||
harmEv.Invoke();
|
||||
|
||||
if (HP < 35 && !modoDiablo)
|
||||
{
|
||||
modoDiablo = true;
|
||||
AudioManager.instance.FadeMutedIn("boss3", 2, 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
bool flashInProcess = false;
|
||||
IEnumerator bodyFlash()
|
||||
{
|
||||
flashInProcess = true;
|
||||
myMesh.material.SetColor("EmissiveCol", Color.white * .75f);
|
||||
yield return new WaitForSeconds(0.1f);
|
||||
flashInProcess = false;
|
||||
myMesh.material.SetColor("EmissiveCol", Color.black);
|
||||
}
|
||||
|
||||
void Die()
|
||||
{
|
||||
GameMaster.Instance.player.GetComponent<PlayerController>().invencible = true;
|
||||
StartCoroutine(keepSpawningExplosions(.15f));
|
||||
dieEv.Invoke();
|
||||
LeanTween.color(sheenImage.GetComponent<RectTransform>(), Color.white, 3).setOnComplete(resetSheen).setDelay(.5f);
|
||||
Invoke(nameof(wipeAllBullets), 3.5f);
|
||||
GameMaster.Instance.player.GetComponent<PlayerController>().bossKilled = true;
|
||||
|
||||
StartCoroutine(AudioManager.instance.FadeOut("boss2", 1));
|
||||
StartCoroutine(AudioManager.instance.FadeOut("boss3", 1));
|
||||
Invoke(nameof(StopAllSongs), 1);
|
||||
}
|
||||
|
||||
void StopAllSongs()
|
||||
{
|
||||
AudioManager.instance.StopAll();
|
||||
}
|
||||
|
||||
IEnumerator keepSpawningExplosions(float t)
|
||||
{
|
||||
spawnExplosion();
|
||||
yield return new WaitForSeconds(t);
|
||||
StartCoroutine(keepSpawningExplosions(t));
|
||||
}
|
||||
|
||||
void spawnExplosion()
|
||||
{
|
||||
ObjectPooler.instance.SpawnFromPool("BossExplosion", pantalla.position+new Vector3(Random.Range(-2, 2), Random.Range(-1.5f, 1.5f), 0));
|
||||
|
||||
ScreenShakeCall.instance.ShakeCamera(3, .25f);
|
||||
}
|
||||
|
||||
void wipeAllBullets()
|
||||
{
|
||||
foreach (BulletMovement bm in FindObjectsOfType<BulletMovement>())
|
||||
{
|
||||
Destroy(bm.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
void resetSheen()
|
||||
{
|
||||
StopCoroutine(keepSpawningExplosions(.5f));
|
||||
foreach (TurretCoil_Behaviour tc in turrets)
|
||||
{
|
||||
tc.stopShooting();
|
||||
tc.Deploy(false);
|
||||
}
|
||||
LeanTween.color(sheenImage.GetComponent<RectTransform>(), new Color(1, 1, 1, 0), .15f).setDelay(.5f);
|
||||
Invoke(nameof(playerWin), 2);
|
||||
}
|
||||
void playerWin()
|
||||
{
|
||||
GameMaster.Instance.player.GetComponent<PlayerController>().Win();
|
||||
}
|
||||
|
||||
|
||||
void checkStateChange()
|
||||
{
|
||||
BossState auxNewState = null;
|
||||
foreach(BossState bs in states)
|
||||
{
|
||||
if (auxNewState == null || (bs.healthActivation>=HP && !bs.used))
|
||||
{
|
||||
auxNewState = bs;
|
||||
}
|
||||
}
|
||||
|
||||
if (auxNewState != currentState)
|
||||
{
|
||||
if(currentState!=null)
|
||||
currentState.used = true;
|
||||
CurrentState = auxNewState;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Enemies/BossBehaviour.cs.meta
Normal file
11
Assets/Scripts/Enemies/BossBehaviour.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5893a09a179d412479ff172ea1ecd3a9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
217
Assets/Scripts/Enemies/BossFaceController.cs
Normal file
217
Assets/Scripts/Enemies/BossFaceController.cs
Normal file
|
@ -0,0 +1,217 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public enum Expression
|
||||
{
|
||||
Idle, Talk, Angry, Laugh
|
||||
}
|
||||
|
||||
public class BossFaceController : MonoBehaviour
|
||||
{
|
||||
public BossBehaviour boss;
|
||||
|
||||
[MinMaxCustomSlider]
|
||||
public ValueRange moodChangeTime;
|
||||
|
||||
public Expression startExpression;
|
||||
|
||||
public Texture Idle;
|
||||
public Texture IdleGlitch;
|
||||
public Texture Angry;
|
||||
public Texture AngryGlitch;
|
||||
public Texture Talk;
|
||||
public Texture TalkGlitch;
|
||||
public Texture Laugh;
|
||||
public Texture Damage;
|
||||
|
||||
private Material mat;
|
||||
private Texture Tex
|
||||
{
|
||||
set
|
||||
{
|
||||
mat.SetTexture("_FaceTexture", value);
|
||||
if (value == Talk || value == TalkGlitch)
|
||||
{
|
||||
mat.SetFloat("_Cols", 10);
|
||||
StartCoroutine(playQuote());
|
||||
}
|
||||
else
|
||||
mat.SetFloat("_Cols", 5);
|
||||
|
||||
currentTex = value;
|
||||
}
|
||||
}
|
||||
|
||||
private Texture currentTex;
|
||||
|
||||
private float MoodDelay
|
||||
{
|
||||
get
|
||||
{
|
||||
return Random.Range(moodChangeTime.MinValue, moodChangeTime.MaxValue);
|
||||
}
|
||||
}
|
||||
|
||||
Texture RegularToGlitch(Texture _tex)
|
||||
{
|
||||
if (_tex == Idle)
|
||||
return IdleGlitch;
|
||||
else if (_tex == Angry)
|
||||
return AngryGlitch;
|
||||
else if (_tex == Talk)
|
||||
return TalkGlitch;
|
||||
else
|
||||
{
|
||||
Debug.LogError("Unexpected texture at RegularToGlitch method in BossFaceController.cs");
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
Texture ExpressionToTexture(Expression _exp)
|
||||
{
|
||||
switch (_exp)
|
||||
{
|
||||
default:
|
||||
case Expression.Idle:
|
||||
return Idle;
|
||||
case Expression.Angry:
|
||||
return Angry;
|
||||
case Expression.Laugh:
|
||||
return Laugh;
|
||||
case Expression.Talk:
|
||||
return Talk;
|
||||
}
|
||||
}
|
||||
|
||||
Texture GlitchIfNeeded(Texture tex)
|
||||
{
|
||||
return (Random.value * 100 > boss.HP) ? RegularToGlitch(tex) : tex;
|
||||
}
|
||||
|
||||
string PlayRandomQuote()
|
||||
{
|
||||
string name = null;
|
||||
switch((int)Random.Range(0, 4))
|
||||
{
|
||||
case 0:
|
||||
name = "steve4";
|
||||
break;
|
||||
case 1:
|
||||
name = "steve5";
|
||||
break;
|
||||
case 2:
|
||||
name = "steve6";
|
||||
break;
|
||||
case 3:
|
||||
name = "steve8";
|
||||
break;
|
||||
}
|
||||
|
||||
AudioManager.instance.Play(name);
|
||||
return name;
|
||||
}
|
||||
void StopAllQuotes()
|
||||
{
|
||||
StopCoroutine(playQuote());
|
||||
AudioManager.instance.Stop("steve4");
|
||||
AudioManager.instance.Stop("steve5");
|
||||
AudioManager.instance.Stop("steve6");
|
||||
AudioManager.instance.Stop("steve8");
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
mat = GetComponent<SkinnedMeshRenderer>().material;
|
||||
boss.harmEv.AddListener(setDamagedFace);
|
||||
GameMaster.Instance.player.GetComponent<PlayerController>().damageEv.AddListener(setLaughFace);
|
||||
|
||||
Tex = ExpressionToTexture(startExpression);
|
||||
}
|
||||
|
||||
void decideTexture()
|
||||
{
|
||||
StopAllQuotes();
|
||||
|
||||
//Idling
|
||||
int idlingTexture = Random.Range(0, 3);
|
||||
|
||||
if (((currentTex == Idle || currentTex == IdleGlitch) && idlingTexture == 0) ||
|
||||
((currentTex == Angry || currentTex == AngryGlitch) && idlingTexture == 1) ||
|
||||
((currentTex == Talk || currentTex == TalkGlitch) && idlingTexture == 2))
|
||||
idlingTexture = (++idlingTexture % 3);
|
||||
|
||||
switch (idlingTexture)
|
||||
{
|
||||
case 0:
|
||||
Tex = GlitchIfNeeded(Idle);
|
||||
break;
|
||||
case 1:
|
||||
Tex = GlitchIfNeeded(Angry);
|
||||
break;
|
||||
case 2:
|
||||
Tex = GlitchIfNeeded(Talk);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (boss.HP > 0)
|
||||
Invoke(nameof(decideTexture), MoodDelay);
|
||||
}
|
||||
|
||||
void setDamagedFace()
|
||||
{
|
||||
CancelInvoke(nameof(decideTexture));
|
||||
StopAllQuotes();
|
||||
|
||||
if (boss.HP > 0)
|
||||
{
|
||||
Tex = Damage;
|
||||
mat.SetFloat("_Index", 1);
|
||||
|
||||
Invoke(nameof(decideTexture), .45f);
|
||||
}
|
||||
else
|
||||
{
|
||||
Tex = Angry;
|
||||
AudioManager.instance.PlayOneShot("bossDie");
|
||||
}
|
||||
}
|
||||
|
||||
void setLaughFace()
|
||||
{
|
||||
if (boss.HP > 0)
|
||||
{
|
||||
CancelInvoke(nameof(decideTexture));
|
||||
|
||||
Tex = Laugh;
|
||||
|
||||
Invoke(nameof(decideTexture), .5f);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator playQuote()
|
||||
{
|
||||
float delay = 0;
|
||||
switch (PlayRandomQuote())
|
||||
{
|
||||
default:
|
||||
case "steve4":
|
||||
delay = 1.8f;
|
||||
break;
|
||||
case "steve5":
|
||||
delay = 2.7f;
|
||||
break;
|
||||
case "steve6":
|
||||
delay = 2.3f;
|
||||
break;
|
||||
case "steve8":
|
||||
delay = 2.9f;
|
||||
break;
|
||||
}
|
||||
yield return new WaitForSeconds(delay);
|
||||
Tex = Idle;
|
||||
//StartCoroutine(playQuotes());
|
||||
}
|
||||
}
|
11
Assets/Scripts/Enemies/BossFaceController.cs.meta
Normal file
11
Assets/Scripts/Enemies/BossFaceController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ae6cdab16fcbd6e419d8233e7c363e68
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
21
Assets/Scripts/Enemies/BossJointsIK.cs
Normal file
21
Assets/Scripts/Enemies/BossJointsIK.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[ExecuteAlways]
|
||||
public class BossJointsIK : MonoBehaviour
|
||||
{
|
||||
public float angleThreshold = 0;
|
||||
public Transform joint1;
|
||||
public Transform joint2;
|
||||
public Transform endEffector;
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
joint2.localEulerAngles = new Vector3(0, 0, 180-angleThreshold)-new Vector3(joint1.localEulerAngles.x, joint1.localEulerAngles.x,
|
||||
Utils.remap(Mathf.Abs(joint1.localEulerAngles.z), 0, 90, angleThreshold, 180))+new Vector3(.066f, 3.421f, 0);
|
||||
endEffector.rotation = Quaternion.LookRotation(Vector3.forward, Vector3.up)*Quaternion.Euler(new Vector3(0, 90, 0));
|
||||
endEffector.localEulerAngles += new Vector3(1.066f, 3.421f, 0);
|
||||
}
|
||||
}
|
11
Assets/Scripts/Enemies/BossJointsIK.cs.meta
Normal file
11
Assets/Scripts/Enemies/BossJointsIK.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 756e1a68ba2f9e543af6b5a063d19f42
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
123
Assets/Scripts/Enemies/BulletMovement.cs
Normal file
123
Assets/Scripts/Enemies/BulletMovement.cs
Normal file
|
@ -0,0 +1,123 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class BulletMovement : MonoBehaviour
|
||||
{
|
||||
public enum BulletMovementType
|
||||
{
|
||||
Linear, ZigZag, Wave
|
||||
}
|
||||
|
||||
[Header("General settings")]
|
||||
public BulletMovementType movementType;
|
||||
public int damage = 1;
|
||||
public float speed=1;
|
||||
public float lifetime = 5;
|
||||
|
||||
//Wave data
|
||||
[Header("Wave settings")]
|
||||
[DrawIf("movementType", BulletMovementType.Linear, DrawIfAttribute.DisablingType.ReadOnly, DrawIfAttribute.Comparator.NotEqual)]
|
||||
public float waveLength = 1;
|
||||
[DrawIf("movementType", BulletMovementType.Linear, DrawIfAttribute.DisablingType.ReadOnly, DrawIfAttribute.Comparator.NotEqual)]
|
||||
public float waveAmplitude = 1;
|
||||
|
||||
[Space(3)]
|
||||
public GameObject father = null;
|
||||
|
||||
[Header("Materials")]
|
||||
public Material regularMat;
|
||||
public Material waveMat;
|
||||
public Material zigzagMat;
|
||||
|
||||
[Header("VFX")]
|
||||
public GameObject explosionParticle;
|
||||
|
||||
private float timestamp = 0;
|
||||
private Vector3 lastPosition;
|
||||
private Vector3 startPosition;
|
||||
|
||||
private void setUp()
|
||||
{
|
||||
lastPosition = transform.position;
|
||||
startPosition = transform.position;
|
||||
|
||||
gameObject.LeanScale(transform.localScale, .75f).setFrom(Vector3.zero).setEaseOutElastic();
|
||||
timestamp = Time.time;
|
||||
|
||||
switch (movementType)
|
||||
{
|
||||
case BulletMovementType.Linear:
|
||||
GetComponent<ParticleSystemRenderer>().material = regularMat;
|
||||
break;
|
||||
case BulletMovementType.Wave:
|
||||
GetComponent<ParticleSystemRenderer>().material = waveMat;
|
||||
break;
|
||||
case BulletMovementType.ZigZag:
|
||||
GetComponent<ParticleSystemRenderer>().material = zigzagMat;
|
||||
break;
|
||||
}
|
||||
|
||||
CancelInvoke();
|
||||
InvokeRepeating(nameof(hitScan), 0, .25f);
|
||||
Invoke(nameof(shutDown), lifetime);
|
||||
}
|
||||
private void Start()
|
||||
{
|
||||
setUp();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
setUp();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
Vector3 frameOffset = Vector3.zero;
|
||||
frameOffset += transform.position+transform.forward * speed * Time.deltaTime;
|
||||
|
||||
if (movementType == BulletMovementType.Wave)
|
||||
{
|
||||
float sinFunc = Mathf.Asin(Mathf.Sin((Time.time - timestamp) * 1 / waveLength + Mathf.PI*.67f)) * waveAmplitude * Time.deltaTime;
|
||||
frameOffset += sinFunc * transform.right;
|
||||
}
|
||||
else if (movementType == BulletMovementType.ZigZag)
|
||||
{
|
||||
float sinFunc = (Utils.step(Mathf.Sin((Time.time - timestamp) * 1 / waveLength + Mathf.PI*.67f ), 0)*2-1)*waveAmplitude*Time.deltaTime;
|
||||
frameOffset += sinFunc * transform.right;
|
||||
}
|
||||
|
||||
|
||||
transform.position = frameOffset;
|
||||
}
|
||||
|
||||
void hitScan()
|
||||
{
|
||||
RaycastHit[] rayHits=Physics.RaycastAll(lastPosition, (transform.position - lastPosition), (transform.position - lastPosition).magnitude, ~LayerMask.GetMask("Bullet"));
|
||||
Debug.DrawLine(lastPosition, transform.position, Color.magenta, .1f);
|
||||
|
||||
foreach (RaycastHit rh in rayHits)
|
||||
{
|
||||
if (rh.collider != null && !rh.collider.isTrigger && rh.collider.gameObject!=gameObject && !rh.collider.gameObject.CompareTag("Player"))
|
||||
bulletHit();
|
||||
}
|
||||
|
||||
lastPosition = transform.position;
|
||||
}
|
||||
|
||||
public int bulletHit()
|
||||
{
|
||||
GetComponent<ParticleSystem>().Stop();
|
||||
ObjectPooler.instance.SpawnFromPool("BulletExplosion", transform.position);
|
||||
Invoke(nameof(shutDown), .1f);
|
||||
return damage;
|
||||
}
|
||||
void shutDown()
|
||||
{
|
||||
if (GameMaster.Instance.Pooler != null)
|
||||
gameObject.SetActive(false);
|
||||
else
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
11
Assets/Scripts/Enemies/BulletMovement.cs.meta
Normal file
11
Assets/Scripts/Enemies/BulletMovement.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a178e7c0607b2194983a9f6e15481885
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
69
Assets/Scripts/Enemies/CookieController.cs
Normal file
69
Assets/Scripts/Enemies/CookieController.cs
Normal file
|
@ -0,0 +1,69 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CookieController : MonoBehaviour, IPooledObject{
|
||||
|
||||
[SerializeField] float speed = 5f;
|
||||
[SerializeField, Range(0, 5)] float timeToAttack = 2f;
|
||||
|
||||
bool canMove;
|
||||
PlayerController player;
|
||||
Rigidbody rb;
|
||||
|
||||
[HideInInspector] public EnemySpawner spawner;
|
||||
[HideInInspector] public RoomTrigger room;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Awake(){
|
||||
player = FindObjectOfType<PlayerController>();
|
||||
rb = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
public void OnObjectSpawn(){
|
||||
StartCoroutine(TimeToAttack());
|
||||
canMove = false;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void FixedUpdate(){
|
||||
if (canMove)
|
||||
rb.MovePosition(rb.position + transform.forward * speed * Time.fixedDeltaTime);
|
||||
}
|
||||
|
||||
void OnCollisionEnter(Collision col){
|
||||
if (col.gameObject.CompareTag("Wall")){
|
||||
transform.LookAt(new Vector3(player.transform.position.x, transform.position.y, player.transform.position.z));
|
||||
}
|
||||
|
||||
if (col.gameObject.CompareTag("Disk")){
|
||||
gameObject.SetActive(false);
|
||||
room.Die(gameObject);
|
||||
GameMaster.Instance.Pooler.SpawnFromPool("EnemyExplosion", transform.position);
|
||||
if(Utils.spawnDisk())
|
||||
GameMaster.Instance.Pooler.SpawnFromPool("DiskPickup", transform.position);
|
||||
col.gameObject.GetComponent<Rigidbody>().velocity = Vector3.zero;
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerEnter(Collider col){
|
||||
if (col.CompareTag("Disk")){
|
||||
gameObject.SetActive(false);
|
||||
room.Die(gameObject);
|
||||
GameMaster.Instance.Pooler.SpawnFromPool("EnemyExplosion", transform.position);
|
||||
if (Utils.spawnDisk())
|
||||
GameMaster.Instance.Pooler.SpawnFromPool("DiskPickup", transform.position);
|
||||
col.GetComponent<Rigidbody>().velocity = Vector3.zero;
|
||||
}
|
||||
|
||||
if (col.gameObject.CompareTag("Player")){
|
||||
player.Damage(1);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator TimeToAttack(){
|
||||
yield return new WaitForSeconds(timeToAttack);
|
||||
transform.LookAt(new Vector3(player.transform.position.x, transform.position.y, player.transform.position.z));
|
||||
canMove = true;
|
||||
}
|
||||
}
|
11
Assets/Scripts/Enemies/CookieController.cs.meta
Normal file
11
Assets/Scripts/Enemies/CookieController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b1924e580c7b9be4cb7c00c93f84697c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
45
Assets/Scripts/Enemies/EnemyFrisbie.cs
Normal file
45
Assets/Scripts/Enemies/EnemyFrisbie.cs
Normal file
|
@ -0,0 +1,45 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class EnemyFrisbie : MonoBehaviour, IPooledObject{
|
||||
|
||||
[SerializeField, Range(0, 5f)] float damageVelocityThreshold = 1.5f;
|
||||
|
||||
[Space]
|
||||
[SerializeField] float speed = 10;
|
||||
Rigidbody rb;
|
||||
[SerializeField] Transform frisbie = default;
|
||||
float heightVelocity;
|
||||
float velocity;
|
||||
|
||||
PlayerController player;
|
||||
|
||||
void Awake(){
|
||||
rb = GetComponent<Rigidbody>();
|
||||
player = FindObjectOfType<PlayerController>();
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
public void OnObjectSpawn(){
|
||||
rb.velocity = Vector3.zero;
|
||||
rb.AddForce(transform.forward.normalized * speed, ForceMode.Impulse);
|
||||
}
|
||||
|
||||
void FixedUpdate(){
|
||||
velocity = rb.velocity.magnitude;
|
||||
|
||||
float positionToGo = Mathf.SmoothDamp(frisbie.localPosition.y, -1 + velocity / speed, ref heightVelocity, .1f);
|
||||
frisbie.localPosition = new Vector3(0, positionToGo, 0);
|
||||
}
|
||||
|
||||
void OnCollisionEnter(Collision col){
|
||||
if (col.gameObject.CompareTag("Player")){
|
||||
if(velocity > damageVelocityThreshold){
|
||||
player.Damage(1);
|
||||
gameObject.SetActive(false);
|
||||
ObjectPooler.instance.SpawnFromPool("EnemyDiskBreak", transform.position);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Enemies/EnemyFrisbie.cs.meta
Normal file
11
Assets/Scripts/Enemies/EnemyFrisbie.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8e935a8b1b0290b42b23105146e8bc1f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
140
Assets/Scripts/Enemies/FolderController.cs
Normal file
140
Assets/Scripts/Enemies/FolderController.cs
Normal file
|
@ -0,0 +1,140 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
public class FolderController : MonoBehaviour, IPooledObject{
|
||||
|
||||
[SerializeField] Animator anim = default;
|
||||
[SerializeField] Transform container = default;
|
||||
Rigidbody rb;
|
||||
[SerializeField] float speed = 2;
|
||||
PlayerController player;
|
||||
|
||||
[Space]
|
||||
[SerializeField, Range(0, 15)] float detectionDistance = 10;
|
||||
[SerializeField] LayerMask whatIsPlayer = 8;
|
||||
bool playerDetected;
|
||||
|
||||
bool patroling;
|
||||
bool rotationSelected;
|
||||
|
||||
[Space]
|
||||
[SerializeField, Range(0, 2)] float movementRegainTime = 1f;
|
||||
[SerializeField, Range(0, 10)] float attackForce = 5f;
|
||||
bool walking;
|
||||
float currentTime;
|
||||
Vector3 force;
|
||||
Vector3 posToGo;
|
||||
|
||||
NavMeshAgent agent;
|
||||
|
||||
[HideInInspector] public EnemySpawner spawner;
|
||||
[HideInInspector] public RoomTrigger room;
|
||||
|
||||
[Space]
|
||||
[SerializeField] int percentageAmmount = 1;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Awake(){
|
||||
agent = GetComponent<NavMeshAgent>();
|
||||
rb = GetComponent<Rigidbody>();
|
||||
player = FindObjectOfType<PlayerController>();
|
||||
agent.speed = speed;
|
||||
}
|
||||
|
||||
public void OnObjectSpawn(){
|
||||
rb.isKinematic = true;
|
||||
playerDetected = patroling = rotationSelected = walking = false;
|
||||
currentTime = 0;
|
||||
force = posToGo = Vector3.zero;
|
||||
agent.Warp(transform.position);
|
||||
}
|
||||
|
||||
void Update(){
|
||||
if(!playerDetected && Physics.CheckSphere(transform.position, detectionDistance, whatIsPlayer)){
|
||||
rb.isKinematic = false;
|
||||
playerDetected = true;
|
||||
walking = true;
|
||||
}
|
||||
|
||||
if (playerDetected){
|
||||
if (walking){
|
||||
agent.SetDestination(player.transform.position);
|
||||
agent.isStopped = false;
|
||||
}else{
|
||||
currentTime += 1 / movementRegainTime * Time.deltaTime;
|
||||
container.transform.localPosition = new Vector3(0, 0, 0);
|
||||
rb.velocity = Vector3.Lerp(force, Vector3.zero, currentTime);
|
||||
}
|
||||
}else{
|
||||
if (!patroling && !rotationSelected){
|
||||
posToGo = transform.position + new Vector3(Random.Range(-5f, 5f), 0, Random.Range(-5f, 5f));
|
||||
StartCoroutine(Patrol());
|
||||
rotationSelected = true;
|
||||
patroling = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FixedUpdate(){
|
||||
if(walking && playerDetected){
|
||||
rb.velocity = Vector3.zero;
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator Patrol(){
|
||||
agent.isStopped = false;
|
||||
agent.SetDestination(posToGo);
|
||||
yield return new WaitForSeconds(Random.Range(1f, 2f));
|
||||
rb.velocity = Vector3.zero;
|
||||
patroling = false;
|
||||
rotationSelected = false;
|
||||
agent.isStopped = !playerDetected;
|
||||
}
|
||||
|
||||
void OnCollisionEnter(Collision col){
|
||||
if (col.gameObject.CompareTag("Player")){
|
||||
anim.SetTrigger("Hit");
|
||||
walking = false;
|
||||
currentTime = 0;
|
||||
agent.isStopped = true;
|
||||
rb.velocity = -container.forward * attackForce;
|
||||
force = rb.velocity;
|
||||
StartCoroutine(RegainMobility());
|
||||
player.Damage(1);
|
||||
}
|
||||
|
||||
if (col.gameObject.CompareTag("Disk")){
|
||||
gameObject.SetActive(false);
|
||||
room.Die(gameObject);
|
||||
GameMaster.Instance.Pooler.SpawnFromPool("EnemyExplosion", transform.position);
|
||||
if (Utils.spawnDisk())
|
||||
GameMaster.Instance.Pooler.SpawnFromPool("DiskPickup", transform.position);
|
||||
player.percentage += percentageAmmount;
|
||||
col.gameObject.GetComponent<Rigidbody>().velocity = Vector3.zero;
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerEnter(Collider col){
|
||||
if (col.CompareTag("Disk")){
|
||||
gameObject.SetActive(false);
|
||||
room.Die(gameObject);
|
||||
GameMaster.Instance.Pooler.SpawnFromPool("EnemyExplosion", transform.position);
|
||||
if (Utils.spawnDisk())
|
||||
GameMaster.Instance.Pooler.SpawnFromPool("DiskPickup", transform.position);
|
||||
player.percentage += percentageAmmount;
|
||||
col.GetComponent<Rigidbody>().velocity = Vector3.zero;
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator RegainMobility(){
|
||||
yield return new WaitForSeconds(movementRegainTime);
|
||||
rb.velocity = Vector3.zero;
|
||||
walking = true;
|
||||
}
|
||||
|
||||
void OnDrawGizmosSelected(){
|
||||
Gizmos.DrawWireSphere(transform.position, detectionDistance);
|
||||
}
|
||||
}
|
11
Assets/Scripts/Enemies/FolderController.cs.meta
Normal file
11
Assets/Scripts/Enemies/FolderController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: da1508f13deaad745b99607eafc321d8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
147
Assets/Scripts/Enemies/GusilightController.cs
Normal file
147
Assets/Scripts/Enemies/GusilightController.cs
Normal file
|
@ -0,0 +1,147 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
public class GusilightController : MonoBehaviour, IPooledObject{
|
||||
|
||||
[Header("Lifes")]
|
||||
[SerializeField] GameObject life1 = default;
|
||||
[SerializeField] GameObject life2 = default;
|
||||
[SerializeField] GameObject life3 = default;
|
||||
int life;
|
||||
Rigidbody rb;
|
||||
|
||||
[Space]
|
||||
[SerializeField, Range(0, 1)] float rotationSpeed = .5f;
|
||||
[SerializeField, Range(0, 3)] float attackRotationSpeed = 1.5f;
|
||||
[SerializeField] float regainMobilityDelay = 1f;
|
||||
[SerializeField] float patrolingSpeed = 2f;
|
||||
[SerializeField] float speed = 4f;
|
||||
[SerializeField] Animator anim = default;
|
||||
|
||||
bool patroling, rotationSelected, playerDetected, walking;
|
||||
Vector3 posToGo;
|
||||
PlayerController player;
|
||||
BoxCollider boxCollider;
|
||||
|
||||
[HideInInspector] public EnemySpawner spawner;
|
||||
[HideInInspector] public RoomTrigger room;
|
||||
|
||||
NavMeshAgent agent;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Awake(){
|
||||
boxCollider = GetComponent<BoxCollider>();
|
||||
player = FindObjectOfType<PlayerController>();
|
||||
agent = GetComponent<NavMeshAgent>();
|
||||
agent.speed = speed;
|
||||
rb = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
public void OnObjectSpawn(){
|
||||
life1.SetActive(false);
|
||||
life2.SetActive(false);
|
||||
life3.SetActive(false);
|
||||
|
||||
rb.isKinematic = true;
|
||||
boxCollider.isTrigger = false;
|
||||
agent.Warp(transform.position);
|
||||
playerDetected = false;
|
||||
life = 3;
|
||||
}
|
||||
|
||||
void Update(){
|
||||
if (playerDetected){
|
||||
if (walking){
|
||||
agent.SetDestination(player.transform.position);
|
||||
agent.isStopped = false;
|
||||
}
|
||||
}else{
|
||||
if (!patroling && !rotationSelected){
|
||||
posToGo = transform.position + new Vector3(Random.Range(-5f, 5f), 0, Random.Range(-5f, 5f));
|
||||
StartCoroutine(Patrol());
|
||||
rotationSelected = true;
|
||||
patroling = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnCollisionEnter(Collision col){
|
||||
if (col.gameObject.CompareTag("Disk")){
|
||||
if (!playerDetected){
|
||||
rb.isKinematic = false;
|
||||
playerDetected = true;
|
||||
walking = true;
|
||||
}else{
|
||||
switch (life){
|
||||
case 3:
|
||||
life3.SetActive(true);
|
||||
break;
|
||||
case 2:
|
||||
life2.SetActive(true);
|
||||
break;
|
||||
case 1:
|
||||
life1.SetActive(true);
|
||||
agent.isStopped = true;
|
||||
break;
|
||||
}
|
||||
life--;
|
||||
if (life == 0){
|
||||
gameObject.SetActive(false);
|
||||
player.percentage += Utils.RAM_cleanseBig;
|
||||
room.Die(gameObject);
|
||||
GameMaster.Instance.Pooler.SpawnFromPool("EnemyExplosion", transform.position);
|
||||
if (Utils.spawnDisk())
|
||||
GameMaster.Instance.Pooler.SpawnFromPool("DiskPickup", transform.position);
|
||||
}
|
||||
}
|
||||
|
||||
col.gameObject.GetComponent<Rigidbody>().velocity = Vector3.zero;
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerEnter(Collider col){
|
||||
if (col.CompareTag("Disk")){
|
||||
if (!playerDetected){
|
||||
rb.isKinematic = false;
|
||||
playerDetected = true;
|
||||
walking = true;
|
||||
}else{
|
||||
switch (life){
|
||||
case 3:
|
||||
life3.SetActive(true);
|
||||
break;
|
||||
case 2:
|
||||
life2.SetActive(true);
|
||||
break;
|
||||
case 1:
|
||||
life1.SetActive(true);
|
||||
agent.isStopped = true;
|
||||
break;
|
||||
}
|
||||
life--;
|
||||
if(life == 0){
|
||||
player.percentage += Utils.RAM_cleanseBig;
|
||||
gameObject.SetActive(false);
|
||||
room.Die(gameObject);
|
||||
GameMaster.Instance.Pooler.SpawnFromPool("EnemyExplosion", transform.position);
|
||||
if (Utils.spawnDisk())
|
||||
GameMaster.Instance.Pooler.SpawnFromPool("DiskPickup", transform.position);
|
||||
}
|
||||
}
|
||||
|
||||
col.GetComponent<Rigidbody>().velocity = Vector3.zero;
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator Patrol(){
|
||||
agent.isStopped = false;
|
||||
agent.SetDestination(posToGo);
|
||||
yield return new WaitForSeconds(Random.Range(1f, 2f));
|
||||
rb.velocity = Vector3.zero;
|
||||
patroling = false;
|
||||
rotationSelected = false;
|
||||
agent.isStopped = !playerDetected;
|
||||
}
|
||||
}
|
11
Assets/Scripts/Enemies/GusilightController.cs.meta
Normal file
11
Assets/Scripts/Enemies/GusilightController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a7ae8b5397c24ca4eb5d63abe64b6da3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
124
Assets/Scripts/Enemies/HardDriveController.cs
Normal file
124
Assets/Scripts/Enemies/HardDriveController.cs
Normal file
|
@ -0,0 +1,124 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
public class HardDriveController : MonoBehaviour, IPooledObject{
|
||||
|
||||
[SerializeField, Min(0)] float speed = 2f;
|
||||
|
||||
[Space]
|
||||
[SerializeField, Range(0, 10)] float playerDetectionRange = 3.5f;
|
||||
[SerializeField] LayerMask whatIsPlayer = 8;
|
||||
[SerializeField] LayerMask whatIsWall = -1;
|
||||
PlayerController player;
|
||||
bool followingPlayer;
|
||||
|
||||
bool walking;
|
||||
bool rotationSelected;
|
||||
|
||||
[Header("Attack")]
|
||||
[SerializeField, Min(0)] Vector3 playerHitRange = Vector3.one;
|
||||
[SerializeField] Transform playerHitPos = default;
|
||||
bool attacking;
|
||||
[SerializeField, Range(0, 1)] float particleDelay = .25f;
|
||||
[SerializeField, Range(0, 2)] float attackDuration = .5f;
|
||||
|
||||
[Space]
|
||||
[SerializeField] Animator anim = default;
|
||||
[SerializeField, Range(1, 5)] int damageAmount = 2;
|
||||
|
||||
NavMeshAgent agent;
|
||||
Vector3 posToGo;
|
||||
|
||||
[HideInInspector] public EnemySpawner spawner;
|
||||
[HideInInspector] public RoomTrigger room;
|
||||
|
||||
[SerializeField] Transform explosionPos = default;
|
||||
[SerializeField, Range(0, 1)] float disappearDelay = .5f;
|
||||
|
||||
[Space]
|
||||
[SerializeField, Range(0, 5)] float explosionRange;
|
||||
|
||||
void Awake(){
|
||||
player = FindObjectOfType<PlayerController>();
|
||||
agent = GetComponent<NavMeshAgent>();
|
||||
agent.speed = speed;
|
||||
}
|
||||
|
||||
public void OnObjectSpawn(){
|
||||
walking = rotationSelected = followingPlayer = attacking = false;
|
||||
posToGo = transform.position;
|
||||
agent.Warp(transform.position);
|
||||
agent.isStopped = true;
|
||||
}
|
||||
|
||||
void Update(){
|
||||
if (Physics.CheckSphere(transform.position, playerDetectionRange, whatIsPlayer) && !followingPlayer){
|
||||
followingPlayer = true;
|
||||
}
|
||||
|
||||
if (followingPlayer && !attacking){
|
||||
if (Physics.CheckBox(playerHitPos.position, playerHitRange / 2, playerHitPos.rotation, whatIsPlayer)){
|
||||
attacking = true;
|
||||
agent.isStopped = true;
|
||||
StartCoroutine(Attack());
|
||||
}else{
|
||||
agent.isStopped = false;
|
||||
agent.SetDestination(player.transform.position);
|
||||
}
|
||||
}else if (!attacking){
|
||||
if (!walking && !rotationSelected){
|
||||
posToGo = transform.position + new Vector3(Random.Range(-5f, 5f), 0, Random.Range(-5f, 5f));
|
||||
StartCoroutine(Patrol());
|
||||
walking = true;
|
||||
rotationSelected = true;
|
||||
}else if (!Physics.CheckBox(playerHitPos.position, playerHitRange / 2, playerHitPos.rotation, whatIsWall)){
|
||||
agent.isStopped = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator Patrol(){
|
||||
agent.isStopped = false;
|
||||
agent.SetDestination(posToGo);
|
||||
yield return new WaitForSeconds(Random.Range(1f, 2f));
|
||||
walking = false;
|
||||
rotationSelected = false;
|
||||
agent.isStopped = !followingPlayer;
|
||||
}
|
||||
|
||||
IEnumerator Attack(){
|
||||
anim.SetTrigger("Attack");
|
||||
yield return new WaitForSeconds(particleDelay);
|
||||
ObjectPooler.instance.SpawnFromPool("HDDExplosion", explosionPos.position);
|
||||
AudioManager.instance.PlayOneShot("electro1");
|
||||
AudioManager.instance.PlayOneShot("explo1");
|
||||
yield return new WaitForSeconds(attackDuration - particleDelay);
|
||||
if (Physics.CheckBox(playerHitPos.position, playerHitRange / 2, playerHitPos.rotation, whatIsPlayer)){
|
||||
player.Damage(damageAmount);
|
||||
}
|
||||
yield return new WaitForSeconds(disappearDelay);
|
||||
if(Physics.CheckSphere(explosionPos.position, explosionRange, whatIsPlayer)){
|
||||
player.Damage(1);
|
||||
}
|
||||
player.percentage += Utils.RAM_cleanseSmall;
|
||||
room.Die(gameObject);
|
||||
if (Utils.spawnDisk())
|
||||
GameMaster.Instance.Pooler.SpawnFromPool("DiskPickup", transform.position);
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
void OnDrawGizmosSelected(){
|
||||
Gizmos.DrawWireSphere(transform.position, playerDetectionRange);
|
||||
Gizmos.color = Color.red;
|
||||
Gizmos.DrawWireSphere(explosionPos.position, explosionRange);
|
||||
}
|
||||
|
||||
void OnDrawGizmos(){
|
||||
Gizmos.color = Color.red;
|
||||
if (playerHitPos != null){
|
||||
Gizmos.DrawWireCube(playerHitPos.position, playerHitRange);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Enemies/HardDriveController.cs.meta
Normal file
11
Assets/Scripts/Enemies/HardDriveController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 03a0203063a5494449f541d22bdc5c76
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
272
Assets/Scripts/Enemies/TurretCoil_Behaviour.cs
Normal file
272
Assets/Scripts/Enemies/TurretCoil_Behaviour.cs
Normal file
|
@ -0,0 +1,272 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[System.Serializable]
|
||||
public class ShootingPattern
|
||||
{
|
||||
public enum ShootingStyle
|
||||
{
|
||||
None, All, Cross, Cardinal, CW_Loop, CCW_Loop, ChrisCross
|
||||
}
|
||||
|
||||
public ShootingPattern(float _initialDelay, float _repeatDelay)
|
||||
{
|
||||
initialDelay = _initialDelay;
|
||||
repeatDelay = _repeatDelay;
|
||||
}
|
||||
|
||||
public static ShootingPattern operator *(ShootingPattern a, float b) => new ShootingPattern(a.initialDelay * b, a.repeatDelay * b);
|
||||
|
||||
public float initialDelay = 0;
|
||||
public float repeatDelay = 1;
|
||||
|
||||
public static readonly ShootingPattern[] chrissCross = new ShootingPattern[8] {
|
||||
new ShootingPattern(0, 1),
|
||||
new ShootingPattern(.5f, 1),
|
||||
new ShootingPattern(0, 1),
|
||||
new ShootingPattern(.5f, 1),
|
||||
new ShootingPattern(0, 1),
|
||||
new ShootingPattern(.5f, 1),
|
||||
new ShootingPattern(0, 1),
|
||||
new ShootingPattern(.5f, 1)};
|
||||
public static readonly ShootingPattern[] cross = new ShootingPattern[8] {
|
||||
new ShootingPattern(0, 0),
|
||||
new ShootingPattern(0, 1),
|
||||
new ShootingPattern(0, 0),
|
||||
new ShootingPattern(0, 1),
|
||||
new ShootingPattern(0, 0),
|
||||
new ShootingPattern(0, 1),
|
||||
new ShootingPattern(0, 0),
|
||||
new ShootingPattern(0, 1)};
|
||||
public static readonly ShootingPattern[] cardinal = new ShootingPattern[8] {
|
||||
new ShootingPattern(0, 1),
|
||||
new ShootingPattern(0, 0),
|
||||
new ShootingPattern(0, 1),
|
||||
new ShootingPattern(0, 0),
|
||||
new ShootingPattern(0, 1),
|
||||
new ShootingPattern(0, 0),
|
||||
new ShootingPattern(0, 1),
|
||||
new ShootingPattern(0, 0)};
|
||||
public static readonly ShootingPattern[] ccwLoop = new ShootingPattern[8] {
|
||||
new ShootingPattern(0, 1),
|
||||
new ShootingPattern(0.125f, 1),
|
||||
new ShootingPattern(0.25f, 1),
|
||||
new ShootingPattern(0.375f, 1),
|
||||
new ShootingPattern(0.5f, 1),
|
||||
new ShootingPattern(0.625f, 1),
|
||||
new ShootingPattern(0.75f, 1),
|
||||
new ShootingPattern(0.875f, 1)};
|
||||
public static readonly ShootingPattern[] cwLoop = new ShootingPattern[8] {
|
||||
new ShootingPattern(0, 1),
|
||||
new ShootingPattern(0.875f, 1),
|
||||
new ShootingPattern(0.75f, 1),
|
||||
new ShootingPattern(0.625f, 1),
|
||||
new ShootingPattern(0.5f, 1),
|
||||
new ShootingPattern(0.375f, 1),
|
||||
new ShootingPattern(0.25f, 1),
|
||||
new ShootingPattern(0.125f, 1)};
|
||||
public static readonly ShootingPattern[] all = new ShootingPattern[8] {
|
||||
new ShootingPattern(0, 1),
|
||||
new ShootingPattern(0, 1),
|
||||
new ShootingPattern(0, 1),
|
||||
new ShootingPattern(0, 1),
|
||||
new ShootingPattern(0, 1),
|
||||
new ShootingPattern(0, 1),
|
||||
new ShootingPattern(0, 1),
|
||||
new ShootingPattern(0, 1)};
|
||||
public static readonly ShootingPattern[] none = new ShootingPattern[8] {
|
||||
new ShootingPattern(0, 0),
|
||||
new ShootingPattern(0, 0),
|
||||
new ShootingPattern(0, 0),
|
||||
new ShootingPattern(0, 0),
|
||||
new ShootingPattern(0, 0),
|
||||
new ShootingPattern(0, 0),
|
||||
new ShootingPattern(0, 0),
|
||||
new ShootingPattern(0, 0)};
|
||||
|
||||
public static ShootingPattern[] styleToPattern(ShootingStyle a)
|
||||
{
|
||||
switch (a)
|
||||
{
|
||||
default:
|
||||
case ShootingStyle.None:
|
||||
return (ShootingPattern[])ShootingPattern.none.Clone();
|
||||
case ShootingStyle.All:
|
||||
return (ShootingPattern[])ShootingPattern.all.Clone();
|
||||
case ShootingStyle.Cross:
|
||||
return (ShootingPattern[])ShootingPattern.cross.Clone();
|
||||
case ShootingStyle.Cardinal:
|
||||
return (ShootingPattern[])ShootingPattern.cardinal.Clone();
|
||||
case ShootingStyle.CW_Loop:
|
||||
return (ShootingPattern[])ShootingPattern.cwLoop.Clone();
|
||||
case ShootingStyle.CCW_Loop:
|
||||
return (ShootingPattern[])ShootingPattern.ccwLoop.Clone();
|
||||
case ShootingStyle.ChrisCross:
|
||||
return (ShootingPattern[])ShootingPattern.chrissCross.Clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class TurretCoil_Behaviour : MonoBehaviour
|
||||
{
|
||||
[Header("Necesary fields")]
|
||||
public GameObject bulletPrefab;
|
||||
public string bulletKey="Bullet";
|
||||
public Transform[] shootingSockets = new Transform[8];
|
||||
|
||||
[Header("Turret settings")]
|
||||
public ShootingPattern.ShootingStyle shootingStyle = ShootingPattern.ShootingStyle.ChrisCross;
|
||||
public float shootFrequency = 1;
|
||||
|
||||
[Header("Bullet settings")]
|
||||
public float bulletSpeed = 3;
|
||||
private float bulletSpawnOffset=.15f;
|
||||
public BulletMovement.BulletMovementType bulletMovementType= BulletMovement.BulletMovementType.Linear;
|
||||
[DrawIf("bulletMovementType", BulletMovement.BulletMovementType.Linear, DrawIfAttribute.DisablingType.ReadOnly, DrawIfAttribute.Comparator.NotEqual)]
|
||||
public float waveLength = 1;
|
||||
[DrawIf("bulletMovementType", BulletMovement.BulletMovementType.Linear, DrawIfAttribute.DisablingType.ReadOnly, DrawIfAttribute.Comparator.NotEqual)]
|
||||
public float waveAmplitude = 1;
|
||||
|
||||
[Header("VFX")]
|
||||
public GameObject muzzle;
|
||||
|
||||
private ShootingPattern[] pattern = new ShootingPattern[8];
|
||||
public ShootingPattern[] Pattern
|
||||
{
|
||||
get
|
||||
{
|
||||
return pattern;
|
||||
}
|
||||
set
|
||||
{
|
||||
pattern = value;
|
||||
if (pattern != ShootingPattern.styleToPattern(ShootingPattern.ShootingStyle.None))
|
||||
{
|
||||
for (int i = 0; i < pattern.Length; ++i)
|
||||
{
|
||||
pattern[i] = pattern[i] * (1f / shootFrequency);
|
||||
}
|
||||
Invoke(nameof(startShooting), .5f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Material mat;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
initialHeight = transform.position.y;
|
||||
mat = GetComponentInChildren<MeshRenderer>().material;
|
||||
DeployHard(false);
|
||||
}
|
||||
|
||||
public float initialHeight;
|
||||
private void Start()
|
||||
{
|
||||
if(FindObjectOfType<BossBehaviour>()==null)
|
||||
Deploy(true);
|
||||
|
||||
|
||||
Pattern = ShootingPattern.styleToPattern(shootingStyle);
|
||||
}
|
||||
|
||||
private float height = .51f;
|
||||
private bool deployed = true;
|
||||
[ContextMenu("Deploy_Conceal")]
|
||||
public void Deploy(bool newState)
|
||||
{
|
||||
if (deployed != newState)
|
||||
{
|
||||
deployed = newState;
|
||||
transform.LeanMoveLocalY(!deployed ? -height : initialHeight, .5f).setFrom(transform.position.y).setEaseInOutBack();
|
||||
if (!deployed)
|
||||
stopShooting();
|
||||
}
|
||||
}
|
||||
public void DeployHard(bool newState)
|
||||
{
|
||||
if (deployed != newState)
|
||||
{
|
||||
deployed = newState;
|
||||
transform.position = new Vector3(transform.position.x, (!deployed ? -height : initialHeight), transform.position.z);
|
||||
}
|
||||
}
|
||||
private void shoot(int socket)
|
||||
{
|
||||
StartCoroutine(updateLEDshader(0.25f, socket, 1));
|
||||
|
||||
GameObject bullet;
|
||||
if (GameMaster.Instance.Pooler != null && GameMaster.Instance.Pooler.poolDictionary.ContainsKey("Bullet"))
|
||||
bullet=GameMaster.Instance.Pooler.SpawnFromPool(bulletKey, shootingSockets[socket].position+shootingSockets[socket].forward*bulletSpawnOffset, shootingSockets[socket].rotation);
|
||||
else
|
||||
bullet=Instantiate(bulletPrefab, shootingSockets[socket].position, shootingSockets[socket].rotation);
|
||||
bullet.GetComponent<BulletMovement>().speed = bulletSpeed;
|
||||
bullet.GetComponent<BulletMovement>().father = gameObject;
|
||||
bullet.GetComponent<BulletMovement>().movementType = bulletMovementType;
|
||||
//wave
|
||||
bullet.GetComponent<BulletMovement>().waveAmplitude = waveAmplitude;
|
||||
bullet.GetComponent<BulletMovement>().waveLength = waveLength;
|
||||
|
||||
Instantiate(muzzle, shootingSockets[socket].position, shootingSockets[socket].rotation);
|
||||
}
|
||||
|
||||
private IEnumerator updateLEDshader(float time, int socket, float glow)
|
||||
{
|
||||
mat.SetFloat("LED_"+(socket+1).ToString()+"_Glow", glow);
|
||||
yield return new WaitForSeconds(time);
|
||||
mat.SetFloat("LED_" + (socket + 1).ToString() + "_Glow", 0);
|
||||
}
|
||||
|
||||
public void stopShooting()
|
||||
{
|
||||
StopAllCoroutines();
|
||||
|
||||
for(int i=0; i<shootingSockets.Length; ++i)
|
||||
{
|
||||
mat.SetFloat("LED_" + (i + 1).ToString() + "_Glow", 0);
|
||||
}
|
||||
//StopCoroutine(shootFromPos(0, 0));
|
||||
//StopCoroutine(shootFromPos(0, 0, 0));
|
||||
}
|
||||
|
||||
private bool canStartShooting = true;
|
||||
private void reenableCanStartShooting()
|
||||
{
|
||||
canStartShooting = true;
|
||||
}
|
||||
public void startShooting()
|
||||
{
|
||||
if (canStartShooting)
|
||||
{
|
||||
StopAllCoroutines();
|
||||
if (shootFrequency != 0)
|
||||
{
|
||||
for (int i = 0; i < pattern.Length; ++i)
|
||||
{
|
||||
StartCoroutine(shootFromPos(i, pattern[i].initialDelay, pattern[i].repeatDelay));
|
||||
}
|
||||
}
|
||||
|
||||
canStartShooting = false;
|
||||
Invoke(nameof(reenableCanStartShooting), .35f);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator shootFromPos(int index, float startDelay, float repeatDelay)
|
||||
{
|
||||
if (!(startDelay == 0 && repeatDelay == 0))
|
||||
{
|
||||
yield return new WaitForSeconds(startDelay);
|
||||
shoot(index);
|
||||
StartCoroutine(shootFromPos(index, repeatDelay));
|
||||
}
|
||||
}
|
||||
IEnumerator shootFromPos(int index, float repeatDelay)
|
||||
{
|
||||
yield return new WaitForSeconds(repeatDelay);
|
||||
shoot(index);
|
||||
StartCoroutine(shootFromPos(index, repeatDelay));
|
||||
}
|
||||
|
||||
}
|
11
Assets/Scripts/Enemies/TurretCoil_Behaviour.cs.meta
Normal file
11
Assets/Scripts/Enemies/TurretCoil_Behaviour.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f6e1b4c4815648d4bbfda026da7db6df
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
167
Assets/Scripts/Enemies/TurretController.cs
Normal file
167
Assets/Scripts/Enemies/TurretController.cs
Normal file
|
@ -0,0 +1,167 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
public class TurretController : MonoBehaviour, IPooledObject{
|
||||
|
||||
[SerializeField] float speed = 1f;
|
||||
[SerializeField] Animator anim = default;
|
||||
[SerializeField] GameObject head = default;
|
||||
[SerializeField] GameObject headObj = default;
|
||||
|
||||
[Space]
|
||||
[SerializeField, Range(0, 3f)] float firstAttackDelay = 1f;
|
||||
[SerializeField] int numberOfDisks = 10;
|
||||
int currentDisk;
|
||||
[SerializeField] float maxHeigth = 1f;
|
||||
[SerializeField] float minHeigth = 0f;
|
||||
[SerializeField] GameObject turretObject = default;
|
||||
[SerializeField] Transform shootPos = default;
|
||||
|
||||
[Space]
|
||||
[SerializeField, Range(0, 15)] float shootingDistance = 7f;
|
||||
[SerializeField, Range(0, 5)] float aimingTime = 2f;
|
||||
[SerializeField, Range(0, 1)] float attackDelay = .25f;
|
||||
[SerializeField] LayerMask whatIsPlayer = default;
|
||||
[SerializeField] LayerMask whatIsWall = default;
|
||||
PlayerController player;
|
||||
float rotationVelocity;
|
||||
bool canAttack;
|
||||
bool aiming;
|
||||
bool prepareShooting;
|
||||
bool playerDetected;
|
||||
|
||||
NavMeshAgent agent;
|
||||
|
||||
[HideInInspector] public EnemySpawner spawner;
|
||||
[HideInInspector] public RoomTrigger room;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Awake(){
|
||||
agent = FindObjectOfType<NavMeshAgent>();
|
||||
player = FindObjectOfType<PlayerController>();
|
||||
agent.speed = speed;
|
||||
}
|
||||
|
||||
public void OnObjectSpawn(){
|
||||
currentDisk = numberOfDisks;
|
||||
turretObject.transform.localPosition = new Vector3(minHeigth + (maxHeigth - minHeigth) / numberOfDisks * currentDisk, 0, 0);
|
||||
playerDetected = aiming = prepareShooting = canAttack = false;
|
||||
agent.Warp(transform.position);
|
||||
agent.isStopped = true;
|
||||
StartCoroutine(FirstAttackDelay());
|
||||
}
|
||||
|
||||
IEnumerator FirstAttackDelay(){
|
||||
yield return new WaitForSeconds(firstAttackDelay);
|
||||
canAttack = true;
|
||||
}
|
||||
|
||||
void Update(){
|
||||
if(!playerDetected && Physics.CheckSphere(transform.position, shootingDistance, whatIsPlayer)){
|
||||
agent.isStopped = false;
|
||||
playerDetected = true;
|
||||
}
|
||||
|
||||
Vector3 dire = (player.transform.position - (transform.position + Vector3.up * .3f)).normalized;
|
||||
//Ray rayx = new Ray(transform.position + Vector3.up * .3f, dire * Vector3.Distance(transform.position + Vector3.up * .3f, player.transform.position));
|
||||
//Debug.DrawRay(rayx.origin, rayx.direction * Vector3.Distance(transform.position + Vector3.up, player.transform.position));
|
||||
|
||||
if (Physics.CheckSphere(transform.position, shootingDistance, whatIsPlayer) && canAttack && currentDisk > 0){
|
||||
Ray ray = new Ray(transform.position + Vector3.up * .3f, dire * Vector3.Distance(transform.position + Vector3.up * .3f, player.transform.position));
|
||||
if (!Physics.Raycast(ray, Vector3.Distance(transform.position + Vector3.up * .3f, player.transform.position), whatIsWall)){
|
||||
StartCoroutine(Shoot());
|
||||
canAttack = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (Physics.CheckSphere(transform.position + Vector3.up, shootingDistance, whatIsPlayer) && canAttack && currentDisk == 0){
|
||||
Ray ray = new Ray(transform.position + Vector3.up * .3f, dire * Vector3.Distance(transform.position + Vector3.up * .3f, player.transform.position));
|
||||
if (!Physics.Raycast(ray, Vector3.Distance(transform.position + Vector3.up * .3f, player.transform.position), whatIsWall)){
|
||||
StartCoroutine(ShootHead());
|
||||
canAttack = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (aiming){
|
||||
if (!prepareShooting){
|
||||
agent.SetDestination(player.transform.position);
|
||||
}else{
|
||||
Vector3 pos = player.transform.position - transform.position;
|
||||
float rotY = Mathf.Atan2(-pos.z, pos.x) * Mathf.Rad2Deg;
|
||||
float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, rotY + 90, ref rotationVelocity, .1f);
|
||||
transform.rotation = Quaternion.Euler(0f, angle, 0f);
|
||||
}
|
||||
}else if (playerDetected && !prepareShooting){
|
||||
agent.SetDestination(player.transform.position);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator ShootHead(){
|
||||
aiming = true;
|
||||
yield return new WaitForSeconds(aimingTime);
|
||||
agent.isStopped = true;
|
||||
prepareShooting = true;
|
||||
yield return new WaitForSeconds(attackDelay);
|
||||
agent.isStopped = false;
|
||||
aiming = false;
|
||||
prepareShooting = false;
|
||||
anim.SetTrigger("Shoot");
|
||||
currentDisk--;
|
||||
//turretObject.transform.localPosition = new Vector3(minHeigth + (maxHeigth - minHeigth) / numberOfDisks * currentDisk, 0, 0);
|
||||
headObj.SetActive(false);
|
||||
//FrisbieController frisbie = ObjectPooler.instance.SpawnFromPool("Disk", shootPos.position, transform.rotation).GetComponent<FrisbieController>();
|
||||
ObjectPooler.instance.SpawnFromPool("TurretHead", shootPos.position, transform.rotation);
|
||||
canAttack = true;
|
||||
gameObject.SetActive(false);
|
||||
player.percentage += Utils.RAM_cleanseSmall;
|
||||
room.Die(gameObject);
|
||||
}
|
||||
|
||||
IEnumerator Shoot(){
|
||||
aiming = true;
|
||||
yield return new WaitForSeconds(aimingTime);
|
||||
agent.isStopped = true;
|
||||
prepareShooting = true;
|
||||
yield return new WaitForSeconds(attackDelay);
|
||||
agent.isStopped = false;
|
||||
aiming = false;
|
||||
prepareShooting = false;
|
||||
anim.SetTrigger("Shoot");
|
||||
currentDisk--;
|
||||
turretObject.transform.localPosition = new Vector3(minHeigth + (maxHeigth - minHeigth) / numberOfDisks * currentDisk, 0, 0);
|
||||
ObjectPooler.instance.SpawnFromPool("EnemyDisk", shootPos.position, transform.rotation);
|
||||
//FrisbieController frisbie = Instantiate(bullet, transform.position + Vector3.up, transform.rotation).GetComponent<FrisbieController>();
|
||||
canAttack = true;
|
||||
}
|
||||
|
||||
void OnTriggerEnter(Collider col){
|
||||
if (col.CompareTag("Disk")){
|
||||
player.percentage += Utils.RAM_cleanseSmall;
|
||||
gameObject.SetActive(false);
|
||||
col.GetComponent<Rigidbody>().velocity = Vector3.zero;
|
||||
room.Die(gameObject);
|
||||
GameMaster.Instance.Pooler.SpawnFromPool("EnemyExplosion", transform.position);
|
||||
if (Utils.spawnDisk())
|
||||
GameMaster.Instance.Pooler.SpawnFromPool("DiskPickup", transform.position);
|
||||
StopAllCoroutines();
|
||||
}
|
||||
}
|
||||
void OnCollisionEnter(Collision col){
|
||||
if (col.gameObject.CompareTag("Disk")){
|
||||
player.percentage += Utils.RAM_cleanseSmall;
|
||||
gameObject.SetActive(false);
|
||||
col.gameObject.GetComponent<Rigidbody>().velocity = Vector3.zero;
|
||||
room.Die(gameObject);
|
||||
GameMaster.Instance.Pooler.SpawnFromPool("EnemyExplosion", transform.position);
|
||||
if (Utils.spawnDisk())
|
||||
GameMaster.Instance.Pooler.SpawnFromPool("DiskPickup", transform.position);
|
||||
StopAllCoroutines();
|
||||
}
|
||||
}
|
||||
|
||||
void OnDrawGizmosSelected(){
|
||||
Gizmos.DrawWireSphere(transform.position, shootingDistance);
|
||||
}
|
||||
}
|
11
Assets/Scripts/Enemies/TurretController.cs.meta
Normal file
11
Assets/Scripts/Enemies/TurretController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f3ad027a84e9ef64783582634e6163ed
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
113
Assets/Scripts/ExtDebug.cs
Normal file
113
Assets/Scripts/ExtDebug.cs
Normal file
|
@ -0,0 +1,113 @@
|
|||
using UnityEngine;
|
||||
|
||||
public static class ExtDebug
|
||||
{
|
||||
//Draws just the box at where it is currently hitting.
|
||||
public static void DrawBoxCastOnHit(Vector3 origin, Vector3 halfExtents, Quaternion orientation, Vector3 direction, float hitInfoDistance, Color color)
|
||||
{
|
||||
origin = CastCenterOnCollision(origin, direction, hitInfoDistance);
|
||||
DrawBox(origin, halfExtents, orientation, color);
|
||||
}
|
||||
|
||||
//Draws the full box from start of cast to its end distance. Can also pass in hitInfoDistance instead of full distance
|
||||
public static void DrawBoxCastBox(Vector3 origin, Vector3 halfExtents, Quaternion orientation, Vector3 direction, float distance, Color color)
|
||||
{
|
||||
direction.Normalize();
|
||||
Box bottomBox = new Box(origin, halfExtents, orientation);
|
||||
Box topBox = new Box(origin + (direction * distance), halfExtents, orientation);
|
||||
|
||||
Debug.DrawLine(bottomBox.backBottomLeft, topBox.backBottomLeft, color);
|
||||
Debug.DrawLine(bottomBox.backBottomRight, topBox.backBottomRight, color);
|
||||
Debug.DrawLine(bottomBox.backTopLeft, topBox.backTopLeft, color);
|
||||
Debug.DrawLine(bottomBox.backTopRight, topBox.backTopRight, color);
|
||||
Debug.DrawLine(bottomBox.frontTopLeft, topBox.frontTopLeft, color);
|
||||
Debug.DrawLine(bottomBox.frontTopRight, topBox.frontTopRight, color);
|
||||
Debug.DrawLine(bottomBox.frontBottomLeft, topBox.frontBottomLeft, color);
|
||||
Debug.DrawLine(bottomBox.frontBottomRight, topBox.frontBottomRight, color);
|
||||
|
||||
DrawBox(bottomBox, color);
|
||||
DrawBox(topBox, color);
|
||||
}
|
||||
|
||||
public static void DrawBox(Vector3 origin, Vector3 halfExtents, Quaternion orientation, Color color)
|
||||
{
|
||||
DrawBox(new Box(origin, halfExtents, orientation), color);
|
||||
}
|
||||
public static void DrawBox(Box box, Color color)
|
||||
{
|
||||
Debug.DrawLine(box.frontTopLeft, box.frontTopRight, color);
|
||||
Debug.DrawLine(box.frontTopRight, box.frontBottomRight, color);
|
||||
Debug.DrawLine(box.frontBottomRight, box.frontBottomLeft, color);
|
||||
Debug.DrawLine(box.frontBottomLeft, box.frontTopLeft, color);
|
||||
|
||||
Debug.DrawLine(box.backTopLeft, box.backTopRight, color);
|
||||
Debug.DrawLine(box.backTopRight, box.backBottomRight, color);
|
||||
Debug.DrawLine(box.backBottomRight, box.backBottomLeft, color);
|
||||
Debug.DrawLine(box.backBottomLeft, box.backTopLeft, color);
|
||||
|
||||
Debug.DrawLine(box.frontTopLeft, box.backTopLeft, color);
|
||||
Debug.DrawLine(box.frontTopRight, box.backTopRight, color);
|
||||
Debug.DrawLine(box.frontBottomRight, box.backBottomRight, color);
|
||||
Debug.DrawLine(box.frontBottomLeft, box.backBottomLeft, color);
|
||||
}
|
||||
|
||||
public struct Box
|
||||
{
|
||||
public Vector3 localFrontTopLeft { get; private set; }
|
||||
public Vector3 localFrontTopRight { get; private set; }
|
||||
public Vector3 localFrontBottomLeft { get; private set; }
|
||||
public Vector3 localFrontBottomRight { get; private set; }
|
||||
public Vector3 localBackTopLeft { get { return -localFrontBottomRight; } }
|
||||
public Vector3 localBackTopRight { get { return -localFrontBottomLeft; } }
|
||||
public Vector3 localBackBottomLeft { get { return -localFrontTopRight; } }
|
||||
public Vector3 localBackBottomRight { get { return -localFrontTopLeft; } }
|
||||
|
||||
public Vector3 frontTopLeft { get { return localFrontTopLeft + origin; } }
|
||||
public Vector3 frontTopRight { get { return localFrontTopRight + origin; } }
|
||||
public Vector3 frontBottomLeft { get { return localFrontBottomLeft + origin; } }
|
||||
public Vector3 frontBottomRight { get { return localFrontBottomRight + origin; } }
|
||||
public Vector3 backTopLeft { get { return localBackTopLeft + origin; } }
|
||||
public Vector3 backTopRight { get { return localBackTopRight + origin; } }
|
||||
public Vector3 backBottomLeft { get { return localBackBottomLeft + origin; } }
|
||||
public Vector3 backBottomRight { get { return localBackBottomRight + origin; } }
|
||||
|
||||
public Vector3 origin { get; private set; }
|
||||
|
||||
public Box(Vector3 origin, Vector3 halfExtents, Quaternion orientation) : this(origin, halfExtents)
|
||||
{
|
||||
Rotate(orientation);
|
||||
}
|
||||
public Box(Vector3 origin, Vector3 halfExtents)
|
||||
{
|
||||
halfExtents /= 2;
|
||||
this.localFrontTopLeft = new Vector3(-halfExtents.x, halfExtents.y, -halfExtents.z);
|
||||
this.localFrontTopRight = new Vector3(halfExtents.x, halfExtents.y, -halfExtents.z);
|
||||
this.localFrontBottomLeft = new Vector3(-halfExtents.x, -halfExtents.y, -halfExtents.z);
|
||||
this.localFrontBottomRight = new Vector3(halfExtents.x, -halfExtents.y, -halfExtents.z);
|
||||
|
||||
this.origin = origin;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void Rotate(Quaternion orientation)
|
||||
{
|
||||
localFrontTopLeft = RotatePointAroundPivot(localFrontTopLeft, Vector3.zero, orientation);
|
||||
localFrontTopRight = RotatePointAroundPivot(localFrontTopRight, Vector3.zero, orientation);
|
||||
localFrontBottomLeft = RotatePointAroundPivot(localFrontBottomLeft, Vector3.zero, orientation);
|
||||
localFrontBottomRight = RotatePointAroundPivot(localFrontBottomRight, Vector3.zero, orientation);
|
||||
}
|
||||
}
|
||||
|
||||
//This should work for all cast types
|
||||
static Vector3 CastCenterOnCollision(Vector3 origin, Vector3 direction, float hitInfoDistance)
|
||||
{
|
||||
return origin + (direction.normalized * hitInfoDistance);
|
||||
}
|
||||
|
||||
static Vector3 RotatePointAroundPivot(Vector3 point, Vector3 pivot, Quaternion rotation)
|
||||
{
|
||||
Vector3 direction = point - pivot;
|
||||
return pivot + rotation * direction;
|
||||
}
|
||||
}
|
11
Assets/Scripts/ExtDebug.cs.meta
Normal file
11
Assets/Scripts/ExtDebug.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 62685fd0a893b1d4d9fd4f4c13edf4d6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/FakeShop.meta
Normal file
8
Assets/Scripts/FakeShop.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7db3524727d7e4e4abea750863d784cb
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
43
Assets/Scripts/FakeShop/FakeShopSeller.cs
Normal file
43
Assets/Scripts/FakeShop/FakeShopSeller.cs
Normal file
|
@ -0,0 +1,43 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class FakeShopSeller : MonoBehaviour{
|
||||
|
||||
[SerializeField] GameObject sellerText = default;
|
||||
[SerializeField] TMP_Animated text = default;
|
||||
[SerializeField] Dialogue dialogue = default;
|
||||
[SerializeField] GameObject arrow = default;
|
||||
|
||||
void Awake(){
|
||||
arrow.SetActive(false);
|
||||
}
|
||||
|
||||
void OnTriggerEnter(Collider col){
|
||||
if (col.CompareTag("Player")){
|
||||
arrow.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerStay(Collider col){
|
||||
if (col.CompareTag("Player")){
|
||||
if(Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0)){
|
||||
Time.timeScale = 0;
|
||||
sellerText.SetActive(true);
|
||||
text.ClearText();
|
||||
text.ReadText(dialogue.sentences[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerExit(Collider col){
|
||||
if (col.CompareTag("Player")){
|
||||
arrow.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void EndConversation(){
|
||||
Time.timeScale = 1;
|
||||
}
|
||||
}
|
11
Assets/Scripts/FakeShop/FakeShopSeller.cs.meta
Normal file
11
Assets/Scripts/FakeShop/FakeShopSeller.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3b9c58005cce9bf4d8529acbe07ef993
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
19
Assets/Scripts/GameController.cs
Normal file
19
Assets/Scripts/GameController.cs
Normal file
|
@ -0,0 +1,19 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class GameController : MonoBehaviour{
|
||||
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start(){
|
||||
AudioManager.instance.StopAll();
|
||||
AudioManager.instance.Play("InGameMusic");
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
|
||||
}
|
||||
}
|
11
Assets/Scripts/GameController.cs.meta
Normal file
11
Assets/Scripts/GameController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 69a2880bba15f674caf9e6bbccbe6dc7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
156
Assets/Scripts/GameMaster.cs
Normal file
156
Assets/Scripts/GameMaster.cs
Normal file
|
@ -0,0 +1,156 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
|
||||
public class GameMaster : MonoBehaviour
|
||||
{
|
||||
private static GameMaster _instance;
|
||||
public static GameMaster Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = FindObjectOfType<GameMaster>();
|
||||
|
||||
if (_instance == null)
|
||||
{
|
||||
GameObject container = new GameObject("GameMaster");
|
||||
_instance = container.AddComponent<GameMaster>();
|
||||
}
|
||||
}
|
||||
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
|
||||
//Player
|
||||
[Header("Player")]
|
||||
|
||||
public GameObject player;
|
||||
[SerializeField]
|
||||
private GameObject playerPrefab;
|
||||
|
||||
//Game fields
|
||||
private float difficulty=Utils.mediumDifficultyK;
|
||||
public float Difficulty
|
||||
{
|
||||
get
|
||||
{
|
||||
return difficulty;
|
||||
}
|
||||
}
|
||||
|
||||
[Header("Level")]
|
||||
//Level fields
|
||||
[SerializeField]
|
||||
private static int levelNumber = 0;
|
||||
public int LevelNumber
|
||||
{
|
||||
get
|
||||
{
|
||||
return levelNumber;
|
||||
}
|
||||
}
|
||||
private ObjectPooler pooler;
|
||||
public ObjectPooler Pooler
|
||||
{
|
||||
get
|
||||
{
|
||||
return pooler;
|
||||
}
|
||||
}
|
||||
|
||||
//dungeon
|
||||
private DungeonGen dungeon;
|
||||
public DungeonGen Dungeon
|
||||
{
|
||||
get
|
||||
{
|
||||
return dungeon;
|
||||
}
|
||||
}
|
||||
|
||||
public void nextLevel()
|
||||
{
|
||||
levelNumber++;
|
||||
Debug.Log("You have passed to a new level: From level " + (levelNumber - 1).ToString() + " to " + levelNumber.ToString());
|
||||
//SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex, LoadSceneMode.Single);
|
||||
Loader.Load(SceneManager.GetActiveScene().buildIndex);
|
||||
InitVars();
|
||||
}
|
||||
|
||||
public void bossLevel(){
|
||||
//SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex, LoadSceneMode.Single);
|
||||
Loader.Load(3);
|
||||
InitVars();
|
||||
}
|
||||
|
||||
//Utils
|
||||
public GameObject ReplaceGameObject(GameObject newGO, GameObject oldGO)
|
||||
{
|
||||
GameObject aux = Instantiate(newGO, oldGO.transform);
|
||||
aux.transform.parent = null;
|
||||
|
||||
if (Application.isPlaying)
|
||||
Destroy(oldGO);
|
||||
else if (Application.isEditor)
|
||||
DestroyImmediate(oldGO);
|
||||
|
||||
|
||||
return aux;
|
||||
}
|
||||
|
||||
public void ResetLevel(){
|
||||
levelNumber = 0;
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
InitVars();
|
||||
}
|
||||
void InitVars()
|
||||
{
|
||||
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = this;
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
else
|
||||
Destroy(gameObject);
|
||||
|
||||
//Dungeon setup
|
||||
if (FindObjectOfType<DungeonGen>() != null)
|
||||
{
|
||||
Instance.dungeon = FindObjectOfType<DungeonGen>();
|
||||
}
|
||||
|
||||
//Player setup
|
||||
if (player == null && FindObjectOfType<PlayerController>() != null)
|
||||
{
|
||||
Instance.player = FindObjectOfType<PlayerController>().gameObject;
|
||||
if(Instance.dungeon!=null)
|
||||
Instance.player.transform.position = Instance.dungeon.startingRoom.transform.position+new Vector3(0, 1, 0);
|
||||
}
|
||||
else
|
||||
player = Instantiate(playerPrefab, dungeon.startingRoom.transform.parent).GetComponentInChildren<PlayerController>().gameObject;
|
||||
|
||||
|
||||
//Pooler
|
||||
if (FindObjectOfType<ObjectPooler>() != null)
|
||||
Instance.pooler = FindObjectOfType<ObjectPooler>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
LeanTween.init(800);
|
||||
}
|
||||
|
||||
void dungeonDependantSetUp()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
11
Assets/Scripts/GameMaster.cs.meta
Normal file
11
Assets/Scripts/GameMaster.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 93d02e44d3ed63e4ea7793058fcefeb7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: -25
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
46
Assets/Scripts/Loader.cs
Normal file
46
Assets/Scripts/Loader.cs
Normal file
|
@ -0,0 +1,46 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public static class Loader{
|
||||
|
||||
class LoadingMonoBehaviour : MonoBehaviour { }
|
||||
|
||||
static Action onLoaderCallback;
|
||||
static AsyncOperation loadingAsyncOperation;
|
||||
|
||||
public static void Load(int scene){
|
||||
onLoaderCallback = () => {
|
||||
GameObject loadingGameObject = new GameObject("LoadingGameObject");
|
||||
loadingGameObject.AddComponent<LoadingMonoBehaviour>().StartCoroutine(LoadSceneAsync(scene));
|
||||
};
|
||||
|
||||
SceneManager.LoadScene("Loading");
|
||||
}
|
||||
|
||||
static IEnumerator LoadSceneAsync(int scene){
|
||||
yield return null;
|
||||
loadingAsyncOperation = SceneManager.LoadSceneAsync(scene);
|
||||
|
||||
while (!loadingAsyncOperation.isDone){
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static float GetLoadingProgress(){
|
||||
if(loadingAsyncOperation != null){
|
||||
return loadingAsyncOperation.progress;
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static void LoaderCallback(){
|
||||
if(onLoaderCallback != null){
|
||||
onLoaderCallback();
|
||||
onLoaderCallback = null;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Loader.cs.meta
Normal file
11
Assets/Scripts/Loader.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ffa7c587ec7cf2f4e9a0feca8fc05495
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
13
Assets/Scripts/LoaderCallback.cs
Normal file
13
Assets/Scripts/LoaderCallback.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class LoaderCallback : MonoBehaviour{
|
||||
|
||||
bool isFirstUpdate = true;
|
||||
|
||||
void Update(){
|
||||
isFirstUpdate = false;
|
||||
Loader.LoaderCallback();
|
||||
}
|
||||
}
|
11
Assets/Scripts/LoaderCallback.cs.meta
Normal file
11
Assets/Scripts/LoaderCallback.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5eb05761a203e2e4caec6cb6064bb58d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
19
Assets/Scripts/LoadingProgressBar.cs
Normal file
19
Assets/Scripts/LoadingProgressBar.cs
Normal file
|
@ -0,0 +1,19 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class LoadingProgressBar : MonoBehaviour{
|
||||
|
||||
Image image;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Awake(){
|
||||
image = GetComponent<Image>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
image.fillAmount = Loader.GetLoadingProgress();
|
||||
}
|
||||
}
|
11
Assets/Scripts/LoadingProgressBar.cs.meta
Normal file
11
Assets/Scripts/LoadingProgressBar.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 668ac9721f6842e4da9aa48b05518e81
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
15
Assets/Scripts/MenuLoader.cs
Normal file
15
Assets/Scripts/MenuLoader.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class MenuLoader : MonoBehaviour{
|
||||
|
||||
public void LoadMenu(){
|
||||
PlayerPrefs.DeleteKey("HP");
|
||||
PlayerPrefs.DeleteKey("Percentage");
|
||||
PlayerPrefs.DeleteKey("TimeSurvived");
|
||||
Time.timeScale = 1;
|
||||
Destroy(GameMaster.Instance.gameObject);
|
||||
Loader.Load(0);
|
||||
}
|
||||
}
|
11
Assets/Scripts/MenuLoader.cs.meta
Normal file
11
Assets/Scripts/MenuLoader.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: faf09019b1f58ea428e4a5f13613b573
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Particles.meta
Normal file
8
Assets/Scripts/Particles.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 81fe0760d3d82474b9c3de58c9f16195
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
34
Assets/Scripts/Particles/FireChildSystems.cs
Normal file
34
Assets/Scripts/Particles/FireChildSystems.cs
Normal file
|
@ -0,0 +1,34 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class FireChildSystems : MonoBehaviour
|
||||
{
|
||||
public bool destroyOnEnd = true;
|
||||
public string soundKey = "";
|
||||
|
||||
[ContextMenu("Fire Shurikens")]
|
||||
void fireChildParticles()
|
||||
{
|
||||
foreach(ParticleSystem ps in GetComponentsInChildren<ParticleSystem>())
|
||||
{
|
||||
ps.Play();
|
||||
}
|
||||
if (soundKey.Length != 0)
|
||||
AudioManager.instance.PlayOneShot(soundKey);
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
fireChildParticles();
|
||||
Invoke(nameof(Autodestroy), 4);
|
||||
}
|
||||
|
||||
void Autodestroy()
|
||||
{
|
||||
if (destroyOnEnd)
|
||||
Destroy(gameObject);
|
||||
else
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
11
Assets/Scripts/Particles/FireChildSystems.cs.meta
Normal file
11
Assets/Scripts/Particles/FireChildSystems.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4a3a455da2415fd45aa36124dafa3d09
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
33
Assets/Scripts/Particles/ParticleSystemAutoDestroy.cs
Normal file
33
Assets/Scripts/Particles/ParticleSystemAutoDestroy.cs
Normal file
|
@ -0,0 +1,33 @@
|
|||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public enum DisablingAction
|
||||
{
|
||||
Destroy, Deactivate
|
||||
}
|
||||
|
||||
public class ParticleSystemAutoDestroy : MonoBehaviour
|
||||
{
|
||||
public DisablingAction action = DisablingAction.Deactivate;
|
||||
private ParticleSystem ps;
|
||||
|
||||
|
||||
public void Start()
|
||||
{
|
||||
ps = GetComponent<ParticleSystem>();
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (ps)
|
||||
{
|
||||
if (!ps.IsAlive())
|
||||
{
|
||||
if (action == DisablingAction.Deactivate)
|
||||
gameObject.SetActive(false);
|
||||
else
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Particles/ParticleSystemAutoDestroy.cs.meta
Normal file
11
Assets/Scripts/Particles/ParticleSystemAutoDestroy.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: eb47a169d3ce5a6489ef2f5b15d4434b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Player.meta
Normal file
8
Assets/Scripts/Player.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f46262ef0be41864490b27ee29404845
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
17
Assets/Scripts/Player/DistanceConstraint.cs
Normal file
17
Assets/Scripts/Player/DistanceConstraint.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class DistanceConstraint : MonoBehaviour{
|
||||
|
||||
public Transform source;
|
||||
public float maxDistance;
|
||||
[Range(0, 1)] public float maxHeight = .15f;
|
||||
|
||||
void Update(){
|
||||
if ((transform.position - source.position).magnitude > maxDistance){
|
||||
transform.position = source.position + (transform.position - source.position).normalized * maxDistance;
|
||||
transform.localPosition = new Vector3(transform.localPosition.x, maxHeight, transform.localPosition.z);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Player/DistanceConstraint.cs.meta
Normal file
11
Assets/Scripts/Player/DistanceConstraint.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 95a5d012580aac74981717162f274387
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
24
Assets/Scripts/Player/DungeonIntruder.cs
Normal file
24
Assets/Scripts/Player/DungeonIntruder.cs
Normal file
|
@ -0,0 +1,24 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class DungeonIntruder : MonoBehaviour
|
||||
{
|
||||
public Room currentRoom;
|
||||
public UnityEvent roomChange;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
roomChange = new UnityEvent();
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (other.gameObject.GetComponent<Room>() != null && other.gameObject.GetComponent<Room>()!=currentRoom)
|
||||
{
|
||||
currentRoom = other.gameObject.GetComponent<Room>();
|
||||
roomChange.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Player/DungeonIntruder.cs.meta
Normal file
11
Assets/Scripts/Player/DungeonIntruder.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 87e63aad25b099d4d9350db316e276ef
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
184
Assets/Scripts/Player/FrisbieController.cs
Normal file
184
Assets/Scripts/Player/FrisbieController.cs
Normal file
|
@ -0,0 +1,184 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class FrisbieController : MonoBehaviour, IPooledObject{
|
||||
|
||||
[System.Serializable] public enum FrisbieType { Default, Explosive, Boomerang }
|
||||
public FrisbieType frisbieType = default;
|
||||
|
||||
[Space]
|
||||
[SerializeField, Range(0, 3)] float damageVelocityThreshold = 1.5f;
|
||||
|
||||
[Header("Default")]
|
||||
[SerializeField] float speed = 10f;
|
||||
Rigidbody rb;
|
||||
[SerializeField] Transform frisbie = default;
|
||||
float heightVelocity;
|
||||
public PhysicMaterial defaultMaterial;
|
||||
|
||||
[Header("Explosive")]
|
||||
[SerializeField] float explosiveSpeed = 5f;
|
||||
private bool canExplode = false;
|
||||
public float explosionSpeedThreshold = 0.5f;
|
||||
public float explosionRad = 1;
|
||||
public float explosionBlastSpeed = 20;
|
||||
public SphereCollider explosionCol;
|
||||
public PhysicMaterial explosiveMaterial;
|
||||
|
||||
[Header("Boomerang")]
|
||||
[SerializeField] float boomerangSpeed = 5f;
|
||||
public float boomerangReturnStrength = 5;
|
||||
private Vector3 boomerangReturnDir = Vector3.zero;
|
||||
public PhysicMaterial boomerangMaterial;
|
||||
|
||||
[Space]
|
||||
[SerializeField, Range(0, 1)] float pickUpEnableDelay = .3f;
|
||||
[SerializeField] GameObject pickUpCollider = default;
|
||||
[SerializeField] GameObject[] disks = default;
|
||||
|
||||
void Awake(){
|
||||
rb = GetComponent<Rigidbody>();
|
||||
|
||||
if (PlayerPrefs.HasKey("Disk")){
|
||||
for (int i = 0; i < disks.Length; i++){
|
||||
if (PlayerPrefs.GetInt("Disk") != i){
|
||||
disks[i].SetActive(false);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
PlayerPrefs.SetInt("Disk", 0);
|
||||
for (int i = 0; i < disks.Length; i++){
|
||||
if(PlayerPrefs.GetInt("Disk") != i){
|
||||
disks[i].SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnValidate()
|
||||
{
|
||||
explosionCol.radius = explosionRad;
|
||||
}
|
||||
|
||||
public void OnObjectSpawn(){
|
||||
explosionCol.enabled = false;
|
||||
gameObject.tag = "Disk";
|
||||
rb.velocity = Vector3.zero;
|
||||
switch (frisbieType)
|
||||
{
|
||||
case FrisbieType.Default:
|
||||
GetComponent<Collider>().material = defaultMaterial;
|
||||
break;
|
||||
case FrisbieType.Boomerang:
|
||||
GetComponent<Collider>().material = boomerangMaterial;
|
||||
break;
|
||||
case FrisbieType.Explosive:
|
||||
GetComponent<Collider>().material = explosiveMaterial;
|
||||
break;
|
||||
}
|
||||
boomerangReturnDir = transform.forward * -1;
|
||||
if(pickUpCollider != null)
|
||||
pickUpCollider.SetActive(false);
|
||||
StartCoroutine(EnablePickUpCollider());
|
||||
}
|
||||
|
||||
public void AddForce(Vector3 velocity){
|
||||
//rb.velocity = velocity / 2;
|
||||
//rb.velocity = new Vector3(velocity.x, 0, velocity.z) / 2;
|
||||
switch (frisbieType){
|
||||
case FrisbieType.Default:
|
||||
rb.AddForce(transform.forward.normalized * speed, ForceMode.Impulse);
|
||||
break;
|
||||
case FrisbieType.Explosive:
|
||||
rb.AddForce(transform.forward.normalized * explosiveSpeed, ForceMode.Impulse);
|
||||
break;
|
||||
case FrisbieType.Boomerang:
|
||||
rb.AddForce(transform.forward.normalized * boomerangSpeed, ForceMode.Impulse);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void FixedUpdate(){
|
||||
float velocity = rb.velocity.magnitude;
|
||||
float positionToGo = 0;
|
||||
|
||||
if(velocity < damageVelocityThreshold)
|
||||
gameObject.tag = "Untagged";
|
||||
else
|
||||
gameObject.tag = "Disk";
|
||||
|
||||
switch (frisbieType)
|
||||
{
|
||||
case FrisbieType.Default:
|
||||
positionToGo = Mathf.SmoothDamp(frisbie.localPosition.y, -1 + velocity / speed, ref heightVelocity, .1f);
|
||||
frisbie.localPosition = new Vector3(0, positionToGo, 0);
|
||||
break;
|
||||
case FrisbieType.Boomerang:
|
||||
if (boomerangReturnDir != Vector3.zero)
|
||||
rb.AddForce(boomerangReturnDir * Mathf.Lerp(0, boomerangReturnStrength, 1), ForceMode.Acceleration);
|
||||
else
|
||||
{
|
||||
positionToGo = Mathf.SmoothDamp(frisbie.localPosition.y, -1 + velocity / speed, ref heightVelocity, .5f);
|
||||
frisbie.localPosition = new Vector3(0, positionToGo, 0);
|
||||
}
|
||||
break;
|
||||
case FrisbieType.Explosive:
|
||||
positionToGo = Mathf.SmoothDamp(frisbie.localPosition.y, -1 + velocity / speed, ref heightVelocity, .1f);
|
||||
frisbie.localPosition = new Vector3(0, positionToGo, 0);
|
||||
|
||||
if (velocity < explosionSpeedThreshold)
|
||||
Kaboom();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Kaboom()
|
||||
{
|
||||
if (canExplode)
|
||||
{
|
||||
explosionCol.enabled = true;
|
||||
ObjectPooler.instance.SpawnFromPool("Explosion", transform.position);
|
||||
//Harm all enemies within explosionCol
|
||||
if (Random.value > 0.5f)
|
||||
{
|
||||
ObjectPooler.instance.SpawnFromPool("DiskBits", transform.position);
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector3 explosionDir = Random.onUnitSphere;
|
||||
explosionDir.y = 1;
|
||||
explosionDir.Normalize();
|
||||
rb.velocity = Vector3.zero;
|
||||
AddForce(explosionDir * explosionBlastSpeed);
|
||||
}
|
||||
canExplode = false;
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator EnablePickUpCollider(){
|
||||
yield return new WaitForSeconds(pickUpEnableDelay);
|
||||
if (pickUpCollider != null)
|
||||
pickUpCollider.SetActive(true);
|
||||
canExplode = true;
|
||||
}
|
||||
|
||||
private void OnCollisionEnter(Collision collision)
|
||||
{
|
||||
if (collision.gameObject.CompareTag("Wall"))
|
||||
{
|
||||
switch (frisbieType)
|
||||
{
|
||||
case FrisbieType.Default:
|
||||
break;
|
||||
case FrisbieType.Boomerang:
|
||||
boomerangReturnDir = Vector3.zero;
|
||||
break;
|
||||
case FrisbieType.Explosive:
|
||||
Invoke(nameof(Kaboom), .05f);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Player/FrisbieController.cs.meta
Normal file
11
Assets/Scripts/Player/FrisbieController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6ac47d21cb257814588f8400f884fc6f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
54
Assets/Scripts/Player/InputNameScore.cs
Normal file
54
Assets/Scripts/Player/InputNameScore.cs
Normal file
|
@ -0,0 +1,54 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class InputNameScore : MonoBehaviour{
|
||||
|
||||
string scoreName;
|
||||
|
||||
[SerializeField] GameObject nextScreen = default;
|
||||
[SerializeField] Percentage percentage = default;
|
||||
|
||||
void Awake(){
|
||||
nextScreen.SetActive(false);
|
||||
}
|
||||
|
||||
public void InputName(string name){
|
||||
scoreName = name;
|
||||
}
|
||||
|
||||
public void Submit(){
|
||||
if(scoreName.ToCharArray().Length == 3){
|
||||
PlayerController player = FindObjectOfType<PlayerController>();
|
||||
AddHighscoreEntry(Mathf.RoundToInt(player.timeSurvived), player.percentage, scoreName.ToUpper(), player.bossKilled);
|
||||
gameObject.SetActive(false);
|
||||
nextScreen.SetActive(true);
|
||||
percentage.UpdateSlider();
|
||||
}
|
||||
}
|
||||
|
||||
void AddHighscoreEntry(int time, int percentage, string name, bool boss){
|
||||
HighscoreEntry highscoreEntry = new HighscoreEntry { name = name, percentage = percentage, time = time, boss = boss };
|
||||
|
||||
string jsonString = PlayerPrefs.GetString("HighscoreTable");
|
||||
Highscores highscores = JsonUtility.FromJson<Highscores>(jsonString);
|
||||
|
||||
highscores.highscoreEntryList.Add(highscoreEntry);
|
||||
|
||||
string json = JsonUtility.ToJson(highscores);
|
||||
PlayerPrefs.SetString("HighscoreTable", json);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
|
||||
class Highscores{
|
||||
public List<HighscoreEntry> highscoreEntryList;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
class HighscoreEntry{
|
||||
public bool boss;
|
||||
public int time;
|
||||
public int percentage;
|
||||
public string name;
|
||||
}
|
||||
}
|
11
Assets/Scripts/Player/InputNameScore.cs.meta
Normal file
11
Assets/Scripts/Player/InputNameScore.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6e742fe5abd7c4b46860fdac216cd82f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
13
Assets/Scripts/Player/LoadMenu.cs
Normal file
13
Assets/Scripts/Player/LoadMenu.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class LoadMenu : MonoBehaviour{
|
||||
public void LoadLevel(){
|
||||
Destroy(GameMaster.Instance.gameObject);
|
||||
PlayerPrefs.DeleteKey("HP");
|
||||
PlayerPrefs.DeleteKey("Percentage");
|
||||
PlayerPrefs.DeleteKey("TimeSurvived");
|
||||
Loader.Load(0);
|
||||
}
|
||||
}
|
11
Assets/Scripts/Player/LoadMenu.cs.meta
Normal file
11
Assets/Scripts/Player/LoadMenu.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: afca2ca37a9f5d44fb386b0c01fb6051
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
264
Assets/Scripts/Player/PlayerController.cs
Normal file
264
Assets/Scripts/Player/PlayerController.cs
Normal file
|
@ -0,0 +1,264 @@
|
|||
using Cinemachine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerController : MonoBehaviour{
|
||||
|
||||
[Space]
|
||||
[HideInInspector] public bool bossKilled;
|
||||
[HideInInspector] public float timeSurvived;
|
||||
public int percentage;
|
||||
|
||||
[SerializeField] Transform container = default;
|
||||
Rigidbody rb;
|
||||
[SerializeField] float speed = 6f;
|
||||
[SerializeField] LayerMask whatIsGround = -1;
|
||||
[SerializeField] Animator anim = default;
|
||||
float rotationVelocity;
|
||||
[SerializeField] ParticleSystem stepParticle = default;
|
||||
bool walking;
|
||||
|
||||
[Space]
|
||||
public int weaponSelected;
|
||||
[SerializeField] Transform shootPos = default;
|
||||
[SerializeField] Animator deathScreenAnim = default;
|
||||
[SerializeField] Animator winScreenAnim = default;
|
||||
|
||||
[Space]
|
||||
[SerializeField] Transform aimPos = default;
|
||||
public PlayerHealth health;
|
||||
Camera mainCamera;
|
||||
|
||||
[SerializeField, Range(0, .5f)] float timeBetweenSteps = .1f;
|
||||
float currentStepTime;
|
||||
bool step;
|
||||
|
||||
[SerializeField] ParticleSystem shootParticles = default;
|
||||
[SerializeField] Animator getDiskIcon;
|
||||
|
||||
[HideInInspector]
|
||||
public UnityEngine.Events.UnityEvent damageEv=new UnityEngine.Events.UnityEvent();
|
||||
|
||||
[SerializeField] CinemachineVirtualCamera trackedCam = default;
|
||||
[SerializeField, Range(0, 1)] float camRotationSpeed = .2f;
|
||||
[SerializeField] Transform track = default;
|
||||
CinemachineTrackedDolly cmTrack;
|
||||
bool dead;
|
||||
|
||||
[HideInInspector] public bool invencible;
|
||||
|
||||
bool wayToTheBoss;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Awake(){
|
||||
timeSurvived = PlayerPrefs.GetFloat("TimeSurvived", 0);
|
||||
percentage = PlayerPrefs.GetInt("Percentage", 1);
|
||||
rb = GetComponent<Rigidbody>();
|
||||
weaponSelected = 1;
|
||||
health = FindObjectOfType<PlayerHealth>();
|
||||
mainCamera = Camera.main;
|
||||
trackedCam.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
percentage = Mathf.Clamp(percentage, 0, 100);
|
||||
if (!wayToTheBoss && percentage >= 100){
|
||||
wayToTheBoss = true;
|
||||
FindObjectOfType<Portal>().bossPortal = true;
|
||||
}
|
||||
|
||||
Vector3 movementInput = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical")).normalized;
|
||||
|
||||
Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);
|
||||
RaycastHit hit;
|
||||
|
||||
if(Physics.Raycast(ray, out hit, 1000f, whatIsGround) && Time.timeScale != 0 && Input.GetMouseButtonDown(0) && health && health.currentHp > 0){
|
||||
Vector3 pos = hit.point - transform.position;
|
||||
float rotY = Mathf.Atan2(-pos.z, pos.x) * Mathf.Rad2Deg;
|
||||
transform.rotation = Quaternion.Euler(0f, rotY + 90, 0f);
|
||||
}
|
||||
|
||||
if (Input.GetMouseButtonDown(0) && Time.timeScale != 0 && health && health.currentHp > 0){
|
||||
FrisbieController frisbie = ObjectPooler.instance.SpawnFromPool("Disk", new Vector3(shootPos.position.x, .3f, shootPos.position.z), transform.rotation).GetComponent<FrisbieController>();
|
||||
//FrisbieController frisbie = Instantiate(disk, transform.position, transform.rotation).GetComponent<FrisbieController>();
|
||||
if(AudioManager.instance!=null)
|
||||
AudioManager.instance.PlayOneShot("laser" + Random.Range(1, 6));
|
||||
shootParticles.Play();
|
||||
switch (weaponSelected){
|
||||
case 1:
|
||||
frisbie.frisbieType = FrisbieController.FrisbieType.Default;
|
||||
frisbie.AddForce(movementInput * speed);
|
||||
break;
|
||||
case 2:
|
||||
frisbie.frisbieType = FrisbieController.FrisbieType.Boomerang;
|
||||
frisbie.AddForce(movementInput * speed);
|
||||
break;
|
||||
case 3:
|
||||
frisbie.frisbieType = FrisbieController.FrisbieType.Explosive;
|
||||
frisbie.AddForce(movementInput * speed);
|
||||
break;
|
||||
}
|
||||
health.RemoveDisk();
|
||||
if (health.currentHp == 0){
|
||||
AudioManager.instance.Pause("InGameMusic");
|
||||
AudioManager.instance.Play("clock2-loop");
|
||||
deathScreenAnim.SetTrigger("Die");
|
||||
}
|
||||
if (ScreenShakeCall.instance!=null)
|
||||
ScreenShakeCall.instance.ShakeCamera(.5f, .25f);
|
||||
}
|
||||
|
||||
if (dead){
|
||||
cmTrack.m_PathPosition += Time.unscaledDeltaTime * camRotationSpeed;
|
||||
}else{
|
||||
timeSurvived += Time.deltaTime;
|
||||
}
|
||||
}
|
||||
|
||||
void FixedUpdate(){
|
||||
Vector3 movementInput = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical")).normalized;
|
||||
anim.SetFloat("Speed", movementInput.magnitude);
|
||||
if (movementInput.magnitude >= .1f && !Input.GetMouseButtonDown(0)){
|
||||
float targetAngle = Mathf.Atan2(movementInput.x, movementInput.z) * Mathf.Rad2Deg + mainCamera.transform.eulerAngles.y;
|
||||
float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref rotationVelocity, .1f);
|
||||
transform.rotation = Quaternion.Euler(0, angle, 0);
|
||||
|
||||
Vector3 moveDirection = Quaternion.Euler(0, targetAngle, 0) * Vector3.forward;
|
||||
//rb.MovePosition(rb.position + moveDirection.normalized * speed * Time.deltaTime);
|
||||
rb.velocity = moveDirection.normalized * speed;
|
||||
|
||||
currentStepTime -= Time.deltaTime;
|
||||
if(currentStepTime <= 0 && AudioManager.instance!=null){
|
||||
stepParticle.Play();
|
||||
if (step){
|
||||
AudioManager.instance.PlayOneShot("paso1");
|
||||
step = false;
|
||||
}else{
|
||||
AudioManager.instance.PlayOneShot("paso2");
|
||||
step = true;
|
||||
}
|
||||
currentStepTime = timeBetweenSteps;
|
||||
}
|
||||
}else{
|
||||
rb.velocity = Vector3.zero;
|
||||
}
|
||||
|
||||
if(movementInput.magnitude >= .1f && !Input.GetMouseButtonDown(0) && !walking){
|
||||
currentStepTime = 0;
|
||||
walking = true;
|
||||
}else if(movementInput.magnitude < .1f && !Input.GetMouseButtonDown(0)){
|
||||
walking = false;
|
||||
}
|
||||
}
|
||||
|
||||
void LateUpdate(){
|
||||
Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);
|
||||
RaycastHit hit;
|
||||
|
||||
if (Physics.Raycast(ray, out hit, 1000f, whatIsGround) && Time.timeScale != 0){
|
||||
aimPos.position = new Vector3(hit.point.x, aimPos.position.y, hit.point.z);
|
||||
}
|
||||
|
||||
Vector3 targetVector = transform.position - mainCamera.transform.position;
|
||||
getDiskIcon.transform.rotation = Quaternion.LookRotation(targetVector, mainCamera.transform.rotation * Vector3.up);
|
||||
}
|
||||
|
||||
void damageSheen()
|
||||
{
|
||||
Debug.Log("sheeen");
|
||||
foreach (SkinnedMeshRenderer mr in GetComponentsInChildren<SkinnedMeshRenderer>())
|
||||
mr.material.SetColor("EmissiveCol", Color.white);
|
||||
Invoke(nameof(revertDamageSheen), .1f);
|
||||
}
|
||||
void revertDamageSheen()
|
||||
{
|
||||
foreach (SkinnedMeshRenderer mr in GetComponentsInChildren<SkinnedMeshRenderer>())
|
||||
mr.material.SetColor("EmissiveCol", Color.black);
|
||||
}
|
||||
|
||||
public void Damage(int amt){
|
||||
if (invencible)
|
||||
return;
|
||||
|
||||
float randomSound = Random.Range(0, 300);
|
||||
if(randomSound < 100){
|
||||
AudioManager.instance.PlayOneShot("grito2");
|
||||
}else if(randomSound >= 100 && randomSound < 200){
|
||||
AudioManager.instance.PlayOneShot("grito5");
|
||||
}else{
|
||||
AudioManager.instance.PlayOneShot("grito11");
|
||||
}
|
||||
|
||||
if (health.currentHp == 0){
|
||||
Die();
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < amt; i++){
|
||||
damageSheen();
|
||||
if (health != null){
|
||||
health.RemoveDisk();
|
||||
damageEv.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
if (health.currentHp == 0){
|
||||
AudioManager.instance.Pause("InGameMusic");
|
||||
AudioManager.instance.Play("clock2-loop");
|
||||
deathScreenAnim.SetTrigger("Die");
|
||||
}
|
||||
|
||||
if (ScreenShakeCall.instance!=null)
|
||||
ScreenShakeCall.instance.ShakeCamera(1, .5f);
|
||||
}
|
||||
|
||||
void OnTriggerEnter(Collider col){
|
||||
if (col.CompareTag("Disk") || col.CompareTag("DiskPickup")){
|
||||
if (health.currentHp == 0){
|
||||
AudioManager.instance.UnPause("InGameMusic");
|
||||
StartCoroutine(AudioManager.instance.FadeOut("clock2-loop", .5f));
|
||||
deathScreenAnim.SetTrigger("GetDisk");
|
||||
|
||||
getDiskIcon.SetTrigger("GetDisk");
|
||||
health.AddDisk();
|
||||
col.transform.parent.gameObject.SetActive(false);
|
||||
}else{
|
||||
if (health.AddDisk()){
|
||||
getDiskIcon.SetTrigger("GetDisk");
|
||||
AudioManager.instance.PlayOneShot("recogerdisco2");
|
||||
col.transform.parent.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Die(){
|
||||
GameMaster.Instance.ResetLevel();
|
||||
track.position = new Vector3(transform.position.x, 0, transform.position.z);
|
||||
trackedCam.gameObject.SetActive(true);
|
||||
cmTrack = trackedCam.GetCinemachineComponent<CinemachineTrackedDolly>();
|
||||
dead = true;
|
||||
Time.timeScale = 0;
|
||||
deathScreenAnim.updateMode = AnimatorUpdateMode.UnscaledTime;
|
||||
AudioManager.instance.StopAll();
|
||||
PlayerPrefs.DeleteKey("HP");
|
||||
}
|
||||
|
||||
public void Win(){
|
||||
GameMaster.Instance.ResetLevel();
|
||||
winScreenAnim.SetTrigger("Win");
|
||||
dead = true;
|
||||
PlayerPrefs.DeleteKey("HP");
|
||||
StartCoroutine(WinPause());
|
||||
}
|
||||
|
||||
IEnumerator WinPause(){
|
||||
yield return new WaitForSeconds(1f);
|
||||
StartCoroutine(AudioManager.instance.FadeIn("MainPiano", 1));
|
||||
FindObjectOfType<PauseMenu>().enabled = false;
|
||||
winScreenAnim.updateMode = AnimatorUpdateMode.UnscaledTime;
|
||||
Time.timeScale = 0;
|
||||
}
|
||||
}
|
11
Assets/Scripts/Player/PlayerController.cs.meta
Normal file
11
Assets/Scripts/Player/PlayerController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 020038eeca8cf7b4d91eef999c143bea
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
12
Assets/Scripts/Player/PlayerDeath.cs
Normal file
12
Assets/Scripts/Player/PlayerDeath.cs
Normal file
|
@ -0,0 +1,12 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerDeath : MonoBehaviour{
|
||||
|
||||
[SerializeField] PlayerController player = default;
|
||||
|
||||
public void Die(){
|
||||
player.Die();
|
||||
}
|
||||
}
|
11
Assets/Scripts/Player/PlayerDeath.cs.meta
Normal file
11
Assets/Scripts/Player/PlayerDeath.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 44a107ce4b40c054fb5e490134ebc1a2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
60
Assets/Scripts/Player/PlayerHealth.cs
Normal file
60
Assets/Scripts/Player/PlayerHealth.cs
Normal file
|
@ -0,0 +1,60 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerHealth : MonoBehaviour{
|
||||
|
||||
[SerializeField] GameObject disk = default;
|
||||
[SerializeField, Min(0)] int startHp = 10;
|
||||
[SerializeField] RectTransform healthStartPos = default;
|
||||
public int currentHp;
|
||||
[SerializeField, Range(0, 100)] float distanceBetweenDisks = 30f;
|
||||
Vector3 nextDiskPos;
|
||||
|
||||
List<Animator> diskAnimators = new List<Animator>();
|
||||
|
||||
[Space]
|
||||
[SerializeField, Min(0)] int maxHp = 15;
|
||||
[SerializeField] bool hasMaxHp = false;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start(){
|
||||
currentHp = PlayerPrefs.GetInt("HP", startHp);
|
||||
if (currentHp == 0)
|
||||
currentHp = startHp;
|
||||
|
||||
for (int i = 0; i < currentHp; i++){
|
||||
GameObject newDisk = Instantiate(disk, Vector3.zero, Quaternion.identity, transform);
|
||||
newDisk.GetComponent<RectTransform>().anchoredPosition3D = healthStartPos.anchoredPosition3D + Vector3.right * distanceBetweenDisks * i;
|
||||
diskAnimators.Add(newDisk.GetComponent<Animator>());
|
||||
nextDiskPos = Vector3.right * distanceBetweenDisks * (i + 1);
|
||||
}
|
||||
}
|
||||
|
||||
public bool AddDisk(){
|
||||
if (hasMaxHp && currentHp >= maxHp)
|
||||
return false;
|
||||
|
||||
foreach(Animator a in diskAnimators){
|
||||
a.SetTrigger("RestartAnimation");
|
||||
}
|
||||
GameObject newDisk = Instantiate(disk, Vector3.zero, Quaternion.identity, transform);
|
||||
newDisk.GetComponent<RectTransform>().anchoredPosition3D = healthStartPos.anchoredPosition3D + nextDiskPos;
|
||||
diskAnimators.Add(newDisk.GetComponent<Animator>());
|
||||
nextDiskPos += Vector3.right * distanceBetweenDisks;
|
||||
currentHp++;
|
||||
PlayerPrefs.SetInt("HP", currentHp);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void RemoveDisk(){
|
||||
if(currentHp > 0){
|
||||
Animator anim = diskAnimators[diskAnimators.Count - 1];
|
||||
diskAnimators.Remove(anim);
|
||||
Destroy(anim.gameObject);
|
||||
nextDiskPos -= Vector3.right * distanceBetweenDisks;
|
||||
currentHp--;
|
||||
PlayerPrefs.SetInt("HP", currentHp);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Player/PlayerHealth.cs.meta
Normal file
11
Assets/Scripts/Player/PlayerHealth.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ed9fc316b730d0f4d82e0963ce7fdf37
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
33
Assets/Scripts/Player/ProjectileCollisionChecker.cs
Normal file
33
Assets/Scripts/Player/ProjectileCollisionChecker.cs
Normal file
|
@ -0,0 +1,33 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ProjectileCollisionChecker : MonoBehaviour
|
||||
{
|
||||
public float colliderScalar = .75f;
|
||||
void Update()
|
||||
{
|
||||
Collider[] colliders = Physics.OverlapBox(transform.position,transform.parent.localScale*colliderScalar, transform.rotation);
|
||||
|
||||
ExtDebug.DrawBox(transform.position, transform.parent.localScale * colliderScalar, transform.rotation, Color.red);
|
||||
|
||||
foreach (Collider c in colliders)
|
||||
{
|
||||
if (c.GetComponent<BulletMovement>() != null)
|
||||
{
|
||||
c.GetComponent<BulletMovement>().bulletHit();
|
||||
GetComponent<PlayerController>().Damage(1);
|
||||
Debug.Log("Player hit");
|
||||
if (GameMaster.Instance.Pooler != null)
|
||||
c.gameObject.SetActive(false);
|
||||
else
|
||||
Destroy(c.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
//void OnDrawGizmos()
|
||||
//{
|
||||
// Gizmos.color = Color.red;
|
||||
// Gizmos.DrawWireCube(transform.position, transform.parent.localScale * colliderScalar);
|
||||
//}
|
||||
}
|
11
Assets/Scripts/Player/ProjectileCollisionChecker.cs.meta
Normal file
11
Assets/Scripts/Player/ProjectileCollisionChecker.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 726d113c7c974e044bfa3ecf20c84d0e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
12
Assets/Scripts/Player/UpdateShader.cs
Normal file
12
Assets/Scripts/Player/UpdateShader.cs
Normal file
|
@ -0,0 +1,12 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class UpdateShader : MonoBehaviour
|
||||
{
|
||||
|
||||
void Update()
|
||||
{
|
||||
Shader.SetGlobalVector("Player_position", transform.position);
|
||||
}
|
||||
}
|
11
Assets/Scripts/Player/UpdateShader.cs.meta
Normal file
11
Assets/Scripts/Player/UpdateShader.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a48a9903a54c2d143b1a0b315a0422bd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
72
Assets/Scripts/Player/WeaponSelectedUI.cs
Normal file
72
Assets/Scripts/Player/WeaponSelectedUI.cs
Normal file
|
@ -0,0 +1,72 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class WeaponSelectedUI : MonoBehaviour{
|
||||
|
||||
int currentSelected = 0;
|
||||
[SerializeField] Transform rollPivot = default;
|
||||
float currentRot;
|
||||
float rotationVelocity;
|
||||
PlayerController player;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Awake(){
|
||||
currentRot = rollPivot.eulerAngles.z;
|
||||
player = GameMaster.Instance.player.GetComponent<PlayerController>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
currentRot = 90 * currentSelected;
|
||||
//currentRot += 90 * Mathf.Clamp(Input.mouseScrollDelta.y, -1, 1);
|
||||
if(Mathf.Clamp(Input.mouseScrollDelta.y, -1, 1) == 1){
|
||||
switch (currentSelected){
|
||||
case 0:
|
||||
Debug.Log("Boomerang");
|
||||
player.weaponSelected = 2;
|
||||
currentSelected = 1;
|
||||
break;
|
||||
case 1:
|
||||
Debug.Log("Default");
|
||||
player.weaponSelected = 1;
|
||||
currentSelected = 2;
|
||||
break;
|
||||
case 2:
|
||||
Debug.Log("Explosive");
|
||||
currentSelected = 3;
|
||||
player.weaponSelected = 3;
|
||||
break;
|
||||
case 3:
|
||||
Debug.Log("Default");
|
||||
currentSelected = 0;
|
||||
player.weaponSelected = 1;
|
||||
break;
|
||||
}
|
||||
}else if(Mathf.Clamp(Input.mouseScrollDelta.y, -1, 1) == -1){
|
||||
switch (currentSelected){
|
||||
case 0:
|
||||
Debug.Log("Explosive");
|
||||
currentSelected = 3;
|
||||
player.weaponSelected = 3;
|
||||
break;
|
||||
case 1:
|
||||
Debug.Log("Default");
|
||||
player.weaponSelected = 1;
|
||||
currentSelected = 0;
|
||||
break;
|
||||
case 2:
|
||||
Debug.Log("Boomerang");
|
||||
player.weaponSelected = 2;
|
||||
currentSelected = 1;
|
||||
break;
|
||||
case 3:
|
||||
Debug.Log("Default");
|
||||
player.weaponSelected = 1;
|
||||
currentSelected = 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
rollPivot.rotation = Quaternion.Euler(0, 0, Mathf.SmoothDampAngle(rollPivot.eulerAngles.z, currentRot, ref rotationVelocity, .1f));
|
||||
}
|
||||
}
|
11
Assets/Scripts/Player/WeaponSelectedUI.cs.meta
Normal file
11
Assets/Scripts/Player/WeaponSelectedUI.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3e38a246731b05049bd43684d414013f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
11
Assets/Scripts/PlayerData.cs
Normal file
11
Assets/Scripts/PlayerData.cs
Normal file
|
@ -0,0 +1,11 @@
|
|||
[System.Serializable]
|
||||
public class PlayerData{
|
||||
|
||||
public bool bossKilled;
|
||||
public float playDuration;
|
||||
|
||||
public PlayerData(PlayerController player){
|
||||
bossKilled = player.bossKilled;
|
||||
playDuration = player.timeSurvived;
|
||||
}
|
||||
}
|
11
Assets/Scripts/PlayerData.cs.meta
Normal file
11
Assets/Scripts/PlayerData.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 69777ba4034fa9347a10aba5f79e0732
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Portal.meta
Normal file
8
Assets/Scripts/Portal.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9f63af004aa3b894ba999161a5b48ec5
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
59
Assets/Scripts/Portal/Portal.cs
Normal file
59
Assets/Scripts/Portal/Portal.cs
Normal file
|
@ -0,0 +1,59 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Portal : MonoBehaviour
|
||||
{
|
||||
private bool BossPortal = false;
|
||||
public bool bossPortal
|
||||
{
|
||||
get
|
||||
{
|
||||
return BossPortal;
|
||||
}
|
||||
set
|
||||
{
|
||||
BossPortal = value;
|
||||
if (bossPortal)
|
||||
{
|
||||
GetComponentInChildren<MeshRenderer>().material = redPortal;
|
||||
particleDots.GetComponent<ParticleSystemRenderer>().material.SetColor("_Color", Color.red);
|
||||
bits.GetComponent<ParticleSystem>().startColor = Color.red;
|
||||
}
|
||||
else
|
||||
{
|
||||
GetComponentInChildren<MeshRenderer>().material = greenPortal;
|
||||
particleDots.GetComponent<ParticleSystemRenderer>().material.SetColor("_Color", Color.green);
|
||||
bits.GetComponent<ParticleSystem>().startColor = Color.green;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Material redPortal;
|
||||
public Material greenPortal;
|
||||
public GameObject particleDots;
|
||||
public GameObject bits;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
bossPortal = BossPortal;
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (other.CompareTag("Player"))
|
||||
{
|
||||
PlayerController player = FindObjectOfType<PlayerController>();
|
||||
PlayerPrefs.SetFloat("TimeSurvived", player.timeSurvived);
|
||||
PlayerPrefs.SetInt("Percentage", player.percentage);
|
||||
|
||||
if (bossPortal){
|
||||
GameMaster.Instance.bossLevel();
|
||||
return;
|
||||
}
|
||||
|
||||
//Añadir cortinita y delay si hace falta
|
||||
GameMaster.Instance.nextLevel();
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Portal/Portal.cs.meta
Normal file
11
Assets/Scripts/Portal/Portal.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b6e3c87fb7b934a43ab940df449debcb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
34
Assets/Scripts/SaveSystem.cs
Normal file
34
Assets/Scripts/SaveSystem.cs
Normal file
|
@ -0,0 +1,34 @@
|
|||
using System.IO;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using UnityEngine;
|
||||
|
||||
public static class SaveSystem{
|
||||
|
||||
public static void SavePlayer(PlayerController player){
|
||||
BinaryFormatter formatter = new BinaryFormatter();
|
||||
|
||||
string path = Application.persistentDataPath + "/gaviota.man";
|
||||
FileStream stream = new FileStream(path, FileMode.Create);
|
||||
|
||||
PlayerData data = new PlayerData(player);
|
||||
|
||||
formatter.Serialize(stream, data);
|
||||
stream.Close();
|
||||
}
|
||||
|
||||
public static PlayerData LoadPlayer(){
|
||||
string path = Application.persistentDataPath + "/gaviota.man";
|
||||
if (File.Exists(path)){
|
||||
BinaryFormatter formatter = new BinaryFormatter();
|
||||
FileStream stream = new FileStream(path, FileMode.Open);
|
||||
|
||||
PlayerData data = formatter.Deserialize(stream) as PlayerData;
|
||||
stream.Close();
|
||||
|
||||
return data;
|
||||
}else{
|
||||
Debug.LogError("Save file not found in " + path);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/SaveSystem.cs.meta
Normal file
11
Assets/Scripts/SaveSystem.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 275ed86a60c723c49b28ab5e638cf3c9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Spawner.meta
Normal file
8
Assets/Scripts/Spawner.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d9f44fe2cf935c1468b4e33330d555b5
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue