### Wait for Model Setup with Progress Callback in C# Source: https://github.com/bbkuan/my-mate-engine/blob/main/Assets/LLMUnity/README.md Demonstrates how to wait for the LLM model setup while also receiving progress updates. This allows for displaying download progress to the user, enhancing the user experience during model loading. ```csharp await LLM.WaitUntilModelSetup(SetProgress); void SetProgress(float progress){ string progressPercent = ((int)(progress * 100)).ToString() + "% flexibility"; Debug.Log($"Download progress: {progressPercent}"); } ``` -------------------------------- ### Set Up Pre-commit Hooks Source: https://github.com/bbkuan/my-mate-engine/blob/main/Assets/LLMUnity/CONTRIBUTING.md Installs pre-commit hooks for the LLMUnity project by executing a setup script. This helps ensure code quality before commits. ```shell sh ./.github/setup.sh ``` -------------------------------- ### Wait for Model Setup on Mobile in C# Source: https://github.com/bbkuan/my-mate-engine/blob/main/Assets/LLMUnity/README.md Illustrates how to wait for the LLM model to be fully set up, particularly relevant for mobile applications where models might be downloaded on the first launch. This ensures the model is ready before interaction. ```csharp await LLM.WaitUntilModelSetup(); ``` -------------------------------- ### Pure Text Completion in C# Source: https://github.com/bbkuan/my-mate-engine/blob/main/Assets/LLMUnity/README.md Provides an example of using the `Complete` method for pure text completion. This method takes a message and callback functions for handling the reply and completion. ```csharp void Game(){ // your game function ... string message = "The cat is away"; _ = llmCharacter.Complete(message, HandleReply, ReplyCompleted); ... } ``` -------------------------------- ### Unity C# Mod System Setup with MEReceiver Source: https://context7.com/bbkuan/my-mate-engine/llms.txt This script sets up the MEReceiver and MEReplacer in Unity to dynamically inject custom animator controllers and MonoBehaviour components into VRM models at runtime. It requires the Unity Engine namespace and System.Collections.Generic. It takes default and custom VRM models as input and configures replacement entries for animators and custom scripts. ```csharp using UnityEngine; using System.Collections.Generic; // Setup receiver on the avatar parent public class ModSystemSetup : MonoBehaviour { public GameObject defaultVRMModel; public GameObject customVRMModel; void Start() { // Create receiver on Model parent GameObject modelParent = new GameObject("Model"); var receiver = modelParent.AddComponent(); receiver.VRMModel = defaultVRMModel; receiver.CustomVRM = customVRMModel; // Create mod replacer GameObject modObject = new GameObject("CustomAnimMod"); var replacer = modObject.AddComponent(); // Setup source object with custom animator controller GameObject sourceObject = new GameObject("AnimationSource"); var sourceAnimator = sourceObject.AddComponent(); sourceAnimator.runtimeAnimatorController = Resources.Load("Custom/MyAnimController"); // Add custom component to override var customScript = sourceObject.AddComponent(); customScript.speed = 2.5f; customScript.enabled = true; // Configure replacement replacer.replacements = new List { new MEReplacer.ReplacementEntry { sourceObject = sourceObject } }; Debug.Log("Mod system configured"); Debug.Log("When VRM loads, it will receive:"); Debug.Log("- Custom animator controller"); Debug.Log("- CustomBehavior component with speed=2.5"); } } public class CustomBehavior : MonoBehaviour { public float speed = 1.0f; public string customText = "Modified"; void Update() { transform.Rotate(Vector3.up, speed * Time.deltaTime); } } // Runtime behavior: // 1. MEReplacer detects when receiver.VRMModel or receiver.CustomVRM changes // 2. Copies RuntimeAnimatorController from source to target // 3. For each MonoBehaviour on source: // - Finds or adds same component type on target // - Copies all serialized fields/properties // - Skips null/empty/default values // 4. Disables source components // 5. Hides source GameObject ``` -------------------------------- ### Save and Load RAG State Source: https://github.com/bbkuan/my-mate-engine/blob/main/Assets/LLMUnity/README.md Provides code examples for saving the current state of the RAG system to a file and subsequently loading it back. This is useful for persistence and avoiding re-computation of embeddings. ```csharp rag.Save("rag.zip"); await rag.Load("rag.zip"); ``` -------------------------------- ### Radial Menu System Setup Source: https://context7.com/bbkuan/my-mate-engine/llms.txt Sets up a radial menu system in Unity that includes movement blocking, bone-following UI, and customizable menu entries. It allows for configuration of menu prefabs, input keys, and visual tracking behavior. The system can block player movement and other interactions when menus are active. ```csharp using UnityEngine; using System.Collections.Generic; public class RadialMenuSetup : MonoBehaviour { public GameObject settingsMenu; public GameObject radialMenuPrefab; void Start() { var menuActions = gameObject.AddComponent(); // Register settings menu menuActions.menuEntries = new List { new MenuEntry { menu = settingsMenu, blockMovement = true, // Prevent dragging when open blockHandTracking = false, blockReaction = false, blockChibiMode = false } }; // Configure radial menu menuActions.radialMenuObject = Instantiate(radialMenuPrefab); menuActions.radialMenuKey = KeyCode.F1; menuActions.radialDraggingBlocks = true; menuActions.radialBlockMovement = true; // Bone following configuration menuActions.followBone = true; menuActions.targetBone = HumanBodyBones.Head; menuActions.followSmoothness = 0.15f; // Lower = smoother Debug.Log("Radial menu: Press F1 to toggle"); } // Check if movement is blocked void Update() { if (MenuActions.IsMovementBlocked()) { Debug.Log("Movement blocked by open menu"); } if (Input.GetMouseButtonDown(0)) { // Example: Only allow dragging if not blocked if (!MenuActions.IsMovementBlocked()) { // Start drag operation } } } } // Expected output when F1 pressed: // - Radial menu appears at head bone position // - Menu follows head smoothly as character moves // - Movement/interaction blocked based on settings // - Plays menu open/close sounds ``` -------------------------------- ### Manipulate JSON with LINQ to JSON using Json.NET Source: https://github.com/bbkuan/my-mate-engine/blob/main/Assets/Packages/Newtonsoft.Json.13.0.3/README.md Illustrates using LINQ to JSON with Json.NET to create and manipulate JSON structures programmatically. This example shows creating a JArray and a JObject, then converting them to a JSON string. ```csharp JArray array = new JArray(); array.Add("Manual text"); array.Add(new DateTime(2000, 5, 23)); JObject o = new JObject(); o["MyArray"] = array; string json = o.ToString(); // { // "MyArray": [ // "Manual text", // "2000-05-23T00:00:00" // ] // } ``` -------------------------------- ### RAG Integration for LLM Prompting Source: https://github.com/bbkuan/my-mate-engine/blob/main/Assets/LLMUnity/README.md Demonstrates how to use the RAG system to retrieve relevant data based on a user's query and then incorporate that data into a prompt for an LLM. This enhances the LLM's ability to provide contextually accurate responses. ```csharp string message = "How is the weather?"; (string[] similarPhrases, float[] distances) = await rag.Search(message, 3); string prompt = "Answer the user query based on the provided data.\n\n"; prompt += $"User query: {message}\n\n"; prompt += $"Data:\n"; foreach (string similarPhrase in similarPhrases) prompt += $"\n- {similarPhrase}"; _ = llmCharacter.Chat(prompt, HandleReply, ReplyCompleted); ``` -------------------------------- ### Serialization and Serving Index from Disk Source: https://github.com/bbkuan/my-mate-engine/blob/main/Assets/LLMUnity/Runtime/RAG/usearch/README.md Demonstrates how to serialize and deserialize USearch indexes to and from disk files. It covers saving, loading, and restoring indexes, as well as creating a view of an index from a file. ```python index.save("index.usearch") loaded_copy = index.load("index.usearch") view = Index.restore("index.usearch", view=True) other_view = Index(ndim=..., metric=...) other_view.view("index.usearch") ``` -------------------------------- ### Initialize RAG Script in Unity Source: https://github.com/bbkuan/my-mate-engine/blob/main/Assets/LLMUnity/README.md Initializes the RAG component with specified search and chunking methods, and the LLM instance. This is the programmatic way to set up RAG in your Unity project. ```csharp RAG rag = gameObject.AddComponent(); rag.Init(SearchMethods.DBSearch, ChunkingMethods.SentenceSplitter, llm); ``` -------------------------------- ### Create Outfit Menu UI with Buttons - C# Source: https://context7.com/bbkuan/my-mate-engine/llms.txt This script sets up a UI outfit menu dynamically at runtime. It instantiates a canvas, panel, and up to 8 outfit buttons, assigning them to an AvatarClothesHandler. Button labels are configured using TextMeshProUGUI. The script also initializes animation parameters for the buttons. ```csharp using UnityEngine; using UnityEngine.UI; using TMPro; public class OutfitMenuSetup : MonoBehaviour { public GameObject menuPanelPrefab; void Start() { // Create outfit menu UI GameObject menuCanvas = new GameObject("OutfitMenuCanvas"); var canvas = menuCanvas.AddComponent(); canvas.renderMode = RenderMode.ScreenSpaceOverlay; menuCanvas.AddComponent(); menuCanvas.AddComponent(); GameObject panel = Instantiate(menuPanelPrefab, menuCanvas.transform); panel.SetActive(false); // Setup handler var handler = gameObject.AddComponent(); handler.menuPanel = panel; // Create 8 outfit buttons handler.outfitButtons = new Button[8]; handler.buttonLabels = new TextMeshProUGUI[8]; for (int i = 0; i < 8; i++) { GameObject buttonObj = new GameObject($"OutfitButton{i}"); buttonObj.transform.SetParent(panel.transform); var rectTransform = buttonObj.AddComponent(); rectTransform.sizeDelta = new Vector2(200, 50); rectTransform.anchoredPosition = new Vector2(0, -60 * i); var button = buttonObj.AddComponent