K3
                
              
                
                
              
                  
                  
              1
              
             
            
              Original Discord Post by or_rmo | 2024-08-08 06:57:37
As you advised, I tried to apply HandleVoiceInput to a button using eventtrigger.
However, an error occurs.
I changed HandleVoiceInput to public in the player interaction manager and called it.
Please help me,
Images:
             
            
              
              
              
            
            
           
          
            
              
                K3
                
              
              
                  
                  
              2
              
             
            
              Reply by k3kalinix | 2024-08-08 08:03:42
Hello <@684027455433998381> 
             
            
              
              
              
            
            
           
          
            
              
                K3
                
              
              
                  
                  
              3
              
             
            
              Reply by k3kalinix | 2024-08-08 08:03:59
Is the Npc active?
             
            
              
              
              
            
            
           
          
            
              
                K3
                
              
              
                  
                  
              4
              
             
            
              Reply by or_rmo | 2024-08-08 08:07:40
Yes, it is activated.
             
            
              
              
              
            
            
           
          
            
              
                K3
                
              
                
              
                  
                  
              5
              
             
            
              Reply by or_rmo | 2024-08-08 08:08:48
Images:
             
            
              
              
              
            
            
           
          
            
              
                K3
                
              
              
                  
                  
              6
              
             
            
              Reply by k3kalinix | 2024-08-08 08:09:25
Why don’t you use our mobile talk button?
             
            
              
              
              
            
            
           
          
            
              
                K3
                
              
              
                  
                  
              7
              
             
            
              Reply by or_rmo | 2024-08-08 08:10:35
There is no mobile call button because it is webgl,
             
            
              
              
              
            
            
           
          
            
              
                K3
                
              
              
                  
                  
              8
              
             
            
              Reply by k3kalinix | 2024-08-08 08:12:39
You added a new interaction  manager.
             
            
              
              
              
            
            
           
          
            
              
                K3
                
              
              
                  
                  
              9
              
             
            
              Reply by k3kalinix | 2024-08-08 08:13:02
You have to create a new script.
             
            
              
              
              
            
            
           
          
            
              
                K3
                
              
              
                  
                  
              10
              
             
            
              Reply by or_rmo | 2024-08-08 08:19:45
Are you saying that I need to write a script that activates the microphone and inputs text when the button is pressed?
             
            
              
              
              
            
            
           
          
            
              
                K3
                
              
              
                  
                  
              11
              
             
            
              Reply by or_rmo | 2024-08-08 08:22:54
Do you have an example??
             
            
              
              
              
            
            
           
          
            
              
                K3
                
              
              
                  
                  
              12
              
             
            
              Reply by k3kalinix | 2024-08-08 08:23:34
