Adding Config to Naninovel/Resources menu

Posted: 24 Apr 2023 04:50
by BigBenEco

I have set up a simple custom Configuration thingy

Image

trying to see if I can add it to this list

Image

been digging through the engine source code and the inventory example, but I can't seem to find what i'm looking for.

Also can't seem to get ResourceContext to work such that the list shows up in the @unlockOutfit command but that may be because I don't fully understand how everything works. and yes I've tried "Update Metadata" to try to get the resource names to show up, but i'm obviously not connecting something together, here is what I have for code

Code: Select all

using Naninovel;
using UnityEngine;

namespace UnlockableOutfits
{
    /// <summary>
    /// Contains configuration data for the Unlockable Outfit system.
    /// </summary>
    [EditInProjectSettings]
    public class UnlockableOutfitConfiguration : Configuration
    {
        /// <summary>
        /// Used to distinguish unlockable outfit records among other resources.
        /// </summary>
        public const string DefaultPathPrefix = "UnlockableOutfit";

        [Header("Outfit Options")]
        public string[] Outfits;

        //[Tooltip("Configuration of the resource loader used with unlockable outfit resources.")]
        //public ResourceLoaderConfiguration Loader = new ResourceLoaderConfiguration { PathPrefix = DefaultPathPrefix };
        // not sure if I need this
    }
}

Code: Select all

using Naninovel;
using UnityEngine;

namespace UnlockableOutfits
{
    [CommandAlias("unlockOutfit"),Documentation("A simple command to unlock outfits for main character.")]
    public class UnlockOutfitCommand : Command
    {
        [RequiredParameter, ParameterAlias(NamelessParameterAlias), Documentation("Identifier of the outfit to unlock."),ResourceContext(UnlockableOutfitConfiguration.DefaultPathPrefix) ]
        public NamedStringParameter outfit;

        UnlockableOutfitManager outfitManager = Engine.GetService<UnlockableOutfitManager>(); // get access my outfit manager
        public override UniTask ExecuteAsync (AsyncToken asyncToken = default)
        {

            outfitManager.Unlock(outfit); // just debug logs the input for now

            return UniTask.CompletedTask;
        }
    }
}

Re: Adding Config to Naninovel/Resources menu

Posted: 24 Apr 2023 08:23
by idaot

Adding the configuration to the Naninovel menu is just a matter of adding a MenuItem attribute: https://docs.unity3d.com/ScriptReference/MenuItem.html

As for the ResourceContext, you'll need a Resources menu for the values to be passed to the metadata. Check MoviesConfiguration.cs, MoviesSettings and PlayMovie.cs for a simple configuration with resources plus command with ResourceContext.


Re: Adding Config to Naninovel/Resources menu

Posted: 25 Apr 2023 04:48
by BigBenEco

Thanks @idaot!
So it was more of a Unity thing, good to know.

Going through Naninovel's code and example projects I have noticed some patterns (UISettings vs UIConfiguration), but looking for the MenuItem attribute helped me locate some more files and patterns, still trying to get my mind around Naninovel's design