### Using Unity Mathematics for Vector Operations C# Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.mathematics@1.3.2/Documentation~/getting-started.md This C# snippet demonstrates how to include the `Unity.Mathematics` library using a static `using` directive for direct access to `math` functions. It initializes two 3D float vectors (`float3`), normalizes them using the `normalize` function, and calculates their dot product using the `dot` function. ```C# using static Unity.Mathematics.math; namespace MyNamespace { using Unity.Mathematics; ... var v1 = float3(1,2,3); var v2 = float3(4,5,6); v1 = normalize(v1); v2 = normalize(v2); var v3 = dot(v1, v2); ... } ``` -------------------------------- ### Demonstrating Subscript and Superscript Tags HTML Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/RichTextSubSuper.md This snippet shows a basic example of combining normal text with superscript (m³) and subscript (H₂O) formatting using the and rich text tags. ```HTML We have 1m3 of H2O. ``` -------------------------------- ### Example Usage of Sprite Tag - Rich Text Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/RichTextSprite.md This snippet demonstrates various ways to insert sprites using the tag within a text string. It shows the shorthand index method, explicit index, and referencing a sprite by name while also applying a specific color tint. ```Text Sprites! More sprites! And even more! ``` -------------------------------- ### Inserting Sprites with Tag (Rich Text) Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/exportdoc.md Shows how to insert images from a Sprite Asset using the tag. Examples include accessing sprites by index, name, from a specific asset, and applying color tinting using the 'tint' or 'color' attributes. ```Rich Text Sprites! More sprites! And even more! ``` -------------------------------- ### Applying Strikethrough and Underline TextMeshPro Rich Text Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/RichTextStrikethroughUnderline.md This snippet demonstrates the application of TextMeshPro's rich text tags `` for strikethrough and `` for underline. Text enclosed within `` will have a line drawn through it, while text within `` will be underlined. This is a simple example showing how to format specific words within a sentence. ```TextMeshPro Rich Text The quick brown fox jumps over the lazy dog. ``` -------------------------------- ### Applying 15% Line Indentation in Rich Text Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/RichTextLineIndentation.md This snippet demonstrates applying a 15% line indentation using the `` tag. The specified indentation value (15%) is applied to every subsequent line that is manually broken until a `` tag is encountered. This affects the text starting from the second line onwards in this example. ```Rich Text Markup This is the first line of this text example. This is the second line of the same text. ``` -------------------------------- ### Applying Mark Tag Example - Knight Markup Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/RichTextMark.md This snippet demonstrates the basic syntax for applying the `` tag in Knight Rich Text. It wraps the target text 'can be marked with' within the opening `` tag, specifying a semitransparent yellow color (hex with alpha), and the closing `` tag. This applies a colored overlay to the enclosed text. ```Knight Markup Text can be marked with an overlay. ``` -------------------------------- ### Applying Indentation with Rich Text Tags (Generic) Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/RichTextIndentation.md Demonstrates how to use the `` rich text tag to control horizontal text positioning that persists across lines. The example shows applying a 15% indentation for list items, useful for creating bullet points that handle word-wrapping correctly. ```Generic 1. It is useful for things like bullet points. 2. It is handy. ``` -------------------------------- ### Applying Line Indentation in TextMesh Pro Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/exportdoc.md Shows how to use the tag to add horizontal space at the beginning of lines. This tag only affects manual line breaks and continues until a closing tag is encountered. Example uses percentage. ```TextMesh Pro Rich Text This is the first line of this text example.\nThis is the second line of the same text. ``` -------------------------------- ### Demonstrating Text Alignment using Rich Text Tags Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/RichTextAlignment.md This snippet provides examples of how to use the rich text tag within text content to specify different horizontal alignments. It illustrates the syntax for applying left, center, right, justified, and flush alignments to subsequent lines or paragraphs. ```Rich Text Left-aligned Center-aligned Right-aligned Justified: stretched to fill the display area (except for the last line) Flush: stretched to fill the display area (including the last line) ``` -------------------------------- ### Adjusting Font Size in TextMesh Pro Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/exportdoc.md Demonstrates the tag for changing the font size. Sizes can be specified in pixels, font units, or percentages. Relative pixel adjustments (+1, -1) are based on the original size. Example uses percentage values. ```TextMesh Pro Rich Text Echo Echo Echo Echo Echo ``` -------------------------------- ### Setting Horizontal Caret Position in TextMesh Pro Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/exportdoc.md Demonstrates using the tag to directly control the horizontal drawing position of the caret. The position is relative to the line start and is best used with left alignment. Example uses percentage values. ```TextMesh Pro Rich Text at 75%\nat 25%\nat 50%\nat 0% ``` -------------------------------- ### Setting Text Margins in TextMesh Pro Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/exportdoc.md Demonstrates how to use the tag to increase the horizontal margins (left and right) of text. The example uses font units (em). Negative values are ignored, and the effect lasts until a closing tag. ```TextMesh Pro Rich Text Our margins used to be very wide.\nBut those days are long gone. ``` -------------------------------- ### Applying Text Alignment - Rich Text Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/exportdoc.md Demonstrates how to use the rich text tag to override an object's default text alignment. Shows examples for left, center, right, justified, and flush alignment. The tag affects text until a closing or another alignment tag is encountered. ```Rich Text Left-aligned Center-aligned Right-aligned Justified: stretched to fill the display area (except for the last line) Flush: stretched to fill the display area (including the last line) ``` -------------------------------- ### Setting Horizontal Position Rich Text Markup Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/RichTextPos.md This snippet demonstrates how to use the `` tag to explicitly set the horizontal caret position within a line using percentage units. The text following the tag will appear at the specified horizontal offset from the line's start. ```Rich Text Markup at 75% at 25% at 50% at 0% ``` -------------------------------- ### Demonstrating Larger Text Rotation (TMP Rich Text) Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/RichTextRotate.md This example applies a larger positive rotation of 45 degrees to text using the `` tag. It illustrates how increased rotation can affect character spacing and potentially cause overlapping characters, as shown in the accompanying image. ```TMP Rich Text Rotate text counter-clockwise<\/rotate> ``` -------------------------------- ### Inserting Horizontal Space in Rich Text Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/RichTextSpace.md This snippet demonstrates how to use the `` tag to insert horizontal spacing within text. It uses the tag `` where 'value' specifies the offset, which can be in pixels or 'em' (font units). This example adds 5 font units of space between two words. ```Rich Text Syntax Give me some space. ``` -------------------------------- ### Applying Rotation Tag to Text (TMP Rich Text) Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/RichTextRotate.md This snippet shows how to use the `` tag to rotate specific parts of a text string. It includes examples of both negative values for clockwise rotation and positive values for counter-clockwise rotation, applied to different words within the same line. ```TMP Rich Text Rotate text counter-clockwise<\/rotate> or clockwise<\/rotate> ``` -------------------------------- ### Rotating Characters in TextMesh Pro Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/exportdoc.md Illustrates using the tag to rotate individual characters. Positive values rotate counter-clockwise, negative clockwise. Rotation can affect character spacing and cause overlap, which may need correction with . Includes examples of rotation alone and rotation with spacing correction. ```TextMesh Pro Rich Text Rotate text counter-clockwise or clockwise ``` ```TextMesh Pro Rich Text Rotate text counter-clockwise ``` ```TextMesh Pro Rich Text Rotate text counter-clockwise ``` -------------------------------- ### Applying Width Tag TextMesh Pro Rich Text Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/RichTextWidth.md This snippet shows a basic example of using the tag to reduce the text area width to 60% for a specific line following the tag. The width adjustment takes effect immediately after the tag and applies only to the subsequent text on that line. Requires a TextMesh Pro component that supports rich text. The value inside the tag can be pixels (), font units (), or percentages (). ```TextMesh Pro Rich Text I remember when we had lots of space for text. But those days are long gone. ``` -------------------------------- ### Applying Multiple Rich Text Tags Directly (TextMesh Pro) Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/CustomStyles.md This snippet demonstrates applying multiple rich text tags (, , ,
) directly to text to achieve complex formatting. This approach is shown to be cumbersome and difficult to maintain compared to using styles. ```TextMesh Pro Rich Text *Heading*

``` -------------------------------- ### Implementing Binary Serialization for Configuration Class - C# Source: https://github.com/winddyhe/knight/blob/master/Doc/english-doc/GameConfig.md This C# partial class provides the concrete implementation for serializing and deserializing the generated configuration data classes. It implements the `ISerializerBinary` interface, providing methods to write the class fields to and read them from a binary stream using custom `BinaryWriter` and `BinaryReader` objects. ```C# public partial class SkillConfig : ISerializerBinary { public void Serialize(BinaryWriter rWriter) { rWriter.Serialize(this.ID); rWriter.Serialize(this.SkillCastTargetType); rWriter.Serialize(this.SkillName); rWriter.Serialize(this.TargetSelectAngleOrWidth); rWriter.Serialize(this.TargetSelectCampType); rWriter.Serialize(this.TargetSelectRadiusOrHeight); rWriter.Serialize(this.TargetSelectSearchType); } public void Deserialize(BinaryReader rReader) { this.ID = rReader.Deserialize(this.ID); this.SkillCastTargetType = rReader.Deserialize(this.SkillCastTargetType); this.SkillName = rReader.Deserialize(this.SkillName); this.TargetSelectAngleOrWidth = rReader.Deserialize(this.TargetSelectAngleOrWidth); this.TargetSelectCampType = rReader.Deserialize(this.TargetSelectCampType); this.TargetSelectRadiusOrHeight = rReader.Deserialize(this.TargetSelectRadiusOrHeight); this.TargetSelectSearchType = rReader.Deserialize(this.TargetSelectSearchType); } } ``` -------------------------------- ### Applying Custom Style Tag Syntax Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/RichTextStyle.md Demonstrates the basic syntax for applying a named custom style using the ` ``` -------------------------------- ### Applying Gradient Presets - Rich Text Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/exportdoc.md Demonstrates applying a pre-defined gradient preset to text using the tag. Gradients are multiplied by the current vertex color unless the color is first reset to white using a tag. ```Rich Text Apply any gradient preset to your text ``` ```Rich Text This Light to Dark Green gradient is tinted by the red vertex color ``` ```Rich Text This Light to Dark Green gradient is no longer tinted by the red vertex color ``` -------------------------------- ### Applying Sequential Gradient Presets TextMesh Pro Rich Text Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/RichTextGradient.md This snippet demonstrates applying multiple different gradient presets sequentially to parts of a text string. The bold tag `` is also used for formatting. The closing `` tag is used at the end of the last gradient application. ```TextMesh Pro Rich Text Apply any gradient preset to your text ``` -------------------------------- ### Defining ViewModel Properties and ViewController Logic in C# Source: https://github.com/winddyhe/knight/blob/master/Doc/中文文档/MVMC的UI框架.md This snippet demonstrates how to define a ViewModel using the `[DataBinding]` attribute for basic properties, `[DataBindingRelated]` for properties dependent on others, and how to define a ViewController using `[ViewModelKey]` to link ViewModels and `[DataBindingEvent]` for exposing methods as UI event handlers. It shows initializing ViewModel data in `OnOpen` and handling UI button/list events. ```C# [DataBinding] public partial class PlayerViewModel : ViewModel { // Data Binding [DataBinding] public string Name { get; set; } [DataBinding] public int Level { get; set; } [DataBinding] public int Exp { get; set; } [DataBinding] public int Coin { get; set; } [DataBinding] public string Password { get; set; } // Related Binding with single property [DataBindingRelated("Name")] public string NameRelatedTest1 => this.Name + "_RelatedTest1"; // Related Binding with multiple properties [DataBindingRelated("Level, Exp")] public string LevelRelatedTest1 => (this.Level + this.Exp).ToString(); // List Binding [DataBinding] public List TestList { get; set; } } public class PlayerViewController : ViewController { [ViewModelKey("Test1")] public PlayerViewModel Test1; [ViewModelKey("Test2")] public PlayerViewModel Test2; protected override async UniTask OnOpen() { await base.OnOpen(); this.Test1.Name = "Test444."; this.Test1.Level = 100; this.Test1.Exp =200; this.Test1.Coin = 300; var rPlayerTestItems = new List(); for (int i = 0; i < 100; i++) { var rPlayerTestItem = new PlayerTestItem(); rPlayerTestItem.Test1 = $"Test1-{i}"; rPlayerTestItem.Test2 = $"Test2-{i}"; rPlayerTestItems.Add(rPlayerTestItem); } this.Test1.TestList = rPlayerTestItems; } protected override void OnClose() { } [DataBindingEvent(false)] public void OnBtnEnter_Clicked() { this.Test1.TestList[4].Test1 = this.Test1.Name; this.Test1.Exp = 400; LogManager.LogError($"OnBtnEnter_Clicked Test..{this.Test2.Password}, {this.Test1.Name}"); ViewManager.Instance.Close(this.View.GUID); HotfixBattle.Instance.Initialize().WrapErrors(); } [DataBindingEvent(true)] public void OnListBtnComfirmClicked(int nIndex) { LogManager.LogError($"OnListButton_Clicked Test..{nIndex}, {this.Test1.TestList[nIndex].Test1}"); } } ``` -------------------------------- ### Defining Hot Update Entry Points - C# Source: https://github.com/winddyhe/knight/blob/master/Doc/中文文档/hybridclr热更新.md This C# code defines the entry points for both the main project (Game.dll) and the hot update project (Game.Hotfix.dll). The `MainLogic` class, residing in the main project, is responsible for initializing, updating, and destroying the hotfix logic by instantiating `HotfixMainLogic` from the hotfix assembly via `HotfixManager`. The `HotfixMainLogic` class provides the structure for the actual game logic residing in the hotfix assembly. ```C# // 主工程Game.dll的调用入口 public class MainLogic : TSingleton { private bool mIsInitialized = false; private MainLogic() { } public async Task Initialize() { this.mIsInitialized = false; HotfixMainLogicManager.Instance = HotfixManager.Instance.Instantiate("Game.Hotfix", "Game.HotfixMainLogic"); await HotfixMainLogicManager.Instance.Initialize(); this.mIsInitialized = true; } public void Update(float fDeltaTime) { if (!this.mIsInitialized) return; HotfixMainLogicManager.Instance?.Update(fDeltaTime); } public void LateUpdate(float fDeltaTime) { if (!this.mIsInitialized) return; HotfixMainLogicManager.Instance?.LateUpdate(fDeltaTime); } public void Destroy() { HotfixMainLogicManager.Instance?.Destroy(); this.mIsInitialized = false; } } // 热更新工程Game.Hotfix.dll的调用入口 public class HotfixMainLogic : IHotfixMainLogic { public async UniTask Initialize() { } public void Destroy() { } public void LateUpdate(float fDeltaTime) { } public void Update(float fDeltaTime) { } } ``` -------------------------------- ### Generating Random Floats with Unity.Mathematics in C# Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.mathematics@1.3.2/Documentation~/random-numbers.md This snippet demonstrates how to initialize a random number generator using Unity.Mathematics.Random with a seed and generate float values. It shows generating floats within the default [0, 1) range and a specified [-5, 5) range using the NextFloat method. Requires the Unity.Mathematics namespace. ```c# // Unity Mathematics example void RandomNumberUnityMathematics() { // Choose some non-zero seed and set up the random number generator state. uint seed = 1; Unity.Mathematics.Random rng = new Unity.Mathematics.Random(seed); // [0, 1) exclusive float randomFloat1 = rng.NextFloat(); // [-5, 5) exclusive float randomFloat2 = rng.NextFloat(-5.0f, 5.0f); } ``` -------------------------------- ### Defining Game Configuration Data Class - C# Source: https://github.com/winddyhe/knight/blob/master/Doc/english-doc/GameConfig.md This C# partial class is automatically generated based on the structure defined in an Excel spreadsheet. It serves as a data container for configuration entries, specifying the fields and their types. Attributes like `[SerializerBinary]` and `[SBGroup]` are used for the subsequent serialization process. ```C# [SerializerBinary] [SBGroup("GameConfig")] /// /// Auto generate code, don't modify it. /// public partial class SkillConfig { public int ID; public string SkillName; public int SkillCastTargetType; public int TargetSelectCampType; public int TargetSelectSearchType; public int TargetSelectRadiusOrHeight; public int TargetSelectAngleOrWidth; } ``` -------------------------------- ### Creating 4x4 Matrix in Unity Mathematics (C#) Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.mathematics@1.3.2/Documentation~/4x4-matrices.md This snippet demonstrates how to create a 4x4 matrix (`float4x4`) in Unity Mathematics by initializing four `float4` column vectors and using them to construct the matrix. Requires the Unity.Mathematics namespace. ```c# // Unity Mathematics example void Build4x4UnityMathematics() { var c0 = new float4(1.0f, 0.0f, 0.0f, 0.0f); var c1 = new float4(0.0f, 1.0f, 0.0f, 0.0f); var c2 = new float4(0.0f, 0.0f, 1.0f, 0.0f); var c3 = new float4(0.0f, 0.0f, 0.0f, 1.0f); var m = new float4x4(c0, c1, c2, c3); } ``` -------------------------------- ### Applying Rich Text Capitalization Tags - Markup Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/RichTextLetterCase.md This snippet demonstrates how to apply , , , and tags to text. It shows how each tag affects the capitalization of the enclosed string before rendering, illustrating the output differences (lowercase, uppercase, all caps, small caps). ```Rich Text Markup Alice and Bob watched TV. Alice and Bob watched TV. Alice and Bob watched TV. Alice and Bob watched TV. ``` -------------------------------- ### Implementing Custom Message Interface MonoBehaviour C# Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/MessagingSystem.md This snippet demonstrates implementing a custom message interface on a Unity MonoBehaviour script. The class must inherit from MonoBehaviour and the custom interface, providing concrete implementations for the interface methods that will be executed when a message is sent to this GameObject. ```C# public class CustomMessageTarget : MonoBehaviour, ICustomMessageTarget { public void Message1() { Debug.Log ("Message 1 received"); } public void Message2() { Debug.Log ("Message 2 received"); } } ``` -------------------------------- ### Adding Strikethrough and Underline in TextMesh Pro Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/exportdoc.md Shows how to use the (or ) and (or ) tags to draw lines through or under text. Underline is slightly below the baseline, and strikethrough is slightly above. ```TextMesh Pro Rich Text The quick brown fox jumps over the lazy dog. ``` -------------------------------- ### Managing UI Screen Transitions in Unity C# Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/HOWTO-UIScreenTransition.md This C# script, `ScreenManager`, facilitates managing transitions between different UI panels in a Unity scene. It uses Unity's Animator component to trigger 'Open' and 'Closed' animations and handles navigation by setting the selected GameObject appropriately when screens are opened or closed. It requires panels to have an Animator with a boolean 'Open' parameter. ```csharp using UnityEngine; using UnityEngine.UI; using UnityEngine.EventSystems; using System.Collections; using System.Collections.Generic; public class ScreenManager : MonoBehaviour { //Screen to open automatically at the start of the Scene public Animator initiallyOpen; //Currently Open Screen private Animator m_Open; //Hash of the parameter we use to control the transitions. private int m_OpenParameterId; //The GameObject Selected before we opened the current Screen. //Used when closing a Screen, so we can go back to the button that opened it. private GameObject m_PreviouslySelected; //Animator State and Transition names we need to check against. const string k_OpenTransitionName = "Open"; const string k_ClosedStateName = "Closed"; public void OnEnable() { //We cache the Hash to the "Open" Parameter, so we can feed to Animator.SetBool. m_OpenParameterId = Animator.StringToHash (k_OpenTransitionName); //If set, open the initial Screen now. if (initiallyOpen == null) return; OpenPanel(initiallyOpen); } //Closes the currently open panel and opens the provided one. //It also takes care of handling the navigation, setting the new Selected element. public void OpenPanel (Animator anim) { if (m_Open == anim) return; //Activate the new Screen hierarchy so we can animate it. anim.gameObject.SetActive(true); //Save the currently selected button that was used to open this Screen. (CloseCurrent will modify it) var newPreviouslySelected = EventSystem.current.currentSelectedGameObject; //Move the Screen to front. anim.transform.SetAsLastSibling(); CloseCurrent(); m_PreviouslySelected = newPreviouslySelected; //Set the new Screen as then open one. m_Open = anim; //Start the open animation m_Open.SetBool(m_OpenParameterId, true); //Set an element in the new screen as the new Selected one. GameObject go = FindFirstEnabledSelectable(anim.gameObject); SetSelected(go); } //Finds the first Selectable element in the providade hierarchy. static GameObject FindFirstEnabledSelectable (GameObject gameObject) { GameObject go = null; var selectables = gameObject.GetComponentsInChildren (true); foreach (var selectable in selectables) { if (selectable.IsActive () && selectable.IsInteractable ()) { go = selectable.gameObject; break; } } return go; } //Closes the currently open Screen //It also takes care of navigation. //Reverting selection to the Selectable used before opening the current screen. public void CloseCurrent() { if (m_Open == null) return; //Start the close animation. m_Open.SetBool(m_OpenParameterId, false); //Reverting selection to the Selectable used before opening the current screen. SetSelected(m_PreviouslySelected); //Start Coroutine to disable the hierarchy when closing animation finishes. StartCoroutine(DisablePanelDeleyed(m_Open)); //No screen open. m_Open = null; } //Coroutine that will detect when the Closing animation is finished and it will deactivate the //hierarchy. IEnumerator DisablePanelDeleyed(Animator anim) { bool closedStateReached = false; bool wantToClose = true; while (!closedStateReached && wantToClose) { if (!anim.IsInTransition(0)) closedStateReached = anim.GetCurrentAnimatorStateInfo(0).IsName(k_ClosedStateName); wantToClose = !anim.GetBool(m_OpenParameterId); yield return new WaitForEndOfFrame(); } if (wantToClose) anim.gameObject.SetActive(false); } //Make the provided GameObject selected //When using the mouse/touch we actually want to set it as the previously selected and //set nothing as selected for now. private void SetSelected(GameObject go) { //Select the GameObject. EventSystem.current.SetSelectedGameObject(go); //If we are using the keyboard right now, that's all we need to do. var standaloneInputModule = EventSystem.current.currentInputModule as StandaloneInputModule; if (standaloneInputModule != null) return; //Since we are using a pointer device, we don't want anything selected. //But if the user switches to the keyboard, we want to start the navigation from the provided game object. //So here we set the current Selected to null, so the provided gameObject becomes the Last Selected in the EventSystem. EventSystem.current.SetSelectedGameObject(null); } } ``` -------------------------------- ### Applying Text Colors (Named/Hex) - Rich Text Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/exportdoc.md Illustrates changing text color using either predefined color names (e.g., "red") or hexadecimal color codes (with optional alpha). Shows how successive color tags override previous ones. ```Rich Text Red Dark Green <#0000FF>Blue Semitransparent Red ``` -------------------------------- ### Applying Subscript and Superscript Tags (Rich Text) Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/exportdoc.md Illustrates the use of the and tags to render text as superscript and subscript. These tags are often used for scientific notation and ordinal numbering. ```Rich Text We have 1m3 of H2O. ``` -------------------------------- ### Controlling Text Opacity - Rich Text Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/exportdoc.md Shows how to use the rich text tag to set text opacity using hexadecimal values (00-FF). Demonstrates successive application of the tag within a single line. ```Rich Text FF CC AA 88 66 44 22 00 ``` -------------------------------- ### Applying Custom Style with Tag (Rich Text) Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/exportdoc.md Demonstrates applying a custom text style defined in a style sheet using the tag closes the last opened style. ```Rich Text Styles You can create your own. ``` -------------------------------- ### Highlighting Text with Mark Tag in TextMesh Pro Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/exportdoc.md Shows how to use the tag to add a colored overlay on top of text, typically used for highlighting. A semitransparent color (using hex with Alpha) is required for the text to remain visible. The effect applies until the next or . ```TextMesh Pro Rich Text Text can be marked with an overlay. ``` -------------------------------- ### Performing Component-wise Vector Multiplication using Unity Mathematics in C# Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.mathematics@1.3.2/Documentation~/vector-multiplication.md This C# function demonstrates component-wise multiplication of two `float4` vectors using the `*` operator from the Unity Mathematics library. It initializes two vectors, performs the multiplication, and shows the expected result in a comment, illustrating a common SIMD operation. ```c# // Unity Mathematics example void ComponentwiseVectorMultiplyUnityMathematics() { var v0 = new float4(2.0f, 4.0f, 6.0f, 8.0f); var v1 = new float4(1.0f, -1.0f, 1.0f, -1.0f); var result = v0 * v1; // result == new float4(2.0f, -4.0f, 6.0f, -8.0f). } ``` -------------------------------- ### Applying Text Capitalization Tags (Rich Text) Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/exportdoc.md Shows how to use the , , , and tags to alter text capitalization before rendering in TextMesh Pro. The original text field content remains as entered. ```Rich Text Alice and Bob watched TV. Alice and Bob watched TV. Alice and Bob watched TV. Alice and Bob watched TV. ``` -------------------------------- ### Applying Font Weights - Rich Text Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/exportdoc.md Demonstrates applying different font weights to text using the tag and numeric weight values (e.g., 400 for normal, 700 for bold). Available weights depend on the font asset configuration. The closing tag reverts to the object's default font weight. ```Rich Text Thin Extra-Light Light Regular Medium Semi-Bold Bold Heavy Black ``` -------------------------------- ### Altering Text Capitalization - Rich Text Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/exportdoc.md Illustrates the use of , , , and tags to change the rendering case of text. Explains the difference between / and , which also reduces size. ```Rich Text Alice and Bob watched TV. Alice and Bob watched TV. Alice and Bob watched TV. Alice and Bob watched TV. ``` -------------------------------- ### Applying Font and Material using TextMesh Pro Rich Text Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/RichTextFont.md This snippet demonstrates how to use the `` tag to change the font of text and the `material` attribute within the `` tag to apply a different material, without changing the font, using TextMesh Pro's rich text system. Required assets must be placed in the specified TMP font/material directory. ```TextMesh Pro Rich Text Would you like a different font? or just a different material? ``` -------------------------------- ### Applying Strikethrough and Underline Tags (Rich Text) Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/exportdoc.md Shows how to use the (or ) and (or ) tags to add lines above and below text, respectively. The vertical offset is typically defined in the Font Asset. ```Rich Text The quick brown fox jumps over the lazy dog. ``` -------------------------------- ### Defining MVMC ViewModel and ViewController in C# Source: https://github.com/winddyhe/knight/blob/master/Doc/english-doc/MVMC-UIFramework.md This snippet demonstrates how to define a ViewModel (`PlayerViewModel`) and a ViewController (`PlayerViewController`) in C# using the framework's attributes. The `PlayerViewModel` uses `[DataBinding]` for properties and `[DataBindingRelated]` for computed properties dependent on others. The `PlayerViewController` uses `[ViewModelKey]` to associate ViewModel instances and `[DataBindingEvent]` to mark methods callable from UI events. It shows initializing ViewModel data in `OnOpen` and handling button clicks/list item events. ```C# [DataBinding] public partial class PlayerViewModel : ViewModel { // Data Binding [DataBinding] public string Name { get; set; } [DataBinding] public int Level { get; set; } [DataBinding] public int Exp { get; set; } [DataBinding] public int Coin { get; set; } [DataBinding] public string Password { get; set; } // Related Binding with single property [DataBindingRelated("Name")] public string NameRelatedTest1 => this.Name + "_RelatedTest1"; // Related Binding with multiple properties [DataBindingRelated("Level, Exp")] public string LevelRelatedTest1 => (this.Level + this.Exp).ToString(); // List Binding [DataBinding] public List TestList { get; set; } } public class PlayerViewController : ViewController { [ViewModelKey("Test1")] public PlayerViewModel Test1; [ViewModelKey("Test2")] public PlayerViewModel Test2; protected override async UniTask OnOpen() { await base.OnOpen(); this.Test1.Name = "Test444."; this.Test1.Level = 100; this.Test1.Exp =200; this.Test1.Coin = 300; var rPlayerTestItems = new List(); for (int i = 0; i < 100; i++) { var rPlayerTestItem = new PlayerTestItem(); rPlayerTestItem.Test1 = $"Test1-{i}"; rPlayerTestItem.Test2 = $"Test2-{i}"; rPlayerTestItems.Add(rPlayerTestItem); } this.Test1.TestList = rPlayerTestItems; } protected override void OnClose() { } [DataBindingEvent(false)] public void OnBtnEnter_Clicked() { this.Test1.TestList[4].Test1 = this.Test1.Name; this.Test1.Exp = 400; LogManager.LogError($"OnBtnEnter_Clicked Test..{this.Test2.Password}, {this.Test1.Name}"); ViewManager.Instance.Close(this.View.GUID); HotfixBattle.Instance.Initialize().WrapErrors(); } [DataBindingEvent(true)] public void OnListBtnComfirmClicked(int nIndex) { LogManager.LogError($"OnListButton_Clicked Test..{nIndex}, {this.Test1.TestList[nIndex].Test1}"); } } ``` -------------------------------- ### Applying Bold and Italic in Rich Text Markup Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/RichTextBoldItalic.md This snippet demonstrates how to apply bold and italic styling to text using the `` and `` rich text tags. The tags wrap the text to be styled. The visual rendering of these styles is controlled by the associated font asset. ```Markup The quick brown fox jumps over the lazy dog. ``` -------------------------------- ### Defining Hotfix Entry Points - C# Source: https://github.com/winddyhe/knight/blob/master/Doc/english-doc/Hybridclr-HotUpdate.md Defines the interaction points between the main Unity project and the hotfix assembly. The MainLogic class in the main project manages the lifecycle of the hotfix entry point (HotfixMainLogic) by instantiating it and calling its Initialize, Update, LateUpdate, and Destroy methods via the IHotfixMainLogic interface. The HotfixMainLogic class provides the implementation for these lifecycle methods within the hotfix assembly. ```C# // 主工程Game.dll的调用入口 public class MainLogic : TSingleton { private bool mIsInitialized = false; private MainLogic() { } public async Task Initialize() { this.mIsInitialized = false; HotfixMainLogicManager.Instance = HotfixManager.Instance.Instantiate("Game.Hotfix", "Game.HotfixMainLogic"); await HotfixMainLogicManager.Instance.Initialize(); this.mIsInitialized = true; } public void Update(float fDeltaTime) { if (!this.mIsInitialized) return; HotfixMainLogicManager.Instance?.Update(fDeltaTime); } public void LateUpdate(float fDeltaTime) { if (!this.mIsInitialized) return; HotfixMainLogicManager.Instance?.LateUpdate(fDeltaTime); } public void Destroy() { HotfixMainLogicManager.Instance?.Destroy(); this.mIsInitialized = false; } } // 热更新工程Game.Hotfix.dll的调用入口 public class HotfixMainLogic : IHotfixMainLogic { public async UniTask Initialize() { } public void Destroy() { } public void LateUpdate(float fDeltaTime) { } public void Update(float fDeltaTime) { } } ``` -------------------------------- ### Enabling Rich Text in Unity Editor GUI - C# Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/StyledText.md This snippet shows how to create a custom GUIStyle instance, explicitly enable its richText property, and apply this style to a GUILayout.Label call to render text containing rich text markup within the Unity Editor interface. This is necessary because rich text is disabled by default in the editor GUI system. ```C# GUIStyle style = new GUIStyle (); style.richText = true; GUILayout.Label("Some RICH text
",style); ``` -------------------------------- ### Sending Custom Message ExecuteEvents C# Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/MessagingSystem.md This snippet illustrates how to send a custom message using the static helper class ExecuteEvents.Execute. It requires the target GameObject, optional user data (null in this case), and a functor (lambda) that maps to the specific interface method to be called on components implementing the specified interface on the target GameObject. ```C# ExecuteEvents.Execute(target, null, (x,y)=>x.Message1()); ``` -------------------------------- ### Applying Varying Text Opacity - Rich Text Markup Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/RichTextOpacity.md This snippet illustrates the use of the `` tag to set text opacity. The tag takes a hexadecimal value (e.g., #FF for opaque, #00 for transparent) and applies the corresponding alpha level to the text that follows it until another `` tag is encountered. ```Rich Text Markup FF CC AA 88 66 44 22 00 ``` -------------------------------- ### Switching Font or Material - Rich Text Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/exportdoc.md Illustrates using the tag to switch between different font assets or different materials for the current font asset. Font and material assets must be configured in TextMesh Pro settings. Closing reverts to the previous font or the default. ```Rich Text Would you like a different font? or just a different material? ``` -------------------------------- ### Applying Bold and Italic Styles - Rich Text Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/exportdoc.md Demonstrates how to apply bold () and italic () styling to text using rich text tags. The appearance is defined by the associated font asset. Closing tags (, ) revert to the normal style. ```Rich Text The quick brown fox jumps over the lazy dog. ``` -------------------------------- ### Changing Text Case in TextMesh Pro Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/exportdoc.md Illustrates the use of , , , and tags to modify the capitalization of text for rendering. The original text content remains unchanged. is equivalent to , while also reduces the size of originally lowercase characters. ```TextMesh Pro Rich Text Alice and Bob watched TV.\nAlice and Bob watched TV.\nAlice and Bob watched TV.\nAlice and Bob watched TV. ``` -------------------------------- ### Defining Custom Message Interface C# Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/MessagingSystem.md This snippet shows how to define a custom message interface for the Unity messaging system. The interface must inherit from 'UnityEngine.EventSystems.IEventSystemHandler' and declare the methods that can be invoked via the messaging system. ```C# public interface ICustomMessageTarget : IEventSystemHandler { // functions that can be called via the messaging system void Message1(); void Message2(); } ``` -------------------------------- ### Multiplying 4x4 Matrix and 4D Vector in Unity Mathematics (C#) Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.mathematics@1.3.2/Documentation~/4x4-matrices.md This snippet shows how to use `math.mul` to perform matrix-vector multiplication in Unity Mathematics. It demonstrates multiplying a `float4x4` by a `float4` (matrix * column vector) and a `float4` by a `float4x4` (row vector * matrix). Requires `Unity.Mathematics.math`, `Unity.Mathematics.float4x4`, `Unity.Mathematics.float4`, and assumed predefined `f4x4` and `f4` variables. ```c# // Unity Mathematics example void Multiply4x4AndVector4UnityMathematics() { float4 result1 = math.mul(f4x4, f4); // 4x4 * 4x1 = 4x1 float4 result2 = math.mul(f4, f4x4); // 1x4 * 4x4 = 1x4 } ``` -------------------------------- ### Applying Monospace Formatting (Text Format) Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/RichTextMonospace.md This snippet demonstrates how to use the tag to apply monospacing to a section of text. It sets the character width for the following text to 2.75 'em' units, ensuring all characters occupy the same horizontal space until the effect is overridden. ```Text Format Any font can become monospace, if you really want it. ``` -------------------------------- ### Applying Text Colors (Closing Tag) - Rich Text Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/exportdoc.md Demonstrates the use of the closing tag to revert text color to the previous scope or the object's default color. ```Rich Text Red, Blue, and red again. ``` -------------------------------- ### Applying BR Tag for Line Breaks - HTML Source: https://github.com/winddyhe/knight/blob/master/knight-client/Packages/unity-lib/com.unity.ugui@2.0.0/Documentation~/TextMeshPro/RichTextLineBreak.md Demonstrates the use of the HTML `
` tag to insert explicit line breaks within a block of text. It shows the same text without and with the `
` tags applied to force breaks at specific points. ```HTML Add line breaks wherever you want Add line breaks
wherever
you
want ```