Files
Net.Like.Xue.Tokyo/Packages-Local/Com.Project.B.Unity/AI/AIOpenDoorService.cs

64 lines
2.1 KiB
C#
Raw Normal View History

2025-06-24 23:49:13 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
using BITKit;
using BITKit.Entities;
using Net.BITKit.Quadtree;
using Net.Project.B.Health;
using Net.Project.B.Interaction;
using Net.Project.B.WorldNode;
using Project.B.CharacterController;
using Unity.Mathematics;
using UnityEngine;
namespace Net.Project.B.AI
{
public class AIOpenDoorService:IDisposable
{
private readonly IWorldInteractionService _interactionService;
private readonly QuadTreeService<UnityDoorNode> _quadTreeService;
private readonly IEntitiesService _entitiesService;
private readonly ITicker _ticker;
public AIOpenDoorService(QuadTreeService<UnityDoorNode> quadTreeService, IEntitiesService entitiesService, ITicker ticker, IWorldInteractionService interactionService)
{
_quadTreeService = quadTreeService;
_entitiesService = entitiesService;
_ticker = ticker;
_interactionService = interactionService;
_ticker.Add(OnTick);
}
private void OnTick(float obj)
{
foreach (var (entity,healthComponent,aiBlackBoard,characterController) in _entitiesService.QueryComponents<IEntity,IHealthComponent,AIBlackBoard,ICharacterController>())
{
if(healthComponent.HealthPoint<0)continue;
foreach (var id in _quadTreeService.Quadtree.Query(characterController.ViewPosition.xz,1))
{
if (_entitiesService.Entities[id].ServiceProvider.QueryComponents(out UnityDoorNode doorNode,
out IWorldInteractable interactable))
{
;
if(doorNode.InteractionType is not WorldInteractionProcess.None)continue;
if(doorNode.State is UnityDoorState.Opened)continue;
_interactionService.Interaction(entity, interactable);
}
break;
}
}
}
public void Dispose()
{
_ticker.Remove(OnTick);
}
}
}