# Character

## 🧍 Character Class

Represents a character that can speak, display emotions, and interact with localized systems in the **FeelSpeak** framework.

> Namespace: `Esper.FeelSpeak`\
> Inherits from: `FeelSpeakObject`\
> \
> Type: `class`

***

### 📦 Fields

| Access   | Field                    | Type                     | Description                                                       |
| -------- | ------------------------ | ------------------------ | ----------------------------------------------------------------- |
| `public` | `sprite`                 | `Sprite`                 | The base sprite that represents the character.                    |
| `public` | `idleSpriteAnimation`    | `SpriteAnimation`        | The base sprite animation of the character when not talking.      |
| `public` | `talkingSpriteAnimation` | `SpriteAnimation`        | The base sprite animation of the character when talking.          |
| `public` | `localizedDisplayNames`  | `List<LocaleString>`     | A list of localized names.                                        |
| `public` | `characterName`          | `string`                 | Used when localization is disabled and/or for searching purposes. |
| `public` | `textSound`              | `AudioClip`              | The sound that plays for each dialogue character.                 |
| `public` | `textColor`              | `Color`                  | The text color of this character.                                 |
| `public` | `characterEmotions`      | `List<CharacterEmotion>` | All character emotion data.                                       |

***

### 🧾 Properties

| Access   | Property         | Type              | Description                                      |
| -------- | ---------------- | ----------------- | ------------------------------------------------ |
| `public` | `DatabaseRecord` | `CharacterRecord` | Snapshot of the character data for the database. |

***

### 📁 Static Fields

| Access          | Field           | Type     | Description                                                                 |
| --------------- | --------------- | -------- | --------------------------------------------------------------------------- |
| `public static` | `resourcesPath` | `string` | Path to all generated character objects relative to the `Resources` folder. |

***

### 🧰 Methods

| Access   | Method                                                        | Returns            | Description                                                                                                                           |
| -------- | ------------------------------------------------------------- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------- |
| `public` | `UpdateDatabaseRecord()`                                      | `void`             | Updates the record of this object in the database.                                                                                    |
| `public` | `GetSpriteAnimation(bool isSpeaking, Emotion emotion = null)` | `SpriteAnimation`  | Gets a sprite animation for the specific emotion if available. If emotion is null, the base animations will be returned if available. |
| `public` | `CreateCopy()`                                                | `Character`        | Creates a copy of this character.                                                                                                     |
| `public` | `CopyData(Character other)`                                   | `void`             | Copies all data from another character (excluding ID).                                                                                |
| `public` | `GetName()`                                                   | `string`           | Gets the character name for the selected locale or the fallback name.                                                                 |
| `public` | `GetCharacterEmotion(Emotion emotion)`                        | `CharacterEmotion` | Gets the character emotion settings by an emotion.                                                                                    |
| `public` | `GetSprite(Emotion emotion = null)`                           | `Sprite`           | Gets the sprite associated with the given emotion, or the default.                                                                    |
| `public` | `GetEmotionSoundOverride(Emotion emotion)`                    | `AudioClip`        | Returns the sound override for the specified emotion, if any.                                                                         |
| `public` | `GetTextSoundOverride(Emotion emotion)`                       | `AudioClip`        | Returns the text sound override for the specified emotion, if any.                                                                    |
| `public` | `GetAnimationNameOverride(Emotion emotion)`                   | `string`           | Returns the animation name override for the specified emotion, or empty string.                                                       |
| `public` | `GetAnimationOverride(Emotion emotion)`                       | `(string, int)`    | Returns the animation name and layer index override for the specified emotion, or an empty string and -1.                             |
| `public` | `ValidateLocalizedNames(bool skipInitialization = false)`     | `void`             | Ensures all locales have a corresponding display name.                                                                                |
| `public` | `RebuildCharacterEmotionsList(List<Emotion> emotions)`        | `void`             | Rebuilds the emotion list from a given list of emotions.                                                                              |

***

### 🧩 Nested Structs

#### `public struct CharacterEmotion`

Represents emotion-specific overrides for this character.

| Access   | Field                    | Type              | Description                                             |
| -------- | ------------------------ | ----------------- | ------------------------------------------------------- |
| `public` | `emotion`                | `Emotion`         | The emotion reference.                                  |
| `public` | `sprite`                 | `Sprite`          | Sprite for this emotion.                                |
| `public` | `idleSpriteAnimation`    | `SpriteAnimation` | The sprite animation for this emotion when not talking. |
| `public` | `talkingSpriteAnimation` | `SpriteAnimation` | The sprite animation for this emotion when talking.     |
| `public` | `soundOverride`          | `AudioClip`       | Optional override for the emotion sound.                |
| `public` | `textSoundOverride`      | `AudioClip`       | Optional override for the text sound.                   |
| `public` | `animationNameOverride`  | `string`          | Optional override for the animation name.               |
| `public` | `animationLayerOveride`  | `int`             | Optional override for the animation layer index.        |

## Getting a Character

You can get a `Character` at runtime with their ID or name with the `FeelSpeak.GetCharacter` method.

```csharp
var myCharacter = FeelSpeak.GetCharacter("character name");
```