using Convai.Scripts.Runtime.Core;
using Convai.Scripts.Runtime.LoggerSystem;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace Convai.Scripts.Runtime.UI
{
    public class ConvaiTalkButtonHandler : Button
    {
        private const float NORMAL_ALPHA = 1f; // The alpha when button is not pressed
        private const float PRESSED_ALPHA = 0.5f; // The alpha when button is pressed
        private ConvaiNPC _currentActiveNPC;
        private bool _subscribed;
        protected override void Start()
        {
            base.Start();
            if (ConvaiNPCManager.Instance != null)
            {
                ConvaiNPCManager.Instance.OnActiveNPCChanged += OnActiveNPCChangedHandler;
                ConvaiLogger.Info("Listening to OnActiveNPCChanged event.", ConvaiLogger.LogCategory.Character);
            }
            else
            {
                ConvaiLogger.Warn("Instance of ConvaiNPCManager is not yet initialized.", ConvaiLogger.LogCategory.Character);
            }
        }
        protected override void OnEnable()
        {
            // Check if NPC Manager instance is available before subscribing
            ConvaiNPCManager npcManager = ConvaiNPCManager.Instance;
            if (npcManager != null)
            {
                npcManager.OnActiveNPCChanged += OnActiveNPCChangedHandler;
                _currentActiveNPC = npcManager.GetActiveConvaiNPC();
                if (!_subscribed)
                {
                    _subscribed = true;
                    ConvaiLogger.Info("Subscribed to OnActiveNPCChanged event.", ConvaiLogger.LogCategory.Character);
                }
            }
            else
            {
                ConvaiLogger.Warn("NPC Manager instance is not available during enabling.", ConvaiLogger.LogCategory.Character);
            }
        }
        protected override void OnDisable()
        {
            // Always make sure to unsubscribe from events when the object is disabled
            ConvaiNPCManager npcManager = ConvaiNPCManager.Instance;
            if (npcManager != null)
            {
                npcManager.OnActiveNPCChanged -= OnActiveNPCChangedHandler;
                if (_subscribed)
                {
                    _subscribed = false;
                    ConvaiLogger.Info("Unsubscribed from OnActiveNPCChanged event.", ConvaiLogger.LogCategory.Character);
                }
            }
        }
        protected override void OnDestroy()
        {
            if (ConvaiNPCManager.Instance != null)
            {
                ConvaiNPCManager.Instance.OnActiveNPCChanged -= OnActiveNPCChangedHandler;
                ConvaiLogger.Info("Stopped listening to OnActiveNPCChanged event.", ConvaiLogger.LogCategory.Character);
            }
        }
        private void OnActiveNPCChangedHandler(ConvaiNPC newActiveNPC)
        {
            _currentActiveNPC = newActiveNPC;
            if (_currentActiveNPC != null)
                ConvaiLogger.Info($"Active NPC has changed to: {_currentActiveNPC.name}", ConvaiLogger.LogCategory.Character);
        }
             
            
              
              
              
            
            
           
          
            
              
                K3
                
              
              
                  
                  
              13
              
             
            
              Reply by k3kalinix | 2024-08-08 08:23:37
public override void OnPointerDown(PointerEventData eventData)
        {
            base.OnPointerDown(eventData);
            ColorBlock colorBlock = colors;
            colorBlock.normalColor = new Color(colorBlock.normalColor.r, colorBlock.normalColor.g,
                colorBlock.normalColor.b,
                PRESSED_ALPHA);
            colors = colorBlock;
            if (_currentActiveNPC != null)
            {
                // _grpcAPI.InterruptCharacterSpeech();
                _currentActiveNPC.playerInteractionManager.UpdateActionConfig();
                _currentActiveNPC.StartListening();
                IncreaseScale();
                ConvaiLogger.DebugLog($"{gameObject.name} Was Clicked.", ConvaiLogger.LogCategory.Character);
            }
            else
            {
                ConvaiLogger.Warn("No active NPC found when button was pressed.", ConvaiLogger.LogCategory.Character);
            }
        }
        public override void OnPointerUp(PointerEventData eventData)
        {
            base.OnPointerUp(eventData);
            ColorBlock colorBlock = colors;
            colorBlock.normalColor =
                new Color(colorBlock.normalColor.r, colorBlock.normalColor.g, colorBlock.normalColor.b, NORMAL_ALPHA);
            colors = colorBlock;
            if (_currentActiveNPC != null)
            {
                _currentActiveNPC.StopListening();
                DecreaseScale();
                ConvaiLogger.DebugLog($"{gameObject.name} Was Released.", ConvaiLogger.LogCategory.Character);
            }
            else
            {
                ConvaiLogger.Warn("No active NPC found when button was released.", ConvaiLogger.LogCategory.Character);
            }
        }
        private void IncreaseScale()
        {
            Vector3 targetScale = new(1.25f, 1.25f, 1.25f);
            transform.localScale = Vector3.Lerp(transform.localScale, targetScale, 1f);
        }
        private void DecreaseScale()
        {
            Vector3 targetScale = new(1, 1, 1);
            transform.localScale = Vector3.Lerp(transform.localScale, targetScale, 1f);
        }
    }
}
             
            
              
              
              
            
            
           
          
            
              
                K3
                
              
                
              
                  
                  
              14
              
             
            
              Reply by or_rmo | 2024-08-08 08:45:35
An error occurs saying that the definition is not included.
Images:
             
            
              
              
              
            
            
           
          
            
              
                K3
                
              
                
              
                  
                  
              15
              
             
            
              Reply by or_rmo | 2024-08-08 09:52:39
Images:
             
            
              
              
              
            
            
           
          
            
              
                K3
                
              
              
                  
                  
              16
              
             
            
              Reply by k3kalinix | 2024-08-08 09:52:48
This is from core sdk
             
            
              
              
              
            
            
           
          
            
              
                K3
                
              
              
                  
                  
              17
              
             
            
              Reply by k3kalinix | 2024-08-08 09:52:56
So you have to remove this line
             
            
              
              
              
            
            
           
          
            
              
                K3
                
              
              
                  
                  
              18
              
             
            
              Reply by or_rmo | 2024-08-08 09:53:57
I removed this line and ran it, and it worked. Thank you!!
             
            
              
              
              
            
            
           
          
            
              
                K3
                
              
              
                  
                  
              19
              
             
            
              Reply by k3kalinix | 2024-08-08 09:54:04
Amazing!
             
            
              
              
              
            
            
           
          
            
              
                K3
                
              
              
                  
                  
              20
              
             
            
              Reply by or_rmo | 2024-08-08 09:54:38
Thank you so much!