2026-03-24 11:39:01 +08:00

113 lines
2.7 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace SuperScrollView.AI
{
public enum MsgTypeEnum
{
Str = 0,
Picture,
Count,
}
public class PersonInfo
{
public int mId;
public string mName;
public Sprite mHeadIcon;
}
public class ChatMsg
{
public int mPersonId;
public MsgTypeEnum mMsgType;
public string mSrtMsg;
public Sprite mPicMsgSprite;
}
public class ChatMsgDataSourceMgr : MonoBehaviour
{
Dictionary<int, PersonInfo> mPersonInfoDict = new Dictionary<int, PersonInfo>();
List<ChatMsg> mChatMsgList = new List<ChatMsg>();
static ChatMsgDataSourceMgr instance = null;
public Sprite[] headIcons;
public static ChatMsgDataSourceMgr Get
{
get
{
if (instance == null)
{
instance = Object.FindObjectOfType<ChatMsgDataSourceMgr>();
}
return instance;
}
}
void Awake()
{
Init();
}
public PersonInfo GetPersonInfo(int personId)
{
PersonInfo ret = null;
if(mPersonInfoDict.TryGetValue(personId, out ret))
{
return ret;
}
return null;
}
public void Init()
{
mPersonInfoDict.Clear();
PersonInfo tInfo = new PersonInfo();
tInfo.mHeadIcon = headIcons[0];
tInfo.mId = 0;
tInfo.mName = "小智";
mPersonInfoDict.Add(tInfo.mId, tInfo);
tInfo = new PersonInfo();
tInfo.mHeadIcon = headIcons[1];
tInfo.mId = 1;
tInfo.mName = "您";
mPersonInfoDict.Add(tInfo.mId, tInfo);
InitChatDataSource();
}
public ChatMsg GetChatMsgByIndex(int index)
{
if (index < 0 || index >= mChatMsgList.Count)
{
return null;
}
return mChatMsgList[index];
}
public int TotalItemCount
{
get
{
return mChatMsgList.Count;
}
}
void InitChatDataSource()
{
mChatMsgList.Clear();
}
public void AppendOneMsg(int personId,MsgTypeEnum msgTypeEnum,string str,Sprite sprite = null)
{
ChatMsg tMsg = new ChatMsg();
tMsg.mMsgType = msgTypeEnum;
tMsg.mPersonId = personId;
tMsg.mSrtMsg = str;
tMsg.mPicMsgSprite = sprite;
mChatMsgList.Add(tMsg);
}
}
}