using System.Collections.Generic; using System.IO; using AOT; using CoreGame; using CoreGame.Render; using Entitas; using UnityEngine.Animations; namespace CoreGame.Render { public class DetachAssetSystem : ReactiveSystem { public DetachAssetSystem(Contexts contexts) : base(contexts.combat) { } protected override ICollector GetTrigger(IContext context) { return context.CreateCollector(CombatMatcher.DetachAsset); } protected override bool Filter(CombatEntity entity) { return entity.hasAsset; } private void DetachHand(BindPointProxy parentBp, int b1) { if (parentBp.GetBindPointMap().TryGetValue(b1, out var bp2)) { if (bp2.gameObject.TryGetComponent(out var positionConstraint)) { positionConstraint.constraintActive = false; } } } protected override void Execute(List entities) { for (var index = 0; index < entities.Count; index++) { var e = entities[index]; var detachAssetComponent = e.detachAsset; e.RemoveDetachAsset(); var reuseGoData = e.asset.mainAssetParam.reuseGoData; if (reuseGoData.go) { reuseGoData.go.UnLink(); } var parentParentEntity = e.parentRecorder.ParentEntity; var assetComponent = parentParentEntity.asset; if (assetComponent != null) { assetComponent.UnRecordLinkEnt(e.creationIndex); } parentParentEntity.bindPointProxy.DetachFallbackBindPoint(e.bindPointProxy.GetBindPointMap()); DetachHand(parentParentEntity.bindPointProxy, (int)BindPointType.LHand); DetachHand(parentParentEntity.bindPointProxy, (int)BindPointType.RHand); GunSrv.DestoryCircleVfx(parentParentEntity, e); // 如果有动画,也要挂载进去 var parentEntityAnimationProxy = parentParentEntity.animationProxy; if (parentEntityAnimationProxy != null && assetComponent != null) { var subAssetData = SptPool.Malloc(); subAssetData.reuseGoData = reuseGoData; var path = assetComponent.mainAssetParam.path; var fileName = Path.GetFileName(path); if (path != null) { var skinParam = new SkinParam { bpType = detachAssetComponent.bindPointType, path = UnrealNames.GetFName(path.Substring(0, path.Length - fileName.Length - 1)), animPrefix = UnrealNames.GetFName(fileName.Substring(0, fileName.LastIndexOf('.'))) }; parentEntityAnimationProxy.PopPartAnimancer(subAssetData, skinParam); } subAssetData.reuseGoData = null; SptPool.Free(ref subAssetData); } } } } }