Skip to content

Commit

Permalink
Merge pull request #60 from josephpdf/docs-scripts-comments
Browse files Browse the repository at this point in the history
Documentation: Documenting Codes in the Scripts Folder
  • Loading branch information
CristopherAguilar10 authored Nov 24, 2024
2 parents c440711 + c33f1c5 commit 143ef71
Show file tree
Hide file tree
Showing 9 changed files with 204 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,37 @@
using UnityEngine;
using UnityEngine.SceneManagement;

/// <summary>
/// Manages the character selection screen functionality, allowing players to browse and select different characters
/// before starting the game.
/// </summary>
public class CharacterSelection : MonoBehaviour
{
/// <summary>
/// Array containing references to all available character GameObjects that can be selected.
/// Only one character should be active at a time.
/// </summary>
public GameObject[] characters;
/// <summary>
/// Index of the currently selected character in the characters array.
/// </summary>
public int selectedCharacter = 0;

/// <summary>
/// Switches to the next character in the selection screen.
/// Deactivates the current character and activates the next one in a circular manner.
/// </summary>
public void NextCharacter()
{
characters[selectedCharacter].SetActive(false);
selectedCharacter = (selectedCharacter + 1) % characters.Length;
characters[selectedCharacter].SetActive(true);
}

/// <summary>
/// Switches to the previous character in the selection screen.
/// Deactivates the current character and activates the previous one in a circular manner.
/// </summary>
public void PreviusCharacter()
{
characters[selectedCharacter].SetActive(false);
Expand All @@ -26,6 +45,10 @@ public void PreviusCharacter()
characters[selectedCharacter].SetActive(true);
}

/// <summary>
/// Starts the game with the selected character.
/// Saves the selected character index to PlayerPrefs and loads the game scene.
/// </summary>
public void StartGame()
{
PlayerPrefs.SetInt("selectedCharacter", selectedCharacter);
Expand Down
33 changes: 26 additions & 7 deletions Unity/Assets/Scripts/CharacterSelectionScript/LoadCharacter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,46 @@
using UnityEngine;
using TMPro;

/// <summary>
/// Handles the loading and instantiation of character prefabs based on player selection.
/// This script is used in game scenes where the selected character needs to be spawned.
/// It reads the player's character selection from PlayerPrefs and instantiates the corresponding prefab.
/// </summary>
public class LoadCharacter : MonoBehaviour
{
/// <summary>
/// Array of character prefabs that can be instantiated.
/// These should be assigned in the Unity Inspector.
/// </summary>
public GameObject[] characterPrefab;
/// <summary>
/// Transform reference for the position where the character will be spawned.
/// Should be set in the Unity Inspector.
/// </summary>
public Transform spawnPoint;
/// <summary>
/// TextMeshPro UI component to display the selected character's name.
/// Optional - can be left unassigned if character name display is not needed.
/// </summary>
public TMP_Text label;

void Start() // Corrige aquí el error de "Star"
/// <summary>
/// Initializes the character loading process when the script starts.
/// Retrieves the selected character index from PlayerPrefs and instantiates the corresponding prefab.
/// Also updates the character name label if one is assigned.
/// </summary>
void Start()
{
// Obtén el índice del personaje seleccionado guardado en PlayerPrefs
int selectedCharacter = PlayerPrefs.GetInt("selectedCharacter", 0); // Usa 0 como valor predeterminado
int selectedCharacter = PlayerPrefs.GetInt("selectedCharacter", 0);
if (selectedCharacter < 0 || selectedCharacter >= characterPrefab.Length)
{
Debug.LogError("Índice de personaje seleccionado está fuera de rango. Verifica los prefabs asignados en el inspector.");
Debug.LogError("�ndice de personaje seleccionado est� fuera de rango. Verifica los prefabs asignados en el inspector.");
return;
}

// Instancia el prefab en el punto de spawn
GameObject prefab = characterPrefab[selectedCharacter];
GameObject clone = Instantiate(prefab, spawnPoint.position, Quaternion.identity); // Corrige aquí "Quanternion" a "Quaternion"
GameObject clone = Instantiate(prefab, spawnPoint.position, Quaternion.identity);

// Actualiza el texto del nombre del personaje, si está asignado
if (label != null)
{
label.text = prefab.name;
Expand Down
40 changes: 39 additions & 1 deletion Unity/Assets/Scripts/CharacterSelectionScript/NPCInteraction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,34 @@
using TMPro;
using System.Collections;

/// <summary>
/// Controls NPC dialogue interactions and display of interaction prompts.
/// This script should be attached to NPC GameObjects to enable player-NPC dialogue interactions.
/// </summary>
public class NPCInteraction : MonoBehaviour
{
/// <summary>
/// UI panel that contains the dialogue elements
/// </summary>
public GameObject dialogueUI;
/// <summary>
/// Text component that displays the NPC's dialogue
/// </summary>
public TextMeshProUGUI dialogueText;
/// <summary>
/// UI element showing the interaction prompt (e.g., "Press E to interact")
/// </summary>
public GameObject interactionText;
public string[] greetings = { "Hola, bienvenido a Citizen of Arcanis!", "¿Qué tal el día?", "¡Es un placer verte!", "Espero que disfrutes tu aventura.", "¿Necesitas ayuda?" };
/// <summary>
/// Array of possible greeting messages that the NPC can display
/// </summary>
public string[] greetings = { "Hola, bienvenido a Citizen of Arcanis!", "�Qu� tal el d�a?", "�Es un placer verte!", "Espero que disfrutes tu aventura.", "�Necesitas ayuda?" };
private bool isPlayerNearby = false;
private Coroutine typingCoroutine;

/// <summary>
/// Initializes the dialogue UI elements to their default hidden state
/// </summary>
void Start()
{
if (interactionText != null)
Expand All @@ -23,6 +42,10 @@ void Start()
}
}

/// <summary>
/// Handles player entering the NPC's interaction zone
/// </summary>
/// <param name="other">The collider that entered the trigger zone</param>
void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
Expand All @@ -35,6 +58,10 @@ void OnTriggerEnter(Collider other)
}
}

/// <summary>
/// Handles player leaving the NPC's interaction zone
/// </summary>
/// <param name="other">The collider that exited the trigger zone</param>
void OnTriggerExit(Collider other)
{
if (other.CompareTag("Player"))
Expand All @@ -56,6 +83,9 @@ void OnTriggerExit(Collider other)
}
}

/// <summary>
/// Checks for player input to trigger dialogue interaction
/// </summary>
void Update()
{
if (isPlayerNearby && Input.GetKeyDown(KeyCode.E))
Expand All @@ -64,6 +94,9 @@ void Update()
}
}

/// <summary>
/// Toggles the dialogue panel visibility and manages the typing animation
/// </summary>
void TogglePanel()
{
if (dialogueUI != null)
Expand Down Expand Up @@ -103,6 +136,11 @@ void TogglePanel()
}
}

