Forum rules - please read before posting.

Taking notes in-game

Is it possible to create a diary or notebook that allows the player to input their own text as notes, which can then be saved?

Comments

  • If you have a Unity UI-based Menu, you can make use of Unity's own Input Field component to allow the player to enter text. This doesn't actually need to be linked with AC's Menu Manager as an element to work - only the prefab itself if you want AC to be able to hide/show it.

    The tricky part, which would have to involve AC, is storing its contents in save-game files.

    To save its contents, you then need to write a script that stores the Input element's contents into a Global String variable.

    This tutorial covers the process, but an equivalent script for reading/updating an InputField inside a Menu would be something like:

    using UnityEngine;
    using UnityEngine.UI;
    using AC;
    
    public class SaveDiaryText : MonoBehaviour
    {
    
        public int varID;
        public string menuName = "MyMenu";
    
        private void OnEnable ()
        {
            EventManager.OnBeforeSaving += BeforeSave;
            EventManager.OnFinishLoading += AfterLoad;
        }
    
        private void OnDisable ()
        {
            EventManager.OnBeforeSaving -= BeforeSave;
            EventManager.OnFinishLoading -= AfterLoad;
        }
    
        private void BeforeSave (int saveID)
        {
            GlobalVariables.SetStringValue (varID, GetInputField ().text);
        }
    
        private void AfterLoad ()
        {
            GetInputField ().text = GlobalVariables.GetStringValue (varID);
        }
    
        private InputField GetInputField ()
        {
            Canvas canvas = PlayerMenus.GetMenuWithName ("MyMenu").RuntimeCanvas;
            InputField inputField = canvas.GetComponentInChildren<InputField> ();
            return inputField;
        }
    
    } 
    
  • Thanks, Chris. I'll take a look at this over the next couple of days.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.