Forum rules - please read before posting.

Creating a menu which is always visible and becomes completely visible with .IsPointInside

Hello AC community,

since a while I'm trying to create a menu (unity prefab) with AC which:

  1. Always visible except:
    a. when a dialog (dialog system) is running
    b. The Title, Options, Pause, Credit scene has been loaded.

My menu (inventory) should always be visible in the game like a bookmark and then when I move the cursor over the visible menu the menu should move completely with an animation clip.

I tried the functions: TurnOff and DisableUI in Menu.cs to adjust the RuntimeCanvas.gameObject.SetActive (false); that the function is not always called. But it happens that the menu can be seen in the loading scene.

If something is unclear, please let me know.
Thanks for any help!

Comments

  • Welcome to the community, @toborrm.

    As this is a visual problem, any screenshots you can share would help clarify the situation.

    Sounds like a two-pronged issue - the "bookmark" icon and the "open inventory" bar are separate problems.

    Having the "open inventory" bar could be handled either purely by scripting, or by creating a separate, invisible menu over the same space as the "bookmark" icon, set its Appear type to Mouse Over, and then use its Turn on ActionList / field to handle the opening-up animation for the original Menu.

    Let's deal with the bookmark icon's visibility first, though.

    To be clear: by "dialogue system", are you referring to Pixel Crusher's asset, or AC's Conversation system?

    If you're manipulating it through script, don't call DisableUI - turn it off with TurnOff. However, you'll need to make sure that its Appear type is set to Manual - otherwise, it'll turn itself on again if its appear condition is still met.

    What you could try, however, is instead setting this property to Except When Paused. That will show it during gameplay and cutscenes, but hide it whenever the game is paused (i.e. a "pause" Menu is on).

    To then hide it during other times (e.g. when Dialogue System is running), you can lock the Menu - either with the Menu: Change state Action, or by affecting the Menu's isLocked property. When a Menu is locked, it will not be visible even if its Appear type condition is met.

  • Hey @ChrisIceBox ,

    Thank you for taking care of my problem!

    Yes, I mean the Pixel Crusher's asset. I used the "appearType" for MouseOver to save myself from having to write a separate MouseOver script.

    Here are some pictures for you:
    (Here the function: "RuntimeCanvas.gameObject.SetActive (false);" in DisableUI (Menu.cs) was commented out. This gives the desired result, but as can be seen in the second picture, I rob AC of the function that when a scene is changed Menu can be hidden.)

    Here the MouseOver function is activated:

    Here you can see the Unity prefab menu in the loading screen:

    If you have an idea how I can solve this let me know. Otherwise, do you think I have to set "appearType" to Manual and trigger the MouseOver myself?

  • Hey @ChrisIceBox,

    here is a test script which I use on my menu. I tried to model the AC Menu script a bit for my needs. The only problem I have here is that the animation clip is not played completely. I think your tip with "appearType" Manual is better than MouseOver. Maybe you have an idea how I can fix my problem.

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public enum FadeType { fadeIn, fadeOut };
    
    public class MouseOverMenu : MonoBehaviour
    {
        [SerializeField] private RectTransform rectTransform;
        [SerializeField] private Vector2 invertedMouse;
        [SerializeField] private Animator _animator;
        [SerializeField] private bool answer;
        [SerializeField] private FadeType fadeType = FadeType.fadeIn;
        [SerializeField] private bool isOff;
        [SerializeField] private float transitionProgress = 0f;
    
    
        void Start()
        {
            _animator = GetComponentInParent<Animator>();
            rectTransform = GetComponent<RectTransform>();
            Initalise();
        }
    
    
        void Update()
        {
            invertedMouse = AC.KickStarter.playerInput.GetInvertedMouse ();
            answer = RectTransformUtility.RectangleContainsScreenPoint(rectTransform,
                new Vector2(invertedMouse.x, AC.ACScreen.height - invertedMouse.y), null);
    
            if (answer)
            {
                if (!isOff) return;
                TurnOn();
            }
            else
            {
                TurnOff();
            }
        }
    
        public void Initalise()
        {
            transitionProgress = 0f;
            TurnOff();
            SetAnimState();
        }
    
        private void SetAnimState()
        {
            if (fadeType == FadeType.fadeIn)
            {
                _animator.Play ("On", -1, transitionProgress);
            }
            else
            {
                _animator.Play ("Off", -1, 1f - transitionProgress);
            }
        }
    
        public void TurnOff()
        {
            fadeType = FadeType.fadeOut;
            isOff = true;
            transitionProgress = 0f;
            SetAnimState();
        }
    
        public void TurnOn()
        {
            fadeType = FadeType.fadeIn;
            isOff = false;
            transitionProgress = 1f;
            SetAnimState();
        }
    }
    

    The menu should slowly open and close over my animation clips ...

  • In Menu.cs, and in your code above, transitionProgress is used as to set the "normalized time" parameter in Unity's Animator.Play function.

    For a smooth transition, this value would have to be updated over time from 0 -> 1 and in reverse.

    You could do this by adding the following to your Update function:

    float transitionSpeed = 5f; // Change the speed with this
    transitionProgress = Mathf.MoveTowards (transitionProgress, isOff ? 0f : 1f, Time.deltaTime * transitionSpeed);
    

    For the scene-loading issue, don't comment out AC's ability to hide the canvas. Instead - if the Appear type is set to Manual - you can turn it off when the scene-loading process begins, and turn it back on afterwards. This best done with custom events:

    private void OnEnable ()
    {
        EventManager.OnBeforeChangeScene += OnBeforeChangeScene;
        EventManager.OnAfterChangeScene += OnAfterChangeScene;
    }
    
    private void OnDisable ()
    {
        EventManager.OnAfterChangeScene -= OnAfterChangeScene;
        EventManager.OnAfterChangeScene -= OnAfterChangeScene;
    }
    
    void OnBeforeChangeScene (string nextSceneName)
    {
        PlayerMenus.GetMenuWithName ("MyMenu").TurnOff (false);
    }
    
    private void OnAfterChangeScene (LoadingGame loadingGame)
    {
        PlayerMenus.GetMenuWithName ("MyMenu").TurnOn (false);
    }
    

    Custom events can also be used to turn the Menu on/off automatically at other times - for example, the OnMenuTurnOn event can be listened to so that the Menu is turned off when the "Pause" menu is turned on:

    private void OnEnable ()
    {
        EventManager.OnMenuTurnOn += OnMenuTurnOn;
    }
    
    private void OnDisable ()
    {
        EventManager.OnMenuTurnOn -= OnMenuTurnOn;
    }
    
    void OnMenuTurnOn (Menu menu, bool isInstant)
    {
        if (menu.title == "Pause")
            PlayerMenus.GetMenuWithName ("MyMenu").TurnOff (false);
    }
    

    For more details on working with Menus through script, see the Manual's "Menu scripting" chapter.

  • edited October 2022

    I did things for you just like you said. It works perfectly! Thank you so much!

    I haven't worked much with the EventManager in general, so maybe I should.

    Take care!

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.