using QFramework; using System.Collections; using System.Collections.Generic; using UnityEngine; using XMLTool; public class PlayerController : MonoSingleton { private PlayerController() { } public class HasDeviceData { public Device device; public int count; } public Dictionary hasDevicesDict = new Dictionary(); public int DropDevice(string key, int count = 1) { if (hasDevicesDict.ContainsKey(key)) { var dev = hasDevicesDict[key]; dev.count -= count; if (dev.count <= 0) { hasDevicesDict.Remove(key); return 0; } return dev.count; } return -1; } public void PickDevice(string key, int count = 1) { Device device = null; if (hasDevicesDict.ContainsKey(key)) { device = hasDevicesDict[key].device; hasDevicesDict[key].count += count; } else { device = DeviceController.Instance.GetDevice(key); hasDevicesDict.Add(key, new HasDeviceData() { count = count, device = device }); } TypeEventSystem.Global.Send(new OnPickDevice() { device = device, count = count }); } public HasDeviceData HasDevice(string key) { if (hasDevicesDict.ContainsKey(key)) { var dev = hasDevicesDict[key]; if (dev.count > 0) { return dev; } } return null; } }