What other features can we add in this following script :
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using UnityEngine.Audio;
using com.ootii.Actors;
using com.ootii.Actors.AnimationControllers;
using com.ootii.Cameras;
using com.ootii.Input;
using System.Collections;
[System.Serializable]
public class Page
{
public TextAsset pageTextAsset;
// You can add more properties if needed, such as rightPageText, images, etc.
}
[System.Serializable]
public class Book
{
public string bookTitle;
public Sprite bookIcon;
public Sprite bookBackground;
public string puzzleHint; // Puzzle hint specific to the book
public Sprite puzzleHintBackground; // Background sprite for the puzzle hint
public AudioClip ambientSound; // Ambient sound specific to the book
public List pages;
public bool requiresKnowledge = true; // New property to determine if the book requires knowledge to read
public Book(string title)
{
bookTitle = title;
pages = new List<Page>();
}
// You can add more properties and methods specific to a book here
}
public class BookController : MonoBehaviour
{
public List books = new List(); // List of all books
private Book currentBook; // The currently selected book
private int currentBookIndex = 0; // Index of the current book
private int currentPageIndex = 0; // Index of the current page within the current book
public TextMeshProUGUI titleTextUI; // TextMeshProGUI for the title
public TextMeshProUGUI pageTextUI; // TextMeshProUGUI for the page
public Image bookIconUI; // UI element for the book icon
public Image bookBackgroundUI; // UI element for the book background
public TextMeshProUGUI puzzleHintTextUI; // Reference to the puzzle hint TextMeshPro element
public Image puzzleHintBackgroundUI; // Reference to the puzzle hint background Image element
public Button nextButton; // Button to flip forward
public Button prevButton; // Button to flip backward
public Button closeButton;
public GameObject puzzleHintUI;
public AudioMixer audioMixer;
public AudioSource pageAudioSource;
public AudioSource ambientAudioSource;
public AudioClip closeSound;
public AudioClip pageTurnClip; // Assign this in the inspector
// Fade-in duration in seconds
public float fadeInDuration = 2.0f;
// Fade-out duration in seconds
public float fadeOutDuration = 2.0f;
public Animator animator; // Animator for page flip animations
public bool playerHasKnowledge = false; // Player's ability to read the real text
//private int currentPageIndex = 0; // Index of the current page
private InsaneMode insaneModeScript;
public UnityInputSource InputSource;
public CameraController camRig;
public ActorController actorController;
public MotionController motionController;
private Dictionary<string, string> lovecraftianDictionary = new Dictionary<string, string>
{
// Common words
{"the", "yog"}, {"and", "soth"}, {"to", "leng"}, {"of", "oveh"}, {"a", "cthun"},
{"in", "fhtagn"}, {"is", "gnaiih"}, {"you", "yhah"}, {"that", "n'gha"}, {"it", "zhro"},
{"he", "tharanak"}, {"with", "ephai"}, {"as", "s'uhn"}, {"for", "y'hah"}, {"his", "gotha"},
{"on", "n'ghft"}, {"are", "or'azh"}, {"by", "zhro"}, {"be", "throd"}, {"was", "nafl"},
{"this", "ilyaa"}, {"not", "nah"}, {"but", "bug"}, {"from", "fhalma"}, {"they", "tharan"},
{"her", "hrii"}, {"we", "wgah'n"}, {"have", "agl"}, {"which", "kadishtu"}, {"an", "uln"},
{"at", "kn'a"}, {"can", "k'yarnak"}, {"my", "nog"}, {"all", "fhalma"}, {"your", "li'hee"},
{"their", "ron"}, {"has", "gnaiih"}, {"do", "nafl"}, {"our", "or'azh"}, {"more", "nafll"},
{"one", "uaaah"}, {"who", "uh'e"}, {"I", "ai"}, {"them", "throd"},
{"what", "tharanak"}, {"when", "zhro"}, {"would", "y'hah"}, {"there", "y'hah'nn"},
{"like", "lyeh'n"}, {"if", "ph'nglui"}, {"time", "eeeh"}, {"no", "nog"}, {"out", "yugg"},
// Extended words
{"people", "sll'ha"}, {"could", "cthro"}, {"then", "th'nglui"}, {"into", "ntar"},
{"just", "y'st"}, {"him", "hupadgh"}, {"know", "k'yarnak"}, {"take", "t'la"},
{"over", "og'n"}, {"also", "az'ath"}, {"back", "byahee"},
{"use", "uaaah"}, {"two", "tcho"}, {"how", "h'chtelegoth"},
{"first", "f'ah"}, {"well", "w'ah"}, {"way", "wgahnagl"},
{"even", "ee'ghft"}, {"new", "nafl'fhalma"}, {"want", "w'ah'nn"}, {"because", "byatis"},
{"any", "ai'y"}, {"these", "th'shugg"}, {"day", "dag'n"}, {"most", "m'latgh"},
{"us", "ulth'ri"}, {"work", "wgha"}, {"part", "phlegeth"}, {"place", "pl'hah"},
{"made", "m'nagl"}, {"live", "li'hee"}, {"where", "whai"}, {"after", "ath'nak"},
{"little", "lloig"}, {"only", "ooboshu"}, {"round", "r'luhhor"}, {"man", "mh'ithrha"},
{"year", "y'hah"}, {"came", "c'ah"}, {"show", "shagg"}, {"every", "ee'gor"},
{"good", "gof'nn"}, {"me", "mnahn'"}, {"give", "gla'aki"},
{"under", "uaaah"}, {"name", "nafl'fhalma"}, {"very", "vulgtlagln"}, {"through", "thy'l"},
{"form", "fm'latgh"}, {"sentence", "shtunggli"}, {"great", "gof'nn"},
{"say", "s'uhn"}, {"help", "hai"}, {"low", "lohg-lo"},
{"line", "li'lne"}
};
public int CurrentBookIndex
{
get { return currentBookIndex; }
set { SelectBookByIndex(value); }
}
public void RefreshBooksList()
{
// Implement this method if you need to dynamically update the books list
// For example, reading from a file or database
}
void Start()
{
// Find the InsaneMode instance in the scene
insaneModeScript = FindObjectOfType<InsaneMode>();
InputSource = FindObjectOfType<UnityInputSource>();
camRig = FindObjectOfType<CameraController>();
actorController = FindObjectOfType<ActorController>();
motionController = FindObjectOfType<MotionController>();
if (insaneModeScript == null)
{
Debug.LogError("InsaneMode script not found in the scene!");
}
// Check if we have any books and if the first book has pages before selecting it
if (books.Count > 0 && books[0].pages.Count > 0)
{
SelectBook(0); // Start with the first book
}
else
{
Debug.LogError("Books list is empty or the first book has no pages.");
return; // Exit early if we have no books or pages
}
nextButton.onClick.AddListener(NextPage);
prevButton.onClick.AddListener(PreviousPage);
closeButton.onClick.AddListener(CloseBook);
// Analyze all books for unmapped words
foreach (var book in books)
{
if (book.pages.Count == 0)
{
Debug.LogWarning($"The book '{book.bookTitle}' has no pages.");
continue; // Skip to the next book
}
foreach (var page in book.pages)
{
AnalyzeTextForTranslation(page.pageTextAsset.text);
}
}
}
// Public method to select a book by index
public void SelectBookByIndex(int index)
{
if (index >= 0 && index < books.Count)
{
SelectBook(index);
}
else
{
Debug.LogError("Invalid book index selected.");
}
}
void SelectBook(int index)
{
if (index < 0 || index >= books.Count)
{
Debug.LogError("Book index out of range.");
return;
}
currentBookIndex = index;
currentBook = books[currentBookIndex];
currentPageIndex = 0; // Reset to the first page of the new book
UpdateUI();
}
void Update()
{
// Update playerHasKnowledge based on the insaneMode
if (insaneModeScript != null)
{
playerHasKnowledge = !insaneModeScript.insaneMode;
}
// Call the method to update the hint visibility
UpdatePuzzleHintVisibility();
// Optionally, only call UpdateUI if the knowledge state has changed
// ...
}
void UpdatePuzzleHintVisibility()
{
// Ensure the hint UI element and the insaneModeScript are assigned
if (puzzleHintUI != null && insaneModeScript != null)
{
// Show the hint only when the player has knowledge
puzzleHintUI.SetActive(playerHasKnowledge);
}
}
void UpdateUI()
{
if (currentBook == null || pageTextUI == null || titleTextUI == null)
return;
// Assume that each book has at least one page for simplicity
Page currentPage = currentBook.pages[currentPageIndex];
// Determine if the book requires knowledge and if the player has it
bool canRead = !currentBook.requiresKnowledge || (currentBook.requiresKnowledge && playerHasKnowledge);
// Display the book title and page text based on whether the player can read it
string displayedTitle = canRead ? currentBook.bookTitle : TransformToLovecraftian(currentBook.bookTitle);
string displayedText = canRead ? currentPage.pageTextAsset.text : TransformToLovecraftian(currentPage.pageTextAsset.text);
// Update the UI elements with the book title and page text
titleTextUI.text = displayedTitle;
pageTextUI.text = displayedText;
// Update the interactable state of the previous and next buttons
prevButton.interactable = currentPageIndex > 0;
nextButton.interactable = currentPageIndex < currentBook.pages.Count - 1;
// Update the book icon and background
if (bookIconUI != null && currentBook.bookIcon != null)
{
bookIconUI.sprite = currentBook.bookIcon;
bookIconUI.gameObject.SetActive(true); // Ensure the UI element is active
}
else
{
bookIconUI.gameObject.SetActive(false); // Hide the icon if it's not available
}
if (bookBackgroundUI != null && currentBook.bookBackground != null)
{
bookBackgroundUI.sprite = currentBook.bookBackground;
bookBackgroundUI.gameObject.SetActive(true); // Ensure the UI element is active
}
else
{
bookBackgroundUI.gameObject.SetActive(false); // Hide the background if it's not available
}
// Update the puzzle hint visibility, text, and background
if (puzzleHintTextUI != null && puzzleHintBackgroundUI != null)
{
if (playerHasKnowledge && !string.IsNullOrEmpty(currentBook.puzzleHint))
{
puzzleHintTextUI.text = currentBook.puzzleHint;
puzzleHintTextUI.gameObject.SetActive(true); // Show the hint text
// If the book has a hint background, display it
if (currentBook.puzzleHintBackground != null)
{
puzzleHintBackgroundUI.sprite = currentBook.puzzleHintBackground;
puzzleHintBackgroundUI.gameObject.SetActive(true); // Show the hint background
}
else
{
puzzleHintBackgroundUI.gameObject.SetActive(false); // Hide the background if not available
}
}
else
{
puzzleHintTextUI.gameObject.SetActive(false); // Hide the hint text
puzzleHintBackgroundUI.gameObject.SetActive(false); // Hide the hint background
}
}
// Trigger the page-turning animation
if (animator != null)
{
animator.SetTrigger("TurnPage");
}
}
string TransformToLovecraftian(string originalText)
{
// Split the text into words and transform each word using the dictionary
var words = Regex.Split(originalText.ToLower(), @"(\s+|\b)").ToList(); ;
var transformedText = new System.Text.StringBuilder();
f