This commit is contained in:
Gerard Gascón 2025-04-24 14:30:07 +02:00
commit 102013b228
1443 changed files with 1065651 additions and 0 deletions

View file

@ -0,0 +1,140 @@
using UnityEngine;
using TMPro;
public class CharSelCharacterController : MonoBehaviour
{
[SerializeField] public string charName;
public string phrase;
[SerializeField] float speed;
[SerializeField] float rotationSpeed;
[SerializeField] Transform spawnPointLeft;
[SerializeField] Transform spawnPointRight;
[SerializeField] Transform spawnPointCenter;
[SerializeField] TextMeshProUGUI phraseText;
[SerializeField] GameObject phrasePanel;
[SerializeField] public Animator anim;
bool canWalk;
bool moveLeft;
bool moveRight;
bool stopAtCenter;
bool restoreRotation;
private void OnEnable()
{
canWalk = false;
moveLeft = false;
moveRight = false;
moveRight = false;
transform.localRotation = Quaternion.Euler(0, 180, 0);
}
// Update is called once per frame
void Update()
{
if (canWalk)
{
anim.SetFloat("Dance", 0f);
Quaternion targetRotation = Quaternion.identity;
Vector3 targetPosition = Vector3.zero;
if (moveLeft)
{
targetRotation = Quaternion.LookRotation(spawnPointLeft.localPosition - transform.localPosition);
targetPosition = new Vector3(spawnPointLeft.localPosition.x, 0f, 0f);
}
else if (moveRight)
{
targetRotation = Quaternion.LookRotation(spawnPointRight.localPosition - transform.localPosition);
targetPosition = new Vector3(spawnPointRight.localPosition.x, 0f, 0f);
}
if (stopAtCenter)
{
targetPosition = new Vector3(spawnPointCenter.localPosition.x, 0f, 0f);
}
transform.localRotation = Quaternion.Slerp(transform.localRotation, targetRotation, rotationSpeed * Time.deltaTime);
transform.localPosition = Vector3.MoveTowards(transform.localPosition, targetPosition, speed * Time.deltaTime);
anim.SetFloat("VelocityY", 1f);
if (stopAtCenter && (Mathf.Round(transform.localPosition.x * 10f) / 10f) == spawnPointCenter.localPosition.x)
{
canWalk = false;
moveLeft = false;
moveRight = false;
stopAtCenter = false;
restoreRotation = true;
phraseText.text = phrase;
phrasePanel.GetComponent<Animator>().SetBool("visible", true);
anim.SetFloat("VelocityY", 0f);
anim.SetFloat("Dance", GetComponent<CharacterIdController>().Dance);
}
else if(!stopAtCenter && (transform.localPosition.x == spawnPointRight.localPosition.x || transform.localPosition.x == spawnPointLeft.localPosition.x))
{
canWalk = false;
moveLeft = false;
moveRight = false;
gameObject.SetActive(false);
anim.SetFloat("VelocityY", 0f);
}
}
if (restoreRotation)
{
transform.localRotation = Quaternion.Slerp(transform.localRotation, Quaternion.Euler(0, 180, 0), rotationSpeed * Time.deltaTime);
if (transform.localRotation.eulerAngles.y > 160 && transform.localRotation.eulerAngles.y < 200)
{
}
if (transform.localRotation == Quaternion.Euler(0, 180, 0))
{
restoreRotation = false;
}
}
}
public void WalkLeft(bool stopCharAtCenter)
{
restoreRotation = false;
canWalk = true;
moveLeft = true;
stopAtCenter = stopCharAtCenter;
}
public void WalkRight(bool stopCharAtCenter)
{
restoreRotation = false;
canWalk = true;
moveRight = true;
stopAtCenter = stopCharAtCenter;
}
void StopRestoringRotation()
{
restoreRotation = false;
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 40044a5789dc33e4095a2744d9b3b75e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,179 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using Cinemachine;
public class CharSelSelectionController : MonoBehaviour
{
[Space(10)]
[SerializeField] GameObject levelNPCs;
[SerializeField] List<GameObject> npcList;
[Space(10)]
[SerializeField] List<GameObject> characterList;
[SerializeField] GameObject selectedCharacter;
[Space(10)]
[SerializeField] Transform spawnPointLeft;
[SerializeField] Transform spawnPointRight;
[Space(10)]
[SerializeField] TextMeshProUGUI phraseText;
[SerializeField] GameObject phrasePanel;
[SerializeField] GameObject nextButton;
[SerializeField] GameObject prevButton;
[SerializeField] GameObject playButton;
[SerializeField] GameObject characters;
[SerializeField] GameObject player;
[SerializeField] GameObject trackCamera;
[SerializeField] GameObject cam;
int selectedCharacterIndex = 0;
bool canSpawnCharacter = true;
void Awake()
{
selectedCharacter = characterList[selectedCharacterIndex];
phraseText.text = selectedCharacter.GetComponent<CharSelCharacterController>().phrase;
}
public void OnPlayClick()
{
if (canSpawnCharacter)
{
GameObject.Find("Menu").GetComponent<InvitationController>().OpensConfirmDirectly(selectedCharacter.GetComponent<CharSelCharacterController>().charName);
}
}
public void ConfirmPlay()
{
BetweenScenePass data = BetweenScenePass.instance;
CharacterIdController selecterCharacterCustom = selectedCharacter.GetComponent<CharacterIdController>();
phrasePanel.SetActive(false);
nextButton.SetActive(false);
prevButton.SetActive(false);
playButton.SetActive(false);
characters.SetActive(false);
levelNPCs.transform.position = new Vector3(levelNPCs.transform.position.x, 0, levelNPCs.transform.position.z);
trackCamera.SetActive(false);
int selectedCharId = selecterCharacterCustom.CharacterId;
data.PlayerCharacterId = selectedCharId;
GameObject selectedNPC = null;
for (int i = 0; i < npcList.Count; i++)
{
if(npcList[i].GetComponent<CharacterIdController>().CharacterId == selectedCharId)
{
selectedNPC = npcList[i];
}
else
{
data.NpcCharacterId.Add(npcList[i].GetComponent<CharacterIdController>().CharacterId);
}
}
player.GetComponent<MenuPlayerMovement>().anim = player.GetComponent<CharacterIdController>().SetPlayerCustom();
player.transform.position = new Vector3(selectedNPC.transform.position.x, 1.08f, selectedNPC.transform.position.z);
player.transform.rotation = selectedNPC.transform.rotation;
selectedNPC.SetActive(false);
player.SetActive(true);
cam.SetActive(true);
gameObject.SetActive(false);
}
public void OnPrevCharacterClick()
{
if (canSpawnCharacter && (phrasePanel.transform.localScale.x > 0.5 || phrasePanel.transform.localScale.x < 0.5))
{
canSpawnCharacter = false;
StartCoroutine(MoveCharacter(0));
}
}
public void OnNextCharacterClick()
{
if (canSpawnCharacter && (phrasePanel.transform.localScale.x > 0.5 || phrasePanel.transform.localScale.x < 0.5))
{
canSpawnCharacter = false;
StartCoroutine(MoveCharacter(1));
}
}
void UpdateIndex(int direction)
{
if (selectedCharacterIndex == 0 && direction == 0)
{
selectedCharacterIndex = characterList.Count - 1;
}else if (selectedCharacterIndex == characterList.Count - 1 && direction == 1)
{
selectedCharacterIndex = 0;
}
else
{
selectedCharacterIndex += direction == 0 ? -1 : 1;
}
}
void UpdateSelectedCharacter(float posX)
{
selectedCharacter = characterList[selectedCharacterIndex];
selectedCharacter.transform.localPosition = new Vector3(posX, 0, selectedCharacter.transform.localPosition.z);
selectedCharacter.SetActive(true);
}
void EmptyCharacterPhrase()
{
phraseText.text = " ";
phrasePanel.GetComponent<Animator>().SetBool("visible", false);
}
IEnumerator MoveCharacter(int direction)
{
EmptyCharacterPhrase();
yield return new WaitForSeconds(0.15f);
if (direction == 0)
selectedCharacter.GetComponent<CharSelCharacterController>().WalkLeft(false);
else if(direction == 1)
selectedCharacter.GetComponent<CharSelCharacterController>().WalkRight(false);
yield return new WaitForSeconds(0.2f);
UpdateIndex(direction);
if (direction == 0)
{
UpdateSelectedCharacter(spawnPointRight.transform.localPosition.x);
selectedCharacter.GetComponent<CharSelCharacterController>().WalkLeft(true);
}
else if (direction == 1)
{
UpdateSelectedCharacter(spawnPointLeft.transform.localPosition.x);
selectedCharacter.GetComponent<CharSelCharacterController>().WalkRight(true);
}
yield return new WaitForSeconds(0.5f);
canSpawnCharacter = true;
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 41cead2536b82f84caeea430b223366f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,101 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class CharacterIdController : MonoBehaviour
{
public int characterId;
[SerializeField] int dance;
[SerializeField] Animator anim;
[SerializeField] List<GameObject> models;
public int CharacterId { get => characterId; set => characterId = value; }
public int Dance { get => dance; set => dance = value; }
private void Awake()
{
if(gameObject.CompareTag("Player"))
anim = GetComponent<CharacterIdController>().SetPlayerCustom();
if (characterId > -1)
{
if (Dance > 0)
{
DanceDance(Dance);
}
}
}
public void DanceDance(int _dance)
{
Dance = _dance;
anim.SetFloat("Dance", Dance);
}
public Animator SetRandomNpcCustom()
{
BetweenScenePass data = BetweenScenePass.instance;
if (data && data.NpcCharacterId.Count > 0)
{
characterId = data.NpcCharacterId[Random.Range(0, data.NpcCharacterId.Count-1)];
}
else
{
characterId = 5;
}
return ActivateModel(characterId);
}
public Animator SetNpcCustom(int npcId)
{
BetweenScenePass data = BetweenScenePass.instance;
if (data && data.NpcCharacterId.Count > 0)
{
if (data.NpcCharacterId.Contains(npcId))
characterId = data.NpcCharacterId[data.NpcCharacterId.IndexOf(npcId)];
else if (npcId == data.PlayerCharacterId)
characterId = data.PlayerCharacterId;
}
else
{
characterId = 5;
}
return ActivateModel(npcId);
}
public Animator ActivateModel(int npcId)
{
characterId = npcId;
models[npcId].SetActive(true);
anim = models[npcId].GetComponent<Animator>();
return models[npcId].GetComponent<Animator>();
}
public Animator SetPlayerCustom()
{
BetweenScenePass data = BetweenScenePass.instance;
if (data && data.PlayerCharacterId > -1)
{
characterId = data.PlayerCharacterId;
}
else
{
characterId = 0;
}
return ActivateModel(characterId);
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3fb5599a903e3c849bf5ec998669e1fc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,369 @@

using UnityEngine;
using TMPro;
using UnityEngine.SceneManagement;
using System.Collections;
public class InvitationController : MonoBehaviour
{
[SerializeField] ScenesTransitionController sceneTransition;
[SerializeField] GameTutorialControler tutorial;
[Space(20)]
[SerializeField] float showDelay;
[SerializeField] float hideDelay;
[Header("Invitation Panels")]
[SerializeField] GameObject leftPanelBack;
[SerializeField] GameObject leftPanel;
[SerializeField] GameObject rightPanel;
[Header("Menu Panels")]
[SerializeField] GameObject title;
[SerializeField] GameObject mainMenu;
[SerializeField] GameObject pauseMenu;
[SerializeField] GameObject controls;
[SerializeField] GameObject options;
[SerializeField] GameObject credits;
[SerializeField] GameObject confirmationRight;
[SerializeField] GameObject confirmationLeft;
[Space(10)]
[SerializeField] TextMeshProUGUI confirmationQuestionRight;
[SerializeField] TextMeshProUGUI confirmationQuestionLeft;
[Space(10)]
[SerializeField] Animator anim;
[Space(10)]
[SerializeField] bool mainMenuOnBackClick;
[Header("Player Selector Objects (MAIN MENU ONLY)")]
[SerializeField] GameObject characterSelectorController;
[SerializeField] GameObject characters;
[SerializeField] GameObject npcs;
[SerializeField] GameObject panelPhrase;
[SerializeField] GameObject nextCharButton;
[SerializeField] GameObject prevCharButton;
[SerializeField] GameObject playButton;
[SerializeField] GameObject backMenuButton;
[SerializeField] bool pauseIsUp;
[SerializeField] string confirmTrigger;
[SerializeField] GameObject lastShowedPanel;
CursorLockMode cursorLastState;
void Awake()
{
if (GameObject.Find("BetweenScenePass") != null)
StartCoroutine(StartInvitation());
else
{
MenuShowConfig();
options.SetActive(false);
}
}
IEnumerator StartInvitation()
{
yield return new WaitUntil(() => BetweenScenePass.instance != null);
MenuShowConfig();
options.SetActive(false);
}
void MenuShowConfig()
{
if (BetweenScenePass.instance && !BetweenScenePass.instance.GameRestarted && mainMenuOnBackClick)
mainMenuOnBackClick = false;
if (mainMenuOnBackClick)
{
title.SetActive(true);
mainMenu.SetActive(true);
leftPanelBack.SetActive(true);
leftPanel.SetActive(true);
rightPanel.SetActive(true);
lastShowedPanel = mainMenu;
Invoke("HideTitle", 17.5f);
}
else
{
if (SceneManager.GetActiveScene().name == "EndGame")
backMenuButton.SetActive(false);
pauseMenu.SetActive(true);
anim.SetBool("iddle", true);
lastShowedPanel = pauseMenu;
}
if (backMenuButton != null)
{
backMenuButton.SetActive(false);
}
}
void HideTitle()
{
title.SetActive(false);
}
// Update is called once per frame
void Update()
{
if (tutorial == null || tutorial.gameStarted)
{
if (!mainMenuOnBackClick && Input.GetKeyDown(KeyCode.Escape) && (characterSelectorController == null || !characterSelectorController.activeInHierarchy))
{
if (pauseIsUp)
{
Time.timeScale = 1;
anim.SetTrigger("pauseDown");
Invoke("ReactivatePauseMenuAfterGoDown", 0.2f);
if (cursorLastState == CursorLockMode.Locked)
{
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
}
else
{
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
}
}
else
{
Time.timeScale = 0;
anim.SetTrigger("pauseUp");
cursorLastState = Cursor.lockState;
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
}
pauseIsUp = !pauseIsUp;
}
}
}
void ReactivatePauseMenuAfterGoDown()
{
pauseMenu.SetActive(true);
controls.SetActive(false);
options.SetActive(false);
credits.SetActive(false);
confirmationRight.SetActive(false);
confirmationLeft.SetActive(false);
mainMenu.SetActive(false);
lastShowedPanel = pauseMenu;
StopAllCoroutines();
}
public void OnPlayClick()
{
mainMenuOnBackClick = false;
anim.SetTrigger("pauseDown");
pauseIsUp = false;
Invoke("ReactivatePauseMenuAfterGoDown", 0.2f);
characterSelectorController.SetActive(true);
characters.SetActive(true);
npcs.transform.position = new Vector3(npcs.transform.position.x, -10, npcs.transform.position.z);
panelPhrase.SetActive(true);
nextCharButton.SetActive(true);
prevCharButton.SetActive(true);
playButton.SetActive(true);
}
public void OnResumeClick()
{
Time.timeScale = 1;
anim.SetTrigger("pauseDown");
pauseIsUp = false;
if (cursorLastState == CursorLockMode.Locked)
{
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
}
else
{
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
}
}
public void OnControlsClick()
{
StartCoroutine(HidePanel(lastShowedPanel));
StartCoroutine(ShowPanel(controls));
anim.SetTrigger("rotate");
}
public void OnOptionsClick()
{
StartCoroutine(HidePanel(lastShowedPanel));
StartCoroutine(ShowPanel(options));
anim.SetTrigger("rotate");
}
public void OnCreditsClick()
{
StartCoroutine(HidePanel(lastShowedPanel));
StartCoroutine(ShowPanel(credits));
anim.SetTrigger("rotate");
}
public void OnExitClick()
{
confirmationQuestionLeft.text = "¿Estás seguro de que deseas salir?";
confirmTrigger = "EXIT";
StartCoroutine(HidePanel(lastShowedPanel));
StartCoroutine(ShowPanel(confirmationLeft));
anim.SetTrigger("rotate");
}
public void OnExitClickDirectly()
{
Application.Quit();
}
public void OnExitMenuClick()
{
confirmationQuestionLeft.text = "¿Estás seguro de que deseas reiniciar el juego?\r\nTodo el progreso se perderá.";
confirmTrigger = "RESTART";
StartCoroutine(AudioManager.instance.FadeOut("01_jardin", 1));
StartCoroutine(HidePanel(lastShowedPanel));
StartCoroutine(ShowPanel(confirmationLeft));
anim.SetTrigger("rotate");
}
public void OnExitMenuClickDirectly()
{
AudioManager.instance.StopAll();
BetweenScenePass.instance.GameRestarted = true;
BetweenScenePass.instance.RestartData();
sceneTransition.CloseScene("Scenes/Menu");
}
public void OnBacktMenuClick()
{
confirmationQuestionLeft.text = "¿Estás seguro de que deseas volver al jardín?";
confirmTrigger = "BACK_MENU";
StartCoroutine(HidePanel(lastShowedPanel));
StartCoroutine(ShowPanel(confirmationLeft));
anim.SetTrigger("rotate");
}
public void OnBackClick()
{
StartCoroutine(HidePanel(lastShowedPanel));
if (mainMenuOnBackClick)
{
StartCoroutine(ShowPanel(mainMenu));
}
else
{
StartCoroutine(ShowPanel(pauseMenu));
}
anim.SetTrigger("rotate");
}
public void OnConfirmAccept()
{
switch (confirmTrigger)
{
case "EXIT":
Application.Quit();
break;
case "RESTART":
Time.timeScale = 1;
BetweenScenePass.instance.GameRestarted = true;
BetweenScenePass.instance.RestartData();
AudioManager.instance.StopAll();
sceneTransition.CloseScene("Scenes/Menu");
break;
case "BACK_MENU":
Time.timeScale = 1;
BetweenScenePass.instance.GameRestarted = false;
AudioManager.instance.StopAll();
sceneTransition.CloseScene("Scenes/Menu");
break;
case "SELECT_CHAR":
characterSelectorController.GetComponent<CharSelSelectionController>().ConfirmPlay();
anim.SetTrigger("pauseDown");
Invoke("ReactivatePauseMenuAfterGoDown", 0.2f);
break;
}
confirmTrigger = "";
}
public void OnConfirmCancel()
{
switch (confirmTrigger)
{
case "SELECT_CHAR":
nextCharButton.SetActive(true);
prevCharButton.SetActive(true);
playButton.SetActive(true);
anim.SetTrigger("pauseDown");
Invoke("ReactivatePauseMenuAfterGoDown", 0.2f);
break;
default:
OnBackClick();
break;
}
confirmTrigger = "";
}
public void OpensConfirmDirectly(string charName)
{
nextCharButton.SetActive(false);
prevCharButton.SetActive(false);
playButton.SetActive(false);
anim.SetTrigger("pauseUp");
confirmationQuestionRight.text = "Quieres jugar con "+ charName + "? ";
pauseMenu.SetActive(false);
confirmationRight.SetActive(true);
confirmTrigger = "SELECT_CHAR";
}
IEnumerator ShowPanel(GameObject panel)
{
yield return new WaitForSecondsRealtime(showDelay);
panel.SetActive(true);
lastShowedPanel = panel;
}
IEnumerator HidePanel(GameObject panel)
{
yield return new WaitForSecondsRealtime(hideDelay);
panel.SetActive(false);
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f9dd5688318195d4ab12a95ba6d3fd98
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,102 @@
using Cinemachine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class MainMenuDelay : MonoBehaviour{
[SerializeField] float delay;
[SerializeField] GameObject invitation;
[SerializeField] CMCameraRail cinematic;
[SerializeField] GameObject cam;
[SerializeField] GameObject mainCam;
[SerializeField] GameObject track;
[SerializeField] GameObject player;
// Start is called before the first frame update
void Awake(){
StartCoroutine(StartCameraController());
}
private void Start()
{
}
IEnumerator StartCameraController()
{
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
yield return new WaitUntil(() => BetweenScenePass.instance != null);
if (BetweenScenePass.instance && BetweenScenePass.instance.GameRestarted)
{
AudioManager.instance.Play("transicion", 0f);
AudioManager.instance.Play("SFX_vocesBackground");
cam.SetActive(true);
track.SetActive(true);
player.SetActive(false);
cinematic.StartRail();
StartCoroutine(ActivateMenu(false));
}
else
{
AudioManager.instance.Play("01_jardin", 0f);
player.transform.position = new Vector3(0f, 1.08f, -7.68f);
track.SetActive(false);
player.SetActive(true);
cam.SetActive(false);
mainCam.SetActive(true);
mainCam.GetComponent<CinemachineFreeLook>().m_YAxis.Value = 0.5f;
mainCam.GetComponent<CinemachineFreeLook>().m_XAxis.Value = -180;
GameObject selectedNPC;
if (BetweenScenePass.instance.PlayerCharacterId >= 0)
{
selectedNPC = GameObject.Find("LevelNPC_" + BetweenScenePass.instance.PlayerCharacterId);
}
else
{
selectedNPC = GameObject.Find("LevelNPC_0");
}
player.GetComponent<MenuPlayerMovement>().anim = player.GetComponent<CharacterIdController>().SetPlayerCustom();
player.GetComponent<MenuPlayerMovement>().anim.SetFloat("Dance", Random.Range(1f, 6f));
//player.transform.position = new Vector3(selectedNPC.transform.position.x, 1.08f, selectedNPC.transform.position.z);
//player.transform.rotation = selectedNPC.transform.rotation;
selectedNPC.SetActive(false);
delay = 0;
StartCoroutine(ActivateMenu(true));
}
}
IEnumerator ActivateMenu(bool lockMouse){
yield return new WaitForSecondsRealtime(delay);
StartCoroutine(AudioManager.instance.FadeOut("transicion", 1));
StartCoroutine(AudioManager.instance.FadeIn("01_jardin", 1));
invitation.GetComponent<Animator>().SetTrigger("startMainMenu");
if (lockMouse)
{
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
}
else
{
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f98f96de459bb134a92c1f749c98b7ef
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: