From 5e11329b86401432adc46f5ea9942499594b33aa Mon Sep 17 00:00:00 2001 From: shenjianxing <”315615051@qq.com“> Date: Thu, 8 May 2025 17:21:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=BA=BA=E7=89=A9=E6=8E=A7?= =?UTF-8?q?=E5=88=B6=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/Controller/PlayerController.cs | 45 +++++++++++++++++++ .../Controller/PlayerController.cs.meta | 11 +++++ Assets/Scripts/Xml/XmlParser.cs | 2 + 3 files changed, 58 insertions(+) create mode 100644 Assets/Scripts/Controller/PlayerController.cs create mode 100644 Assets/Scripts/Controller/PlayerController.cs.meta diff --git a/Assets/Scripts/Controller/PlayerController.cs b/Assets/Scripts/Controller/PlayerController.cs new file mode 100644 index 00000000..d9bb945b --- /dev/null +++ b/Assets/Scripts/Controller/PlayerController.cs @@ -0,0 +1,45 @@ +using QFramework; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using XMLTool; + +public class PlayerController : MonoSingleton +{ + private PlayerController() { } + + public class HasDevice + { + public Device device; + public int count; + } + + + Dictionary hasDevices = new Dictionary(); + + public void DropDevice(string key, int count = 1) + { + if (hasDevices.ContainsKey(key)) + { + hasDevices[key].count -= count; + if (hasDevices[key].count <= 0) + { + hasDevices.Remove(key); + } + } + } + + public void PickDevice(string key, int count = 1) + { + if (hasDevices.ContainsKey(key)) + { + hasDevices[(string)key].count += count; + } + else + { + hasDevices.Add(key, new HasDevice() { count = count, device = DeviceController.Instance.GetDevice(key) }); + } + + } + +} diff --git a/Assets/Scripts/Controller/PlayerController.cs.meta b/Assets/Scripts/Controller/PlayerController.cs.meta new file mode 100644 index 00000000..5daecb62 --- /dev/null +++ b/Assets/Scripts/Controller/PlayerController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d963e03aaa61c0241a2a7b3a8e7bf611 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Xml/XmlParser.cs b/Assets/Scripts/Xml/XmlParser.cs index ebc95d0e..f7cd8253 100644 --- a/Assets/Scripts/Xml/XmlParser.cs +++ b/Assets/Scripts/Xml/XmlParser.cs @@ -58,6 +58,8 @@ namespace XMLTool public string BoxColliderCenter { get; set; } public bool MeshCollider { get; set; } + + public int Count = -1; }