From 1e4643f20f204f6fa60842f930b031f8135b1398 Mon Sep 17 00:00:00 2001 From: CortexCore <2630229280@qq.com> Date: Thu, 26 Jun 2025 23:34:50 +0800 Subject: [PATCH] 1 --- Src/Health/HealthService.cs | 20 ++- Src/Health/KnockedService.cs | 12 +- Src/PlayerAction.meta | 8 ++ .../Net.Project.B.PlayerAction.asmdef | 18 +++ .../Net.Project.B.PlayerAction.asmdef.meta | 7 + Src/PlayerAction/PlayerActionService.cs | 79 +++++++++++ Src/PlayerAction/PlayerActionService.cs.meta | 11 ++ Src/UX/UXDefine.cs | 1 + Src/WorldNode/Net.Project.B.WorldNode.asmdef | 3 +- Src/WorldNode/UnityContainerNode.cs | 10 +- Src/WorldNode/UnityEnvironmentController.cs | 4 + Src/WorldNode/UnityLootContainerVisualNode.cs | 18 +++ .../UnityLootContainerVisualNode.cs.meta | 11 ++ Src/WorldNode/UnityLootNode.cs | 129 +++++++++++++++++- Src/WorldNode/UnityVehicleNode.cs | 4 +- 15 files changed, 318 insertions(+), 17 deletions(-) create mode 100644 Src/PlayerAction.meta create mode 100644 Src/PlayerAction/Net.Project.B.PlayerAction.asmdef create mode 100644 Src/PlayerAction/Net.Project.B.PlayerAction.asmdef.meta create mode 100644 Src/PlayerAction/PlayerActionService.cs create mode 100644 Src/PlayerAction/PlayerActionService.cs.meta create mode 100644 Src/WorldNode/UnityLootContainerVisualNode.cs create mode 100644 Src/WorldNode/UnityLootContainerVisualNode.cs.meta diff --git a/Src/Health/HealthService.cs b/Src/Health/HealthService.cs index 394b84c..9e4c95b 100644 --- a/Src/Health/HealthService.cs +++ b/Src/Health/HealthService.cs @@ -6,6 +6,7 @@ using BITKit.Entities; using BITKit.WorldNode; using Cysharp.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; namespace Net.Project.B.Health @@ -73,10 +74,13 @@ namespace Net.Project.B.Health private readonly IEntitiesService _entitiesService; private static readonly ConcurrentDictionary HealthComponents = new(); - - public HealthService(IEntitiesService entitiesService) + + private readonly ILogger _logger; + + public HealthService(IEntitiesService entitiesService, ILogger logger) { _entitiesService = entitiesService; + _logger = logger; _singleton = this; _entitiesService.OnAdd += OnAdd; @@ -128,7 +132,17 @@ namespace Net.Project.B.Health } var newHp = Math.Clamp(current + value, -1, HealthComponents[id].MaxHealthPoint); Healths.Set(id,HealthComponents[id].HealthPoint = newHp); - OnHealthChanged?.Invoke(id,current,newHp,arg); + + try + { + OnHealthChanged?.Invoke(id, current, newHp, arg); + } + catch (Exception e) + { + _logger.LogCritical(e, e.Message); + } + + return UniTask.FromResult(newHp); } diff --git a/Src/Health/KnockedService.cs b/Src/Health/KnockedService.cs index 7fd333c..99af573 100644 --- a/Src/Health/KnockedService.cs +++ b/Src/Health/KnockedService.cs @@ -83,8 +83,16 @@ namespace Net.Project.B.Health } _knockedHealth.TryAdd(id, 100); _knocked.Add(id); - _onKnocked?.Invoke(id, true); - // _logger.LogInformation($"Entity {id} 被击倒了"); + try + { + _onKnocked?.Invoke(id, true); + } + catch (Exception e) + { + _logger.LogCritical(e, e.Message); + } + + // _logger.LogInformation($"Entity {id} 被击倒了"); //return 0; return -Math.Abs(oldHp-1); } diff --git a/Src/PlayerAction.meta b/Src/PlayerAction.meta new file mode 100644 index 0000000..3dd0fd9 --- /dev/null +++ b/Src/PlayerAction.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b134b5b4630796a48afc0bfc8353c787 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Src/PlayerAction/Net.Project.B.PlayerAction.asmdef b/Src/PlayerAction/Net.Project.B.PlayerAction.asmdef new file mode 100644 index 0000000..eac394e --- /dev/null +++ b/Src/PlayerAction/Net.Project.B.PlayerAction.asmdef @@ -0,0 +1,18 @@ +{ + "name": "Net.Project.B.PlayerAction", + "rootNamespace": "", + "references": [ + "GUID:14fe60d984bf9f84eac55c6ea033a8f4", + "GUID:f51ebe6a0ceec4240a699833d6309b23", + "GUID:d8b63aba1907145bea998dd612889d6b" + ], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": true +} \ No newline at end of file diff --git a/Src/PlayerAction/Net.Project.B.PlayerAction.asmdef.meta b/Src/PlayerAction/Net.Project.B.PlayerAction.asmdef.meta new file mode 100644 index 0000000..bad5024 --- /dev/null +++ b/Src/PlayerAction/Net.Project.B.PlayerAction.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 91a84969978233c4480e0c9f2fed1153 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Src/PlayerAction/PlayerActionService.cs b/Src/PlayerAction/PlayerActionService.cs new file mode 100644 index 0000000..3b57788 --- /dev/null +++ b/Src/PlayerAction/PlayerActionService.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Threading; +using BITKit; +using BITKit.Tween; +using Cysharp.Threading.Tasks; +using Unity.Mathematics; + +namespace Net.Project.B.PlayerAction +{ + public interface IPlayerAction + { + string Name { get; } + float Progress { get; } + float Duration { get;} + bool IsCancelable { get; } + UniTaskCompletionSource CompletionSource { get; } + public event Action OnProgress; + UniTask StartAsync(); + } + + public class PlayerAction:IPlayerAction,IDisposable + { + public PlayerAction() + { + OnProgress += SetProgress; + } + + private void SetProgress(float obj) + { + Progress = obj; + } + + public string Name { get; set; } = "Busy"; + public float Duration { get; set; } = 1; + public float Progress { get;private set; } + public bool IsCancelable { get; set; } + public UniTaskCompletionSource CompletionSource { get; } = new(); + public event Action OnProgress; + public async UniTask StartAsync() + { + try + { + await BITween.Lerp(OnProgress, 0f, 1f, Duration, math.lerp); + + CompletionSource.TrySetResult(); + } + catch (Exception e) + { + BIT4Log.LogException(e); + } + } + + public void Dispose() + { + CompletionSource.TrySetCanceled(); + } + } + + public interface IPlayerActionComponent + { + public event Action OnPlayerActionStarted; + UniTask StartAction(IPlayerAction action); + } + + public class PlayerActionComponent : IPlayerActionComponent + { + public event Action OnPlayerActionStarted; + + public async UniTask StartAction(IPlayerAction action) + { + OnPlayerActionStarted?.Invoke(action); + await action.StartAsync(); + } + } + +} + diff --git a/Src/PlayerAction/PlayerActionService.cs.meta b/Src/PlayerAction/PlayerActionService.cs.meta new file mode 100644 index 0000000..9a8e8a3 --- /dev/null +++ b/Src/PlayerAction/PlayerActionService.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2d05900e4cb7b0e4884283b4e93af142 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Src/UX/UXDefine.cs b/Src/UX/UXDefine.cs index 5a80cdb..ad97c23 100644 --- a/Src/UX/UXDefine.cs +++ b/Src/UX/UXDefine.cs @@ -13,6 +13,7 @@ namespace Net.Project.B.UX { public ValidHandle InCinematicMode { get; } } + public interface IUXAction: IUXPanel{} public interface IUXInitialize:IUXPanel,ILogger {} public interface IUXBuyStation:IUXPanel{} public interface IUXControlMode:IUXPanel{} diff --git a/Src/WorldNode/Net.Project.B.WorldNode.asmdef b/Src/WorldNode/Net.Project.B.WorldNode.asmdef index abefec4..fa054e0 100644 --- a/Src/WorldNode/Net.Project.B.WorldNode.asmdef +++ b/Src/WorldNode/Net.Project.B.WorldNode.asmdef @@ -9,7 +9,8 @@ "GUID:e527b3ce3106f974585be5134b6200e9", "GUID:e18d548755c9bc8458ca189e16813742", "GUID:d8b63aba1907145bea998dd612889d6b", - "GUID:1193c2664d97cc049a6e4c486c6bce71" + "GUID:1193c2664d97cc049a6e4c486c6bce71", + "GUID:677cd05ca06c46b4395470200b1acdad" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/Src/WorldNode/UnityContainerNode.cs b/Src/WorldNode/UnityContainerNode.cs index 708441c..adb0cdf 100644 --- a/Src/WorldNode/UnityContainerNode.cs +++ b/Src/WorldNode/UnityContainerNode.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using BITKit; using BITKit.WorldNode; #if UNITY_5_3_OR_NEWER using UnityEngine; @@ -9,15 +10,18 @@ using UnityEngine; namespace Net.Project.B.WorldNode { [Serializable] - public struct UnityContainerNode :IWorldNode + public class UnityContainerNode :RuntimeItemContainer,IWorldNode,IRuntimeItemContainer { + public bool allowAdd; + public bool addRemove=true; /// /// 添加物品 /// - public bool AllowAdd { get; set; } + public bool AllowAdd => allowAdd; + /// /// 移除物品 /// - public bool AllowRemove { get; set; } + public bool AllowRemove => addRemove; } } diff --git a/Src/WorldNode/UnityEnvironmentController.cs b/Src/WorldNode/UnityEnvironmentController.cs index 78df9a1..56231aa 100644 --- a/Src/WorldNode/UnityEnvironmentController.cs +++ b/Src/WorldNode/UnityEnvironmentController.cs @@ -38,6 +38,10 @@ namespace Net.Project.B.WorldNode { staticGameObjects = GetComponentsInChildren().Where(x=>x.gameObject.isStatic).Select(x=>x.gameObject).ToArray(); } + + #if UNITY_EDITOR + UnityEditor.EditorUtility.SetDirty(this); + #endif Debug.Log($"已获取到{staticGameObjects.Length}个物体"); } diff --git a/Src/WorldNode/UnityLootContainerVisualNode.cs b/Src/WorldNode/UnityLootContainerVisualNode.cs new file mode 100644 index 0000000..3ab6291 --- /dev/null +++ b/Src/WorldNode/UnityLootContainerVisualNode.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using BITKit.WorldNode; +using UnityEngine; + +namespace Net.Project.B.WorldNode +{ + [Serializable] + public class LootContainerVisualNode:IWorldNode + + { + public Transform visualJoint; + public Vector3 emptyJointPosition; + public Vector3 emptyJointEuler; + public Transform visualModel; + } +} \ No newline at end of file diff --git a/Src/WorldNode/UnityLootContainerVisualNode.cs.meta b/Src/WorldNode/UnityLootContainerVisualNode.cs.meta new file mode 100644 index 0000000..e3e3e0b --- /dev/null +++ b/Src/WorldNode/UnityLootContainerVisualNode.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b4272bb2066222d4f80e8809411f3886 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Src/WorldNode/UnityLootNode.cs b/Src/WorldNode/UnityLootNode.cs index f290818..e047147 100644 --- a/Src/WorldNode/UnityLootNode.cs +++ b/Src/WorldNode/UnityLootNode.cs @@ -7,15 +7,132 @@ using BITKit.WorldNode; using UnityEngine; #endif -namespace Net.Project.B.WorldNode +namespace Net.Project.B.WorldNode.Loot { + [Serializable] + public struct CommonLootNode : IReference + { + public string Get() => "loot_common"; + } + + [Serializable] + public struct MedicalLootNode : IReference + { + public string Get() => "loot_medical"; + } + + [Serializable] + public struct MilitaryLootNode : IReference + { + public string Get() => "loot_military"; + } + + [Serializable] + public struct FoodLootNode : IReference + { + public string Get() => "loot_food"; + } + + [Serializable] + public struct BeverageLootNode : IReference + { + public string Get() => "loot_beverage"; + } + + [Serializable] + public struct HouseholdToolsLootNode : IReference + { + public string Get() => "loot_household_tools"; + } + + [Serializable] + public struct HardwareToolsLootNode : IReference + { + public string Get() => "loot_hardware_tools"; + } + + [Serializable] + public struct SurvivalGearLootNode : IReference + { + public string Get() => "loot_survival_gear"; + } + + [Serializable] + public struct ConstructionLootNode : IReference + { + public string Get() => "loot_construction"; + } + + [Serializable] + public struct ClothingLootNode : IReference + { + public string Get() => "loot_clothing"; + } + + [Serializable] + public struct ElectronicsLootNode : IReference + { + public string Get() => "loot_electronics"; + } + + [Serializable] + public struct FuelLootNode : IReference + { + public string Get() => "loot_fuel"; + } + + [Serializable] + public struct MeleeWeaponLootNode : IReference + { + public string Get() => "loot_melee_weapon"; + } + + [Serializable] + public struct RangedWeaponLootNode : IReference + { + public string Get() => "loot_ranged_weapon"; + } + + [Serializable] + public struct ThrowableLootNode : IReference + { + public string Get() => "loot_throwable"; + } + + [Serializable] + public struct TrapLootNode : IReference + { + public string Get() => "loot_trap"; + } + + [Serializable] + public struct QuestItemLootNode : IReference + { + public string Get() => "loot_quest_item"; + } + + [Serializable] + public struct TradeGoodsLootNode : IReference + { + public string Get() => "loot_trade_goods"; + } + + [Serializable] + public struct AnimalProductLootNode : IReference + { + public string Get() => "loot_animal_product"; + } +} + +namespace Net.Project.B.WorldNode + { [Serializable] public class UnityLootNode : IWorldNode { - #if UNITY_5_3_OR_NEWER - [SerializeReference, SubclassSelector] private IReference lootName; - - public string LootName=> lootName?.Value; - #endif +#if UNITY_5_3_OR_NEWER + [SerializeReference, SubclassSelector] public IReference lootName; + + public string LootName => lootName?.Value; +#endif } } diff --git a/Src/WorldNode/UnityVehicleNode.cs b/Src/WorldNode/UnityVehicleNode.cs index b1fae14..fbdee26 100644 --- a/Src/WorldNode/UnityVehicleNode.cs +++ b/Src/WorldNode/UnityVehicleNode.cs @@ -27,13 +27,13 @@ namespace Net.Project.B.WorldNode public bool allowAckermannSteering; - public float steeringWheelAngle=180; + public float steeringWheelAngle { get; set; } = 45; public float maxForwardSpeed = 100f; // 100f default public float maxReverseSpeed = 30f; // 30f default public float horsePower = 1000f; // 100f0 default public float brakePower = 2000f; // 2000f default - public float handbrakeForce = 3000f; // 3000f default + public float handbrakeForce = 1000f; // 3000f default public float maxSteerAngle = 30f; // 30f default public float steeringSpeed = 5f; // 0.5f default public float stopThreshold = 1f; // 1f default. At what speed car will make a full stop