Forum rules - please read before posting.

unity ui how to connect ac save load system

hi i want to make my own unity ui but question is how i add save load system from ac to my own unity ui? i want for unity to use all ac settings normally but only change view of menu to the unity ui layout so how should i add saving loading starting scenes etc via prefab buttons?

Comments

  • Working with Unity UI is a case of defining Menus in the Menu Manager, defining Elements within those Menus (such as a SavesList, to display a list of saves), and then linking them to the corresponding Unity UI component.

    Details can be found in the Manual's "Unity UI menus" chapter, and this tutorial covers a practical example.

    The default Save menu, however, already works with Unity UI - just set its Source field to Unity Ui Prefab, and open up its Linked Canvas prefab to begin editing it. Though, you may find it easier to rely on the Adventure Creator Source option, as it's generally quicker/easier for rapid prototyping.

  • so for egzample how i add save load logic to unity ui using ac save system then?

  • is it possible to make short tutorial for that? same like with inventory one but concentrated on save load system from ac

  • edited May 2024

    The principles covered by the tutorial are the same for any Menu type, but the default Save and Load menus are already compatible with Unity UI. If you've run the New Game Wizard to generate your Managers, they'll be included with the default interface. Is this the case? Sharing screenshots of your Menu Manager will help clarify your situation.

    When creating Menus - particularly for the first time - I recommend doing so with the Adventure Creator source option. Create a new Menu, leave its Source field as Adventure Creator, and then keep the Game window open to preview the Menu as you build it.

    In the list of Element types beneath, create a new SavesList element - this'll represent the various save slots. Set its List type to Save to have clicks to it save the game, or Load to have them load files.

    Once you're happy with the logic (don't worry about the appearance too much), you can create a UI Canvas equivalent - with regular UI Buttons for the save slots. It's then a case of applying the Canvas and components to the Menu in the same way as the tutorial.

    A couple of ready-made Save/Load menus are also available on the Downloads page - including one that provides screenshots. You can import and apply the Template file to have AC install it for you automatically.

  • the problem is i use modern ui pack thats based on ugui but little diffrent i have mostly problem with dropdown they look like this and i cannot move them to grephic options setup that is already made https://ibb.co/ykPYc28

  • so was wondering how can i use them with ac for normal buttons i use something like this; https://ibb.co/svF8nvD

  • edited May 2024

    here;

    using UnityEngine;
    using Michsky.MUIP; // Namespace for Modern UI Pack
    using System.Collections.Generic;
    using AC; // Namespace for Adventure Creator

    public class OptionsManager : MonoBehaviour
    {
    public CustomDropdown resolutionDropdown;
    public CustomDropdown qualityPresetDropdown;
    public CustomDropdown textureQualityDropdown;
    public CustomDropdown antialiasingDropdown;
    public CustomDropdown vSyncDropdown;

    private void Start()
    {
        InitializeDropdowns();
    }
    
    private void InitializeDropdowns()
    {
        // Initialize resolution dropdown
        PopulateResolutionDropdown();
    
        // Initialize quality preset dropdown
        PopulateDropdown(qualityPresetDropdown, QualitySettings.names, "", 2);
    
        // Initialize texture quality dropdown
        List<string> textureQualityNames = new List<string>();
        for (int i = 0; i <= 3; i++)
        {
            textureQualityNames.Add("Level " + i);
        }
        PopulateDropdown(textureQualityDropdown, textureQualityNames.ToArray(), "", 3);
    
        // Initialize antialiasing dropdown
        PopulateDropdown(antialiasingDropdown, new string[] { "Off", "2x", "4x", "8x" }, "", 4);
    
        // Initialize VSync dropdown
        PopulateDropdown(vSyncDropdown, new string[] { "Off", "On" }, "", 5);
    
        // Load saved settings
        LoadSettings();
    }
    
    private void PopulateDropdown(CustomDropdown dropdown, IEnumerable<object> items, string itemNameSuffix, int variableID)
    {
        dropdown.items.Clear(); // Clear existing items
        foreach (var item in items)
        {
            dropdown.items.Add(new CustomDropdown.Item() { itemName = item.ToString() + itemNameSuffix });
        }
        dropdown.SetupDropdown(); // Refresh dropdown UI
        dropdown.onValueChanged.AddListener(delegate { SaveSetting(variableID, dropdown.selectedItemIndex); });
    }
    
    private void PopulateResolutionDropdown()
    {
        resolutionDropdown.items.Clear(); // Clear existing items
        foreach (var resolution in Screen.resolutions)
        {
            string resolutionString = resolution.width + " x " + resolution.height;
            resolutionDropdown.items.Add(new CustomDropdown.Item() { itemName = resolutionString });
        }
        resolutionDropdown.SetupDropdown(); // Refresh dropdown UI
        resolutionDropdown.onValueChanged.AddListener(delegate { SaveSetting(1, resolutionDropdown.selectedItemIndex); });
    }
    
    private void ChangeResolution(int resolutionIndex)
    {
        Resolution resolution = Screen.resolutions[resolutionIndex];
        Screen.SetResolution(resolution.width, resolution.height, Screen.fullScreen);
    }
    
    private void SaveSetting(int variableID, int value)
    {
        GlobalVariables.SetIntegerValue(variableID, value);
        SaveSettings();
    }
    
    private void SaveSettings()
    {
        SaveSystem.SaveAutoSave(); // Save the game to preserve settings
    }
    
    public void LoadSettings()
    {
        resolutionDropdown.selectedItemIndex = GlobalVariables.GetIntegerValue(1);
        qualityPresetDropdown.selectedItemIndex = GlobalVariables.GetIntegerValue(2);
        textureQualityDropdown.selectedItemIndex = GlobalVariables.GetIntegerValue(3);
        antialiasingDropdown.selectedItemIndex = GlobalVariables.GetIntegerValue(4);
        vSyncDropdown.selectedItemIndex = GlobalVariables.GetIntegerValue(5);
    
        ChangeResolution(resolutionDropdown.selectedItemIndex);
    }
    

    }
    my script for options

  • there are corresponding but i cannot change values

  • almoust fixed still 1 error left while saving options ArgumentOutOfRangeException: StartIndex cannot be less than zero.
    Parameter name: startIndex
    System.Text.StringBuilder.Remove (System.Int32 startIndex, System.Int32 length) (at <467a840a914a47078e4ae9b0b1e8779e>:0)
    AC.PlayerMenus.CreateMenuElementVisibilityData () (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:3533)
    AC.PlayerMenus.SaveMainData (AC.MainData mainData) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:3433)
    AC.SaveOperation.SendSaveToFile () (at Assets/AdventureCreator/Scripts/Save system/SaveOperation.cs:141)
    AC.SaveOperation.BeginOperation (AC.SaveData& saveData, AC.SaveFile saveFile) (at Assets/AdventureCreator/Scripts/Save system/SaveOperation.cs:83)
    AC.SaveSystem+d__61.MoveNext () (at Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs:1071)
    UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <55fbbbd17b724c15b6abe8c1a3e3289c>:0)
    UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

  • the problem is i use modern ui pack thats based on ugui but little diffrent i have mostly problem with dropdown they look like this and i cannot move them to grephic options setup that is already made

    Thanks for the details.

    If you're using a separate UI asset that has its own UI scripts etc, then bypassing the Menu Manager and accessing AC functions/variables directly is a good option.

    In the case of running an ActionList when a Button is clicked: you can run an ActionList component or asset by invoking its Interact function as part of the Button's "OnClick" event. The way you've set it up here is correct - though you'll want to rely on an ActionList asset file if you intend to prefab the UI.

    ArgumentOutOfRangeException: StartIndex cannot be less than zero.

    What's your AC version?

    If you open up AC's PlayerMenus script, look for the following around line 3533:

    if (menus.Count > 0)
    {
        visibilityString.Remove (visibilityString.Length-1, 1);
    }
    

    Replace it with:

    if (menus.Count > 0 && visibilityString.Length > 0)
    {
        visibilityString.Remove (visibilityString.Length-1, 1);
    }
    
  • ty works for me now :)

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.