1
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using BITKit.Entities;
|
||||
using Cinemachine;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITKit.Scene
|
||||
{
|
||||
public class CinemachineEntitiesGroup : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private IEntitiesService _entitiesService;
|
||||
[SerializeField] private CinemachineTargetGroup targetGroup;
|
||||
[SerializeField] private Optional<Entity[]> initialEntities;
|
||||
private void Update()
|
||||
{
|
||||
// foreach (var x in initialEntities.IfNotAllow(()=>_entitiesService.Query<IHealth>().Cast<Entity>().ToArray()))
|
||||
// {
|
||||
//
|
||||
// }
|
||||
targetGroup.m_Targets =
|
||||
initialEntities.IfNotAllow(() => _entitiesService.Query<IHealth>().Cast<Entity>().ToArray())
|
||||
.Select(x => new CinemachineTargetGroup.Target()
|
||||
{
|
||||
target = x.transform,
|
||||
radius = 1,
|
||||
weight = x.TryGetComponent<IHealth>(out var heal) ? heal.IsAlive ? 1 : 0 : 0
|
||||
})
|
||||
.ToArray();
|
||||
if (targetGroup.m_Targets.Length is 0)
|
||||
{
|
||||
targetGroup.m_Targets = initialEntities.IfNotAllow(() => _entitiesService.Query<IHealth>().Cast<Entity>().ToArray()).Select(
|
||||
x=>
|
||||
new CinemachineTargetGroup.Target()
|
||||
{
|
||||
target = x.transform,
|
||||
radius = 1,
|
||||
weight = 1
|
||||
}
|
||||
).ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user