Forum rules - please read before posting.

Active graphic vs Cursor (optional) graphic

One of my items has a four-frame graphic assigned to "cursor (optional)", and under "additional settings" I have "always animate?" checked. The main graphic is empty, but I use this script to animate the icon in the inventory as well. Here's the relevant snippet:

    void Update()
    {
        // This is to animate the lantern icon in the inventory
       if (AC.KickStarter.runtimeInventory.IsCarryingItem(1))
        {

            IconAnimated = AC.KickStarter.runtimeInventory.GetItem(1).cursorIcon.GetAnimatedTexture(true);

            if (IconMain != IconAnimated)
            {
                AC.KickStarter.runtimeInventory.GetItem(1).tex = IconAnimated;
                IconMain = IconAnimated;

            }

        }  
    }

Now I've just assigned a graphic to "active graphic" as well, hoping that when I hover the selected item over a hotspot or an inventory item with an interaction, the active graphic will be displayed. If the active graphic could be animated, that would be cool, but I'm not too fussed - the main issue I'm having here is that it never switches from "cursor (optional)" to "active graphic" at all. Is this intended?

Comments

  • If a dedicated cursor graphic is assigned, then that will be shown at all times.

    If this cursor graphic is animated, however, you can have it play the animation as part of the "active" FX - while only playing the first frame otherwise. This can be done by unchecking Always animate? in its animation properties.

    If you wanted to have two animations - i.e. one when normal, another when "active", you'd need to replace the texture of cursorIcon itself.

    AC.KickStarter.runtimeInventory.GetItem(1).cursorIcon.ReplaceTexture (myNewTexture);
    
  • Thanks! Yeah, I wanted to either have two animations, or only one animation but the other way around (i.e. animated when inactive, not animated when active). I think I understand how replacing the texture works, but I'm having a hard time figuring out how to check whether the state is active or not so I can replace the texture at the appropriate moment.

  • Something that I've noticed too is that after I run AC.KickStarter.runtimeInventory.GetItem(1).cursorIcon.ReplaceTexture (myNewTexture);, my script above stops updating the main graphic with the current animated frame pulled from "cursor (optional)", and instead it pulls the entire "cursor (optional)" texture. So even if I could check for the active state, the texture replacement part wouldn't work correctly.

    Just so it's easier to understand what I'm trying to achieve: I have a flask item filled with fireflies. I'm trying to get the fireflies to bounce around the flask at all times (both when the item is in the inventory and when it's selected as a cursor). I also want to highlight the flask when it is placed over a hotspot or item it can be combined with.

  • edited June 2023

    I'm having a hard time figuring out how to check whether the state is active or not so I can replace the texture at the appropriate moment.

    If you want to check if a Hotspot is currently active:

    if (KickStarter.playerInteraction.GetActiveHotspot ())
    

    You can also read this function's return value to check properties of this Hotspot, if necessary.

    the texture replacement part wouldn't work correctly.

    Should the item in the Inventory remain animated even when the cursor is changed to the "active" mode?

    If so, you're probably better off copying the icon completely so that it uses a separate icon that's unaffected by further changes.

    Something like:

    CursorIcon originalIcon = new CursorIcon ();
    
    void Start ()
    {
        originalIcon.Copy (KickStarter.inventoryManager.GetItem (1).cursorIcon);
    }
    
    // And then in update:
    // IconAnimated = originalIcon.GetAnimatedTexture(true);
    
  • edited June 2023

    I think I got closer, but still not quite there:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using AC;
    
    public class AnimatedIcon : MonoBehaviour
    {
    
        public Texture lanternTexture;
        public Texture lanternActiveTexture;
    
        private Texture IconAnimatedFrame;
        private CursorIcon originalIcon = new CursorIcon();
    
    
        private void Start()
        {
            originalIcon.Copy(KickStarter.inventoryManager.GetItem(1).cursorIcon);
            originalIcon.ReplaceTexture(lanternTexture);
        }
    
        void Update()
        {
    
            // This is to animate the lantern icon in the inventory and change the animation to a highlighted one when active
    
            if (AC.KickStarter.runtimeInventory.IsCarryingItem(1))
            {
    
                // Animate the unselected item in the inventory. It should only be animated with the regular texture.
                IconAnimatedFrame = originalIcon.GetAnimatedTexture(true);
                AC.KickStarter.runtimeInventory.GetItem(1).tex = IconAnimatedFrame;
    
                // Animate the cursor when the item is selected. Check whether the interaction is active.
                if (KickStarter.playerInteraction.GetActiveHotspot() != null && KickStarter.runtimeInventory.SelectedItem.id == 1)
                {
                   // Use the highlighted animation texture when the interaction is active.
                    AC.KickStarter.runtimeInventory.GetItem(1).cursorIcon.ReplaceTexture(lanternActiveTexture);
                }
                else
                {
                    //Use the regular animation texture when the interaction is not active.
                    AC.KickStarter.runtimeInventory.GetItem(1).cursorIcon.ReplaceTexture(lanternTexture);                
                }             
    
            }
        }
    }
    

    There are two issues here:

    (1) KickStarter.playerInteraction.GetActiveHotspot() only returns interactions with hotspots, not combine interactions between items, so this will return null when you hover one item over the other, even if they can be combined.

    (2) AC.KickStarter.runtimeInventory.GetItem(1).cursorIcon.ReplaceTexture(lanternActiveTexture); kind of works - the texture will change correctly in the inventory manager! But this is not actually reflected in the game. The regular texture is displayed.

  • Ok, an alternate solution that ALMOST works! This is what I did:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using AC;
    
    public class AnimatedIcon : MonoBehaviour
    {    
        public Texture lanternTexture;
        public Texture lanternActiveTexture;    
    
        private CursorIcon originalIcon = new CursorIcon();
        private CursorIcon animatedIcon = new CursorIcon();
    
        void Start()
        {
            originalIcon.Copy(KickStarter.inventoryManager.GetItem(19).cursorIcon);
            animatedIcon.Copy(KickStarter.inventoryManager.GetItem(19).cursorIcon);
            originalIcon.ReplaceTexture(lanternTexture);
            animatedIcon.ReplaceTexture(lanternActiveTexture);
        }
    
        void Update()
        {
    
            AC.KickStarter.runtimeInventory.GetItem(1).tex = originalIcon.GetAnimatedTexture(true);
            AC.KickStarter.runtimeInventory.GetItem(1).activeTex = animatedIcon.GetAnimatedTexture(true);
        }
    
    }
    

    (1) Create a dummy item, add the texture with multiple frames to its "cursor (optional)" field, and configure all the animation settings you want. In this case, my dummy item's ID is 19, and the real item is 1.

    (2) For item 1 (the real item to be used), add a main graphic and active graphic texture. They will be replaced at runtime, but it's important that they are assigned.

    (3) Run the game. It works as intended!

    The one problem I'm running into is that when I exit Play Mode, the manager's main graphic and active graphic will revert back to unassigned. You'd think this wouldn't be a problem because the script above assigns them at runtime, but for some reason, AC will only use the active graphic if there was already one assigned there before you click Play.

  • edited June 2023

    If anyone's interested, I've managed to make this work with this adaptation:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using AC;
    
    public class AnimatedIcon : MonoBehaviour
    {    
        public Texture lanternTexture;
        public Texture lanternActiveTexture;    
    
        private CursorIcon originalIcon = new CursorIcon();
        private CursorIcon activeIcon= new CursorIcon();
    
        void Start()
        {
            originalIcon.Copy(KickStarter.inventoryManager.GetItem(19).cursorIcon);
            activeIcon.Copy(KickStarter.inventoryManager.GetItem(19).cursorIcon);
            originalIcon.ReplaceTexture(lanternTexture);
            activeIcon.ReplaceTexture(lanternActiveTexture);
        }
    
        void Update()
        {
    
            if (AC.KickStarter.runtimeInventory.SelectedItem != null)
            {
                if (AC.KickStarter.runtimeInventory.SelectedItem.id == 1)
                {
                    AC.KickStarter.runtimeInventory.SelectedInstance.ActiveTex = activeIcon.GetAnimatedTexture(true);
                }
            }
    
            AC.KickStarter.inventoryManager.GetItem(1).tex = originalIcon.GetAnimatedTexture(true);
    
        }
    
    }
    

    Basically, by updating the item's tex in the inventory manager, the main graphic will animate in all inventories and containers. And I solved the ActiveTex issue I described above by updating only the selected instance's active texture. This means that the active texture in the manager won't be changed to none upon exiting Play Mode, which was what was breaking my previous solution.

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.