This commit is contained in:
CortexCore 2025-06-26 23:34:50 +08:00
parent a772331918
commit 1e4643f20f
15 changed files with 318 additions and 17 deletions

View File

@ -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<int, IHealthComponent> HealthComponents = new();
public HealthService(IEntitiesService entitiesService)
private readonly ILogger<HealthService> _logger;
public HealthService(IEntitiesService entitiesService, ILogger<HealthService> 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);
}

View File

@ -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);
}

8
Src/PlayerAction.meta Normal file
View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b134b5b4630796a48afc0bfc8353c787
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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
}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 91a84969978233c4480e0c9f2fed1153
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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<float> 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<float> 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<IPlayerAction> OnPlayerActionStarted;
UniTask StartAction(IPlayerAction action);
}
public class PlayerActionComponent : IPlayerActionComponent
{
public event Action<IPlayerAction> OnPlayerActionStarted;
public async UniTask StartAction(IPlayerAction action)
{
OnPlayerActionStarted?.Invoke(action);
await action.StartAsync();
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2d05900e4cb7b0e4884283b4e93af142
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -13,6 +13,7 @@ namespace Net.Project.B.UX
{
public ValidHandle InCinematicMode { get; }
}
public interface IUXAction: IUXPanel{}
public interface IUXInitialize:IUXPanel,ILogger<IUXInitialize> {}
public interface IUXBuyStation:IUXPanel{}
public interface IUXControlMode:IUXPanel{}

View File

@ -9,7 +9,8 @@
"GUID:e527b3ce3106f974585be5134b6200e9",
"GUID:e18d548755c9bc8458ca189e16813742",
"GUID:d8b63aba1907145bea998dd612889d6b",
"GUID:1193c2664d97cc049a6e4c486c6bce71"
"GUID:1193c2664d97cc049a6e4c486c6bce71",
"GUID:677cd05ca06c46b4395470200b1acdad"
],
"includePlatforms": [],
"excludePlatforms": [],

View File

@ -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;
/// <summary>
/// 添加物品
/// </summary>
public bool AllowAdd { get; set; }
public bool AllowAdd => allowAdd;
/// <summary>
/// 移除物品
/// </summary>
public bool AllowRemove { get; set; }
public bool AllowRemove => addRemove;
}
}

View File

@ -38,6 +38,10 @@ namespace Net.Project.B.WorldNode
{
staticGameObjects = GetComponentsInChildren<Transform>().Where(x=>x.gameObject.isStatic).Select(x=>x.gameObject).ToArray();
}
#if UNITY_EDITOR
UnityEditor.EditorUtility.SetDirty(this);
#endif
Debug.Log($"已获取到{staticGameObjects.Length}个物体");
}

View File

@ -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;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b4272bb2066222d4f80e8809411f3886
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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
}
}

View File

@ -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