I would like to link the bool type variable specified by Unity

Discuss authoring naninovel scenario scripts.
Post Reply
booksuny
Posts: 47
Joined: 26 Sep 2022 12:37

I would like to link the bool type variable specified by Unity

Post by booksuny »

Code: Select all

[System.Serializable]
public class ItemProperty
{
    public string name;
    public string textin;
    public Sprite sprite;
    public bool get;
}

I made the properties of the items to manage the items in the game.

There is also a boolean variable to indicate that an item has been obtained. All of this is managed by the inspector.

However, this prevents naninovell from saving or loading.
If you turn the game off and on, the item disappears.

Is there a function of Nanninovel to access Unity's inspector?
Or, is there a way to save or load variables created by Unity?

Last edited by booksuny on 27 Dec 2022 08:57, edited 1 time in total.
idaot
support
Posts: 262
Joined: 01 Aug 2020 08:25

Re: I would like to link the bool type variable specified by Unity

Post by idaot »

For your information, Naninovel has an inventory extension that you are free to modify and I suggest using that as the basis: https://naninovel.com/guide/inventory.html#inventory

Otherwise, create a custom engine service which manages the objects (https://naninovel.com/guide/engine-serv ... e-services) and custom commands to make changes to the objects at runtime.

booksuny
Posts: 47
Joined: 26 Sep 2022 12:37

Re: I would like to link the bool type variable specified by Unity

Post by booksuny »

idaot wrote: 27 Dec 2022 08:48

For your information, Naninovel has an inventory extension that you are free to modify and I suggest using that as the basis: https://naninovel.com/guide/inventory.html#inventory

Otherwise, create a custom engine service which manages the objects (https://naninovel.com/guide/engine-serv ... e-services) and custom commands to make changes to the objects at runtime.

Thank you for your reply. I received an answer while revising the text.

I want to save or load variables made from naninovell to unity. Otherwise, if i turn off and on Game, the item disappears!

Is the method of solving this problem at naninovell the same as the comment you just gave me?
Or is there an easier way?

idaot
support
Posts: 262
Joined: 01 Aug 2020 08:25

Re: I would like to link the bool type variable specified by Unity

Post by idaot »

booksuny
Posts: 47
Joined: 26 Sep 2022 12:37

Re: I would like to link the bool type variable specified by Unity

Post by booksuny »

idaot wrote: 27 Dec 2022 13:57

Check the custom state guide: https://naninovel.com/guide/state-manag ... stom-state

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Naninovel;

public class MyCustomBehaviour : MonoBehaviour
{
    // 직렬화 코드
    [System.Serializable]
    public class ItemProperty 
    { 
        // 아이템의 정보를 적어줄 변수들
        public string name;
        public string textin;
        public Sprite sprite;
        public bool get;
    }

// get 상태만 저장해주면 된다,
private bool get;
private IStateManager stateManager;

private void Awake ()
{
    stateManager = Engine.GetService<IStateManager>();
}

private void OnEnable ()
{
    stateManager.AddOnGameSerializeTask(SerializeState);
    stateManager.AddOnGameDeserializeTask(DeserializeState);
}

private void OnDisable ()
{
    stateManager.RemoveOnGameSerializeTask(SerializeState);
    stateManager.RemoveOnGameDeserializeTask(DeserializeState);
}

private void SerializeState (GameStateMap stateMap)
{
    var state = new ItemProperty() {
        get = get,
    };
    stateMap.SetState(state);
}

private UniTask DeserializeState (GameStateMap stateMap)
{
    var state = stateMap.GetState<ItemProperty>();
    if (state is null) return UniTask.CompletedTask;

    get = state.get;
    return UniTask.CompletedTask;
}
}

I wrote the following code with your help.

However, the boolean get still does not work with naninovel. Even if you save the game, there are no items left.

Did I make a mistake in the code?

idaot
support
Posts: 262
Joined: 01 Aug 2020 08:25

Re: I would like to link the bool type variable specified by Unity

Post by idaot »

I suggest studying the InventoryManager.cs script found in the Inventory example project.

Alternatively, consider converting them to Naninovel custom variables in case you want to use them in naniscript: https://naninovel.com/guide/custom-vari ... ables-in-c

Post Reply