76 lines
3.0 KiB
C#
76 lines
3.0 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using TMPro;
|
||
using UnityEngine;
|
||
|
||
namespace BrewMonster.Scripts.Chat.EmotionData
|
||
{
|
||
/// <summary>
|
||
/// Snapshot một bộ Emotions{N} (dùng embed trong EmotionLibrarySO hoặc copy sang EmotionSetDataSO).
|
||
/// One Emotions{N} snapshot (embedded in EmotionLibrarySO or copied to EmotionSetDataSO).
|
||
/// </summary>
|
||
[Serializable]
|
||
public class EmotionSetSnapshot
|
||
{
|
||
public int EmotionSetIndex;
|
||
public int CellWidth = 32;
|
||
public int CellHeight = 32;
|
||
public Texture2D SourceAtlas;
|
||
public string SourceTxtAssetPath = "";
|
||
|
||
[Tooltip("TMP_SpriteAsset tương ứng với atlas này (cell_0000…). Bắt buộc cho emoji động (nhiều frame). " +
|
||
"TMP_SpriteAsset matching this atlas (cell_0000…). Required for animated emoji (multi-frame).")]
|
||
public TMP_SpriteAsset TmpSpriteAsset;
|
||
|
||
[Tooltip("Bản sao tên asset (khớp TmpSpriteAsset.name) — dùng khi build tag chat từ thread mạng; không được đọc TmpSpriteAsset.name ngoài main thread. " +
|
||
"Cached asset name (matches TmpSpriteAsset.name) — used when building chat tags from the network thread; never read TmpSpriteAsset.name off the main thread.")]
|
||
public string TmpSpriteAssetName = "";
|
||
|
||
public List<EmotionEntryData> Entries = new List<EmotionEntryData>();
|
||
}
|
||
|
||
/// <summary>
|
||
/// Một ScriptableObject chứa nhiều bộ emotion (vd. emotions0–emotions7).
|
||
/// Single SO holding multiple emotion sets (e.g. all 8 atlases).
|
||
/// </summary>
|
||
[CreateAssetMenu(fileName = "EmotionLibrary", menuName = "Perfect World/Chat/Emotion Library (All Sets)", order = 1)]
|
||
public class EmotionLibrarySO : ScriptableObject
|
||
{
|
||
[Tooltip("Danh sách các bộ theo EmotionSetIndex (0,1,2,…).")]
|
||
public List<EmotionSetSnapshot> Sets = new List<EmotionSetSnapshot>();
|
||
|
||
private void OnValidate()
|
||
{
|
||
SyncCachedTmpSpriteAssetNamesFromObjects();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 把各 set 的 TmpSpriteAsset.name 写入 TmpSpriteAssetName(仅应在主线程调用,例如 Awake / OnValidate)。
|
||
/// Writes each set's TmpSpriteAsset.name into TmpSpriteAssetName (call from main thread only, e.g. Awake / OnValidate).
|
||
/// </summary>
|
||
public void SyncCachedTmpSpriteAssetNamesFromObjects()
|
||
{
|
||
if (Sets == null)
|
||
return;
|
||
foreach (EmotionSetSnapshot s in Sets)
|
||
{
|
||
if (s == null)
|
||
continue;
|
||
s.TmpSpriteAssetName = s.TmpSpriteAsset != null ? s.TmpSpriteAsset.name : string.Empty;
|
||
}
|
||
}
|
||
|
||
public EmotionSetSnapshot GetSetOrNull(int emotionSetIndex)
|
||
{
|
||
if (Sets == null) return null;
|
||
foreach (var s in Sets)
|
||
{
|
||
if (s != null && s.EmotionSetIndex == emotionSetIndex)
|
||
return s;
|
||
}
|
||
|
||
return null;
|
||
}
|
||
}
|
||
}
|