Forum rules - please read before posting.

[Feature request] Save more data with "RememberHotspot" component

I'm currently experimenting with a feature that turns off the "Look at" interaction and sets the hotspot's "Single 'Use' interaction" flag (Hotspot.oneClick). This works as long as the scene is not changed. I added a "RememberHotspot" component to the hotspot, but it only saves the name, the state and interaction's states. The state of the ".oneClick" bool is not saved.
I think I could copy the "RememberHotspot" script, add the data to the HotspotData class and call it "RememberHotspotCustom" or something to use it instead of the original "HotspotRemember" component, but that could course serious problems in the future when something on AC side is changed with the "RememberHotspot" script.
So my question: Would it be possible to implement the .oneClick bool and the .doubleClickingHotspot value in AC's "RememberHotspot" script so that these attributes could be changed by script and be part of the save system?

Regards
Marcus

Comments

  • Those properties aren't intended to be changed at runtime. Feasibly they can - through script - but they aren't something that can be controlled using AC's provided Actions.

    You can, however, attach a custom Remember script that purely saves this data, separately:

    using UnityEngine;
    using AC;
    
    [RequireComponent (typeof (Hotspot))]
    public class RememberHotspotExtra : Remember
    {
    
        public override string SaveData ()
        {
            HotspotExtraData data = new HotspotExtraData ();
            data.objectID = constantID;
            data.savePrevented = savePrevented;
    
            Hotspot hotspot = GetComponent<Hotspot> ();
            data.oneClick = hotspot.oneClick;
            data.doubleClick = (int) hotspot.doubleClickingHotspot;
    
            return Serializer.SaveScriptData <HotspotExtraData> (data);
        }
    
        public override void LoadData (string stringData)
        {
            HotspotExtraData data = Serializer.LoadScriptData <HotspotExtraData> (stringData);
            if (data == null)
            {
                return;
            }
            SavePrevented = data.savePrevented; if (savePrevented) return;
    
            Hotspot hotspot = GetComponent<Hotspot> ();
            hotspot.oneClick = data.oneClick;
            hotspot.doubleClickingHotspot = (DoubleClickingHotspot) data.doubleClick;
            loadedData = true;
        }
    
    }
    
    [System.Serializable]
    public class HotspotExtraData : RememberData
    {
    
        public bool oneClick;
        public int doubleClick;
    
        public HotspotExtraData () { }
    }
    
  • Thanks for the script. A very good idea to implement this. I already have a custom action to set these attributes from ActionLists. I guess the data is also saved in a save game file because it derives from the Remember class?

    What about an option for the Hotspot component like "Use Single 'Use' Interaction if only one interaction is active?". This could be a very convenient and automated system for Hotspots when using the "Choose Hotspot Then Interaction" interaction method.

  • I guess the data is also saved in a save game file because it derives from the Remember class?

    That's all the script does, yes.

    What about an option for the Hotspot component like "Use Single 'Use' Interaction if only one interaction is active?".

    I'm not sure about a built-in option, but certainly this can be achieved with a single custom script placed in the scene:

    using UnityEngine;
    using AC;
    
    public class AutoSetSingleClick : MonoBehaviour
    {
    
        void OnEnable ()
        {
            EventManager.OnInitialiseScene += OnInitialiseScene;
            EventManager.OnEnterGameState += OnEnterGameState;
        }
    
        void OnDisable ()
        {
            EventManager.OnInitialiseScene -= OnInitialiseScene;
            EventManager.OnEnterGameState -= OnEnterGameState;
        }
    
        void OnEnterGameState (GameState gameState) { UpdateHotspots (); }
        void OnInitialiseScene () { UpdateHotspots (); }
    
        void UpdateHotspots ()
        {
            foreach (Hotspot hotspot in KickStarter.stateHandler.Hotspots)
            {
                UpdateHotspot (hotspot);
            }
        }
    
        void UpdateHotspot (Hotspot hotspot)
        {
            bool hasOneUse = false;
            foreach (AC.Button button in hotspot.useButtons)
            {
                if (!button.isDisabled)
                {
                    if (!hasOneUse)
                    {
                        hasOneUse = true;
                    }
                    else
                    {
                        hasOneUse = false;
                        break;
                    }
                }
            }
            hotspot.oneClick = hasOneUse;
        }
    
    }
    
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.