Documentation for Modular Female Character System
### Documentation for ModularFemaleCharacter System
#### Overview
The `ModularFemaleCharacter` system is designed to provide a flexible and modular way to handle character customization in Unity. This system allows for various parts of a character (such as bottoms, tops, glasses, hair, and shoes) to be toggled on or off, enabling the creation of numerous character variations.
#### Components
1. **CharacterProperties Structure**
2. **ModularFemaleCharacter Class**
#### CharacterProperties Structure
The `CharacterProperties` structure holds the references and indices for the various character parts. Each part is represented by a `Transform` and an `int` index, which indicates the active child under the `Transform`.
##### Fields:
- `bottomTransform`: Transform containing bottom part variations.
- `bottomIndex`: Index of the active bottom part (0-4).
- `topTransform`: Transform containing top part variations.
- `topIndex`: Index of the active top part (0-4).
- `glassesTransform`: Transform containing glasses variations.
- `glassesIndex`: Index of the active glasses (0-2).
- `hairTransform`: Transform containing hair variations.
- `hairIndex`: Index of the active hair (0-6).
- `shoesTransform`: Transform containing shoes variations.
- `shoesIndex`: Index of the active shoes (0-4).
#### ModularFemaleCharacter Class
The `ModularFemaleCharacter` class is responsible for initializing and managing the character properties defined in `CharacterProperties`.
##### Methods:
- **Start()**
- Calls `Init` to set initial character part states based on `characterProperties`.
- **Init()**
- Sets the initial state of each character part using their respective indices.
- **OnValidate()**
- Ensures that any changes made in the Unity editor are immediately reflected.
- **ActivateSelected(Transform t, int value)**
- Deactivates all child objects under the given `Transform`, then activates the child at the specified index.
- **SetBottomIndex(int value)**
- Sets the active bottom part based on the provided index.
- **SetTopIndex(int value)**
- Sets the active top part based on the provided index.
- **SetGlassesIndex(int value)**
- Sets the active glasses based on the provided index.
- **SetHairIndex(int value)**
- Sets the active hair based on the provided index.
- **SetShoesIndex(int value)**
- Sets the active shoes based on the provided index.
#### Usage
1. Attach the `ModularFemaleCharacter` script to a GameObject in the Unity Editor.
2. Assign the relevant Transforms to the `CharacterProperties` fields.
3. Set the initial indices for each part as desired.
4. Run the scene to see the character with the specified parts active.
5. Use the public methods (`SetBottomIndex`, `SetTopIndex`, etc.) to dynamically change the character's appearance at runtime.
This setup allows for a highly customizable character system, ideal for games or applications requiring dynamic character customization.
Comments
Post a Comment