/// <summary>
/// Creates a typing animation effect for displaying dialogue text
/// </summary>
/// <param name="message">The message to be displayed character by character</param>
/// <returns>IEnumerator for the coroutine system</returns>
IEnumerator TypeText(string message)
{
dialogueText.text = "";
Expand Down
27 changes: 22 additions & 5 deletions Unity/Assets/Scripts/DroneMovement/DroneMovement.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,47 @@
using UnityEngine;

/// <summary>
/// Controls the circular movement of a drone around a center point.
/// This script should be attached to a drone GameObject that needs to orbit around a specific point in the scene.
/// </summary>
public class DroneMovement : MonoBehaviour
{
/// <summary>
/// Reference to the transform that serves as the center point for the drone's circular movement.
/// </summary>
public Transform centerPoint;
/// <summary>
/// The radius of the circular path that the drone follows.
/// </summary>
public float radius = 10f;
/// <summary>
/// The speed at which the drone moves along its circular path.
/// Higher values result in faster orbital movement.
/// </summary>
public float speed = 1f;
/// <summary>
/// The speed at which the drone rotates around its local right axis.
/// </summary>
public float rotationSpeed = 50f;

private float angle = 0f;

/// <summary>
/// Updates the drone's position and rotation each frame.
/// Calculates the new position based on circular movement around the center point
/// and updates the drone's rotation to face its movement direction.
/// </summary>
void Update()
{

angle += speed * Time.deltaTime;

float x = centerPoint.position.x + Mathf.Cos(angle) * radius;
float z = centerPoint.position.z + Mathf.Sin(angle) * radius;
float y = transform.position.y;


transform.position = new Vector3(x, y, z);


transform.Rotate(Vector3.right, rotationSpeed * Time.deltaTime);


Vector3 direction = new Vector3(x, y, z) - transform.position;
transform.rotation = Quaternion.LookRotation(direction);
}
Expand Down
19 changes: 15 additions & 4 deletions Unity/Assets/Scripts/Minimap/MinimapController.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
using UnityEngine;

/// <summary>
/// Controls the minimap camera behavior by following the player's position.
/// This script should be attached to the minimap camera object in the scene.
/// </summary>
public class MinimapController : MonoBehaviour
{
public Transform player; // El jugador al que seguirá el minimapa
/// <summary>
/// Reference to the player's transform that the minimap camera will follow.
/// Must be assigned through the Unity Inspector.
/// </summary>
public Transform player;

/// <summary>
/// Updates the minimap camera position to follow the player.
/// Called after all Update functions have been called.
/// </summary>
private void LateUpdate()
{
if (player == null) return; // Asegúrate de que el jugador está asignado
if (player == null) return;

// Actualizar la posición de la cámara para que siga al jugador
Vector3 newPosition = player.position;
newPosition.y = transform.position.y; // Mantener la altura configurada en el Inspector
newPosition.y = transform.position.y;

transform.position = newPosition;
}
Expand Down
42 changes: 32 additions & 10 deletions Unity/Assets/Scripts/RegistrySystem/SaveSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,58 @@
using UnityEngine;
using TMPro;


/// <summary>
/// Manages the saving and loading of player data, specifically handling player name storage
/// using Unity's PlayerPrefs system. This script is typically attached to a UI manager in
/// scenes where player data needs to be persisted.
/// </summary>
public class Save : MonoBehaviour
{
/// <summary>
/// Input field where the player enters their name
/// </summary>
public TMP_InputField inputField;
public TMP_Text warningText; // Optional: Warning text in the UI
/// <summary>
/// Text component used to display warning messages to the user
/// </summary>
public TMP_Text warningText;
/// <summary>
/// Text component that displays the current player name
/// </summary>
public TMP_Text playerNameText;

/// <summary>
/// Saves the player's name to PlayerPrefs if the input field is not empty.
/// Displays a warning message if no name is entered.
/// </summary>
public void SaveData()
{
string playerName = inputField.text;

// Check if the text field is empty
if (string.IsNullOrEmpty(playerName))
{
// If empty, display warning and do not save
Debug.LogWarning("The name field is empty. Please enter a name.");

// Display warning message in UI if exists
if (warningText != null)
{
warningText.text = "Please enter your name before saving.";
}
return; // Exit method without saving
}

// Save the name in PlayerPrefs
PlayerPrefs.SetString("PlayerName", playerName);
PlayerPrefs.Save();
Debug.Log("Saved name: " + playerName);

// Clear warning message if saved correctly
if (warningText != null)
{
warningText.text = "";
}
}
// Method for loading data

/// <summary>
/// Loads the previously saved player name from PlayerPrefs and displays it
/// in the input field. Shows a warning if no data exists.
/// </summary>
public void LoadData()
{
if (PlayerPrefs.HasKey("PlayerName"))
Expand All @@ -54,6 +69,10 @@ public void LoadData()
}
}

/// <summary>
/// Deletes the stored player name from PlayerPrefs and clears the input field.
/// Shows a warning if no data exists to delete.
/// </summary>
public void DeleteData()
{
if (PlayerPrefs.HasKey("PlayerName"))
Expand All @@ -68,7 +87,10 @@ public void DeleteData()
}
}

// Method for loading the character selection scene
/// <summary>
/// Transitions the game to the character selection scene.
/// This method is typically called after the player's name has been saved.
/// </summary>
public void LoadCharacterSelectionScene()
{
SceneManager.LoadScene("DemoSelectionCharacter");
Expand Down
Loading

0 comments on commit 143ef71

Please sign in to comment.