BITFALL/Assets/Artists/Scripts/Entity/Inventory/PlayerInventoryService.cs

41 lines
1.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using BITKit;
using BITKit.Entities;
using UnityEngine;
#if GameDesigner && UNITY
namespace BITFALL
{
/// <summary>
/// 玩家背包服务
/// </summary>
public class PlayerInventoryService : MonoBehaviour
{
public bool ServerAddItem(IEntity entity,IBasicItem item)
{
var unityEntity = entity as Entity;
//如果获取到entity包括了物品容器背包组件
//在服务器上处理添加物品的行为
if (!unityEntity!.TryGetComponent<IBasicItemContainer>(out var inventory)) return false;
if (!inventory.Add(item)) return false;
RpcAddItem(entity, item);
return true;
}
public bool RpcAddItem(IEntity entity, IBasicItem item)
{
var unityEntity = entity as Entity;
//在客户端上处理添加物品的行为
if (unityEntity!.TryGetComponent<IBasicItemContainer>(out var inventory))
{
inventory.Add(item);
return true;
}
return false;
}
}
}
#endif