|
| 1 | +# Yahalom UI Components |
| 2 | + |
| 3 | +A custom Unity UI component library for MapColonies projects with built-in Hebrew (RTL) language support. |
| 4 | + |
| 5 | +**Package:** `com.mapcolonies.yahalom-ui` |
| 6 | +**Version:** 1.0.2 |
| 7 | +**Minimum Unity Version:** 6000.1 |
| 8 | + |
| 9 | +## Table of Contents |
| 10 | + |
| 11 | +- [Installation](#installation) |
| 12 | +- [Package Structure](#package-structure) |
| 13 | +- [UI Components](#ui-components) |
| 14 | + - [YahalomButton](#yahalombutton) |
| 15 | + - [Compass](#compass) |
| 16 | +- [Fonts](#fonts) |
| 17 | +- [Testing](#testing) |
| 18 | +- [API Reference](#api-reference) |
| 19 | + |
| 20 | +--- |
| 21 | + |
| 22 | +## Installation |
| 23 | + |
| 24 | +### Option 1: Git URL (Recommended) |
| 25 | + |
| 26 | +Add to your `Packages/manifest.json`: |
| 27 | + |
| 28 | +```json |
| 29 | +{ |
| 30 | + "dependencies": { |
| 31 | + "com.mapcolonies.yahalom-ui": "https://github.com/MapColonies/yahalom-ui-components.git?path=Assets/YahalomUIPackage" |
| 32 | + } |
| 33 | +} |
| 34 | +``` |
| 35 | + |
| 36 | +### Option 2: Local Package |
| 37 | + |
| 38 | +1. Copy the `YahalomUIPackage` folder to your project's `Packages` directory |
| 39 | +2. Unity will automatically detect and import the package |
| 40 | + |
| 41 | +--- |
| 42 | + |
| 43 | +## Package Structure |
| 44 | + |
| 45 | +``` |
| 46 | +YahalomUIPackage/ |
| 47 | +├── Runtime/ |
| 48 | +│ ├── YahalomButton/ |
| 49 | +│ │ └── YahalomButton.cs # Button component script |
| 50 | +│ ├── Compass/ |
| 51 | +│ │ └── Compass.cs # Compass component script |
| 52 | +│ └── Resources/ |
| 53 | +│ ├── YahalomButton/ |
| 54 | +│ │ └── YahalomButton.prefab # Button prefab |
| 55 | +│ └── Compass/ |
| 56 | +│ └── Compass.prefab # Compass prefab |
| 57 | +├── Editor/ |
| 58 | +│ └── YahalomButton/ |
| 59 | +│ └── YahalomButtonEditor.cs # Custom inspector |
| 60 | +├── Fonts/ # Hebrew fonts (NotoSansHebrew) |
| 61 | +├── UI/PNG/ # UI sprite assets |
| 62 | +├── Atlas/ # Sprite atlas |
| 63 | +└── package.json # Package configuration |
| 64 | +``` |
| 65 | + |
| 66 | +--- |
| 67 | + |
| 68 | +## UI Components |
| 69 | + |
| 70 | +### YahalomButton |
| 71 | + |
| 72 | +A customizable button component with state-based color transitions for text and icons, supporting RTL text. |
| 73 | + |
| 74 | +**Location:** `Runtime/YahalomButton/YahalomButton.cs` |
| 75 | +**Prefab:** `Runtime/Resources/YahalomButton/YahalomButton.prefab` |
| 76 | + |
| 77 | +#### Features |
| 78 | + |
| 79 | +- Extends Unity's native `Button` class |
| 80 | +- Separate color configurations for text and icon per state |
| 81 | +- Smooth color transitions with configurable fade duration |
| 82 | +- RTL text support via TextMeshPro |
| 83 | +- Custom inspector for easy configuration |
| 84 | + |
| 85 | +#### Button States |
| 86 | + |
| 87 | +| State | Description | |
| 88 | +|-------|-------------| |
| 89 | +| Normal | Default appearance | |
| 90 | +| Highlighted | Hover/focus state | |
| 91 | +| Pressed | Click/tap state | |
| 92 | +| Selected | Selected state | |
| 93 | +| Disabled | Inactive state | |
| 94 | + |
| 95 | +#### Usage |
| 96 | + |
| 97 | +**Adding to Scene:** |
| 98 | + |
| 99 | +1. **Via Prefab:** Drag `YahalomButton.prefab` from `Runtime/Resources/YahalomButton/` into your Canvas |
| 100 | +2. **Via Code:** |
| 101 | + ```csharp |
| 102 | + var buttonPrefab = Resources.Load<GameObject>("YahalomButton/YahalomButton"); |
| 103 | + var button = Instantiate(buttonPrefab, parentCanvas.transform); |
| 104 | + ``` |
| 105 | + |
| 106 | +**Configuring in Inspector:** |
| 107 | + |
| 108 | +1. Select the YahalomButton in the hierarchy |
| 109 | +2. In the Inspector, configure: |
| 110 | + - **Text Mesh:** Reference to the TextMeshProUGUI component |
| 111 | + - **Icon:** Reference to the icon Image component |
| 112 | + - **Text Colors:** Set colors for each button state |
| 113 | + - **Icon Colors:** Set colors for each button state |
| 114 | + - **Fade Duration:** Transition time between states (default: 0.1s) |
| 115 | + |
| 116 | +#### Prefab Hierarchy |
| 117 | + |
| 118 | +``` |
| 119 | +YahalomButton (Button, Image, HorizontalLayoutGroup) |
| 120 | +├── Text - RTLTMP (TextMeshProUGUI) |
| 121 | +└── Icon (Image) |
| 122 | +``` |
| 123 | + |
| 124 | +--- |
| 125 | + |
| 126 | +### Compass |
| 127 | + |
| 128 | +A navigation compass component displaying heading direction, angle, and geographic coordinates. |
| 129 | + |
| 130 | +**Location:** `Runtime/Compass/Compass.cs` |
| 131 | +**Prefab:** `Runtime/Resources/Compass/Compass.prefab` |
| 132 | + |
| 133 | +#### Features |
| 134 | + |
| 135 | +- 8-point directional system (N, NE, E, SE, S, SW, W, NW) |
| 136 | +- Smooth angle interpolation |
| 137 | +- Latitude/Longitude coordinate display |
| 138 | +- Debug mode for testing |
| 139 | +- Auto-rotating direction labels |
| 140 | + |
| 141 | +#### Usage |
| 142 | + |
| 143 | +**Adding to Scene:** |
| 144 | + |
| 145 | +1. **Via Prefab:** Drag `Compass.prefab` from `Runtime/Resources/Compass/` into your Canvas |
| 146 | +2. **Via Code:** |
| 147 | + ```csharp |
| 148 | + var compassPrefab = Resources.Load<GameObject>("Compass/Compass"); |
| 149 | + var compass = Instantiate(compassPrefab, parentCanvas.transform); |
| 150 | + ``` |
| 151 | + |
| 152 | +**Controlling the Compass:** |
| 153 | + |
| 154 | +```csharp |
| 155 | +using YahalomUIPackage.Runtime.Compass; |
| 156 | + |
| 157 | +// Get reference to compass component |
| 158 | +Compass compass = GetComponent<Compass>(); |
| 159 | + |
| 160 | +// Set heading (0-360 degrees, 0 = North) |
| 161 | +compass.SetHeading(45f); // Points NE |
| 162 | +
|
| 163 | +// Set coordinates |
| 164 | +compass.SetCoordinates(new Vector2(35.2150f, 31.7825f)); // (longitude, latitude) |
| 165 | +``` |
| 166 | + |
| 167 | +#### Public API |
| 168 | + |
| 169 | +| Method | Parameters | Description | |
| 170 | +|--------|------------|-------------| |
| 171 | +| `SetHeading(float)` | `heading`: 0-360 degrees | Updates compass rotation and direction text | |
| 172 | +| `SetCoordinates(Vector2)` | `latLong`: x=longitude, y=latitude | Updates coordinate display | |
| 173 | + |
| 174 | +#### Inspector Properties |
| 175 | + |
| 176 | +| Property | Description | |
| 177 | +|----------|-------------| |
| 178 | +| Compass Transform | Reference to the rotating compass RectTransform | |
| 179 | +| Angle Text | TextMeshPro for heading display (e.g., "45°NE") | |
| 180 | +| Coordinates Text | TextMeshPro for lat/long display | |
| 181 | +| Directions Text | Array of 4 cardinal direction labels (N, E, S, W) | |
| 182 | +| Start Angle | Offset angle for compass rotation | |
| 183 | +| Smooth Time | Interpolation smoothness (default: 0.1s) | |
| 184 | +| Enable Debug Slider | Toggle debug mode in editor | |
| 185 | +| Debug Angle | Manual angle control (0-360) | |
| 186 | +| Debug Coordinates | Manual coordinate input | |
| 187 | + |
| 188 | +--- |
| 189 | + |
| 190 | +## Fonts |
| 191 | + |
| 192 | +The package includes **NotoSansHebrew** fonts for Hebrew language support: |
| 193 | + |
| 194 | +| Font Weight | Files | |
| 195 | +|-------------|-------| |
| 196 | +| ExtraLight | `NotoSansHebrew-ExtraLight.ttf`, `.asset` | |
| 197 | +| Medium | `NotoSansHebrew-Medium.ttf`, `.asset` | |
| 198 | +| SemiBold | `NotoSansHebrew-SemiBold.ttf`, `.asset` | |
| 199 | + |
| 200 | +**Location:** `Fonts/` |
| 201 | + |
| 202 | +These fonts are pre-configured as TextMesh Pro SDF assets for high-quality text rendering. |
| 203 | + |
| 204 | +--- |
| 205 | + |
| 206 | +## Testing |
| 207 | + |
| 208 | +### Testing in the Sample Scene |
| 209 | + |
| 210 | +1. Open the sample scene: `Assets/Scenes/SampleScene.unity` |
| 211 | +2. Add UI components from the package to test |
| 212 | + |
| 213 | +### Testing YahalomButton |
| 214 | + |
| 215 | +1. Create a Canvas in your scene (`GameObject > UI > Canvas`) |
| 216 | +2. Drag the `YahalomButton.prefab` into the Canvas |
| 217 | +3. Enter Play Mode |
| 218 | +4. Interact with the button to verify: |
| 219 | + - Hover state (mouse over) |
| 220 | + - Click state (mouse down) |
| 221 | + - Normal state (mouse exit) |
| 222 | + - Disabled state (disable the button via Inspector) |
| 223 | + |
| 224 | +**Verifying Color Transitions:** |
| 225 | +- Observe text and icon color changes between states |
| 226 | +- Adjust fade duration to test transition smoothness |
| 227 | + |
| 228 | +### Testing Compass |
| 229 | + |
| 230 | +1. Create a Canvas in your scene |
| 231 | +2. Drag the `Compass.prefab` into the Canvas |
| 232 | +3. Enable **Debug Mode** in the Compass Inspector: |
| 233 | + - Check "Enable Debug Slider" |
| 234 | + - Use the "Debug Angle" slider (0-360) to rotate the compass |
| 235 | + - Modify "Debug Coordinates" to test coordinate display |
| 236 | +4. Enter Play Mode to see live updates |
| 237 | + |
| 238 | +**Testing via Script:** |
| 239 | + |
| 240 | +```csharp |
| 241 | +using UnityEngine; |
| 242 | +using YahalomUIPackage.Runtime.Compass; |
| 243 | + |
| 244 | +public class CompassTester : MonoBehaviour |
| 245 | +{ |
| 246 | + public Compass compass; |
| 247 | + |
| 248 | + void Update() |
| 249 | + { |
| 250 | + // Rotate compass based on time |
| 251 | + float heading = (Time.time * 30f) % 360f; |
| 252 | + compass.SetHeading(heading); |
| 253 | + |
| 254 | + // Set test coordinates |
| 255 | + compass.SetCoordinates(new Vector2(35.2150f, 31.7825f)); |
| 256 | + } |
| 257 | +} |
| 258 | +``` |
| 259 | + |
| 260 | +### Running Unit Tests |
| 261 | + |
| 262 | +The project includes test assemblies for automated testing: |
| 263 | + |
| 264 | +1. Open the Test Runner: `Window > General > Test Runner` |
| 265 | +2. Run **Play Mode Tests** for runtime behavior testing |
| 266 | +3. Run **Edit Mode Tests** for editor functionality testing |
| 267 | + |
| 268 | +--- |
| 269 | + |
| 270 | +## API Reference |
| 271 | + |
| 272 | +### YahalomButton |
| 273 | + |
| 274 | +**Namespace:** `YahalomUIPackage.Runtime.YahalomButton` |
| 275 | + |
| 276 | +```csharp |
| 277 | +public class YahalomButton : Button |
| 278 | +{ |
| 279 | + // Serialized Fields (configurable in Inspector) |
| 280 | + [SerializeField] private TextMeshProUGUI _textMesh; |
| 281 | + [SerializeField] private Image _icon; |
| 282 | + |
| 283 | + // Text color states |
| 284 | + [SerializeField] private Color _normalTextColor; |
| 285 | + [SerializeField] private Color _highlightedTextColor; |
| 286 | + [SerializeField] private Color _pressedTextColor; |
| 287 | + [SerializeField] private Color _selectedTextColor; |
| 288 | + [SerializeField] private Color _disabledTextColor; |
| 289 | + |
| 290 | + // Icon color states |
| 291 | + [SerializeField] private Color _normalIconColor; |
| 292 | + [SerializeField] private Color _highlightedIconColor; |
| 293 | + [SerializeField] private Color _pressedIconColor; |
| 294 | + [SerializeField] private Color _selectedIconColor; |
| 295 | + [SerializeField] private Color _disabledIconColor; |
| 296 | + |
| 297 | + // Transition settings |
| 298 | + [SerializeField] private float _fadeDuration = 0.1f; |
| 299 | +} |
| 300 | +``` |
| 301 | + |
| 302 | +### Compass |
| 303 | + |
| 304 | +**Namespace:** `YahalomUIPackage.Runtime.Compass` |
| 305 | + |
| 306 | +```csharp |
| 307 | +public class Compass : MonoBehaviour |
| 308 | +{ |
| 309 | + // Public Methods |
| 310 | + public void SetHeading(float heading); |
| 311 | + public void SetCoordinates(Vector2 latLong); |
| 312 | + |
| 313 | + // Inspector Properties |
| 314 | + [SerializeField] private RectTransform _compassTransform; |
| 315 | + [SerializeField] private TextMeshProUGUI _angleText; |
| 316 | + [SerializeField] private TextMeshProUGUI _coordinatesText; |
| 317 | + [SerializeField] private TextMeshProUGUI[] _directionsText; |
| 318 | + [SerializeField] private float _startAngle; |
| 319 | + [SerializeField] private float _smoothTime = 0.1f; |
| 320 | + |
| 321 | + // Debug Properties |
| 322 | + [SerializeField] private bool _enableDebugSlider; |
| 323 | + [SerializeField] private float _debugAngle; |
| 324 | + [SerializeField] private Vector2 _debugCoordinates; |
| 325 | +} |
| 326 | +``` |
| 327 | + |
| 328 | +--- |
| 329 | + |
| 330 | +## Sprite Assets |
| 331 | + |
| 332 | +**Location:** `UI/PNG/` |
| 333 | + |
| 334 | +### MainButton Sprites |
| 335 | +- `primary_button_default.png` - Normal state |
| 336 | +- `primary_button_hover.png` - Highlighted state |
| 337 | +- `primary_button_click.png` - Pressed state |
| 338 | +- `primary_button_disabled.png` - Disabled state |
| 339 | + |
| 340 | +### Compass Sprites |
| 341 | +- `Compass_BG@2x.png` - Compass background |
| 342 | +- `Compass lines@2x.png` - Compass rose/direction lines |
| 343 | + |
| 344 | +**Sprite Atlas:** `Atlas/MainUIAtlas.spriteatlasv2` - Optimized sprite collection |
| 345 | + |
| 346 | +--- |
| 347 | + |
| 348 | +## Dependencies |
| 349 | + |
| 350 | +- TextMesh Pro (included with Unity) |
| 351 | +- RTLTMPro (for RTL text support) |
| 352 | + |
| 353 | +--- |
| 354 | + |
| 355 | +## Changelog |
| 356 | + |
| 357 | +See [CHANGELOG.md](../../CHANGELOG.md) for version history. |
| 358 | + |
| 359 | +--- |
| 360 | + |
| 361 | +## Support |
| 362 | + |
| 363 | +For issues or feature requests, please contact the MapColonies team or submit an issue to the repository. |
0 commit comments