/* * Copyright (c) Meta Platforms, Inc. and affiliates. * All rights reserved. * * This source code is licensed under the license found in the * LICENSE file in the root directory of this source tree. */ using Meta.WitAi.Attributes; using UnityEngine; using Utilities; namespace Meta.WitAi.Utilities { [AddComponentMenu("Wit.ai/Utilities/Conversions/String to String")] public class StringToStringEvent : MonoBehaviour { [Tooltip("The string format string that will be used to reformat input strings. Ex: I don't know how to respond to {0}")] [SerializeField] private string _format; [Space(WitRuntimeStyles.HeaderPaddingTop)] [TooltipBox("Triggered when FormatString(float) is called. The string in this event will be formatted based on the format field.")] [SerializeField] public StringEvent onStringEvent = new StringEvent(); /// /// Trigger an onStringEvent with a provided format. /// /// The string format to use in the event /// The value that will get populated in {0} in the format string. public void FormatString(string format, string value) { if (string.IsNullOrEmpty(format)) { onStringEvent?.Invoke(value); } else { onStringEvent?.Invoke(string.Format(format, value)); } } /// /// Trigger an onStringEvent with the built in format value /// /// The text to insert into {0} in the format value. public void FormatString(string value) { FormatString(_format, value); } } }