提交示例代码
This commit is contained in:
47
邮件系统课程完整代码/Server/Hotfix/Mail/Helper/MailFactory.cs
Normal file
47
邮件系统课程完整代码/Server/Hotfix/Mail/Helper/MailFactory.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using Fantasy.Entitas;
|
||||
using Fantasy.Serialize;
|
||||
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
|
||||
|
||||
namespace Fantasy;
|
||||
|
||||
public static class MailFactory
|
||||
{
|
||||
public static readonly ISerialize Serializer = SerializerManager.GetSerializer(FantasySerializerType.Bson);
|
||||
|
||||
/// <summary>
|
||||
/// 创建一个基础的邮件
|
||||
/// </summary>
|
||||
/// <param name="scene"></param>
|
||||
/// <param name="title"></param>
|
||||
/// <param name="content"></param>
|
||||
/// <param name="money"></param>
|
||||
/// <param name="items"></param>
|
||||
/// <param name="mailType"></param>
|
||||
/// <returns></returns>
|
||||
public static Mail Create(Scene scene, MailType mailType, string title, string content, int money = 0, List<Item> items = null)
|
||||
{
|
||||
var mail = Entity.Create<Mail>(scene, true, true);
|
||||
mail.Title = title;
|
||||
mail.Content = content;
|
||||
mail.Money = money;
|
||||
mail.MailType = mailType;
|
||||
mail.MailState = MailState.Unread;
|
||||
|
||||
// if (items is not { Count: > 0 })
|
||||
// {
|
||||
//
|
||||
// }
|
||||
if (items != null && items.Count > 0)
|
||||
{
|
||||
foreach (var item in items)
|
||||
{
|
||||
// 最好的是要个这个Item给克隆出一份来。
|
||||
// 这样就可以保证,无论外面怎么改变也不会影响这个邮件的东西了。
|
||||
var cloneItem = Serializer.Clone(item);
|
||||
mail.Items.Add(cloneItem);
|
||||
}
|
||||
}
|
||||
|
||||
return mail;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user