### GET request to ask documentation question Source: https://docs.twgamesdev.com/uhfps/llms.txt Performs an HTTP GET request on the documentation index with the ask parameter and optional goal parameter. The ask parameter is required and should be a specific, self-contained question in natural language. The goal parameter is optional and describes the broader end goal. ```http GET https://docs.twgamesdev.com/uhfps/getting-started.md?ask=&goal= ``` -------------------------------- ### UHFPSDialogueStarter.cs - Start dialogue on interaction Source: https://docs.twgamesdev.com/uhfps/integrations/meet-and-talk.md Add this component to an NPC with the Interact layer to start a dialogue when the player interacts. Assign the dialogue asset to the Dialogue Container field. ```csharp using UnityEngine; using MEET_AND_TALK; using UHFPS.Runtime; namespace UHFPS.Integrations.MeetAndTalk { public class UHFPSDialogueStarter : MonoBehaviour, IInteractStart { public DialogueContainerSO dialogueContainer; public void InteractStart() { DialogueManager.Instance.StartDialogue(dialogueContainer); } } } ``` -------------------------------- ### Custom Flashlight Editor Script Source: https://docs.twgamesdev.com/uhfps/guides/player-items.md An example of a custom inspector for a Flashlight item. Ensure this script is placed in an Editor folder to access necessary editor class references. ```csharp using UnityEngine; using UnityEditor; using ThunderWire.Editors; namespace UHFPS.Editors { [CustomEditor(typeof(Flashlight))] public class FlashlightEditor : PlayerItemEditor { public override void OnEnable() { // when overriding OnEnable(), do not remove the base.OnEnable() base.OnEnable(); } public override void OnInspectorGUI() { EditorDrawing.DrawInspectorHeader(new GUIContent("Flashlight"), Target); EditorGUILayout.Space(); serializedObject.Update(); { base.OnInspectorGUI(); // this will draw settings dropdown EditorGUILayout.Space(); Properties.Draw("k__BackingField"); Properties.Draw("BatteryItem"); } serializedObject.ApplyModifiedProperties(); } } } ``` -------------------------------- ### Override OnBuildOptionRuntime() to populate dynamic options Source: https://docs.twgamesdev.com/uhfps/guides/options-manager.md Override this method to populate option states dynamically at runtime. This example fills the options with available screen resolutions from Options.Resolutions, converting them to GString values and passing them to Behaviour.SetOptionData. ```csharp public override void OnBuildOptionRuntime() { string[] resolutions = Options.Resolutions.Select(x => $"{x.width}x{x.height}").ToArray(); GString[] gStrings = resolutions.Select(x => new GString($"{x}")).ToArray(); Behaviour.SetOptionData(new StorableCollection() { { "options", gStrings } }); } ``` -------------------------------- ### Filtering Selected Items by GUID Source: https://docs.twgamesdev.com/uhfps/guides/inventory.md Demonstrates how to validate if a selected item matches a specific required item using ItemProperty or ItemGuid. ```csharp using UnityEngine; using UHFPS.Runtime; public class InventorySelector : MonoBehaviour, IInteractStart, IInventorySelector { public ItemProperty RequiredItem; // public ItemGuid RequiredItem; public void InteractStart() { Inventory.Instance.OpenItemSelector(this); } public void OnInventoryItemSelect(Inventory inventory, InventoryItem selectedItem) { if (selectedItem.ItemGuid != RequiredItem) return; // do something } } ``` -------------------------------- ### Override OnLoadOption(bool fromFile) to load settings Source: https://docs.twgamesdev.com/uhfps/guides/options-manager.md Override this method to load the option setting at Start. Use the fromFile parameter to determine if data comes from saved settings; if so, call CheckOption with the expected JTokenType (here Boolean) to retrieve the value. Assign the final value back to Behaviour so the UI reflects the loaded or default value. ```csharp public override void OnLoadOption(bool fromFile) { bool optionValue = DefaultValue; if (fromFile && CheckOption(JTokenType.Boolean, out bool value)) optionValue = value; // do something after loading the value // e.g. apply loaded setting Behaviour.SetOptionValue(optionValue); } ``` -------------------------------- ### Create a player item script deriving from PlayerItemBehaviour Source: https://docs.twgamesdev.com/uhfps/guides/player-items.md Derive from PlayerItemBehaviour and implement the four required overrides: OnItemSelect, OnItemDeselect, OnItemActivate, and OnItemDeactivate. The example includes a public ItemGuid field for a battery item. Use this as the base for any new player item script. ```csharp using UnityEngine; using UHFPS.Runtime; public class Flashlight : PlayerItemBehaviour { public ItemGuid BatteryItem; public override void OnItemSelect() { // do something when the item is selected } public override void OnItemDeselect() { // do something when the item is deselected } public override void OnItemActivate() { // do something when the item is activated } public override void OnItemDeactivate() { // do something when the item is deactivated } } ``` -------------------------------- ### ObserveOption method example Source: https://docs.twgamesdev.com/uhfps/guides/options-manager.md Use this code to observe an option value directly within a MonoBehaviour. The callback receives the option value as an object, which must be cast to the expected type (e.g., bool). ```csharp using UnityEngine; namespace UHFPS.Runtime { public class TestObserver : MonoBehaviour { public bool BoolValue; private void Start() { OptionsManager.ObserveOption("some_option", (value) => BoolValue = (bool)value); } } } ``` -------------------------------- ### TestPuzzle script deriving from PuzzleBase Source: https://docs.twgamesdev.com/uhfps/guides/puzzles.md Example puzzle script that derives from PuzzleBase. Use PuzzleBase for complex puzzles that change the camera, or PuzzleBaseSimple for simple puzzles that only disable interaction. ```csharp using UHFPS.Runtime; // derive from PuzzleBase or PuzzleBaseSimple public class TestPuzzle : PuzzleBase { public string TestString; public float TestFloat; } ``` -------------------------------- ### Get Flashlight UI References via GraphicReferences Source: https://docs.twgamesdev.com/uhfps/guides/game-manager.md Accesses custom UI references by name using the GraphicReferences field. The return value is an array, so references are accessed by index. ```csharp private void Awake() { GameManager gameManager = GameManager.Instance; var behaviours = gameManager.GraphicReferences.Value["Flashlight"]; CanvasGroup flashlightPanel = (CanvasGroup)behaviours[0]; Image batteryIcon = (Image)behaviours[1]; Image batteryFill = (Image)behaviours[2]; } ``` -------------------------------- ### Implementing Inventory Item Selector Source: https://docs.twgamesdev.com/uhfps/guides/inventory.md Shows how to implement the IInventorySelector interface to open the item selector and handle item selection events. ```csharp using UnityEngine; using UHFPS.Runtime; public class InventorySelector : MonoBehaviour, IInteractStart, IInventorySelector { public void InteractStart() { // open inventory selection Inventory.Instance.OpenItemSelector(this); } public void OnInventoryItemSelect(Inventory inventory, InventoryItem selectedItem) { var itemData = selectedItem.CustomData; var json = itemData.GetJson(); Debug.Log(json["name"].ToString()); } } ``` -------------------------------- ### Retrieve a Module Reference with GameManager.Module() Source: https://docs.twgamesdev.com/uhfps/guides/game-manager.md Gets a reference to a manager module using the generic Module method from the GameManager component. ```csharp private void Awake() { TestModule testModule = GameManager.Module(); } ``` -------------------------------- ### Create a Spring Motion Module Source: https://docs.twgamesdev.com/uhfps/guides/motion-controller.md This script demonstrates how to create a custom spring-like motion module by inheriting from SpringMotionModule and implementing the MotionUpdate method. ```csharp using UnityEngine; namespace UHFPS.Runtime { public class TestMotion : SpringMotionModule { public override string Name => "General/Test Motion"; public override void MotionUpdate(float deltaTime) { Vector3 position = Vector3.zero; Vector3 rotation = Vector3.zero; SetTargetPosition(position); // set position motion SetTargetRotation(rotation); // set rotation motion } } } ``` -------------------------------- ### Subscribe to localization changes with SubscribeGloc() Source: https://docs.twgamesdev.com/uhfps/guides/localization.md Subscribes to localization changes by calling SubscribeGloc() in the Start method. This is required to listen for localization or input changes. ```csharp using UnityEngine; using UHFPS.Runtime; public class Example : MonoBehaviour { public GString SomeText; private void Start() { SomeText.SubscribeGloc(); } } ``` -------------------------------- ### Define NoInteract property with CanInteract field Source: https://docs.twgamesdev.com/uhfps/guides/interactions.md Define whether the interaction should be performed by setting NoInteract to false or true. This example uses a new field CanInteract to control the interaction state. ```csharp public bool CanInteract = true; public bool NoInteract => !CanInteract; ``` -------------------------------- ### Override OnApplyOption() to apply settings Source: https://docs.twgamesdev.com/uhfps/guides/options-manager.md Override this method to define what happens when the user confirms settings in the UI. Use the Value parameter (type depends on the Option Behaviour, e.g. OptionsRadio returns an integer) and Behaviour.IsChanged to detect changes. Store the converted value in SerializableData using the option's Name as the key. ```csharp public override void OnApplyOption() { int value = (int)Value; bool converted = value != 0; if (Behaviour.IsChanged) { // do something when the setting changes // e.g. apply the setting } // store the value in SerializableData, which is then serialized into the config file. Options.SerializableData[Name] = new(converted); } ``` -------------------------------- ### Complete test force module Source: https://docs.twgamesdev.com/uhfps/guides/motion-controller/external-motions.md Full implementation of the TestExternalMotion class with the TestForce module assigned to both GetPosition and GetRotation properties. ```csharp using System; using UnityEngine; namespace UHFPS.Runtime { [Serializable] public class TestExternalMotion : ExternalMotionData { [Serializable] public struct TestSettings { public Vector3 Force; public float Duration; } public TestSettings PositionSettings; public TestSettings RotationSettings; public override string Name => "Test Motion"; public override ExternalMotionModule GetPosition => new TestForce(PositionSettings); public override ExternalMotionModule GetRotation => new TestForce(RotationSettings); public sealed class TestForce : ExternalMotionModule { public override bool IsFinished => Time.time > endTime; private readonly Vector3 force; private readonly float endTime; public TestForce(TestSettings settings) { force = settings.Force; endTime = Time.time + settings.Duration; } public override Vector3 Evaluate() { return force; } } } } ``` -------------------------------- ### Add settings structure to ExternalMotionData Source: https://docs.twgamesdev.com/uhfps/guides/motion-controller/external-motions.md Extends the previous class with a TestSettings struct containing Force and Duration, and fields for position and rotation settings. ```csharp using System; using UnityEngine; namespace UHFPS.Runtime { [Serializable] public class TestExternalMotion : ExternalMotionData { [Serializable] public struct TestSettings { public Vector3 Force; public float Duration; } public TestSettings PositionSettings; public TestSettings RotationSettings; public override string Name => "Test Motion"; public override ExternalMotionModule GetPosition => null; public override ExternalMotionModule GetRotation => null; } } ``` -------------------------------- ### Complete TestTimedInteract script implementing IInteractTimed Source: https://docs.twgamesdev.com/uhfps/guides/interactions.md Full example of a custom script implementing IInteractTimed, including the required SerializeField attribute and the NoInteract property. The InteractTimed method is left empty for custom logic. ```csharp using UnityEngine; using UHFPS.Runtime; public class TestTimedInteract : MonoBehaviour, IInteractTimed { [field: SerializeField] public float InteractTime { get; set; } public bool CanInteract = true; public bool NoInteract => !CanInteract; public void InteractTimed() { // do something } } ``` -------------------------------- ### Accessing Custom Inventory Item Data Source: https://docs.twgamesdev.com/uhfps/guides/inventory.md Demonstrates how to retrieve an InventoryItem reference and access its custom data using both JObject and the GetValue method. ```csharp using UHFPS.Runtime; using UnityEngine; public class InventoryTest : MonoBehaviour { public ItemGuid Item; private void Start() { // get reference to the InventoryItem Inventory inventory = Inventory.Instance; var inventoryItem = inventory.GetInventoryItem(Item); var itemData = inventoryItem.CustomData; // get custom data using JObject var json = itemData.GetJson(); string name1 = json["name"].ToString(); int age1 = (int)json["age"]; // get custom data using GetValue string name2 = itemData.GetValue("age"); int age2 = itemData.GetValue("age"); } } ``` -------------------------------- ### CustomOptionObservers custom observer type example Source: https://docs.twgamesdev.com/uhfps/guides/options-manager.md Define a custom OptionObserverType to handle options that don't belong to a script, such as setting AudioListener.volume. The Name property must match the option name in the Options Builder. ```csharp using System; using UnityEngine; namespace UHFPS.Runtime { [Serializable] public class OptionListenerVolume : OptionObserverType { public override string Name => "Audio Listener Volume"; public override void OptionUpdate(object value) { if (value == null) return; AudioListener.volume = (float)value; } } } ``` -------------------------------- ### Create a Custom Manager Module Source: https://docs.twgamesdev.com/uhfps/guides/game-manager.md Defines a new manager module by inheriting from ManagerModule. The class is based on ScriptableObject, so it cannot contain variables with scene references. Override OnAwake, OnStart, and OnUpdate to add custom logic. ```csharp namespace UHFPS.Runtime { public class TestModule : ManagerModule { public override void OnAwake() { } public override void OnStart() { } public override void OnUpdate() { } } } ``` -------------------------------- ### Instantiate a saveable object with SaveGameManager.InstantiateSaveable Source: https://docs.twgamesdev.com/uhfps/guides/save-load-manager.md Use this snippet to instantiate a saveable object at runtime. The SaveGameManager.InstantiateSaveable method automatically locates saveables within the object and adds them to the runtime saveables. The ObjectReference field specifies which object reference to instantiate, providing the GUID instead of a direct GameObject reference. ```csharp using UnityEngine; using UHFPS.Runtime; public class RuntimeSaveableTest : MonoBehaviour { public ObjectReference ObjectReference; private void Start() { GameObject obj = SaveGameManager.InstantiateSaveable(ObjectReference, Vector3.zero, Vector3.zero); // do something with instantiated game object } } ``` -------------------------------- ### C# methods for Dialogue Binder events Source: https://docs.twgamesdev.com/uhfps/guides/narration-system.md These methods should be added to a script attached to the same object as the Dialogue Binder. They handle the events triggered by the Dialogue System: OnDialogueStart (check binderName to activate the speech bubble), OnSubtitle (set text), OnSubtitleFinish (clear text between subtitles), and OnDialogueEnd (hide and reset). The isPlaying flag is used to filter events for the correct binder. ```csharp // will be called when the dialogue starts public void OnDialogueStart(AudioSource _, string binderName) { if(isPlaying = binderName == BinderName) TextMesh.gameObject.SetActive(true); } // will be called at every subtitle public void OnSubtitle(AudioClip _, string subtitleText) { if (!isPlaying) return; TextMesh.text = subtitleText; } // will be called at the end of the subtitle sequence public void OnSubtitleFinish() { if (!isPlaying || !HideBetweenSubtitles) return; TextMesh.text = ""; } // will be called when the dialogue ends public void OnDialogueEnd() { if (!isPlaying) return; TextMesh.gameObject.SetActive(false); TextMesh.text = ""; isPlaying = false; } ```