### Install UICorner via OpenUPM CLI Source: https://github.com/irakli/ui-corner/blob/main/README.md Installs the UICorner package using the OpenUPM command-line interface. This is the recommended installation method for easy updates and management. ```bash openupm add com.iraklichkuaseli.uicorner ``` -------------------------------- ### Install UICorner via Git URL in manifest.json Source: https://github.com/irakli/ui-corner/blob/main/README.md Installs the UICorner package directly from its Git repository by adding an entry to the `Packages/manifest.json` file. This is useful for installing specific branches or unreleased versions. ```json { "dependencies": { "com.iraklichkuaseli.uicorner": "https://github.com/irakli/ui-corner.git" } } ``` -------------------------------- ### Install UICorner via OpenUPM Registry (JSON) Source: https://context7.com/irakli/ui-corner/llms.txt This JSON snippet shows how to configure your project's `Packages/manifest.json` to use the OpenUPM scoped registry for installing the UICorner package. Specify the version for precise control. ```json // Via OpenUPM scoped registry in Packages/manifest.json { "scopedRegistries": [ { "name": "OpenUPM", "url": "https://package.openupm.com", "scopes": ["com.iraklichkuaseli"] } ], "dependencies": { "com.iraklichkuaseli.uicorner": "1.1.1" } } ``` -------------------------------- ### Add and Configure UICorner Component in Unity Source: https://context7.com/irakli/ui-corner/llms.txt Demonstrates how to get or add a UICorner component to a Unity UI Image, set corner radii and styles (Rounded/Chamfered) for each corner, and apply the changes. ```csharp using UnityEngine; using UnityEngine.UI; using IrakliChkuaseli.UI.UICorner; public class UICornerExample : MonoBehaviour { void Start() { // Get or add UICorner component to an Image var image = GetComponent(); var uiCorner = gameObject.AddComponent(); // Set corner radii (topLeft, topRight, bottomRight, bottomLeft) uiCorner.r = new Vector4(40f, 40f, 40f, 40f); // Set individual corner styles uiCorner.topLeft = CornerStyle.Rounded; uiCorner.topRight = CornerStyle.Rounded; uiCorner.bottomRight = CornerStyle.Chamfered; uiCorner.bottomLeft = CornerStyle.Chamfered; // Apply changes uiCorner.Refresh(); } } ``` -------------------------------- ### Dynamically Modify UICorner Properties at Runtime Source: https://context7.com/irakli/ui-corner/llms.txt Provides an example of how to dynamically change corner radii and styles of a UICorner component during runtime, using a sine wave to animate radii and toggling styles periodically. ```csharp using UnityEngine; using IrakliChkuaseli.UI.UICorner; public class AnimatedCorners : MonoBehaviour { private UICorner uiCorner; private float time; void Start() { uiCorner = GetComponent(); } void Update() { time += Time.deltaTime; // Animate corner radii with sine wave float radius = 20f + Mathf.Sin(time * 2f) * 15f; uiCorner.r = new Vector4(radius, radius, radius, radius); // Toggle corner styles every 2 seconds if (Mathf.FloorToInt(time) % 2 == 0) { uiCorner.topLeft = CornerStyle.Rounded; uiCorner.topRight = CornerStyle.Rounded; } else { uiCorner.topLeft = CornerStyle.Chamfered; uiCorner.topRight = CornerStyle.Chamfered; } // Apply changes (automatically called by OnValidate in editor, // but needed for runtime modifications) uiCorner.Refresh(); } } ``` -------------------------------- ### Configure OpenUPM Scoped Registry for UICorner Source: https://github.com/irakli/ui-corner/blob/main/README.md Adds the UICorner package to a Unity project by configuring the `Packages/manifest.json` file to use the OpenUPM scoped registry. This method allows for version pinning. ```json { "scopedRegistries": [ { "name": "OpenUPM", "url": "https://package.openupm.com", "scopes": ["com.iraklichkuaseli"] } ], "dependencies": { "com.iraklichkuaseli.uicorner": "1.1.1" } } ``` -------------------------------- ### Create Mixed Corner Styles with UICorner Source: https://context7.com/irakli/ui-corner/llms.txt Illustrates how to combine different corner styles (Rounded and Chamfered) on a single UI element by setting specific radii and styles for each corner, creating unique visual designs. ```csharp using UnityEngine; using IrakliChkuaseli.UI.UICorner; public class MixedCornerCard : MonoBehaviour { void Start() { var uiCorner = gameObject.AddComponent(); // Create a card with rounded top corners and sharp bottom corners uiCorner.r = new Vector4( 20f, // topLeft 20f, // topRight 0f, // bottomRight - no rounding 0f // bottomLeft - no rounding ); uiCorner.topLeft = CornerStyle.Rounded; uiCorner.topRight = CornerStyle.Rounded; uiCorner.bottomRight = CornerStyle.Rounded; // Style doesn't matter when radius is 0 uiCorner.bottomLeft = CornerStyle.Rounded; uiCorner.Refresh(); } } ``` -------------------------------- ### React to UICorner Property Changes via C# API Source: https://github.com/irakli/ui-corner/blob/main/README.md Demonstrates how to subscribe to the `PropertiesChanged` event exposed by the `UICorner` component in Unity. This allows your scripts to react dynamically when corner properties are modified. ```csharp var uiCorner = GetComponent(); uiCorner.PropertiesChanged += () => { // React to corner property changes }; ``` -------------------------------- ### Interactive Button with Hover Effect (C#) Source: https://context7.com/irakli/ui-corner/llms.txt This script enhances a UI element to have a visual corner effect that changes on hover. It requires the UICorner component and implements Unity's IPointerEnterHandler and IPointerExitHandler interfaces. The script smoothly interpolates between normal and hover corner radii. ```csharp using UnityEngine; using UnityEngine.EventSystems; using IrakliChkuaseli.UI.UICorner; public class InteractiveButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler { private UICorner uiCorner; private Vector4 normalCorners = new Vector4(15f, 15f, 15f, 15f); private Vector4 hoverCorners = new Vector4(30f, 30f, 30f, 30f); private float transitionSpeed = 8f; private Vector4 targetCorners; void Start() { uiCorner = GetComponent(); if (uiCorner == null) { uiCorner = gameObject.AddComponent(); } // Initialize with normal state uiCorner.r = normalCorners; targetCorners = normalCorners; // All corners rounded uiCorner.topLeft = CornerStyle.Rounded; uiCorner.topRight = CornerStyle.Rounded; uiCorner.bottomRight = CornerStyle.Rounded; uiCorner.bottomLeft = CornerStyle.Rounded; } void Update() { // Smooth transition to target corner size uiCorner.r = Vector4.Lerp(uiCorner.r, targetCorners, Time.deltaTime * transitionSpeed); uiCorner.Refresh(); } public void OnPointerEnter(PointerEventData eventData) { targetCorners = hoverCorners; } public void OnPointerExit(PointerEventData eventData) { targetCorners = normalCorners; } } ``` -------------------------------- ### React to UICorner Property Changes with Events Source: https://context7.com/irakli/ui-corner/llms.txt Shows how to subscribe to the PropertiesChanged event of the UICorner component to react to corner modifications, such as updating a shadow component's distance based on corner radius changes. ```csharp using UnityEngine; using IrakliChkuaseli.UI.UICorner; public class CornerEventExample : MonoBehaviour { private UICorner uiCorner; void Start() { uiCorner = GetComponent(); // Subscribe to property changes uiCorner.PropertiesChanged += OnCornerPropertiesChanged; } private void OnCornerPropertiesChanged() { // React to corner radius or style changes Debug.Log("Corner properties updated"); // Example: Update a shadow component var shadow = GetComponent(); if (shadow != null) { shadow.effectDistance = new Vector2( uiCorner.r.x * 0.1f, uiCorner.r.x * 0.1f ); } } void OnDestroy() { if (uiCorner != null) { uiCorner.PropertiesChanged -= OnCornerPropertiesChanged; } } } ``` -------------------------------- ### SDF Shader Logic for UI Corners (HLSL) Source: https://context7.com/irakli/ui-corner/llms.txt This HLSL code implements the Signed Distance Field (SDF) logic for rendering UI corners. It supports both rounded and chamfered styles and includes functions for antialiasing and blending corner types. The `mixedBoxSDF` function is the core, calculating distances for various corner configurations. ```hlsl //UICornerSDF.cginc - Key functions // Calculate antialiased alpha cutoff for smooth edges float AntialiasedCutoff(float distance) { float distanceChange = fwidth(distance) * 0.5; return smoothstep(distanceChange, -distanceChange, distance); } // Per-corner mixed rounded/chamfered box SDF // p: Point to evaluate (centered coordinates) // b: Half-size of box // r: Corner radii (x=topLeft, y=topRight, z=bottomRight, w=bottomLeft) // cornerTypes: Corner styles (0=rounded, 1=chamfered for each corner) float mixedBoxSDF(float2 p, float2 b, float4 r, float4 cornerTypes) { const float SQRT2 = 1.414213562; // Quadrant-based corner selection (IQ's approach) r.xy = (p.x > 0.0) ? r.yz : r.xw; r.x = (p.y > 0.0) ? r.x : r.y; cornerTypes.xy = (p.x > 0.0) ? cornerTypes.yz : cornerTypes.xw; cornerTypes.x = (p.y > 0.0) ? cornerTypes.x : cornerTypes.y; // Work in first quadrant float2 q = abs(p); // Rounded corner (circular arc) - only 1 sqrt operation float2 qRounded = q - b + r.x; float roundedDist = min(max(qRounded.x, qRounded.y), 0.0) + length(max(qRounded, 0.0)) - r.x; // Chamfered corner (45-degree diagonal cut) - no sqrt needed float2 cornerOffset = q - b; float chamferLineDist = (cornerOffset.x + cornerOffset.y + r.x) / SQRT2; float edgeDist = max(cornerOffset.x, cornerOffset.y); float chamferDist = max(edgeDist, chamferLineDist); // Blend between styles based on cornerType (0=rounded, 1=chamfered) return lerp(roundedDist, chamferDist, cornerTypes.x); } // Main entry point called from fragment shader float CalcAlphaForUICorner(float2 samplePosition, float2 halfSize, float4 rect2props, float4 r, float4 cornerTypes) { float2 p = (samplePosition - 0.5) * halfSize * 2.0; float distance = mixedBoxSDF(p, halfSize, r, cornerTypes); return AntialiasedCutoff(distance); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.