Forum rules - please read before posting.

Unity UI Cursor Help

2

Comments

  • edited May 2022

    Assign it in the component we're talking about - not Unity UI Cursor.

  • edited May 2022
    Sorry which component needs to be assigned? I’m unsure. Where do I find the raw image?
  • edited May 2022

    Done it! My bad! Thanks. So from looking at my animator, how would I then have an animation for pulsing chosen interaction (ie Pick Up which is on left of main cursor)? Thanks

  • Would I still need to do this?

    Once the hotspot is clicked I would like for either the clicked interaction icon (use, examine etc) to pulse, and then the cursor to do the close animation.

    You can hook into the OnHotspotInteract event to update the Animator when a Hotspot interaction is run. Use Animator an transition with "Has Exit Time" to automatically play another animation once the "pulse" animation has ended.

    Can you explain more on how I would implement the Pulse on interaction click?

  • Your script will invoke a Trigger parameter in your Animator named "Interaction" when clicking on a Hotspot. Use this to transition to your pulse animation, optionally accounting for the "CursorID" parameter if you want to use different animations for Use, Examine etc.

  • edited May 2022

    Awesome, ok got thay working, my next question is how do I disable the hotspot until the interaction is complete? or another interaction is chosen? As the problem is that once the hotspot closes, it re-opens again as the cursor is in the hotspot area, any way you think that can rectify this?

    See video and animator screenshot

    https://www.dropbox.com/sh/fdq08f7z1wjl0ka/AAArS7pZkiFl4sHGGRq2Io-na?dl=0

  • Check "Cutscene while moving?" in your Hotspot interaction if you want to prevent interactions while the Player moves to a Hotspot.

    To have the cursor react to the game being in cutscene mode, create a new bool parameter named "IsInCutscene", and add this to the Update function:

    _animator.SetBool ("IsInCutscene", KickStarter.stateHandler.IsInCutscene ());
    

    You can then use that parameter to prevent the Hotspot icons from showing during cutscenes.

  • Ok, think I almost have it, problem is, as soon as the interaction choice is now chosen the cursor automatically closes and we now lose the pulse. Is there a way to let the pulse anim happen first and then the IsInCutscene parameter to apply?

  • That's down to how you make use of it in your Animator transitions.

  • Ok thanks, can you offer any clue? Here are screenshots of two versions that I have tried that both don't currently work. (Hotspot - Cutscene while moving is on)

    https://www.dropbox.com/sh/567075mc2lphc1b/AABvAtf3P0cP7WXQh1Zt5saua?dl=0

  • This is no longer an AC issue. If you want animation transitions to occur instantly, however, uncheck "Has Exit Time".

  • Hi, maybe so, but now I have added the line to my script:

    _animator.SetBool ("IsInCutscene", KickStarter.stateHandler.IsInCutscene ());

    and turned on "Cutscene while moving?" the cursor closes regardless of using the IsInCutscene parameter in my animator?

    See video:

    https://www.dropbox.com/s/xoo06ly4w527p2m/CursorClose.mov?dl=0

  • edited May 2022

    Are you able to offer any further help on this? Thanks Chris, I've tried all anim options i am aware of, I think the script my just close it regardless of my pulse anim?

    Also, when I’m cutscene I’d like the ‘cutscene’ cursor to show but after the chosen interaction has pulsed and cursor closed… it’s all quite complex!

    Thanks

  • Aside from displaying the inventory graphic when an item is selected, the script only affects Animator parameter values. How these are used are down to your Animator's transitions - AC is not involved.

    As all of your transitions stem from the "Any State" state, however, they will always trigger regardless of which animation is currently playing. If you want certain transitions to only occur while specific animations are playing, you must rely on transitions between those specific states rather than from "Any State".

  • Ok thanks Chris, am setting up animator without Any State set up, not getting there yet for what I want but I will persist, can you let me know which of these parameters I do not need based on my script and AC's set up?

    using UnityEngine.UI;
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using AC;
    
    public class CursorScript : MonoBehaviour
    {
        public Animator _animator;
        public string useIconIDParameter = "UseIconID";
        public string hasLookIconParameter = "HasLookIcon";
        public string speechParameter = "IsSpeaking";
        public string conversationParameter = "InConversation";
        public RawImage rawImageToControl;
    
    
        private void OnEnable ()
        {
            EventManager.OnStartSpeech_Alt += StartSpeech;
            EventManager.OnStopSpeech_Alt += StopSpeech;
            EventManager.OnStartConversation += StartConversation;
            EventManager.OnEndConversation += EndConversation;
            EventManager.OnClickConversation += ClickConversation;
            EventManager.OnHotspotInteract += OnHotspotInteract;
    
        }
    
        private void OnDisable ()
        {
            EventManager.OnStopSpeech_Alt -= StopSpeech;
            EventManager.OnStartSpeech_Alt -= StartSpeech;
            EventManager.OnStartConversation -= StartConversation;
            EventManager.OnEndConversation -= EndConversation;
            EventManager.OnClickConversation -= ClickConversation;
            EventManager.OnHotspotInteract -= OnHotspotInteract;
    
        }
    
        private void OnHotspotInteract (Hotspot hotspot, AC.Button button)
        {
            _animator.SetTrigger ("Interaction");
        }
    
    
        private void StartSpeech (Speech speech)
        {
            _animator.SetBool (speechParameter, true);
        }
    
        private void StopSpeech (Speech speech)
        {
            _animator.SetBool (speechParameter, false);
        }
    
        private void StartConversation (Conversation conversation)
        {
            _animator.SetBool (conversationParameter, true);
        }
    
        private void EndConversation (Conversation conversation)
        {
    
        }
    
        private void ClickConversation (Conversation conversation, int optionId)
        {
            _animator.SetBool (conversationParameter, false);
        }
    
        private void Update ()
        {
            bool hasLookIcon = false;
            int useIconID = -1;
    
            if (AC.KickStarter.stateHandler.IsInGameplay ())
            {
                AC.Hotspot hotspot = AC.KickStarter.playerInteraction.GetActiveHotspot ();
                if (hotspot)
                {
                    hasLookIcon = hotspot.HasContextLook ();
                    if (hotspot.HasContextUse ())
                    {
                        useIconID = hotspot.GetFirstUseButton ().iconID;
                    }
                }
            }
            int menuOverrideID = KickStarter.playerMenus.GetElementOverCursorID ();
            _animator.SetInteger ("MenuOverrideID", menuOverrideID);
            _animator.SetInteger (useIconIDParameter, useIconID);
            _animator.SetBool (hasLookIconParameter, hasLookIcon);
            _animator.SetInteger ("CursorID", KickStarter.playerCursor.GetSelectedCursorID ());
            _animator.SetInteger ("InvID", (KickStarter.runtimeInventory.SelectedItem != null) ? KickStarter.runtimeInventory.SelectedItem.id : -1);
            _animator.SetBool ("IsInCutscene", KickStarter.stateHandler.IsInCutscene ());
    
    
            if (rawImageToControl)
        {
            if (KickStarter.runtimeInventory.SelectedItem != null)
        {
            _animator.enabled = false;
            rawImageToControl.texture = KickStarter.runtimeInventory.SelectedItem.tex;
        }
            else
        {
            _animator.enabled = true;
        }
    }
    
    
        }
    }
    
  • Also Chris, how would I make my cursor holding an inventory object pulse on interaction? Thanks!

  • can you let me know which of these parameters I do not need based on my script and AC's set up?

    The script requires the presence of UseIconID, HasLookIcon, IsSpeaking, InConversation, Interaction, MenuOverrideID, CursorID, InvID, IsInCutscene parameters.

    how would I make my cursor holding an inventory object pulse on interaction?

    As in, an outline around the item graphic itself? You would need to rely on the InvID parameter I mentioned, and use animation to control the cursor while an item is selected - rather than disable the animator during this time.

  • edited May 2022
    It’s more that when the cursor is holding an inventory object and it is used on another hotspot, it pulses (changes in size).

    Do you think there is an easier way to do what I’m after? I’m terms of interaction, pulse, close
  • Can a UI cursor still draw from the spritesheet cursor animations in the cursor menu? if so I can just animate the raw image as the parameter cursorID call will pull in the animation? Thus reducing the amount of animations I need in my animator?
  • You can have a script hook into the OnSetHardwareCursor custom event to update your RawImage component with the cursor graphic assigned in the Cursor Manager - and will work with the animated cursor options.

    The provided Unity UI Cursor component uses this technique if you assign its "Raw Image To Control" field. Essentially, it's just a case of:

    private void OnSetHardwareCursor (Texture2D texture, Vector2 clickOffset)
    {
        if (rawImageToControl)
        {
            rawImageToControl.texture = texture;
            rawImageToControl.enabled = texture != null;
        }
    }
    

    When combining this with an Animator, you need to be careful not to have your Animator control the RawImage's texture at the same time - otherwise the two will conflict. If your Animator only affected the size of the RawImage object's RectTransform, you'd be fine.

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.