using System.Collections; using System.Collections.Generic; using BITKit; using BITKit.Entities; using UnityEngine; namespace BITFALL.Entities { public class EntityReplacePool : EntityBehavior { [Inject] private IPoolObject _poolObject; [SerializeField] private EntityReplaceComponent source; [SerializeField] private EntityReplaceComponent target; public override void OnAwake() { _poolObject.EnabledHandle.AddListener(OnPool); } private void OnPool(bool obj) { if(obj)return; var ragdoll = PoolService.Get(target.transform); ragdoll.SetPositionAndRotation(source.transform.position, source.transform.rotation); var targetComponent = ragdoll.GetComponent(); foreach (var (key, value) in source.Dictionary) { if (!targetComponent.Dictionary.TryGetValue(key,out var next)) continue; next.TryGetComponent(out Rigidbody _rigidbody); next.localPosition = value.localPosition; next.localRotation = value.localRotation; if (_rigidbody) { _rigidbody.WakeUp(); _rigidbody.velocity = Vector3.down; } if (Vector3.Distance(next.position, value.position) > 0.1f) { BIT4Log.Warning($"Position is not equal {next.position} {value.position}"); } } //Physics.SyncTransforms(); } } }