Forum rules - please read before posting.

Switching documents

Is there a way to load next or previous document data (title, text, texture) by those arrows in the same document menu? All documents contains only one page.

Comments

  • Good question! It requires scripting, but it can be done.

    The buttons you've circled are meant for page-switching, by default. However, if you set their Click type properties to Custom Script, you can use the below to have them cycle left/right through documents that the Player is carrying:

    using UnityEngine;
    using AC;
    
    public class CycleDocuments : MonoBehaviour
    {
    
        private void OnEnable ()
        {
            EventManager.OnMenuElementClick += OnMenuElementClick;
        }
    
        private void OnDisable ()
        {
            EventManager.OnMenuElementClick -= OnMenuElementClick;
        }
    
        private void OnMenuElementClick (AC.Menu menu, MenuElement element, int slot, int buttonPressed)
        {
            Document currentDocument = KickStarter.runtimeDocuments.ActiveDocument;
            if (currentDocument == null || menu.title != "Document") return;
    
            int[] documentIDs = KickStarter.runtimeDocuments.GetCollectedDocumentIDs ();
            int currentIndex = -1;
            for (int i = 0; i < documentIDs.Length; i++)
            {
                if (documentIDs[i] == currentDocument.ID)
                {
                    currentIndex = i;
                    break;
                }
            }
    
            if (currentIndex < 0) return;
    
            if (element.title == "ShiftLeft")
            {
                currentIndex --;
                if (currentIndex < 0) currentIndex = documentIDs.Length - 1;
            }
            else if (element.title == "ShiftRight")
            {
                currentIndex ++;
                if (currentIndex >= documentIDs.Length) currentIndex = 0;
            }
            else
            {
                return;
            }
    
            int newDocumentID = documentIDs[currentIndex];
            KickStarter.runtimeDocuments.OpenDocument (newDocumentID);
        }
    
    }
    

    To use it, paste in a C# file named CycleDocuments.cs, and add the new Cycle Documents component to your scene (or PersistentEngine prefab to have it be present in all scenes).

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.